<commit_before>package infodoc.core.ui.cases;

import infodoc.core.InfodocConstants;
import infodoc.core.container.InfodocContainerFactory;
import infodoc.core.dto.Property;
import infodoc.core.dto.ClassificationValue;
import infodoc.core.dto.PropertyValue;
import infodoc.core.dto.Case;
import infodoc.core.dto.Form;
import infodoc.core.dto.Activity;
import infodoc.core.dto.User;
import infodoc.core.dto.Validation;
import infodoc.core.field.FieldFactory;
import infodoc.core.field.FieldType;
import infodoc.core.ui.common.InfodocTheme;
import infodoc.core.ui.validator.ValidatorFactory;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

public class CaseForm extends com.vaadin.ui.Form {

	private static final long serialVersionUID = 1L;
	
	protected Case instance;
	protected Activity activity;
	protected User user;
	protected List<Property> properties;
	protected boolean focus;
	protected boolean showAllProperties;
	protected boolean showShearchProperties;
	protected TextField commentsTextField;
	
	public CaseForm(Case instance, Activity activity, User user) {
		this(instance, activity, user, false);
	}
	
	public CaseForm(Case instance, Activity activity, User user, boolean focus) {
		this(instance, activity, user, focus, false, false);
	}
	
	public CaseForm(Case instance, Activity activity, User user, boolean focus, boolean showAllProperties, boolean showShearchProperties) {
		this.instance = instance;
		this.activity = activity;
		this.user = user;
		this.focus = focus;
		this.showAllProperties = showAllProperties;
		this.showShearchProperties = showShearchProperties;
	}
	
	@Override
	public void attach() {
		createProperties();
	}
	
	@Override
	public void focus() {
		if(properties != null && !properties.isEmpty()) {
			super.focus();
		}
	}
	
	public void createProperties() {
		if(showAllProperties) {
			properties = InfodocContainerFactory.getPropertyContainer().findByFormId(instance.getForm().getId());
		} else {
			properties = InfodocContainerFactory.getPropertyContainer().findByUserIdAndFormIdAndActivityId(user.getId(), instance.getForm().getId(), activity.getId());
		}
		
		try {
			for(Property property : properties) {
				FieldFactory fieldWrapper = (FieldFactory) Class.forName(property.getJavaClass()).newInstance();
				Field field;
				
				if(showShearchProperties) {
					field = fieldWrapper.getSearchField(property, this, activity, instance.getForm(), getApplication());
				} else {
					field = fieldWrapper.getField(property, this, activity, instance.getForm(), getApplication());
				}
				
				if(property.getIcon() != null && !property.getIcon().isEmpty()) {
					field.setIcon(new ThemeResource(property.getIcon()));
				}
				
				if(property.getColor() != null && !property.getColor().isEmpty()) {
					field.addStyleName(property.getColor());
				}
				
				if(property.getBold()) {
					field.addStyleName(InfodocTheme.CLASS_BOLD);
				}
				
				if(property.getItalic()) {
					field.addStyleName(InfodocTheme.CLASS_ITALIC);
				}
				
				field.setWidth("100%");
				field.setCaption(property.getName());
				field.setRequired(property.getRequired() && !showShearchProperties);
				
				Object value = InfodocContainerFactory.getCaseContainer().getValue(instance, property);
				
				if(value != null) {
					field.setValue(value);
				}
				
				if(property.getValidations() != null && !property.getValidations().isEmpty()) {
					addValidations(property, field);
				}
				
				addField(property.getName(), field);
			}
			
			if(activity != null && activity.getAllowComments()) {
				commentsTextField = new TextField(InfodocConstants.uiObservations);
				commentsTextField.setWidth("100%");
				commentsTextField.setIcon(new ThemeResource(InfodocTheme.iconComments));
				addField("_infodoc.observaciones_", commentsTextField);
			}
			
			fireValueChange(false);
			
		} catch (InstantiationException e) {<commit_msg>Fix in cases search.<commit_after>package infodoc.core.ui.cases;

import infodoc.core.InfodocConstants;
import infodoc.core.container.InfodocContainerFactory;
import infodoc.core.dto.Property;
import infodoc.core.dto.ClassificationValue;
import infodoc.core.dto.PropertyValue;
import infodoc.core.dto.Case;
import infodoc.core.dto.Form;
import infodoc.core.dto.Activity;
import infodoc.core.dto.User;
import infodoc.core.dto.Validation;
import infodoc.core.field.FieldFactory;
import infodoc.core.field.FieldType;
import infodoc.core.ui.common.InfodocTheme;
import infodoc.core.ui.validator.ValidatorFactory;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

public class CaseForm extends com.vaadin.ui.Form {

	private static final long serialVersionUID = 1L;
	
	protected Case instance;
	protected Activity activity;
	protected User user;
	protected List<Property> properties;
	protected boolean focus;
	protected boolean showAllProperties;
	protected boolean showShearchProperties;
	protected TextField commentsTextField;
	
	public CaseForm(Case instance, Activity activity, User user) {
		this(instance, activity, user, false);
	}
	
	public CaseForm(Case instance, Activity activity, User user, boolean focus) {
		this(instance, activity, user, focus, false, false);
	}
	
	public CaseForm(Case instance, Activity activity, User user, boolean focus, boolean showAllProperties, boolean showShearchProperties) {
		this.instance = instance;
		this.activity = activity;
		this.user = user;
		this.focus = focus;
		this.showAllProperties = showAllProperties;
		this.showShearchProperties = showShearchProperties;
	}
	
	@Override
	public void attach() {
		createProperties();
	}
	
	@Override
	public void focus() {
		if(properties != null && !properties.isEmpty()) {
			super.focus();
		}
	}
	
	public void createProperties() {
		if(showAllProperties) {
			properties = InfodocContainerFactory.getPropertyContainer().findByFormId(instance.getForm().getId());
		} else {
			properties = InfodocContainerFactory.getPropertyContainer().findByUserIdAndFormIdAndActivityId(user.getId(), instance.getForm().getId(), activity.getId());
		}
		
		try {
			for(Property property : properties) {
				FieldFactory fieldWrapper = (FieldFactory) Class.forName(property.getJavaClass()).newInstance();
				Field field;
				
				if(showShearchProperties) {
					field = fieldWrapper.getSearchField(property, this, activity, instance.getForm(), getApplication());
				} else {
					field = fieldWrapper.getField(property, this, activity, instance.getForm(), getApplication());
				}
				
				if(field != null) {
					if(property.getIcon() != null && !property.getIcon().isEmpty()) {
						field.setIcon(new ThemeResource(property.getIcon()));
					}
					
					if(property.getColor() != null && !property.getColor().isEmpty()) {
						field.addStyleName(property.getColor());
					}
					
					if(property.getBold()) {
						field.addStyleName(InfodocTheme.CLASS_BOLD);
					}
					
					if(property.getItalic()) {
						field.addStyleName(InfodocTheme.CLASS_ITALIC);
					}
					
					field.setWidth("100%");
					field.setCaption(property.getName());
					field.setRequired(property.getRequired() && !showShearchProperties);
					
					Object value = InfodocContainerFactory.getCaseContainer().getValue(instance, property);
					
					if(value != null) {
						field.setValue(value);
					}
					
					if(property.getValidations() != null && !property.getValidations().isEmpty()) {
						addValidations(property, field);
					}
					
					addField(property.getName(), field);
				}
				
			}
			
			if(activity != null && activity.getAllowComments()) {
				commentsTextField = new TextField(InfodocConstants.uiObservations);
				commentsTextField.setWidth("100%");
				commentsTextField.setIcon(new ThemeResource(InfodocTheme.iconComments));
				addField("_infodoc.observaciones_", commentsTextField);
			}
			
			fireValueChange(false);
			
		} catch (InstantiationException e) {
{'fraction_non_alphanumeric': 0.11775384243011013, 'fraction_numerical': 0.0016942998910807214, 'mean_word_length': 4.472847682119205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5381895', 'n_tokens_mistral': 2884, 'n_tokens_neox': 2414, 'n_words': 457}