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

/**
 * This class saves user entered sample and container information 
 * into the database.
 * 
 * @author pansu
 */

/* CVS $Id: CreateSampleAction.java,v 1.13 2006-05-02 22:27:17 pansu Exp $ */

import gov.nih.nci.calab.dto.administration.ContainerBean;
import gov.nih.nci.calab.dto.administration.SampleBean;
import gov.nih.nci.calab.service.administration.ManageSampleService;
import gov.nih.nci.calab.ui.core.AbstractBaseAction;

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.validator.DynaValidatorActionForm;

public class CreateSampleAction extends AbstractBaseAction {
	public ActionForward executeTask(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward forward = null;
		HttpSession session = request.getSession();

		// TODO fill in details for sample information */
		DynaValidatorActionForm theForm = (DynaValidatorActionForm) form;
		String sampleNamePrefix = (String) theForm.get("sampleNamePrefix");
		String sampleType = (String) theForm.get("sampleType");
		String sampleSOP = (String) theForm.get("sampleSOP");
		String sampleDescription = (String) theForm.get("sampleDescription");
		String sampleSource = (String) theForm.get("sampleSource");
		String sourceSampleId = (String) theForm.get("sourceSampleId");
		String dateReceived = (String) theForm.get("dateReceived");
		String solubility = (String) theForm.get("solubility");
		String lotId = (String) theForm.get("lotId");
		String lotDescription = (String) theForm.get("lotDescription");
		String numContainers = (String) theForm.get("numberOfContainers");
		String generalComments = (String) theForm.get("generalComments");
		ManageSampleService manageSampleService = new ManageSampleService();
		String sampleName = manageSampleService.getSampleName(sampleNamePrefix,
				lotId);

		// get user and date information from session
		String sampleSubmitter = (String) session.getAttribute("creator");
		String accessionDate = (String) session.getAttribute("creationDate");

		ContainerBean[] containers = (ContainerBean[]) theForm
				.get("containers");

		SampleBean sample = new SampleBean(sampleNamePrefix, sampleName,
				sampleType, sampleSOP, sampleDescription, sampleSource,
				sourceSampleId, dateReceived, solubility, lotId,
				lotDescription, numContainers, generalComments,
				sampleSubmitter, accessionDate, containers);

		request.setAttribute("sample", sample);

		manageSampleService.saveSample(sample, containers);
		// set a flag to indicate that new sample have been created so session
		// can be refreshed in initSession.do
		session.setAttribute("newSampleCreated", "yes");

		forward = mapping.findForward("success");

		return forward;
	}

	public boolean loginRequired() {
		return true;
	}
}

@@ -203,9 +203,9 @@
  1.1
-3
+4
  200
@@ -214,24 +214,25 @@
 05-0
-2 22:27:17 pansu
+8 18:58:23 zengje
  Exp
@@ -422,16 +422,124 @@
 ervice;%0A
+import gov.nih.nci.calab.service.util.CalabConstants;%0Aimport gov.nih.nci.calab.service.util.PropertyReader;%0A
 import g
@@ -855,16 +855,111 @@
 apping;%0A
+import org.apache.struts.action.ActionMessage;%0Aimport org.apache.struts.action.ActionMessages;%0A
 import o
@@ -1494,24 +1494,465 @@
 mePrefix%22);%0A
+%09%09String preconfiguredPrefix = PropertyReader.getProperty(CalabConstants.CALAB_PROPERTY,%22samplePrefix%22);%0A%09%09if (!sampleNamePrefix.equals(preconfiguredPrefix)) %7B%0A%09%09%09%0A%09%09%09ActionMessages msgs = new ActionMessages();%0A%09%09%09ActionMessage msg = new ActionMessage(%22error.createSample.SampleIDFormat%22, preconfiguredPrefix);%0A%09%09%09msgs.add(%22error%22, msg);%0A%09%09%09saveMessages(request, msgs);%0A%09%09%09%0A%09%09%09forward = mapping.findForward(%22input%22);%0A%0A%09%09%09return forward;%0A%09%09%7D%0A
 %09%09String sam
@@ -3714,13 +3714,231 @@
 n true;%0A
-
 %09%7D%0A
+%09%0A%09private boolean validateSamplePrefix(String samplePrefix) %7B%0A%09%09if (samplePrefix.equals(PropertyReader.getProperty(CalabConstants.CALAB_PROPERTY,%22samplePrefix%22))) %7B%0A%09%09%09return true;%0A%09%09%7Delse %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%7D%0A%09%0A
 %7D%0A

Check if users enter the wrong format of the sample id prefix