package gov.nih.nci.cananolab.dto.particle;

import gov.nih.nci.cananolab.domain.common.Keyword;
import gov.nih.nci.cananolab.domain.common.Source;
import gov.nih.nci.cananolab.domain.particle.NanoparticleSample;
import gov.nih.nci.cananolab.util.StringUtils;

import java.util.Date;
import java.util.HashSet;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * This class represents shared properties of nanoparticle samples to be shown
 * in the view pages.
 * 
 * @author pansu
 * 
 */
public class ParticleBean {
	private String keywordsStr;

	private String[] visibilityGroups = new String[0];

	private NanoparticleSample domainParticleSample = new NanoparticleSample();

	private String createdBy;

	private boolean hidden;

	private SortedSet<String> keywordSet = new TreeSet<String>();

	private String location; // e.g. local, caNanoLab-WashU, etc

	private String[] nanoparticleEntityClassNames;

	private String[] functionalizingEntityClassNames;

	private String[] functionClassNames;

	private String[] characterizationClassNames;

	public ParticleBean() {
		domainParticleSample.setSource(new Source());
	}

	public ParticleBean(NanoparticleSample particleSample) {
		this.domainParticleSample = particleSample;

		if (particleSample.getKeywordCollection() != null) {
			for (Keyword keyword : particleSample.getKeywordCollection()) {
				keywordSet.add(keyword.getName());
			}
		}
		keywordsStr = StringUtils.join(keywordSet, "\r\n");
	}

	public String[] getVisibilityGroups() {
		return this.visibilityGroups;
	}

	public void setVisibilityGroups(String[] visibilityGroups) {
		this.visibilityGroups = visibilityGroups;
	}

	public String getKeywordsStr() {
		return this.keywordsStr;
	}

	public NanoparticleSample getDomainParticleSample() {
		return domainParticleSample;
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public void setupDomainParticleSample() {
		// always update createdBy and createdDate
		domainParticleSample.setCreatedBy(createdBy);
		domainParticleSample.setCreatedDate(new Date());
		if (domainParticleSample.getKeywordCollection() != null) {
			domainParticleSample.getKeywordCollection().clear();
		} else {
			domainParticleSample.setKeywordCollection(new HashSet<Keyword>());
		}
		if (keywordsStr.length() > 0) {
			String[] strs = keywordsStr.split("\r\n");
			for (String str : strs) {
				// change to upper case
				Keyword keyword = new Keyword();
				keyword.setName(str.toUpperCase());
				domainParticleSample.getKeywordCollection().add(keyword);
			}
		}
	}

	public void setKeywordsStr(String keywordsStr) {
		this.keywordsStr = keywordsStr;
	}

	public boolean isHidden() {
		return hidden;
	}

	public void setHidden(boolean hidden) {
		this.hidden = hidden;
	}

	public SortedSet<String> getKeywordSet() {
		return keywordSet;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public void setDomainParticleSample(NanoparticleSample domainParticleSample) {
		this.domainParticleSample = domainParticleSample;
	}

	public String[] getNanoparticleEntityClassNames() {
		return nanoparticleEntityClassNames;
	}

	public void setNanoparticleEntityClassNames(
			String[] nanoparticleEntityClassNames) {
		this.nanoparticleEntityClassNames = nanoparticleEntityClassNames;
	}

	public String[] getFunctionalizingEntityClassNames() {
		return functionalizingEntityClassNames;
	}

	public void setFunctionalizingEntityClassNames(
			String[] functionalizingEntityClassNames) {
		this.functionalizingEntityClassNames = functionalizingEntityClassNames;
	}

	public String[] getFunctionClassNames() {
		return functionClassNames;
	}

	public void setFunctionClassNames(String[] functionClassNames) {
		this.functionClassNames = functionClassNames;
	}

	public String[] getCharacterizationClassNames() {
		return characterizationClassNames;
	}

	public void setCharacterizationClassNames(String[] characterizationClassNames) {
		this.characterizationClassNames = characterizationClassNames;
	}
}

@@ -900,32 +900,46 @@
 EntityClassNames
+=new String%5B0%5D
 ;%0A%0A%09private Stri
@@ -966,32 +966,46 @@
 EntityClassNames
+=new String%5B0%5D
 ;%0A%0A%09private Stri
@@ -1023,24 +1023,38 @@
 onClassNames
+=new String%5B0%5D
 ;%0A%0A%09private 
@@ -1088,16 +1088,30 @@
 assNames
+=new String%5B0%5D
 ;%0A%0A%09publ

initialize className arrays