Beispiel #1
0
  /**
   * Finds any missing information from the sample object, and fills it in so that DB writeback will
   * be complete.
   *
   * @param sample may or may not have all its data.
   * @throws Exception by called methods.
   */
  private void prepareSampleForWriteback(
      Sample sample, String actorName, Date transactionDate, Session session) throws DAOException {

    handleNonNewSample(sample, session);
    handleCreationTracking(sample, actorName, transactionDate, session);
    handleProjectRelation(sample, sample.getProjectName(), sample.getSampleName(), session);
  }
Beispiel #2
0
 public void update(Sample sample, Date transactionDate, Session session) throws DAOException {
   try {
     if (sample.getModifiedDate() == null) {
       sample.setModifiedDate(transactionDate);
     }
     session.merge(sample);
   } catch (Exception ex) {
     throw new DAOException(ex);
   }
 }
Beispiel #3
0
 private void handleNonNewSample(Sample sample, Session session) throws DAOException {
   // See: any old sample by same name, and in same project?  Then throw exception.
   Criteria crit = session.createCriteria(Sample.class);
   String sampleName = sample.getSampleName();
   crit.add(Restrictions.eq("sampleName", sampleName));
   crit.add(Restrictions.eq("projectId", sample.getProjectId()));
   List results = crit.list();
   if (results != null && results.size() > 0) {
     throw new DAOException(
         "Do not call writeback loop with an existing sample.  Sample "
             + sampleName
             + " is in the database.");
   }
 }
Beispiel #4
0
  private Sample feedSampleData(Sample sample) throws Exception {
    sample.setProjectId(projectId);
    sample.setProjectName(projectName);

    // set project level by adding 1 to selected parent project's level
    if (sample.getParentSampleName() == null || sample.getParentSampleName().equals("0"))
      sample.setParentSampleName(null);

    String parentSampleName = sample.getParentSampleName();
    if (parentSampleName != null && !parentSampleName.isEmpty() && !parentSampleName.equals("0")) {
      Sample selectedParentSample = readPersister.getSample(projectId, parentSampleName);
      sample.setSampleLevel(selectedParentSample.getSampleLevel() + 1);
    } else {
      sample.setParentSampleId(null);
      sample.setSampleLevel(1);
    }

    return sample;
  }
Beispiel #5
0
  private MultiLoadParameter createMultiLoadParameter(
      String projectName, Project project, Sample sample, List<FileReadAttributeBean> frab)
      throws Exception {

    MultiLoadParameter loadParameter = new MultiLoadParameter();
    boolean isSampleRegistration = false;
    boolean isProjectRegistration = false;

    if (this.eventName.equals(Constants.EVENT_PROJECT_REGISTRATION)
        && project.getProjectName() != null
        && !project.getProjectName().isEmpty()) {
      isProjectRegistration = true;

      List<Project> projectList = new ArrayList<Project>();
      projectList.add(feedProjectData(project));
      loadParameter.addProjects(projectList);

      /*
       *   loads all event meta attributes from the parent
       *   by hkim 6/11/13
       */
      List<EventMetaAttribute> emas =
          this.readPersister.getEventMetaAttributes(
              projectName, null); // , Constants.EVENT_PROJECT_REGISTRATION);
      if (emas != null && emas.size() > 0) {
        List<EventMetaAttribute> newEmas = new ArrayList<EventMetaAttribute>(emas.size());

        for (EventMetaAttribute ema : emas) {
          EventMetaAttribute newEma = new EventMetaAttribute();
          newEma.setProjectName(project.getProjectName());
          newEma.setEventName(ema.getEventName());
          newEma.setEventTypeLookupId(ema.getEventTypeLookupId());
          newEma.setAttributeName(ema.getAttributeName());
          newEma.setNameLookupId(ema.getNameLookupId());
          newEma.setActive(ema.isActive());
          newEma.setRequired(ema.isRequired());
          newEma.setDesc(ema.getDesc());
          newEma.setDataType(ema.getDataType());
          newEma.setLabel(ema.getLabel());
          newEma.setOntology(ema.getOntology());
          newEma.setOptions(ema.getOptions());
          newEma.setSampleRequired(ema.isSampleRequired());
          newEmas.add(newEma);
        }
        loadParameter.addEventMetaAttributes(newEmas);
      } else {
        throw new Exception(
            String.format(
                "Event Metadata has not been set up for the parent project and the '%s' event type.",
                Constants.EVENT_PROJECT_REGISTRATION));
      }

      List<SampleMetaAttribute> smas = this.readPersister.getSampleMetaAttributes(projectId);
      if (smas != null && smas.size() > 0) {
        List<SampleMetaAttribute> newSmas = new ArrayList<SampleMetaAttribute>(smas.size());
        for (SampleMetaAttribute sma : smas) {
          SampleMetaAttribute newSma = new SampleMetaAttribute();
          newSma.setProjectName(project.getProjectName());
          newSma.setAttributeName(sma.getAttributeName());
          newSma.setNameLookupId(sma.getNameLookupId());
          newSma.setDataType(sma.getDataType());
          newSma.setDesc(sma.getDesc());
          newSma.setLabel(sma.getLabel());
          newSma.setOntology(sma.getOntology());
          newSma.setOptions(sma.getOptions());
          newSma.setRequired(sma.isRequired());
          newSma.setActive(sma.isActive());
          newSmas.add(newSma);
        }
        loadParameter.addSampleMetaAttributes(newSmas);
      }

      List<ProjectMetaAttribute> pmas = this.readPersister.getProjectMetaAttributes(projectName);
      if (pmas != null && pmas.size() > 0) {
        List<ProjectMetaAttribute> newPmas = new ArrayList<ProjectMetaAttribute>(pmas.size());
        for (ProjectMetaAttribute pma : pmas) {
          ProjectMetaAttribute newPma = new ProjectMetaAttribute();
          newPma.setProjectName(project.getProjectName());
          newPma.setAttributeName(pma.getAttributeName());
          newPma.setDataType(pma.getDataType());
          newPma.setDesc(pma.getDesc());
          newPma.setLabel(pma.getLabel());
          newPma.setNameLookupId(pma.getNameLookupId());
          newPma.setOntology(pma.getOntology());
          newPma.setOptions(pma.getOptions());
          newPma.setRequired(pma.isRequired());
          newPma.setActive(pma.isActive());
          newPmas.add(newPma);
        }
        loadParameter.addProjectMetaAttributes(newPmas);
      }
    } else if (this.eventName.equals(Constants.EVENT_SAMPLE_REGISTRATION)
        && sample.getSampleName() != null
        && !sample.getSampleName().isEmpty()) {
      isSampleRegistration = true;

      List<Sample> sampleList = new ArrayList<Sample>();
      sampleList.add(feedSampleData(sample));
      loadParameter.addSamples(sampleList);
    }

    List<FileReadAttributeBean> loadingList = null;
    if (frab != null && frab.size() > 0) {
      loadingList =
          processFileReadBeans(
              isProjectRegistration ? project.getProjectName() : projectName,
              isSampleRegistration ? sample.getSampleName() : this.sampleName,
              frab);
    }
    if (loadingList != null && loadingList.size() > 0) {
      if (isProjectRegistration) {
        loadParameter.addProjectRegistrations(Constants.EVENT_PROJECT_REGISTRATION, loadingList);
      } else if (isSampleRegistration) {
        loadParameter.addSampleRegistrations(Constants.EVENT_SAMPLE_REGISTRATION, loadingList);
      } else {
        loadParameter.addEvents(this.eventName, loadingList);
      }
    }
    return loadParameter;
  }
Beispiel #6
0
  public String execute() {
    String rtnVal = SUCCESS;
    UserTransaction tx = null;

    try {
      sampleName = sampleName != null && sampleName.equals("0") ? null : sampleName;

      if (jobType != null) {
        boolean isProjectRegistration = eventName.equals(Constants.EVENT_PROJECT_REGISTRATION);
        boolean isSampleRegistration = eventName.equals(Constants.EVENT_SAMPLE_REGISTRATION);

        if (projectName == null
            || projectName.equals("0")
            || eventName == null
            || eventName.equals("0")) throw new Exception("Project or Event type is not selected.");

        if (jobType.equals("insert")) { // loads single event
          tx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
          tx.begin();
          psewt.loadAll(
              null,
              this.createMultiLoadParameter(projectName, loadingProject, loadingSample, beanList));
          this.reset();
        } else if (jobType.equals("grid")) { // loads multiple events from grid view
          tx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
          tx.begin();
          for (GridBean gBean : gridList) {
            if (gBean != null) {
              if (isProjectRegistration
                  && gBean.getProjectName() != null
                  && gBean.getProjectPublic() != null) {
                loadingProject = new Project();
                loadingProject.setProjectName(gBean.getProjectName());
                loadingProject.setIsPublic(Integer.valueOf(gBean.getProjectPublic()));
              } else if (isSampleRegistration
                  && gBean.getSampleName() != null
                  && gBean.getSamplePublic() != null) {
                loadingSample = new Sample();
                loadingSample.setSampleName(gBean.getSampleName());
                loadingSample.setParentSampleName(gBean.getParentSampleName());
                loadingSample.setIsPublic(Integer.valueOf(gBean.getSamplePublic()));
              } else {
                if (gBean.getSampleName() != null) {
                  this.sampleName = gBean.getSampleName();
                }
              }
              List<FileReadAttributeBean> fBeanList = gBean.getBeanList();
              if (fBeanList != null && fBeanList.size() > 0) {
                psewt.loadAll(
                    null,
                    this.createMultiLoadParameter(
                        projectName, loadingProject, loadingSample, fBeanList));
              }
            }
          }
          this.reset();

        } else if (jobType.equals("file")) { // loads data from a CSV file to grid view
          if (!this.uploadFile.canRead()) {
            throw new Exception("Error in reading the file.");
          } else {
            try {
              CSVReader reader = new CSVReader(new FileReader(this.uploadFile));

              int lineCount = 0;
              List<String> columns = new ArrayList<String>();

              String currProjectName = null;

              gridList = new ArrayList<GridBean>();
              boolean hasSampleName = false;
              String[] line;
              while ((line = reader.readNext()) != null) {
                if (lineCount != 1) {
                  if (lineCount == 0) {
                    Collections.addAll(columns, line);
                    hasSampleName = columns.indexOf("SampleName") >= 0;
                  } else {
                    int colIndex = 0;

                    currProjectName = line[colIndex++];
                    if (!isProjectRegistration && !currProjectName.equals(this.projectName)) {
                      throw new Exception(MULTIPLE_SUBJECT_IN_FILE_MESSAGE);
                    }

                    GridBean gBean = new GridBean();
                    gBean.setProjectName(currProjectName);

                    if (hasSampleName) {
                      gBean.setSampleName(line[(colIndex++)]);
                    }

                    if (isProjectRegistration) {
                      gBean.setProjectName(currProjectName);
                      gBean.setProjectPublic(line[(colIndex++)]);
                    } else if (isSampleRegistration) {
                      gBean.setParentSampleName(line[(colIndex++)]);
                      gBean.setSamplePublic(line[(colIndex++)]);
                    }

                    gBean.setBeanList(new ArrayList<FileReadAttributeBean>());
                    for (; colIndex < columns.size(); colIndex++) {
                      FileReadAttributeBean fBean = new FileReadAttributeBean();
                      fBean.setProjectName(
                          isProjectRegistration ? currProjectName : this.projectName);
                      fBean.setAttributeName(columns.get(colIndex));
                      fBean.setAttributeValue(line[colIndex]);
                      gBean.getBeanList().add(fBean);
                    }
                    this.gridList.add(gBean);
                  }
                }
                lineCount++;
              }
              jobType = "grid";
            } catch (Exception ex) {
              throw ex;
            }
          }
        } else if (jobType.equals("template")) { // download template
          List<EventMetaAttribute> emaList =
              readPersister.getEventMetaAttributes(projectName, eventName);

          /*
           * removing the sanity check on sample requirement since multiple sample support is in action
           * by hkim 5/2/13
          ModelValidator validator = new ModelValidator();
          validator.validateEventTemplateSanity(emaList, projectName, sampleName, eventName);
          */

          TemplatePreProcessingUtils cvsUtils = new TemplatePreProcessingUtils();
          String templateType = jobType.substring(jobType.indexOf("_") + 1);
          downloadStream =
              cvsUtils.buildFileContent(templateType, emaList, projectName, sampleName, eventName);
          downloadContentType = templateType.equals("c") ? "csv" : "vnd.ms-excel";
          rtnVal = Constants.FILE_DOWNLOAD_MSG;
        }
      }

    } catch (Exception ex) {
      logger.error("Exception in EventLoader : " + ex.toString());
      ex.printStackTrace();
      if (ex.getClass() == ForbiddenResourceException.class) {
        addActionError(Constants.DENIED_USER_EDIT_MESSAGE);
        return Constants.FORBIDDEN_ACTION_RESPONSE;
      } else if (ex.getClass() == ForbiddenResourceException.class) {
        addActionError(Constants.DENIED_USER_EDIT_MESSAGE);
        return LOGIN;
      } else if (ex.getClass() == ParseException.class)
        addActionError(Constants.INVALID_DATE_MESSAGE);
      else {
        addActionError(ex.toString());
      }

      // deletes uploaded files in event of error
      if (loadedFiles != null && loadedFiles.size() > 0) {
        for (String filePath : loadedFiles) {
          File tempFile = new File(fileStoragePath + filePath);
          if (tempFile.exists()) tempFile.delete();
        }
      }

      try {
        if (tx != null) tx.rollback();
      } catch (SystemException se) {
        addActionError(se.toString());
      }

      rtnVal = ERROR;
    } finally {
      try {
        // get project list for the drop down box
        List<String> projectNameList = new ArrayList<String>();
        if (projectNames == null || projectNames.equals("")) {
          projectNameList.add("ALL");
        } else if (projectNames.contains(",")) {
          projectNameList.addAll(Arrays.asList(projectNames.split(",")));
        } else {
          projectNameList.add(projectNames);
        }
        projectList = readPersister.getProjects(projectNameList);

        if (tx != null && tx.getStatus() != Status.STATUS_NO_TRANSACTION) {
          tx.commit();
        }

        if (jobType != null && jobType.equals("grid") && this.uploadFile != null) {
          this.uploadFile.delete();
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }

    return rtnVal;
  }