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

import gov.nih.nci.cananolab.domain.common.Keyword;
import gov.nih.nci.cananolab.domain.common.PointOfContact;
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=new String[0];

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

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

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

	public ParticleBean() {
		domainParticleSample.setPrimaryPointOfContact(new PointOfContact());
	}

	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;
	}
}

@@ -1107,24 +1107,54 @@
 w String%5B0%5D;
+%0A%09private String POCName = %22%22;
 %0A%0A%09public Pa
@@ -1239,16 +1239,32 @@
 act());%0A
+%09%09POCName = %22%22;%0A
 %09%7D%0A%0A%09pub
@@ -1534,16 +1534,16 @@
 %09%09%7D%0A%09%09%7D%0A
-
 %09%09keywor
@@ -1588,16 +1588,357 @@
 %5Cr%5Cn%22);%0A
+%09%09if (domainParticleSample!=null) %7B%0A%09%09%09String firstName = domainParticleSample.getPrimaryPointOfContact().getFirstName();%0A%09%09%09POCName = %22%22;%0A%09%09%09if (firstName!=null) %7B%0A%09%09%09%09POCName = firstName +%22 %22;%0A%09%09%09%7D%0A%09%09%09String lastName = domainParticleSample.getPrimaryPointOfContact().getLastName();%0A%09%09%09if (lastName!=null) %7B%0A%09%09%09%09POCName+=lastName;%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%7D%0A%0A%09pub
@@ -4599,11 +4599,203 @@
 ames;%0A%09%7D
+%0A%0A%09/**%0A%09 * @return the pOCName%0A%09 */%0A%09public String getPOCName() %7B%0A%09%09return POCName;%0A%09%7D%0A%0A%09/**%0A%09 * @param name the pOCName to set%0A%09 */%0A%09public void setPOCName(String name) %7B%0A%09%09POCName = name;%0A%09%7D
 %0A%7D%0A

add POCName to particle for particle primaryPointOfContact drop down list