/**
  * gets the site list.
  *
  * @param permittedSitesForUser collection of sites.
  * @return list containing objects of NaneValueBean class.
  */
 public static List<NameValueBean> getSitesAsNVBList(Collection<Site> permittedSitesForUser) {
   final List<NameValueBean> siteNVBList = new ArrayList<NameValueBean>();
   if (permittedSitesForUser != null && permittedSitesForUser.size() > 0) {
     final Iterator<Site> siteIterator = permittedSitesForUser.iterator();
     while (siteIterator.hasNext()) {
       final Site site = siteIterator.next();
       final NameValueBean valueBean = new NameValueBean(site.getName(), site.getId());
       siteNVBList.add(valueBean);
     }
   }
   return siteNVBList;
 }
  /**
   * Called from DefaultBizLogic to get ObjectId for authorization check (non-Javadoc)
   *
   * @param dao : dao
   * @param domainObject : domainObject
   * @return String
   * @see edu.wustl.common.bizlogic.DefaultBizLogic#getObjectId(edu.wustl.common.dao.DAO,
   *     java.lang.Object)
   */
  @Override
  public String getObjectId(DAO dao, Object domainObject) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(Site.class.getName());
    try {
      if (domainObject instanceof StorageContainer) {
        final StorageContainer storageContainer = (StorageContainer) domainObject;
        final Map similarContainerMap = storageContainer.getSimilarContainerMap();
        final Object keys[] = similarContainerMap.keySet().toArray();
        final Set<Long> scIds = new HashSet<Long>();
        final Set<Long> siteIds = new HashSet<Long>();

        for (final Object key : keys) {
          if (key.toString().contains("parentContainerId")) {
            scIds.add(Long.valueOf(similarContainerMap.get(key).toString()));
          }
          if (key.toString().contains("siteId")) {
            siteIds.add(Long.valueOf(similarContainerMap.get(key).toString()));
          }
        }

        for (final Long scId : scIds) {
          Site site = null;
          Object object = null;

          object = dao.retrieveById(StorageContainer.class.getName(), scId);

          if (object != null) {
            final StorageContainer parentContainer = (StorageContainer) object;
            site = parentContainer.getSite();
          }
          if (site != null) {
            if (!siteIds.contains(site.getId())) {
              stringBuffer.append("_" + site.getId().toString());
            }
            siteIds.add(site.getId());
          }
        }

        for (final Long siteId : siteIds) {
          stringBuffer.append("_" + siteId.toString());
        }
      }
    } catch (final DAOException daoExp) {
      this.logger.error(daoExp.getMessage(), daoExp);
      daoExp.printStackTrace();
    }
    return stringBuffer.toString();
  }
 // 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;
 }
 /**
  * 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;
 }
Example #5
0
  private void createSCGUnderCPHavingScientistAsPI() {
    try {
      CollectionProtocol cp = new CollectionProtocol();
      cp.setId(new Long(BizTestCaseUtility.CP_WITH_SCIENTIST_AS_PI));
      Participant participant = BaseTestCaseUtility.initParticipant();
      participant.setSocialSecurityNumber("111-22-3233");
      try {
        participant.setBirthDate(
            Utility.parseDate("05-02-1984", CommonServiceLocator.getInstance().getDatePattern()));
      } catch (ParseException e) {
        Logger.out.debug("" + e);
      }
      System.out.println("Participant" + participant);
      SessionDataBean bean = (SessionDataBean) getSession().getAttribute("sessionData");
      try {
        participant = (Participant) appService.createObject(participant);
      } catch (Exception e) {
        e.printStackTrace();
        assertFalse(e.getMessage(), true);
      }
      BizTestCaseUtility.setNameObjectMap("ParticipantWithScientistAsPI", participant);
      CollectionProtocolRegistration collectionProtocolRegistration =
          new CollectionProtocolRegistration();

      collectionProtocolRegistration.setCollectionProtocol(cp);
      collectionProtocolRegistration.setParticipant(participant);
      collectionProtocolRegistration.setProtocolParticipantIdentifier("");
      collectionProtocolRegistration.setActivityStatus("Active");

      try {
        collectionProtocolRegistration.setRegistrationDate(
            Utility.parseDate("08/15/2006", Utility.datePattern("08/15/2006")));

        collectionProtocolRegistration.setConsentSignatureDate(
            Utility.parseDate("11/23/2006", Utility.datePattern("11/23/2006")));
        System.out.println("Creating CPR");
      } catch (ParseException e) {
        e.printStackTrace();
      }

      collectionProtocolRegistration.setSignedConsentDocumentURL("F:/doc/consentDoc.doc");

      User user = new User();
      user.setId(new Long(1));

      collectionProtocolRegistration.setConsentWitness(user);

      //				Collection consentTierResponseCollection = new LinkedHashSet();
      //				Collection consentTierCollection = new LinkedHashSet();
      //
      //				consentTierCollection = cp.getConsentTierCollection();
      //				System.out.println("Creating CPR");
      //				Iterator consentTierItr = consentTierCollection.iterator();
      //				System.out.println("Creating CPR");
      //				 while(consentTierItr.hasNext())
      //				 {
      //					 ConsentTier consent= (ConsentTier) consentTierItr.next();
      //					 ConsentTierResponse response= new ConsentTierResponse();
      //					 response.setResponse("Yes");
      //					 response.setConsentTier(consent);
      //					 consentTierResponseCollection.add(response);
      //				 }
      //
      //
      //	collectionProtocolRegistration.setConsentTierResponseCollection(consentTierResponseCollection);
      try {
        collectionProtocolRegistration =
            (CollectionProtocolRegistration)
                appService.createObject(collectionProtocolRegistration);
      } catch (Exception e) {
        Logger.out.error(e.getMessage(), e);
        e.printStackTrace();
        assertFalse(e.getMessage(), true);
      }
      BizTestCaseUtility.setNameObjectMap("CPRWithScientistAsPI", collectionProtocolRegistration);

      SpecimenCollectionGroup scg = new SpecimenCollectionGroup();

      scg = (SpecimenCollectionGroup) BaseTestCaseUtility.createSCG(collectionProtocolRegistration);
      Site site = new Site();
      site.setId(new Long(BizTestCaseUtility.CP_WITH_ALLOW_READ_PRIV));
      scg.setSpecimenCollectionSite(site);
      scg.setName("New SCG" + UniqueKeyGeneratorUtil.getUniqueKey());
      scg = (SpecimenCollectionGroup) BaseTestCaseUtility.setEventParameters(scg);
      scg.setSurgicalPathologyNumber("SPN" + UniqueKeyGeneratorUtil.getUniqueKey());
      System.out.println("Creating SCG");

      try {
        scg = (SpecimenCollectionGroup) appService.createObject(scg);
        System.out.println("SCG::" + scg.getName());
      } catch (Exception e) {
        Logger.out.error(e.getMessage(), e);
        e.printStackTrace();
        assertFalse(e.getMessage(), true);
      }

      IdentifiedSurgicalPathologyReport identifiedSurgicalPathologyReport =
          new IdentifiedSurgicalPathologyReport();
      identifiedSurgicalPathologyReport.setActivityStatus(Status.ACTIVITY_STATUS_ACTIVE.toString());
      identifiedSurgicalPathologyReport.setCollectionDateTime(new Date());
      identifiedSurgicalPathologyReport.setIsFlagForReview(new Boolean(false));
      identifiedSurgicalPathologyReport.setReportStatus(CaTIESConstants.PENDING_FOR_DEID);
      identifiedSurgicalPathologyReport.setReportSource(site);
      TextContent textContent = new TextContent();
      String data =
          "[FINAL DIAGNOSIS]\n"
              + "This is the Final Diagnosis Text"
              + "\n\n[GROSS DESCRIPTION]"
              + "The specimen is received unfixed labeled hernia sac and consists of a soft, pink to yellow segment of fibrous and fatty tissue measuring 7.5cm in length x 3.2 x 0.9cm with a partly defined lumen.  Representative tissue submitted labeled 1A.";

      textContent.setData(data);
      textContent.setSurgicalPathologyReport(identifiedSurgicalPathologyReport);
      Set reportSectionCollection = new HashSet();
      ReportSection reportSection1 = new ReportSection();
      reportSection1.setName("GDT");
      reportSection1.setDocumentFragment(
          "The specimen is received unfixed labeled hernia sac and consists of a soft, pink to yellow segment of fibrous and fatty tissue measuring 7.5cm in length x 3.2 x 0.9cm with a partly defined lumen.  Representative tissue submitted labeled 1A.");
      reportSection1.setTextContent(textContent);

      ReportSection reportSection2 = new ReportSection();
      reportSection2.setName("FIN");
      reportSection2.setDocumentFragment("This is the Final Diagnosis Text");
      reportSection2.setTextContent(textContent);

      reportSectionCollection.add(reportSection1);
      reportSectionCollection.add(reportSection2);

      textContent.setReportSectionCollection(reportSectionCollection);

      identifiedSurgicalPathologyReport.setTextContent(textContent);
      identifiedSurgicalPathologyReport.setSpecimenCollectionGroup(scg);
      scg.setSurgicalPathologyNumber("SPN" + UniqueKeyGeneratorUtil.getUniqueKey());

      try {
        identifiedSurgicalPathologyReport =
            (IdentifiedSurgicalPathologyReport)
                appService.createObject(identifiedSurgicalPathologyReport);
      } catch (Exception e) {
        Logger.out.error(e.getMessage(), e);
        e.printStackTrace();
        assertFalse(e.getMessage(), true);
      }
      BizTestCaseUtility.setObjectMap(
          identifiedSurgicalPathologyReport, IdentifiedSurgicalPathologyReport.class);

      BizTestCaseUtility.setNameObjectMap("SCGWithScientistAsPI", scg);
      //				TissueSpecimen specimenObj = (TissueSpecimen) BaseTestCaseUtility.initTissueSpecimen();
      //				specimenObj.setSpecimenCollectionGroup(scg);
      //				StorageContainer sc = new StorageContainer();
      //				sc.setId(new Long(1));
      //				specimenObj.setStorageContainer(sc);
      //				specimenObj.setPositionDimensionOne(new Integer(3));
      //				specimenObj.setPositionDimensionTwo(new Integer(1));
      //				try{
      //					specimenObj =  (TissueSpecimen) appService.createObject(specimenObj);
      //					System.out.println("Mol Specimen:"+ specimenObj.getLabel());
      //				}
      //				catch(Exception e){
      //					Logger.out.error(e.getMessage(),e);
      //		           	e.printStackTrace();
      //		           	assertFalse("Failed to register participant", true);
      //				}
    } catch (Exception e) {
      Logger.out.error(e.getMessage(), e);
      e.printStackTrace();
      assertFalse(e.getMessage(), true);
    }
  }
  /**
   * 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", "");
    }
  }