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

/**
 * This class prepares the form fields in the Create Sample page
 * 
 * @author pansu
 */

/* CVS $Id: PreCreateSampleAction.java,v 1.12 2006-05-03 17:40:11 pansu Exp $ */

import gov.nih.nci.calab.dto.administration.ContainerBean;
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 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 PreCreateSampleAction extends AbstractBaseAction {
	public ActionForward executeTask(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward forward = null;
		DynaValidatorActionForm theForm = (DynaValidatorActionForm) form;
		String sampleNamePrefix = (String) theForm.get("sampleNamePrefix");
		String lotId = (String) theForm.get("lotId");
		int numContainers = Integer.parseInt((String) theForm
				.get("numberOfContainers"));

		ManageSampleService mangeSampleService = new ManageSampleService();
		// set default form values
		if (sampleNamePrefix.length() == 0) {
			theForm.set("sampleNamePrefix", mangeSampleService
					.getDefaultSampleNamePrefix());
		}
		if (lotId.length() == 0) {
			theForm.set("lotId", mangeSampleService.getDefaultLotId());
		}
		ContainerBean[] origContainers = (ContainerBean[]) theForm
				.get("containers");
		ContainerBean[] containers = new ContainerBean[numContainers];

		// reuse containers from the previous request
		// set other containers to have values from the first container
		if (origContainers.length < numContainers) {
			for (int i = 0; i < origContainers.length; i++) {
				containers[i] = new ContainerBean(origContainers[i]);
			}
			for (int i = origContainers.length; i < numContainers; i++) {
				if (origContainers.length > 0) {
					containers[i] = new ContainerBean(origContainers[0]);
				}
				// if no containers from previous request, set them new
				else {
					containers[i] = new ContainerBean();
				}
			}

		} else {
			for (int i = 0; i < numContainers; i++) {
				containers[i] = new ContainerBean(origContainers[i]);
			}
		}
		theForm.set("containers", containers);
		forward = mapping.findForward("success");
		return forward;
	}

	public boolean loginRequired() {
		return true;
	}
}

@@ -178,17 +178,17 @@
 va,v 1.1
-2
+3
  2006-05
@@ -193,24 +193,25 @@
 05-0
-3 17:40:11 pansu
+8 18:58:55 zengje
  Exp
@@ -345,16 +345,124 @@
 ervice;%0A
+import gov.nih.nci.calab.service.util.CalabConstants;%0Aimport gov.nih.nci.calab.service.util.PropertyReader;%0A
 import g
@@ -1563,16 +1563,138 @@
 ));%0A%09%09%7D%0A
+%09%09theForm.set(%22configuredSampleNamePrefix%22, PropertyReader.getProperty(CalabConstants.CALAB_PROPERTY,%22samplePrefix%22));%0A%09%09%0A
 %09%09if (lo

Read sample id prefix from property file ,and then pass it to jsp file.