/**
   * This function returns the RoleClass for given attName
   *
   * @param attName
   * @return RoleClass
   */
  public static Class getRoleClass(String attName) {
    Iterator itr = mappings.iterator();

    while (itr.hasNext()) {
      ClassRelationshipData crd = (ClassRelationshipData) itr.next();
      if (crd.getRoleAttribute().indexOf(attName) != -1) {
        return Utility.getClassObject(crd.getRelatedClassName());
      }
    }
    return null;
  }
Ejemplo n.º 2
0
 /**
  * This method used to set Date values. to prepared statement
  *
  * @param stmt :TODO
  * @param index :
  * @param obj :
  * @throws SQLException : SQLException
  * @throws DAOException : DAOException
  */
 protected void setDateColumns(PreparedStatement stmt, int index, Object obj)
     throws SQLException, DAOException {
   if (obj != null && obj.toString().equals("##")) {
     java.util.Date date = null;
     try {
       date = Utility.parseDate("1-1-9999", "mm-dd-yyyy");
     } catch (ParseException exp) {
       // TODO have to replace this by parse key
       ErrorKey errorKey = ErrorKey.getErrorKey("db.operation.error");
       throw new DAOException(errorKey, exp, "HashedDataHandler.java :");
     }
     Date sqlDate = new Date(date.getTime());
     stmt.setDate(index, sqlDate);
   }
 }
  /**
   * Returns SimpleConditionsNode if the object named aliasName contains the activityStatus data
   * member, else returns null.
   *
   * @param aliasName The alias name of the object.
   * @param className The fully qualified name of the class in which activity status field is to be
   *     searched.
   * @return SimpleConditionsNode if the object named aliasName contains the activityStatus data
   *     member, else returns null.
   */
  private SimpleConditionsNode getActivityStatusCondition(String aliasName, String className)
      throws DAOException, ClassNotFoundException {
    SimpleConditionsNode activityStatusCondition = null;

    if (className.equals(Constants.REPORTED_PROBLEM_CLASS_NAME)) {
      return null;
    }
    // Returns the Class object if it is a valid class else returns null.
    Class classObject = edu.wustl.common.util.Utility.getClassObject(className);
    if (classObject != null) {
      Field[] objectFields = classObject.getDeclaredFields();

      for (int i = 0; i < objectFields.length; i++) {
        if (objectFields[i].getName().equals(Constants.ACTIVITY_STATUS)) {
          activityStatusCondition = new SimpleConditionsNode();
          activityStatusCondition.getCondition().getDataElement().setTableName(aliasName);
          activityStatusCondition
              .getCondition()
              .getDataElement()
              .setField(Constants.ACTIVITY_STATUS_COLUMN);
          activityStatusCondition.getCondition().getOperator().setOperator("!=");
          activityStatusCondition.getCondition().setValue(Constants.ACTIVITY_STATUS_DISABLED);
          activityStatusCondition
              .getCondition()
              .getDataElement()
              .setFieldType(Constants.FIELD_TYPE_VARCHAR);
          return activityStatusCondition;
        }
      }

      Class superClass = classObject.getSuperclass();
      if ((activityStatusCondition == null)
          && (superClass.getName().equals("edu.wustl.common.domain.AbstractDomainObject")
              == false)) {
        String superClassAliasName = getAliasName(superClass);
        activityStatusCondition =
            getActivityStatusCondition(superClassAliasName, superClass.getName());
      }
    }

    return activityStatusCondition;
  }
Ejemplo n.º 4
0
  /**
   * @see
   *     edu.common.dynamicextensions.validation.ValidatorRuleInterface#validate(edu.common.dynamicextensions.domaininterface.AttributeInterface,
   *     java.lang.Object, java.util.Map)
   * @throws DynamicExtensionsValidationException
   */
  public boolean validate(
      AttributeInterface attribute, Object valueObject, Map<String, String> parameterMap)
      throws DynamicExtensionsValidationException {
    boolean valid = false;
    String attributeName = attribute.getName();
    AttributeTypeInformationInterface attributeTypeInformation =
        attribute.getAttributeTypeInformation();

    if (((valueObject != null) && (!((String) valueObject).trim().equals("")))
        && ((attributeTypeInformation != null)
            && (attributeTypeInformation instanceof DateAttributeTypeInformation))) {
      DateAttributeTypeInformation dateAttributeTypeInformation =
          (DateAttributeTypeInformation) attributeTypeInformation;
      String dateFormat = dateAttributeTypeInformation.getFormat();
      String value = (String) valueObject;

      if (dateFormat.equals(ProcessorConstants.MONTH_YEAR_FORMAT)) {
        value = DynamicExtensionsUtility.formatMonthAndYearDate(value);
        value = value.substring(0, value.length() - 4);
      }
      if (dateFormat.equals(ProcessorConstants.YEAR_ONLY_FORMAT)) {
        value = DynamicExtensionsUtility.formatYearDate(value);
        value = value.substring(0, value.length() - 4);
      }

      try {
        Date date = null;
        date = Utility.parseDate(value, "MM-dd-yyyy");
        if (date != null) {
          valid = true;
        }
      } catch (ParseException parseException) {
        List<String> placeHolders = new ArrayList<String>();
        placeHolders.add(attributeName);
        placeHolders.add(dateFormat);
        throw new DynamicExtensionsValidationException(
            "Validation failed", null, "dynExtn.validation.Date", placeHolders);
      }
    }
    return valid;
  }
Ejemplo n.º 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);
    }
  }
  /**
   * Retrieves the records for class name in sourceObjectName according to field values passed in
   * the passed session.
   *
   * @param whereColumnName An array of field names.
   * @param whereColumnCondition The comparision condition for the field values.
   * @param whereColumnValue An array of field values.
   * @param joinCondition The join condition.
   * @param The session object.
   */
  public List retrieve(
      String sourceObjectName,
      String[] selectColumnName,
      String[] whereColumnName,
      String[] whereColumnCondition,
      Object[] whereColumnValue,
      String joinCondition)
      throws DAOException {
    List list = null;
    try {
      StringBuffer sqlBuff = new StringBuffer();

      String className = Utility.parseClassName(sourceObjectName);

      // Logger.out.debug("***********className:"+className);
      if (selectColumnName != null && selectColumnName.length > 0) {
        sqlBuff.append("Select ");

        // Added by Aarti
        // --------------------------------
        //                if(sourceObjectName.equals(Site.class.getName()))
        //                {
        //                    sqlBuff.append(className + "." + Constants.SYSTEM_IDENTIFIER);
        //                    sqlBuff.append(", ");
        //                }
        // ---------------------------------
        for (int i = 0; i < selectColumnName.length; i++) {
          sqlBuff.append(className + "." + selectColumnName[i]);
          if (i != selectColumnName.length - 1) {
            sqlBuff.append(", ");
          }
        }
        sqlBuff.append(" ");
      }
      // Logger.out.debug(" String : "+sqlBuff.toString());

      Query query = null;
      sqlBuff.append("from " + sourceObjectName + " " + className);
      // Logger.out.debug(" String : "+sqlBuff.toString());

      if ((whereColumnName != null && whereColumnName.length > 0)
          && (whereColumnCondition != null && whereColumnCondition.length == whereColumnName.length)
          && (whereColumnValue != null)) {
        if (joinCondition == null) joinCondition = Constants.AND_JOIN_CONDITION;

        sqlBuff.append(" where ");

        // Adds the column name and search condition in where clause.
        for (int i = 0; i < whereColumnName.length; i++) {
          sqlBuff.append(className + "." + whereColumnName[i] + " ");
          if (whereColumnCondition[i].indexOf("in") != -1) {
            sqlBuff.append(whereColumnCondition[i] + "(  ");
            Object valArr[] = (Object[]) whereColumnValue[i];
            for (int j = 0; j < valArr.length; j++) {
              // Logger.out.debug(sqlBuff);
              sqlBuff.append("? ");
              if ((j + 1) < valArr.length) sqlBuff.append(", ");
            }
            sqlBuff.append(") ");
          } else if (whereColumnCondition[i].indexOf("is not null") != -1) {
            sqlBuff.append(whereColumnCondition[i]);
          } else if (whereColumnCondition[i].indexOf("is null") != -1) {
            sqlBuff.append(whereColumnCondition[i]);
          } else {
            sqlBuff.append(whereColumnCondition[i] + " ? ");
          }

          if (i < (whereColumnName.length - 1)) sqlBuff.append(" " + joinCondition + " ");
        }

        // Logger.out.debug(sqlBuff.toString());

        query = session.createQuery(sqlBuff.toString());

        int index = 0;
        // Adds the column values in where clause
        for (int i = 0; i < whereColumnValue.length; i++) {
          // Logger.out.debug("whereColumnValue[i]. " + whereColumnValue[i]);
          if (whereColumnCondition[i].equals("is null")
              || whereColumnCondition[i].equals("is not null")) {
          } else {

            Object obj = whereColumnValue[i];
            if (obj instanceof Object[]) {
              Object[] valArr = (Object[]) obj;
              for (int j = 0; j < valArr.length; j++) {
                query.setParameter(index, valArr[j]);
                index++;
              }
            } else {
              query.setParameter(index, obj);
              index++;
            }
          }
        }
      } else {
        query = session.createQuery(sqlBuff.toString());
      }

      list = query.list();

      //          Added by Aarti
      // --------------------------------

      //            if(sourceObjectName.equals(Site.class.getName()))
      //            {
      //                boolean isAuthorized;
      //                Object[] objects = null;
      //                Object[] newObjects = null;
      //                Long id;
      //                Site site;
      //
      //                if (selectColumnName != null && selectColumnName.length > 0)
      //                {
      //                    if(list != null)
      //                    {
      //                        for(int i=0; i<list.size();)
      //                        {
      //                            objects = (Object[]) list.get(i);
      //
      //                            if(objects != null)
      //                            {
      //                                newObjects = new Object[objects.length-1];
      //                                id = (Long) objects[0];
      //                                isAuthorized = SecurityManager.getInstance(this.getClass())
      //                                .isAuthorized("*****@*****.**",
      //                                        sourceObjectName+"_"+id,
      //                                        Permissions.USE);
      //                                Logger.out.debug(" User's Authorization to update
      // "+sourceObjectName+"_"+id+" "+isAuthorized);
      //                                list.remove(i);
      //                                if(isAuthorized)
      //                                {
      //                                    for(int x = 1;x<objects.length;x++ )
      //                                    {
      //                                        newObjects[x-1] = objects[x];
      //                                    }
      //                                    list.add(i,newObjects);
      //                                    i++;
      //                                }
      //                            }
      //                        }
      //                    }
      //                }
      //                else
      //                {
      //                    if(list != null)
      //                    {
      //                        for(int i=0; i<list.size();)
      //                        {
      //                            site = (Site) list.get(i);
      //                            if(site !=null)
      //                            {
      //                                isAuthorized = SecurityManager.getInstance(this.getClass())
      //                                .isAuthorized("*****@*****.**",
      //                                        sourceObjectName+"_"+site.getId(),
      //                                        Permissions.USE);
      //                                Logger.out.debug(" User's Authorization to update
      // "+sourceObjectName+"_"+site.getId()+" "+isAuthorized);
      //
      //                                if(isAuthorized)
      //                                {
      //                                    i++;
      //                                }
      //                                else
      //                                {
      //                                    list.remove(i);
      //                                }
      //                            }
      //                        }
      //                    }
      //                }
      //            }
      // ---------------------------------

      // Logger.out.debug(" String : " + sqlBuff.toString());
    } catch (HibernateException hibExp) {
      Logger.out.error(hibExp.getMessage(), hibExp);
      throw new DAOException("Error in retrieve " + hibExp.getMessage(), hibExp);
    } catch (Exception exp) {
      Logger.out.error(exp.getMessage(), exp);
      throw new DAOException("Logical Erroe in retrieve method " + exp.getMessage(), exp);
    }
    return list;
  }