package gov.nih.nci.calab.service.submit;

import java.util.ArrayList;
import java.util.List;

import gov.nih.nci.calab.dto.particle.DendrimerBean;
import gov.nih.nci.calab.dto.particle.ParticleBean;
import gov.nih.nci.calab.dto.workflow.FileBean;
import gov.nih.nci.calab.service.security.UserService;
import gov.nih.nci.calab.service.util.CalabConstants;

/**
 * This class includes service calls invovled in creating nanoparticles and
 * adding properties, functions and characterizations for nanoparticles.
 * 
 * @author pansu
 * 
 */
public class SubmitNanoparticleService {
	public void createNanoparticle(String particleType, String particleName,
			String[] keywords, String[] visibilities) throws Exception {

		UserService userService = new UserService(CalabConstants.CSM_APP_NAME);
		http: // www.aahealth.org/news.asp?id=145
		for (String visibility : visibilities) {
			// by default, always set visibility to NCL_PI and NCL_Researcher to
			// be true
			userService.secureObject(particleName, "NCL_PI", "R");
			userService.secureObject(particleName, "NCL_Researcher", "R");
			userService.secureObject(particleName, visibility, "R");
		}
		// TODO add database code to save the nanoparticle
	}

	public void addParticleProperties(String particleType, ParticleBean particle) {
		if (particleType.equalsIgnoreCase("dendrimer")) {
			DendrimerBean dendrimer = (DendrimerBean) particle;
			// TODO update the dendrimer object in the db.
		}
	}

	public void saveAssayResult(String particleName, String fileName,
			String title, String description, String comments, String[] keywords) {

	}

	public List<FileBean> getAllRunFiles(String particleName) {
		List<FileBean> runFiles = new ArrayList<FileBean>();
		// TODO fill in the database query code
		FileBean file = new FileBean();
		file.setId("1");
		file.setShortFilename("NCL_3_distri.jpg");

		runFiles.add(file);
		return runFiles;
	}
}

@@ -47,52 +47,146 @@
 ort 
-java.util.ArrayList;%0Aimport java.util.List;%0A
+gov.nih.nci.calab.db.DataAccessProxy;%0Aimport gov.nih.nci.calab.db.IDataAccess;%0Aimport gov.nih.nci.calab.domain.nano.particle.Nanoparticle;
 %0Aimp
@@ -327,32 +327,149 @@
 kflow.FileBean;%0A
+import gov.nih.nci.calab.exception.DuplicateEntriesException;%0Aimport gov.nih.nci.calab.service.common.LookupService;%0A
 import gov.nih.n
@@ -562,16 +562,90 @@
 tants;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 /**%0A * T
@@ -685,10 +685,10 @@
 invo
-v
 l
+v
 ed i
@@ -997,16 +997,937 @@
 ption %7B%0A
+%09%09%0A%09%09LookupService lookupService=new LookupService();%0A%09%09Map%3CString, String%3Etype2Category=lookupService.getParticleTypeToParticleCategory();%0A%09%09%0A%09%09// save nanoparticle to the database%0A%09%09IDataAccess ida = (new DataAccessProxy())%0A%09%09%09%09.getInstance(IDataAccess.HIBERNATE);%0A//%09%09try %7B%0A//%09%09%09ida.open();%0A//%09%09%09//check if particle already exists in the database%09%09%09%0A//%09%09%09List results = ida.search(%22from Nanoparticle where particleName=%22+particleName);%0A//%09%09%09if (results.size()%3E0) %7B%0A//%09%09%09%09throw new DuplicateEntriesException(%22Nanoparticle alreay exists in the database%22);%0A//%09%09%09%7D%0A//%09%09%09%0A//%09%09%09Nanoparticle particle=new Nanoparticle();%09%09%09%0A//%09%09%09particle.setParticleCategory(type2Category.get(particleType.toLowerCase()));%09%09%09%0A//%09%09%09ida.createObject(particle);%0A//%09%09%09%09%09%09%0A//%09%09%7D catch (Exception e) %7B%0A//%09%09%09e.printStackTrace();%0A//%09%09%09ida.rollback();%0A//%09%09%09throw e;%0A//%09%09%7D finally %7B%0A//%09%09%09ida.close();%0A//%09%09%7D%0A%09%09%0A%09%09// set visibilities for the nanoparticle
 %0A%09%09UserS
@@ -1997,52 +1997,8 @@
 E);%0A
-%09%09http: // www.aahealth.org/news.asp?id=145%0A
 %09%09fo
@@ -2314,60 +2314,8 @@
 %09%09%7D%0A
-%09%09// TODO add database code to save the nanoparticle
 %0A%09%7D%0A

comment out database query code