/** * creates the transit container. * * @param shipmentForm form containing all values. * @return object of StorageContainer class. */ public static StorageContainer createInTransitContainer(BaseShipmentForm shipmentForm) { final StorageContainer container = new StorageContainer(); // Set storage type for the container type being created final StorageType storageType = new StorageType(); storageType.setName(Constants.SHIPMENT_CONTAINER_TYPE_NAME); container.setStorageType(storageType); // Set site for the container being created final Site site = new Site(); site.setName(Constants.IN_TRANSIT_SITE_NAME); container.setSite(site); // Set capacity, create a container of dimensions (number of specimens to be stored) X 1 final Capacity capacity = new Capacity(); capacity.setOneDimensionCapacity(shipmentForm.getSpecimenCounter()); capacity.setTwoDimensionCapacity(1); container.setCapacity(capacity); container.getHoldsSpecimenArrayTypeCollection(); container.setName(Constants.IN_TRANSIT_CONTAINER_NAME_PREFIX + shipmentForm.getLabel()); container.setSpecimenPositionCollection(new LinkedHashSet<SpecimenPosition>()); return container; }
// Overload the method createInTransitContainer(BaseShipmentForm shipmentForm) public static StorageContainer createInTransitContainer(String containerName) { final StorageContainer container = new StorageContainer(); // Set storage type for the container type being created final StorageType storageType = new StorageType(); storageType.setName(Constants.SHIPMENT_CONTAINER_TYPE_NAME); container.setStorageType(storageType); // Set site for the container being created final Site site = new Site(); site.setName(Constants.IN_TRANSIT_SITE_NAME); container.setSite(site); // Set capacity, create a container of dimensions (number of specimens to be stored) X 1 final Capacity capacity = new Capacity(); // Keep the capacity 1 initially and increment on adding a new specimen capacity.setOneDimensionCapacity(1); capacity.setTwoDimensionCapacity(1); container.setCapacity(capacity); container.setName(containerName); container.setSpecimenPositionCollection(new LinkedHashSet<SpecimenPosition>()); return container; }
/** * Saves the storageContainer object in the database. * * @param dao : dao * @param obj The storageType object to be saved. * @param sessionDataBean The session in which the object is saved. * @throws BizLogicException : BizLogicException */ @Override protected void insert(Object obj, DAO dao, SessionDataBean sessionDataBean) throws BizLogicException { final StorageContainer container = (StorageContainer) obj; container.setActivityStatus(Status.ACTIVITY_STATUS_ACTIVE.toString()); final List contList = new ArrayList(); final int noOfContainers = container.getNoOfContainers().intValue(); final Map simMap = container.getSimilarContainerMap(); // --- common values for all similar containers --- new StorageTypeBizLogic().loadStorageType(dao, container); this.logger.debug(simMap); final int checkButton = Integer.parseInt((String) simMap.get("checkedButton")); // int checkButton = 1; try { for (int i = 1; i <= noOfContainers; i++) { final String simContPrefix = "simCont:" + i + "_"; final String IdKey = simContPrefix + "Id"; final String parentContNameKey = simContPrefix + "parentContName"; final String contName = (String) simMap.get(simContPrefix + "name"); String barcode = (String) simMap.get(simContPrefix + "barcode"); if (barcode != null && barcode.equals("")) // this is done // because barcode // is empty string // set by struts { // but barcode in DB is unique but can be null. barcode = null; } final StorageContainer cont = new StorageContainer(container); if (checkButton == 1) // site { final String siteId = (String) simMap.get(simContPrefix + "siteId"); final String siteName = (String) simMap.get(simContPrefix + "siteName"); final Site site = new Site(); /** * Start: Change for API Search --- Jitendra 06/10/2006 In Case of Api Search, previoulsy * it was failing since there was default class level initialization on domain object. For * example in User object, it was initialized as protected String lastName=""; So we * removed default class level initialization on domain object and are initializing in * method setAllValues() of domain object. But in case of Api Search, default values will * not get set since setAllValues() method of domainObject will not get called. To avoid * null pointer exception, we are setting the default values same as we were setting in * setAllValues() method of domainObject. */ ApiSearchUtil.setSiteDefault(site); site.setId(new Long(siteId)); site.setName(siteName); cont.setSite(site); new SiteBizLogic().loadSite(dao, cont); } else // parentContainer { StorageContainer parentContainer = null; final String parentId = (String) simMap.get(simContPrefix + "parentContainerId"); final String posOne = (String) simMap.get(simContPrefix + "positionDimensionOne"); final String posTwo = (String) simMap.get(simContPrefix + "positionDimensionTwo"); final Object object = dao.retrieveById(StorageContainer.class.getName(), new Long(parentId)); if (object != null) { parentContainer = (StorageContainer) object; cont.setSite(parentContainer.getSite()); } final IFactory factory = AbstractFactoryConfig.getInstance().getBizLogicFactory(); final StorageContainerBizLogic storageContainerBizLogic = (StorageContainerBizLogic) factory.getBizLogic(Constants.STORAGE_CONTAINER_FORM_ID); storageContainerBizLogic.checkContainer( dao, StorageContainerUtil.setparameterList( parentContainer.getId().toString(), posOne, posTwo, false), sessionDataBean, null); ContainerPosition cntPos = cont.getLocatedAtPosition(); if (cntPos == null) { cntPos = new ContainerPosition(); } cntPos.setPositionDimensionOne(new Integer(posOne)); cntPos.setPositionDimensionTwo(new Integer(posTwo)); cntPos.setOccupiedContainer(cont); cntPos.setParentContainer(parentContainer); cont.setLocatedAtPosition(cntPos); // Have to set Site object for parentContainer SiteBizLogic siteBiz = new SiteBizLogic(); siteBiz.loadSite(dao, parentContainer); siteBiz.loadSiteFromContainerId(dao, parentContainer); cntPos.setPositionDimensionOne(new Integer(posOne)); cntPos.setPositionDimensionTwo(new Integer(posTwo)); cntPos.setOccupiedContainer(cont); cont.setLocatedAtPosition(cntPos); cont.setSite(parentContainer.getSite()); this.logger.debug("^^>> " + parentContainer.getSite()); simMap.put(parentContNameKey, parentContainer.getName()); } // StorageContainer cont = new StorageContainer(); cont.setName(contName); // <<---- cont.setBarcode(barcode); // <<---- // by falguni // Storage container label generator // Call Storage container label generator if its specified to // use automatic label generator if (edu.wustl.catissuecore.util.global.Variables.isStorageContainerLabelGeneratorAvl) { LabelGenerator storagecontLblGenerator; storagecontLblGenerator = LabelGeneratorFactory.getInstance( Constants.STORAGECONTAINER_LABEL_GENERATOR_PROPERTY_NAME); try { storagecontLblGenerator.setLabel(cont); } catch (LabelGenException e) { this.logger.error(e.getMessage(), e); } } simMap.put(simContPrefix + "name", cont.getName()); this.logger.debug( "cont.getCollectionProtocol().size() " + cont.getCollectionProtocolCollection().size()); cont.setActivityStatus("Active"); dao.insert(cont.getCapacity()); dao.insert(cont); contList.add(cont); container.setId(cont.getId()); simMap.put(IdKey, cont.getId().toString()); } } catch (final DAOException daoExp) { this.logger.error(daoExp.getMessage(), daoExp); daoExp.printStackTrace(); throw this.getBizLogicException(daoExp, daoExp.getErrorKeyName(), daoExp.getMsgValues()); } catch (final NameGeneratorException e) { this.logger.error(e.getMessage(), e); e.printStackTrace(); throw this.getBizLogicException(e, "utility.error", ""); } }