Package uk.ac.bbsrc.tgac.miso.core.data.impl

Examples of uk.ac.bbsrc.tgac.miso.core.data.impl.SubmissionImpl


  //editSubmission.jsp
  public JSONObject saveSubmission(HttpSession session, JSONObject json) {
    try {
      if (json.has("form") && !json.get("form").equals("")) {
        //creates a new submission object using the form info
        Submission newSubmission = new SubmissionImpl();
        //if editing an existing submission
        if (json.has("submissionId") && json.get("submissionId") != "" && !json.get("submissionId").equals(-1)) {
          //calls up the existing submission with this ID
          Submission oldSubmission = requestManager.getSubmissionById(Long.parseLong(json.getString("submissionId")));
          //sets the details of the new one to match the old.
          newSubmission.setId(oldSubmission.getId());
          newSubmission.setAccession(oldSubmission.getAccession());
          //newSubmission.setAlias(oldSubmission.getAlias());
          newSubmission.setCreationDate(oldSubmission.getCreationDate());
          //newSubmission.setDescription(oldSubmission.getDescription());
          newSubmission.setName(oldSubmission.getName());
          newSubmission.setSubmissionDate(oldSubmission.getSubmissionDate());
          //newSubmission.setTitle(oldSubmission.getTitle());
          newSubmission.setVerified(oldSubmission.isVerified());
          newSubmission.setCompleted(oldSubmission.isCompleted());
        }

        //sets the title, alias and description based on form contents
        JSONArray form = JSONArray.fromObject(json.get("form"));
        Set<SequencerPoolPartition> newPartitions = new HashSet<SequencerPoolPartition>();

        for (JSONObject j : (Iterable<JSONObject>) form) {
          if (j.getString("name").equals("title")) {
            newSubmission.setTitle(j.getString("value"));
          }
          if (j.getString("name").equals("alias")) {
            newSubmission.setAlias(j.getString("value"));
          }
          if (j.getString("name").equals("description")) {
            newSubmission.setDescription(j.getString("value"));
          }

          if (j.getString("name").contains("DIL")) {
            Long dilutionId = Long.parseLong(j.getString("name").replaceAll("\\D+", ""));
            Long partitionId = Long.parseLong(j.getString("value").replaceAll("\\D+", ""));
            //and a new Partition created from the ID
            PartitionImpl newPartition = new PartitionImpl();
            newPartition.setId(partitionId);
            //if the partition is not already in the set of newPartitions:
            if (newPartitions.add(newPartition)) {
              // a new pool is created
              Pool<Dilution> newPool = new PoolImpl<Dilution>();
              //details of the original partition's pool are copied to the new one
              Pool<? extends Poolable> oldPool = requestManager.getSequencerPoolPartitionById(partitionId).getPool();
              newPool.setExperiments(oldPool.getExperiments());
              newPool.setPlatformType(oldPool.getPlatformType());
              //the new pool is added to the partition
              newPartition.setPool(newPool);
            }

            for (SequencerPoolPartition nextPartition : newPartitions) {
              if (nextPartition.getId() == partitionId) {
                //Dilution dilution = requestManager.getDilutionByIdAndPlatform(dilutionId, nextPartition.getPool().getPlatformType());
                Dilution dilution = requestManager.getLibraryDilutionById(dilutionId);
                Pool pool = nextPartition.getPool();
                pool.addPoolableElement(dilution);
              }
            }
          }
        }
        //the set of partitions is added to the new Submission
        for (SequencerPoolPartition sequencerPoolPartition : newPartitions) {
          newSubmission.addSubmissionElement(sequencerPoolPartition);
        }
        //the submission is saved
        requestManager.saveSubmission(newSubmission);
        return JSONUtils.SimpleJSONResponse("Submission " + newSubmission.getId() + " saved!");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      return JSONUtils.SimpleJSONError(e.getMessage());
View Full Code Here


    return submission.getId();
  }

  public SubmissionImpl get(long id) throws IOException {
    List eResults = template.query(SUBMISSION_SELECT_BY_ID, new Object[]{id}, new TgacSubmissionMapper());
    SubmissionImpl e = eResults.size() > 0 ? (SubmissionImpl) eResults.get(0) : null;
    return e;
  }
View Full Code Here

  }

  //sets the values of the new Submission object based on those in the SubmissionMapper
  public class TgacSubmissionMapper implements RowMapper<Submission> {
    public SubmissionImpl mapRow(ResultSet rs, int rowNum) throws SQLException {
      SubmissionImpl t = (SubmissionImpl) dataObjectFactory.getSubmission();
      t.setId(rs.getLong("submissionId"));
      t.setAccession(rs.getString("accession"));
      t.setAlias(rs.getString("alias"));
      t.setCreationDate(rs.getDate("creationDate"));
      t.setDescription(rs.getString("description"));
      t.setName(rs.getString("name"));
      t.setSubmissionDate(rs.getDate("submittedDate"));
      t.setTitle(rs.getString("title"));
      t.setVerified(rs.getBoolean("verified"));
      t.setCompleted(rs.getBoolean("completed"));

      try {
        //process submittables
        for (Study study : studyDAO.listBySubmissionId(rs.getLong("submissionId"))) {
          t.addSubmissionElement(study);
          log.debug(t.getName() + ": added " + study.getName());
        }

        for (Sample sample : sampleDAO.listBySubmissionId(rs.getLong("submissionId"))) {
          t.addSubmissionElement(sample);
          log.debug(t.getName() + ": added " + sample.getName());
        }

        for (SequencerPoolPartition partition : partitionDAO.listBySubmissionId(rs.getLong("submissionId"))) {
          //for each partition, lists all the runs on the flowcell/container
          SequencerPoolPartition newPartition = new PartitionImpl();
          newPartition.setId(partition.getId());
          newPartition.setSequencerPartitionContainer(partition.getSequencerPartitionContainer());
          newPartition.setPartitionNumber(partition.getPartitionNumber());

          Pool<Dilution> newPool = new PoolImpl<Dilution>();
          Pool<? extends Poolable> oldPool = partition.getPool();
          newPool.setId(oldPool.getId());
          newPool.setExperiments(oldPool.getExperiments());

          List<Run> runs = new ArrayList<Run>(runDAO.listBySequencerPartitionContainerId(partition.getSequencerPartitionContainer().getId()));
          //if there is 1 run for the flowcell/container, sets the run for that container to the first on on the list
          if (runs.size() == 1) {
            partition.getSequencerPartitionContainer().setRun(runs.get(0));
          }

          List<Long> dilutionIdList = template.queryForList(SUBMISSION_DILUTION_SELECT, Long.class, new Object[]{rs.getLong("submissionId"), partition.getId()});

          log.debug("dilutionIdList for partition " + partition.getId() + "from DB table:" + dilutionIdList.toString());
          for (Long id : dilutionIdList) {
            Dilution dil = libraryDilutionDAO.getLibraryDilutionByIdAndPlatform(id, partition.getPool().getPlatformType());
            try {
              newPool.addPoolableElement(dil);
            }
            catch (Exception e) {
              e.printStackTrace();
            }
          }
          //adds the new pool to the partition
          newPartition.setPool(newPool);

          //replace any existing experiment-linked pools with the new pool
          for (Experiment experiment : experimentDAO.listBySubmissionId(rs.getLong("submissionId"))) {
            if (experiment.getPool().getId() == newPool.getId()) {
              experiment.setPool(newPool);
              t.addSubmissionElement(experiment);
              log.debug(t.getName() + ": added " + experiment.getName());
              break;
            }
          }

          //adds the partition to the submission
          log.debug("submission " + t.getId() + " new partition " + newPartition.getId() + " contains dilutions " + newPartition.getPool().getDilutions().toString());
          t.addSubmissionElement(newPartition);
        }
      }
      catch (IOException ie) {
        log.warn("Cannot map submission: " + ie.getMessage());
        ie.printStackTrace();
View Full Code Here

TOP

Related Classes of uk.ac.bbsrc.tgac.miso.core.data.impl.SubmissionImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.