<commit_before>package gov.nih.nci.cananolab.dto.particle.characterization;

import gov.nih.nci.cananolab.domain.characterization.OtherCharacterization;
import gov.nih.nci.cananolab.domain.characterization.invitro.Cytotoxicity;
import gov.nih.nci.cananolab.domain.characterization.invitro.EnzymeInduction;
import gov.nih.nci.cananolab.domain.characterization.invitro.Transfection;
import gov.nih.nci.cananolab.domain.characterization.physical.PhysicalState;
import gov.nih.nci.cananolab.domain.characterization.physical.Shape;
import gov.nih.nci.cananolab.domain.characterization.physical.Solubility;
import gov.nih.nci.cananolab.domain.characterization.physical.Surface;
import gov.nih.nci.cananolab.domain.common.Datum;
import gov.nih.nci.cananolab.domain.common.ExperimentConfig;
import gov.nih.nci.cananolab.domain.common.File;
import gov.nih.nci.cananolab.domain.common.Finding;
import gov.nih.nci.cananolab.domain.common.Instrument;
import gov.nih.nci.cananolab.domain.common.PointOfContact;
import gov.nih.nci.cananolab.domain.particle.Characterization;
import gov.nih.nci.cananolab.dto.common.ExperimentConfigBean;
import gov.nih.nci.cananolab.dto.common.FindingBean;
import gov.nih.nci.cananolab.dto.common.PointOfContactBean;
import gov.nih.nci.cananolab.dto.common.ProtocolBean;
import gov.nih.nci.cananolab.util.ClassUtils;
import gov.nih.nci.cananolab.util.Comparators;
import gov.nih.nci.cananolab.util.Constants;
import gov.nih.nci.cananolab.util.DateUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * This class represents shared characterization properties to be shown in
 * characterization view pages.
 * 
 * @author pansu
 * 
 */
public class CharacterizationBean {
	private PointOfContactBean pocBean = new PointOfContactBean();

	private String conclusion;

	private String description;

	private String assayType;

	private ExperimentConfigBean theExperimentConfig = new ExperimentConfigBean();

	private FindingBean theFinding = new FindingBean();

	private Instrument theInstrument = new Instrument();

	private List<ExperimentConfigBean> experimentConfigs = new ArrayList<ExperimentConfigBean>();

	private List<FindingBean> findings = new ArrayList<FindingBean>();

	private ProtocolBean protocolBean = new ProtocolBean();

	private Characterization domainChar;

	private String className;

	private String dateString;

	private String characterizationType;

	private String characterizationName;

	private Cytotoxicity cytotoxicity = new Cytotoxicity();

	private PhysicalState physicalState = new PhysicalState();

	private Shape shape = new Shape();

	private Solubility solubility = new Solubility();

	private Surface surface = new Surface();

	private EnzymeInduction enzymeInduction = new EnzymeInduction();

	private boolean withProperties = false;

	private Transfection transfection = new Transfection();

	private String isSoluble; // Data holder for Boolean field in Solubility.
	
	public CharacterizationBean() {
		// initialize finding matrix
//		theFinding.setNumberOfColumns(1);
//		theFinding.setNumberOfRows(1);
//		theFinding.updateMatrix(theFinding.getNumberOfColumns(), theFinding
//				.getNumberOfRows());
	}

	public CharacterizationBean(Characterization chara) {
		domainChar = chara;
		className = ClassUtils.getShortClassName(chara.getClass().getName());
		this.description = chara.getDesignMethodsDescription();
		this.assayType = chara.getAssayType();
		this.conclusion = chara.getAnalysisConclusion();
		if (chara != null) {
			PointOfContact poc = chara.getPointOfContact();
			if (poc != null)
				pocBean = new PointOfContactBean(poc);
		}

		this.dateString = DateUtils.convertDateToString(chara.getDate(),
				Constants.DATE_FORMAT);

		if (chara.getFindingCollection() != null) {
			for (Finding finding : chara.getFindingCollection()) {
				findings.add(new FindingBean(finding));
			}
		}
		Collections.sort(findings, new Comparators.FindingBeanDateComparator());
		if (chara.getProtocol() != null) {
			protocolBean = new ProtocolBean(chara.getProtocol());
		}

		if (chara.getExperimentConfigCollection() != null) {
			for (ExperimentConfig config : chara
					.getExperimentConfigCollection()) {
				experimentConfigs.add(new ExperimentConfigBean(config));
			}
		}
		Collections.sort(experimentConfigs,
				new Comparators.ExperimentConfigBeanDateComparator());
		if (chara instanceof Shape) {
			shape = (Shape) chara;
			withProperties = true;
		} else if (chara instanceof PhysicalState) {
			physicalState = (PhysicalState) chara;
			withProperties = true;
		} else if (chara instanceof Solubility) {
			solubility = (Solubility) chara;
			withProperties = true;
		} else if (chara instanceof Surface) {
			surface = (Surface) chara;
			withProperties = true;
		} else if (chara instanceof Cytotoxicity) {
			cytotoxicity = (Cytotoxicity) chara;
			withProperties = true;
		} else if (chara instanceof EnzymeInduction) {
			enzymeInduction = (EnzymeInduction) chara;
			withProperties = true;
		} else if (chara instanceof Transfection) {
			transfection = (Transfection) chara;
			withProperties = true;
		} else {
			withProperties = false;
		}
		updateType();
		updateName();
	}

	public Characterization getDomainCopy(boolean copyData) {
		Characterization copy = (Characterization) ClassUtils
				.deepCopy(domainChar);
		// clear Ids, reset createdBy and createdDate, add prefix to
		copy.setId(null);
		copy.setCreatedBy(Constants.AUTO_COPY_ANNOTATION_PREFIX);
		copy.setCreatedDate(Calendar.getInstance().getTime());
		Collection<ExperimentConfig> oldConfigs = copy.getExperimentConfigCollection();
		if (oldConfigs == null || oldConfigs.isEmpty()) {
			copy.setExperimentConfigCollection(null);
		} else {
			/**
			 * Create new set for configs, otherwise will lost old configs in old bean.
			 */
			Set<ExperimentConfig> newConfigs = 
				new HashSet<ExperimentConfig>(oldConfigs);
			for (ExperimentConfig newConfig : newConfigs) {
				newConfig.setId(null);
				newConfig.setCreatedBy(Constants.AUTO_COPY_ANNOTATION_PREFIX);
				newConfig.setCreatedDate(Calendar.getInstance().getTime());
			}
			copy.setExperimentConfigCollection(newConfigs);
		}
		Collection<Finding> oldFindings = copy.getFindingCollection();
		if (oldFindings == null	|| oldFindings.isEmpty()) {
			copy.setFindingCollection(null);
		} else {
			/**
			 * Create new set for finding, otherwise will lost old finding in old bean.
			 */
			Set<Finding> newFindings = new HashSet<Finding>(oldFindings);
			for (Finding finding : newFindings) {
				finding.setId(null);
				if (copyData) {
					Collection<Datum> oldDatums = finding.getDatumCollection();
					if (oldDatums == null || oldDatums.isEmpty()) {
						finding.setDatumCollection(null);
					} else {
						Set<Datum> newDatums = new HashSet<Datum>(oldDatums);
						for (Datum datum : newDatums) {
							datum.setId(null);
							datum.setCreatedBy(Constants.AUTO_COPY_ANNOTATION_PREFIX);
							datum.setCreatedDate(Calendar.getInstance().getTime());
						}
						finding.setDatumCollection(newDatums);
					}
				}
				Collection<File> oldFiles = finding.getFileCollection();
				if (oldFiles == null || oldFiles.isEmpty()) {
					finding.setFileCollection(null);
				} else {<commit_msg>Updated for setting new FindingBean for copy.<commit_after>package gov.nih.nci.cananolab.dto.particle.characterization;

import gov.nih.nci.cananolab.domain.characterization.OtherCharacterization;
import gov.nih.nci.cananolab.domain.characterization.invitro.Cytotoxicity;
import gov.nih.nci.cananolab.domain.characterization.invitro.EnzymeInduction;
import gov.nih.nci.cananolab.domain.characterization.invitro.Transfection;
import gov.nih.nci.cananolab.domain.characterization.physical.PhysicalState;
import gov.nih.nci.cananolab.domain.characterization.physical.Shape;
import gov.nih.nci.cananolab.domain.characterization.physical.Solubility;
import gov.nih.nci.cananolab.domain.characterization.physical.Surface;
import gov.nih.nci.cananolab.domain.common.Datum;
import gov.nih.nci.cananolab.domain.common.ExperimentConfig;
import gov.nih.nci.cananolab.domain.common.File;
import gov.nih.nci.cananolab.domain.common.Finding;
import gov.nih.nci.cananolab.domain.common.Instrument;
import gov.nih.nci.cananolab.domain.common.PointOfContact;
import gov.nih.nci.cananolab.domain.particle.Characterization;
import gov.nih.nci.cananolab.dto.common.ExperimentConfigBean;
import gov.nih.nci.cananolab.dto.common.FindingBean;
import gov.nih.nci.cananolab.dto.common.PointOfContactBean;
import gov.nih.nci.cananolab.dto.common.ProtocolBean;
import gov.nih.nci.cananolab.util.ClassUtils;
import gov.nih.nci.cananolab.util.Comparators;
import gov.nih.nci.cananolab.util.Constants;
import gov.nih.nci.cananolab.util.DateUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * This class represents shared characterization properties to be shown in
 * characterization view pages.
 * 
 * @author pansu
 * 
 */
public class CharacterizationBean {
	private PointOfContactBean pocBean = new PointOfContactBean();

	private String conclusion;

	private String description;

	private String assayType;

	private ExperimentConfigBean theExperimentConfig = new ExperimentConfigBean();

	private FindingBean theFinding = new FindingBean();

	private Instrument theInstrument = new Instrument();

	private List<ExperimentConfigBean> experimentConfigs = new ArrayList<ExperimentConfigBean>();

	private List<FindingBean> findings = new ArrayList<FindingBean>();

	private ProtocolBean protocolBean = new ProtocolBean();

	private Characterization domainChar;

	private String className;

	private String dateString;

	private String characterizationType;

	private String characterizationName;

	private Cytotoxicity cytotoxicity = new Cytotoxicity();

	private PhysicalState physicalState = new PhysicalState();

	private Shape shape = new Shape();

	private Solubility solubility = new Solubility();

	private Surface surface = new Surface();

	private EnzymeInduction enzymeInduction = new EnzymeInduction();

	private boolean withProperties = false;

	private Transfection transfection = new Transfection();

	private String isSoluble; // Data holder for Boolean field in Solubility.
	
	public CharacterizationBean() {
		// initialize finding matrix
//		theFinding.setNumberOfColumns(1);
//		theFinding.setNumberOfRows(1);
//		theFinding.updateMatrix(theFinding.getNumberOfColumns(), theFinding
//				.getNumberOfRows());
	}

	public CharacterizationBean(Characterization chara) {
		domainChar = chara;
		className = ClassUtils.getShortClassName(chara.getClass().getName());
		this.description = chara.getDesignMethodsDescription();
		this.assayType = chara.getAssayType();
		this.conclusion = chara.getAnalysisConclusion();
		if (chara != null) {
			PointOfContact poc = chara.getPointOfContact();
			if (poc != null)
				pocBean = new PointOfContactBean(poc);
		}

		this.dateString = DateUtils.convertDateToString(chara.getDate(),
				Constants.DATE_FORMAT);

		if (chara.getFindingCollection() != null) {
			for (Finding finding : chara.getFindingCollection()) {
				findings.add(new FindingBean(finding));
			}
		}
		Collections.sort(findings, new Comparators.FindingBeanDateComparator());
		if (chara.getProtocol() != null) {
			protocolBean = new ProtocolBean(chara.getProtocol());
		}

		if (chara.getExperimentConfigCollection() != null) {
			for (ExperimentConfig config : chara
					.getExperimentConfigCollection()) {
				experimentConfigs.add(new ExperimentConfigBean(config));
			}
		}
		Collections.sort(experimentConfigs,
				new Comparators.ExperimentConfigBeanDateComparator());
		if (chara instanceof Shape) {
			shape = (Shape) chara;
			withProperties = true;
		} else if (chara instanceof PhysicalState) {
			physicalState = (PhysicalState) chara;
			withProperties = true;
		} else if (chara instanceof Solubility) {
			solubility = (Solubility) chara;
			withProperties = true;
		} else if (chara instanceof Surface) {
			surface = (Surface) chara;
			withProperties = true;
		} else if (chara instanceof Cytotoxicity) {
			cytotoxicity = (Cytotoxicity) chara;
			withProperties = true;
		} else if (chara instanceof EnzymeInduction) {
			enzymeInduction = (EnzymeInduction) chara;
			withProperties = true;
		} else if (chara instanceof Transfection) {
			transfection = (Transfection) chara;
			withProperties = true;
		} else {
			withProperties = false;
		}
		updateType();
		updateName();
	}

	public Characterization getDomainCopy(boolean copyData) {
		Characterization copy = (Characterization) ClassUtils
				.deepCopy(domainChar);
		// clear Ids, reset createdBy and createdDate, add prefix to
		copy.setId(null);
		copy.setCreatedBy(Constants.AUTO_COPY_ANNOTATION_PREFIX);
		copy.setCreatedDate(Calendar.getInstance().getTime());
		Collection<ExperimentConfig> oldConfigs = copy.getExperimentConfigCollection();
		if (oldConfigs == null || oldConfigs.isEmpty()) {
			copy.setExperimentConfigCollection(null);
		} else {
			/**
			 * Create new set for configs, otherwise will lost old configs in old bean.
			 */
			Set<ExperimentConfig> newConfigs = 
				new HashSet<ExperimentConfig>(oldConfigs);
			for (ExperimentConfig newConfig : newConfigs) {
				newConfig.setId(null);
				newConfig.setCreatedBy(Constants.AUTO_COPY_ANNOTATION_PREFIX);
				newConfig.setCreatedDate(Calendar.getInstance().getTime());
			}
			copy.setExperimentConfigCollection(newConfigs);
		}
		Collection<Finding> oldFindings = copy.getFindingCollection();
		if (oldFindings == null	|| oldFindings.isEmpty()) {
			copy.setFindingCollection(null);
		} else {
			/**
			 * Create new set for finding, otherwise will lost old finding in old bean.
			 */
			Set<Finding> newFindings = new HashSet<Finding>(oldFindings);
			for (Finding finding : newFindings) {
				finding.setId(null);
				finding.setCreatedBy(Constants.AUTO_COPY_ANNOTATION_PREFIX);
				finding.setCreatedDate(Calendar.getInstance().getTime());
				if (copyData) {
					Collection<Datum> oldDatums = finding.getDatumCollection();
					if (oldDatums == null || oldDatums.isEmpty()) {
						finding.setDatumCollection(null);
					} else {
						Set<Datum> newDatums = new HashSet<Datum>(oldDatums);
						for (Datum datum : newDatums) {
							datum.setId(null);
							datum.setCreatedBy(Constants.AUTO_COPY_ANNOTATION_PREFIX);
							datum.setCreatedDate(Calendar.getInstance().getTime());
						}
						finding.setDatumCollection(newDatums);
					}
				}
				Collection<File> oldFiles = finding.getFileCollection();
				if (oldFiles == null || oldFiles.isEmpty()) {
					finding.setFileCollection(null);
				} else {
{'fraction_non_alphanumeric': 0.10551784394112508, 'fraction_numerical': 0.0002688352711875798, 'mean_word_length': 4.888405223585279, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '422543', 'n_tokens_mistral': 5183, 'n_tokens_neox': 4427, 'n_words': 906}