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

/**
 * This class creates nanoparticle metadata and assigns visibility  
 *  
 * @author pansu
 */

/* CVS $Id: CreateNanoparticleAction.java,v 1.3 2006-08-04 14:08:42 pansu Exp $ */

import gov.nih.nci.calab.service.security.UserService;
import gov.nih.nci.calab.service.util.CalabConstants;
import gov.nih.nci.calab.service.util.StringUtils;
import gov.nih.nci.calab.ui.core.AbstractDispatchAction;
import gov.nih.nci.calab.ui.core.InitSessionSetup;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.DynaValidatorForm;

public class CreateNanoparticleAction extends AbstractDispatchAction {
	public ActionForward create(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward forward = null;		
		// TODO fill in details for sample information */
		DynaValidatorForm theForm = (DynaValidatorForm) form;
		String particleName = (String) theForm.get("particleName");
		String[] visibilities = (String[])theForm.get("visibilities");

		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");
		}
		
		ActionMessages msgs=new ActionMessages();
		ActionMessage msg=new ActionMessage("message.createNanoparticle.secure", StringUtils.join(visibilities, ", "));
		msgs.add("message", msg);
		saveMessages(request, msgs);
		forward = mapping.findForward("success");

		return forward;
	}

	public ActionForward setup(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session = request.getSession();
		InitSessionSetup.getInstance().clearWorkflowSession(session);
		InitSessionSetup.getInstance().clearSearchSession(session);
		InitSessionSetup.getInstance().clearInventorySession(session);
	
		InitSessionSetup.getInstance().setAllSampleContainers(session);	
		return mapping.getInputForward();
	}

	public boolean loginRequired() {
		return true;
	}
}

@@ -74,16 +74,27 @@
 cle 
-metadata
+general information
  and
@@ -192,9 +192,9 @@
 v 1.
-3
+4
  200
@@ -202,19 +202,19 @@
 -08-
-04 14:08:42
+10 16:33:18
  pan
@@ -1302,49 +1302,322 @@
 icle
-Name = (String) theForm.get(%22particleName
+Type = (String) theForm.get(%22particleType%22);%0A%09%09String particleName = (String) theForm.get(%22particleName%22);%0A%09%09HttpSession session = request.getSession();%0A%09%09session.setAttribute(%22particleName%22, particleName);%0A%09%09session.setAttribute(%22particleType%22, particleType);%0A%09%09%0A%09%09String keywords = (String) theForm.get(%22keywords
 %22);%0A
@@ -1681,16 +1681,65 @@
 ties%22);%0A
+%09%09String%5B%5D keywordList=keywords.split(%22%5Cr%5Cn%22);%0A%09%09
 %0A%09%09UserS
@@ -2874,34 +2874,168 @@
 tAll
-SampleContainers(session);
+ParticleTypeParticles(session);%09%0A%09%09InitSessionSetup.getInstance().setAllVisibilityGroups(session);%09%0A%09%09InitSessionSetup.getInstance().setParticleMenu(session);%0A%09
 %09%0A%09%09

put particleName and particleType in session