Package org.cipres.treebase.domain.study

Examples of org.cipres.treebase.domain.study.Submission


    assertTrue("Empty user table.", submitter != null);

    Study s = new Study();
    s.setName(newName);

    Submission sub = getFixture().createSubmission(submitter, s);

    getSubmissionHome().store(sub);

    // force commit immediately, important:
    setComplete();
    endTransaction();

    logger.info("study created: " + s.getName() + "id = " + s.getId());
    logger.info("submission created: " + "id = " + sub.getId());

    onSetUp();

    // 2. add a nexus file:
    // String path = "/12Tx432C.nex"; Failure
    // String path = "/TestNexusFile.nex";
    // String path = "/M12c11.nex";
    String path = "/M1389.nex"; // 17k
    // String path = "/M1001"; //489k
    // String path = "/M999.nx";
    // String path = "/EF1 Spiders.nex";
    // String path = "/wtset.nex";
    // String path = "/multiTrees-label.nex";
    // String path = "/charset-taxset-partition.nex";
    // String path = "/49LBR.PDI-branch-length-continue.nex"; // continuous matrix, provided by
    // Peter M.
    File nexusFile = new File(getClass().getResource(path).toURI());
    Collection<File> files = new ArrayList<File>();
    files.add(nexusFile);

    long t1 = System.currentTimeMillis();
    getSubmissionHome().refresh(sub);
    // sub = (Submission) loadObject(Submission.class, sub.getId());
    s = sub.getStudy();
    assertTrue("Failed to refresh submission.", sub != null);

    getFixture().addNexusFiles(sub, files, null);
    getStudyService().addNexusFiles(s, files);

    // force commit immediately, important:
    setComplete();
    endTransaction();

    long t2 = System.currentTimeMillis();

    logger.info("files added: " + s.getName() + "id = " + s.getId() + " Time =" + (t2 - t1));

    // 3. verify
    String studySQL = "select count(*) from Study where study_id=" + s.getId();
    String subSQL = "select count(*) from Submission where submission_id=" + sub.getId();
    int count = jdbcTemplate.queryForInt(studySQL);
    assertTrue(count == 1);

    count = jdbcTemplate.queryForInt(subSQL);
    assertTrue(count == 1);

    onSetUp();

    // verify clob:
    // Notes: this is important: why?? there are two copies of s in the same session.
    // how???

    Study study2 = (Study) hibernateTemplate.load(Study.class, sub.getStudy().getId());

    // hibernateTemplate.refresh(sub);
    String nexusString = study2.getNexusFiles().values().iterator().next();
    int nexusStringLength = (int) nexusString.length();
    logger.info("test clob: length=" + nexusStringLength + "content = " + nexusString);
    assertTrue(nexusStringLength > 0);

    // 4. delete: delete submission:
    // after add Nexus files, sub is outdated:

    // hibernateTemplate.setFlushMode(HibernateAccessor.FLUSH_COMMIT);

    Submission s2 = (Submission) hibernateTemplate.get(Submission.class, sub.getId());
    t1 = System.currentTimeMillis();
    getFixture().deleteSubmission(s2);
    // getStudyService().deleteStudy(s);
    setComplete();
    endTransaction();
View Full Code Here


    if (logger.isInfoEnabled()) {
      logger.info("\n\t\tRunning Test: " + testName);
    }

    Study s = getTestStudy();
    Submission sub = s.getSubmission();

    // force commit immediately, important:
    setComplete();
    endTransaction();

    logger.info("study found: " + s.getName() + "id = " + s.getId());
    logger.info("submission found: " + "id = " + sub.getId());

    onSetUp();

    // 2. add a nexus file:
    // String path = "/12Tx432C.nex"; Failure
    // String path = "/TestNexusFile.nex";
    // String path = "/M12c11.nex";
    // String path = "/wtset.nex";
    String path = "/charset-taxset-partition.nex";
    // String path = "/49LBR.PDI-branch-length-continue.nex"; // continuous matrix, provided by
    // Peter M.
    File nexusFile = new File(getClass().getResource(path).toURI());
    Collection<File> files = new ArrayList<File>();
    files.add(nexusFile);

    long t1 = System.currentTimeMillis();
    getSubmissionHome().refresh(sub);
    // sub = (Submission) loadObject(Submission.class, sub.getId());
    s = sub.getStudy();
    assertTrue("Failed to refresh submission.", sub != null);

    getFixture().addNexusFiles(sub, files, null);
    getStudyService().addNexusFiles(s, files);

    // force commit immediately, important:
    setComplete();
    endTransaction();

    long t2 = System.currentTimeMillis();

    logger.info("files added: " + s.getName() + "id = " + s.getId() + " Time =" + (t2 - t1));

    onSetUp();

    // 3. verify
    String studySQL = "select count(*) from Study where study_id=" + s.getId();
    String subSQL = "select count(*) from Submission where submission_id=" + sub.getId();
    int count = jdbcTemplate.queryForInt(studySQL);
    assertTrue(count == 1);

    count = jdbcTemplate.queryForInt(subSQL);
    assertTrue(count == 1);

    // verify clob:
    hibernateTemplate.refresh(sub);
    String nexusString = sub.getStudy().getNexusFiles().values().iterator().next();
    int nexusStringLength = (int) nexusString.length();
    logger.info("test clob: length=" + nexusStringLength + "content = " + nexusString);
    assertTrue(nexusStringLength > 0);

    // 4. delete: delete submission:
View Full Code Here

    assertTrue("Empty user table.", submitter != null);

    Study s = new Study();
    s.setName(newName);

    Submission sub = getFixture().createSubmission(submitter, s);

    getSubmissionHome().store(s);

    // force commit immediately, important:
    setComplete();
    endTransaction();

    logger.info("study created: " + s.getName() + "id = " + s.getId());
    logger.info("submission created: " + "id = " + sub.getId());

    onSetUp();

    // 2. add a nexus file:
    // String path = "/TestNexusFile.nex";
    String path = "/M12c11.nex";
    File nexusFile = new File(getClass().getResource(path).toURI());
    Collection<File> files = new ArrayList<File>();
    files.add(nexusFile);

    getSubmissionHome().refresh(sub);
    getFixture().addNexusFiles(sub, files, null);
    getStudyService().addNexusFiles(s, files);

    // force commit immediately, important:
    setComplete();
    endTransaction();

    logger.info("files added: " + s.getName() + "id = " + s.getId());

    onSetUp();

    // 3. verify
    String studySQL = "select count(*) from Study where study_id=" + s.getId();
    String subSQL = "select count(*) from Submission where submission_id=" + sub.getId();
    int count = jdbcTemplate.queryForInt(studySQL);
    assertTrue(count == 1);

    count = jdbcTemplate.queryForInt(subSQL);
    assertTrue(count == 1);

    logger.info(" verified: " + s.getName() + "id = " + s.getId());

    // 4. delete: delete submission:
    // after add Nexus files, sub is outdated:
    hibernateTemplate.refresh(sub);

    getFixture().deleteSubmittedData(sub);

    setComplete();
    endTransaction();

    // 5. verify
    String subTreeSQL = "select count(*) from sub_treeblock where submission_id = "
      + sub.getId();
    String subMatrixSQL = "select count(*) from sub_Matrix where submission_id = "
      + sub.getId();
    String subTaxonLabelSQL = "select count(*) from sub_TaxonLabel where submission_id = "
      + sub.getId();
    count = jdbcTemplate.queryForInt(subTreeSQL);
    assertTrue(count == 0);
    count = jdbcTemplate.queryForInt(subMatrixSQL);
    assertTrue(count == 0);
    count = jdbcTemplate.queryForInt(subTaxonLabelSQL);
View Full Code Here

      logger.info("\n\t\tRunning Test: " + testName);
    }

    // 1. create a new submission:
    Study s = getTestStudy();
    Submission sub = s.getSubmission();

    getFixture().deleteSubmittedData(sub);

    setComplete();
    endTransaction();

    // 5. verify
    String subTreeSQL = "select count(*) from sub_TreeBlock where submission_id = "
      + sub.getId();
    String subMatrixSQL = "select count(*) from sub_Matrix where submission_id = "
      + sub.getId();
    String subTaxonLabelSQL = "select count(*) from sub_TaxonLabel where submission_id = "
      + sub.getId();
    int count = jdbcTemplate.queryForInt(subTreeSQL);
    assertTrue(count == 0);
    count = jdbcTemplate.queryForInt(subMatrixSQL);
    assertTrue(count == 0);
    count = jdbcTemplate.queryForInt(subTaxonLabelSQL);
View Full Code Here

  public void setMatrixDataTypeHome(MatrixDataTypeHome pNewMatrixDataTypeHome) {
    mMatrixDataTypeHome = pNewMatrixDataTypeHome;
  }

  public Submission findSubmissionByID(Long pSubmissionID) {
    Submission sub = getSubmissionHome().findPersistedObjectByID(
      Submission.class,
      pSubmissionID);

    return sub;
  }
View Full Code Here

    long beginTime = System.currentTimeMillis();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("createSubmission(User) - start"); //$NON-NLS-1$
    }

    Submission sub = new Submission();
    if (pSubmitter != null) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(" : new submission created"); //$NON-NLS-1$
      }

      // TODO
      // User pSubmitter might be a detached entity and thus
      // will force an LazyInitializationException() when you access
      // lazy loaded collection submissions
      // Solution reattach the User pSubmitter
      // Jin needs to decide whether getUserHome().update(pSubmitter)
      // is more appropriate
      pSubmitter = getUserHome().merge(pSubmitter);
      // end of fix

      pSubmitter.addSubmission(sub);
    }

    // create a new study. Initialize bi-directional relationships.
    StudyStatus initStatus = getStudyStatusHome().findStatusInProgress();

    if (pStudy == null) {
      pStudy = new Study();
    }
    pStudy.setStudyStatus(initStatus);
    pStudy.setLastModifiedDate(new Date());
    sub.setStudy(pStudy);
    pStudy.setSubmission(sub);

    getSubmissionHome().store(sub);
    getSubmissionHome().flush();

    // default submission number to the unique id.
    sub.setSubmissionNumber("" + sub.getId());
    pStudy.setAccessionNumber("" + pStudy.getId());

    // may not necessary: getSubmissionHome().update();

    if (LOGGER.isDebugEnabled()) {
View Full Code Here

   *
   */
  private NexusDataSet addNexusFile(Submission pSubmission, File pNexusFile) {

    // better to refresh:
    Submission sub = update(pSubmission);

    Study study = sub.getStudy();

    NexusDataSet data = getNexusService().parseNexus(study, pNexusFile);

    if (data != null) {

      long timeStart = System.currentTimeMillis();

      // need to store the taxon labels, don't ask why...
      Collection<TaxonLabel> labels = data.getAllTaxonLabels();
      getTaxonLabelHome().storeAll(labels);
      getTaxonLabelHome().storeAll(data.getTaxonLabelSets());
      sub.addTaxonLabels(labels);
      getTaxonHome().flush();

      sub.getStudy().getTaxonLabelSets().addAll(data.getTaxonLabelSets());

      // Store matrice:
      for (Matrix uploadMatrix : data.getMatrices()) {
        uploadMatrix.setStudy(sub.getStudy());
      }
      getMatrixHome().persistAll(data.getMatrices());
      sub.addMatrices(data.getMatrices());
      getMatrixHome().flush();

      // need to store the trees, don't ask why...
      // List<PhyloTree> alltrees = new ArrayList<PhyloTree>();
      // for (TreeBlock block : data.getTreeBlocks()) {
      // alltrees.addAll(block.getTreeList());
      // }
      // getPhyloTreeHome().storeAll(alltrees);
     
     
      //If there are more than the number of trees in getMaxTreeCount trees in a TreeBlock we need to remove them
      for (TreeBlock treeblock : data.getTreeBlocks()) {
          if (treeblock.getTreeCount() > getMaxTreeCount()) {
            Iterator tree = treeblock.getTreeListIterator();
            int treecount = 1;
           
            while(tree.hasNext()) {
              if (treecount > getMaxTreeCount()) {
                tree.remove();
              }
              tree.next();
              treecount++;
            }
          }
      }
     
      getPhyloTreeHome().storeAll(data.getTreeBlocks());
      sub.addPhyloTreeBlocks(data.getTreeBlocks());
     
     
     
   
      getPhyloTreeHome().flush();
View Full Code Here

      }
      return null;
    }

    // better to refresh:
    Submission sub = update(pSubmission);

    Study study = sub.getStudy();

    NexusDataSet data = getNexusService().parseNexus(study, pNexusFiles, pListener);
    NexusDataSetJDBC dataJDBC = null;

    if (data != null) {

      long timeStart = System.currentTimeMillis();

      // need to store the taxon labels, don't ask why...
      Collection<TaxonLabel> labels = data.getAllTaxonLabels();
      getTaxonLabelHome().storeAll(labels);
      getTaxonLabelHome().storeAll(data.getTaxonLabelSets());
      sub.addTaxonLabels(labels);
      getTaxonHome().flush();

      sub.getStudy().getTaxonLabelSets().addAll(data.getTaxonLabelSets());

      // Store matrice:
      getMatrixHome().persistAll(data.getMatrices());
      sub.addMatrices(data.getMatrices());

      // need to store the trees, don't ask why...
      // List<PhyloTree> alltrees = new ArrayList<PhyloTree>();
      // for (TreeBlock block : data.getTreeBlocks()) {
      // alltrees.addAll(block.getTreeList());
      // }
      // getPhyloTreeHome().storeAll(alltrees);
      getPhyloTreeHome().storeAll(data.getTreeBlocks());

      sub.addPhyloTreeBlocks(data.getTreeBlocks());

      update(sub);

      if (LOGGER.isDebugEnabled()) {
        long timeEnd = System.currentTimeMillis();
View Full Code Here

   *
   * @see org.cipres.treebase.domain.study.SubmissionService#getPermission(java.lang.String,
   *      java.lang.Long)
   */
  public TBPermission getPermission(String pUsername, Long pSubmissionID) {
    Submission sub = findSubmissionByID(pSubmissionID);
    User user = getUserHome().findByUserName(pUsername);

    if (sub == null) {
      return TBPermission.NONE;
    }

    return sub.getPermission(user);
  }
View Full Code Here

  /**
   *
   * @see org.cipres.treebase.domain.study.SubmissionService#updateStudyStatusPublish(java.lang.Long)
   */
  public void updateStudyStatusPublish(Long pSubmissionID) {
    Submission sub = findSubmissionByID(pSubmissionID);

    if (sub == null) {
      throw new IllegalArgumentException(
        "Failed to request publishing a study. The submission is not found:"
          + pSubmissionID);
    }

    Study study = sub.getStudy();

    if (study == null) {
      throw new IllegalArgumentException(
        "Failed to request publishing a study. The study is not found for submission id:"
          + pSubmissionID);
View Full Code Here

TOP

Related Classes of org.cipres.treebase.domain.study.Submission

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.