<commit_before>package marubinotto.piggydb.ui.page.partial;

import marubinotto.piggydb.model.Fragment;
import marubinotto.piggydb.ui.page.control.form.FragmentFormUtils;

public abstract class AbstractFragmentForm extends AbstractSingleFragment {

	public int titleMaxLength = Fragment.TITLE_MAX_LENGTH;
	public String tags;
	
	@Override 
	protected void setModels() throws Exception {
		super.setModels();
		
		if (this.fragment == null) {
			this.fragment = getDomain().getFragmentRepository().newInstance(getUser());
		}
		
		this.tags = FragmentFormUtils.toTagsString(this.fragment.getClassification());
		
		addModel("isMinorEditAvailable", isMinorEditAvailable());
	}
}<commit_msg>#child_form: added a param 'parentId' to marubinotto.piggydb.ui.page.partial.AbstractFragmentForm<commit_after>package marubinotto.piggydb.ui.page.partial;

import org.apache.commons.lang.UnhandledException;

import marubinotto.piggydb.model.Fragment;
import marubinotto.piggydb.model.Tag;
import marubinotto.piggydb.model.exception.AuthorizationException;
import marubinotto.piggydb.model.exception.InvalidTaggingException;
import marubinotto.piggydb.ui.page.control.form.FragmentFormUtils;

public abstract class AbstractFragmentForm extends AbstractSingleFragment {
	
	public Long parentId;
	protected Fragment parent;

	public int titleMaxLength = Fragment.TITLE_MAX_LENGTH;
	public String tags;
	
	@Override 
	protected void setModels() throws Exception {
		super.setModels();
		
		if (this.fragment == null) {
			this.fragment = getDomain().getFragmentRepository().newInstance(getUser());
		}
		
		if (this.parentId != null) {
			this.parent = getDomain().getFragmentRepository().get(this.parentId, false);
			inheritTagsFromParent();
		}
		
		this.tags = FragmentFormUtils.toTagsString(this.fragment.getClassification());
		
		addModel("isMinorEditAvailable", isMinorEditAvailable());
	}
	
	private void inheritTagsFromParent() {
		if (this.parent == null) return;
		
		for (Tag tag : this.parent.getClassification()) {
			if (isInheritedFromParent(tag)) {
				try {
					this.fragment.addTagByUser(tag, getUser());
				}
				catch (InvalidTaggingException e) {
					throw new UnhandledException(e);
				}
				catch (AuthorizationException e) {
					continue;		// don't include not-permitted tags
				}
			}
		}
	}
	
	private static boolean isInheritedFromParent(Tag tag) {
		return !tag.getName().startsWith("#");
	}
}
{'fraction_non_alphanumeric': 0.10894780447390223, 'fraction_numerical': 0.0, 'mean_word_length': 4.977722772277228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5713563', 'n_tokens_mistral': 829, 'n_tokens_neox': 719, 'n_words': 134}