Esempio n. 1
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;
  }
Esempio n. 2
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;
  }