Package org.cipres.treebase.domain.study

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


    long study_id = ControllerUtil.getStudyId(request);
    Long submissionId = null;

    Study study = getStudyService().findByID(study_id);
    if (study != null) {
      Submission sub = study.getSubmission();
      if (sub != null) {
        submissionId = sub.getId();
      }
    }

    // FIXME: move the method to studyService, handle the case study w/o submission
    TBPermission perm = getSubmissionService().getPermission(username, submissionId);
View Full Code Here


 
    }

    public ModelAndView GetRecord( OAIPMHCommand params, Map model){
     
      Submission submission = null
     
      try{
         long id = IdentifyUtil.parseID(params);
           submission = studyService.findByID(id).getSubmission();
      }catch(NumberFormatException nfe){
View Full Code Here

     
    }
   
    public ModelAndView ListMetadataFormats(OAIPMHCommand params, Map model){
   
      Submission submission = null
     
      try{
         long id = IdentifyUtil.parseID(params);
           submission = studyService.findByID(id).getSubmission();
      }catch(NumberFormatException nfe){
View Full Code Here

    if (LOGGER.isInfoEnabled()) {
      LOGGER.info("In FormbackingObject");
    }

    Study study = ControllerUtil.findStudy(request, mStudyService);
    Submission submission = (Submission) study.getSubmission();

    AnalyzedDataCommand command = new AnalyzedDataCommand();
    String analysis_step_id = ServletRequestUtils.getStringParameter(
      request,
      "analysis_step_id",
      null);
    if (TreebaseUtil.isEmpty(analysis_step_id)) {
      return command;
    }
    command.setStep(analysis_step_id);

    // retrieve list of matrix IDs user has previously selected and store in them for lookup
    AnalysisStep analysisStep = mAnalysisStepService.findByID(Long.parseLong(analysis_step_id));
    List<AnalyzedData> selectedData = analysisStep.getDataSetReadOnly();
    Map<Long, Boolean> selectedMatrices = new HashMap<Long, Boolean>();
    Map<Long, Boolean> selectedTrees = new HashMap<Long, Boolean>();
    Map<Long, Boolean> selectedTreeBlocks = new HashMap<Long,Boolean>();
    Map<Long, Boolean> incompleteTreeBlocks = new HashMap<Long,Boolean>();

    for (AnalyzedData data : selectedData) {
      if (data instanceof AnalyzedMatrix) {
        AnalyzedMatrix analyzedMatrix = (AnalyzedMatrix) data;
        selectedMatrices.put(analyzedMatrix.getMatrix().getId(), analyzedMatrix
          .isInputData());
      } else if (data instanceof AnalyzedTree) {
        AnalyzedTree analyzedTree = (AnalyzedTree) data;
        selectedTrees.put(analyzedTree.getTree().getId(), analyzedTree.isInputData());
        TreeBlock treeBlock = analyzedTree.getTree().getTreeBlock();
        Long tbID = treeBlock.getId();
        if ( ! selectedTreeBlocks.containsKey(tbID) && ! incompleteTreeBlocks.containsKey(tbID) ) {
          int seen = 0;
          for ( AnalyzedData innerData : selectedData ) {
            if ( innerData instanceof AnalyzedTree ) {             
              Iterator<PhyloTree> treeIterator = treeBlock.getTreeListIterator();
              FIND: while (treeIterator.hasNext()) {
                PhyloTree treeInBlock = treeIterator.next();
                if ( treeInBlock.getId() == ((AnalyzedTree)innerData).getTree().getId() ) {
                  seen++;
                  break FIND;
                }
              }
            }
          }
          if ( seen == treeBlock.getTreeCount() ) {
            selectedTreeBlocks.put(tbID, true);
          }
          else {
            incompleteTreeBlocks.put(tbID, true);
          }
        }
      }
    }
    // get list of all the matrices and set check = true if it's already been selected
    List<EditFieldCommand> matrixList = new ArrayList<EditFieldCommand>();
    Collection<Matrix> matrices = submission.getSubmittedMatricesReadOnly();
    for (Matrix matrix : matrices) {
      Long id = matrix.getId();
      String selected = new String();
      if (selectedMatrices.containsKey(id)) {
        selected = selectedMatrices.get(id)
          ? (Constants.INPUT_KEY)
          : (Constants.OUTPUT_KEY);
      }
      EditFieldCommand editFieldCommand = new EditFieldCommand(matrix, selected);
      matrixList.add(editFieldCommand);
    }
    command.setMatrixList(matrixList);

    // do the same for trees
    // Iterator<PhyloTree> trees = submission.getTreeIterator();
    List<EditFieldCommand> treeList = new ArrayList<EditFieldCommand>();
    Collection<PhyloTree> trees = submission.getAllSubmittedTrees();
    for (PhyloTree tree : trees) {
      Long id = tree.getId();
      String selected = new String();
      if (selectedTrees.containsKey(id)) {
        selected = selectedTrees.get(id) ? (Constants.INPUT_KEY) : (Constants.OUTPUT_KEY);
      }
      EditFieldCommand editFieldCommand = new EditFieldCommand(tree, selected);
      treeList.add(editFieldCommand);
    }
    command.setTreeList(treeList);
   
    List<EditFieldCommand> treeBlockList = new ArrayList<EditFieldCommand>();
    Collection<TreeBlock> treeBlocks = submission.getSubmittedTreeBlocksReadOnly();
    for (TreeBlock treeBlock : treeBlocks) {
      Long id = treeBlock.getId();
      String selected = new String();
      if ( selectedTreeBlocks.containsKey(id)) {
        selected = selectedTreeBlocks.get(id) ? (Constants.INPUT_KEY) : (Constants.OUTPUT_KEY);
View Full Code Here

    }

    /* pass List<File> to service layer */
    // get user's Submission Object
    Study study = ControllerUtil.findStudy(request, mStudyService);
    Submission submission = study.getSubmission();
    MyProgressionListener listener = new MyProgressionListener();

    UploadFileResult uploadResult = getSubmissionService().addNexusFilesJDBC(
      submission,
      files,
View Full Code Here

    {
      warn("  Removing matrices and trees from pseudosubmissions");
//      Transaction t2 = getSession().beginTransaction();
      for (Matrix m : matrices.values()) {
        // Detach this matrix from the pseudosubmission it was temporarily attached to
        Submission pseudoSubmission = ContextManager.getSubmissionService().findByMatrix(m);
        if (pseudoSubmission != null) {
          warn("    Removing matrix " + m.getId());
          pseudoSubmission.removeMatrix(m);
          ContextManager.getSubmissionService().save(pseudoSubmission);
        }
        flush();
      }
      for (PhyloTree t : trees.values()) {
        // Detach this tree from the pseudosubmission it was temporarily attached to
        TreeBlock tb = t.getTreeBlock();
        if (tb != null) {
          warn("    Removing tree " + t.getId());
          tb.removePhyloTree(t);
          ContextManager.getPhyloTreeService().save(tb);
        }
        flush();
      }
//      t2.commit();
    }
   
//    Transaction t = getSession().beginTransaction();

    Study theStudy = aux.study(ContextManager.getStudyService());
    if (theStudy == null) {
      theStudy = new Study();
      ContextManager.getSubmissionService().createSubmission(null, theStudy);
    }
    theStudy.setTB1StudyID(study_id);
    theStudy.setAccessionNumber(study_id);
    theStudy.setStudyStatus(ContextManager.getStudyStatusHome().findStatusPublished());
    ContextManager.getStudyService().save(theStudy);
   
    Submission theSubmission = theStudy.getSubmission();
    ContextManager.getSubmissionService().save(theSubmission);

    Citation theCitation = theStudy.getCitation();
    if (theCitation == null) {
      theCitation = ContextManager.getCitationService().createCitation("TB1");
      theCitation.setStudy(theStudy);
      theStudy.setCitation(theCitation);
      ContextManager.getStudyService().save(theStudy);
    }
   
    { // Truncate extremely long abstracts
      String theAbstract = aux.getString(null, "abstract");
      if (theAbstract.length() > citationMaxLength - 4) {
        theAbstract = theAbstract.substring(0, citationMaxLength - 4) + "...";
      }
      theCitation.setAbstract(theAbstract);
    }
    // this next isn't quite right, because TB1 "citation" contains title, author, publisher, etc.
    // nothing to be done here, I think.  20080229 MJD
    // We can postprocess the citation data with Perl or something
    // to break it up into its component parts. 20080605 MJD
    // Piel says that Rod Page already did this. 20080702 MJD

    // Rutger has a program in util.CitationDataImporter that should do it 20090220 MJD
    {
      String citation = aux.getString(null, "citation");
      if (citation.length() > 250) {
        // It won't all fit into the "title" field of the database
        citation = citation.substring(0, 250); // XXX
      }
      theCitation.setTitle(citation); // XXX
   
    ContextManager.getCitationService().save(theCitation);
 
    // Create or link authors
    for (ValueSection a : aux.getSections("AUTHOR")) {
      Person theAuthor = new Person();
      theAuthor.setFirstName(a.getsval("first_name"));
      theAuthor.setLastName(a.getsval("last_name"));
      theAuthor.setMiddleName("");
//      ContextManager.getPersonService().save(theAuthor);
      // TB1 "author_id" ??
      Person oldAuthor = ContextManager.getPersonService().findByExactMatch(theAuthor);
      if (oldAuthor != null) {
        theAuthor = oldAuthor;
      } else {
        ContextManager.getPersonService().createPerson(theAuthor);
        theAuthor = ContextManager.getPersonService().findByExactMatch(theAuthor);
      }

      String oldEmail = theAuthor.getEmailAddressString();
      if (oldEmail == null || oldEmail.equals("")) {
        theAuthor.setEmailAddressString(a.getsval("email"));
     

      ContextManager.getPersonService().save(theAuthor);
      theCitation.addAuthor(theAuthor);
    }
    ContextManager.getCitationHome().flush();
    ContextManager.getCitationService().save(theCitation);

    // TODO: submission.setSubmitter
    theSubmission.setTest(isForTesting() ? 0 : 1);

    {
      Date creationDate = aux.getCreationDate();
      if (creationDate != null) {
        theSubmission.setCreateDate(creationDate);
      } else {
        warn("  Couldn't find creation date");
      }
    }

    for (ValueAnalysisSection an : aux.getAnalysisSections()) {
      Analysis theAnalysis = new Analysis();
      theAnalysis.setStudy(theStudy);
      theAnalysis.setName(an.getString("analysis_name"));
     
      // TODO: TB_ANALYSISID

      AnalysisStep theAnalysisStep = new AnalysisStep();
      theAnalysisStep.setAnalysis(theAnalysis);
      theAnalysis.addAnalysisStep(theAnalysisStep);
      ContextManager.getAnalysisService().save(theAnalysis);
      ContextManager.getAnalysisStepService().save(theAnalysisStep);
     
      Algorithm theAlgorithm;
      String tb1Algorithm = an.getString("algorithm");
      if (tb1Algorithm.equalsIgnoreCase("parsimony")) {
        theAlgorithm = new ParsimonyAlgorithm();
      } else if (tb1Algorithm.equalsIgnoreCase("bayesian")) {
        theAlgorithm = new BayesianAlgorithm();
      } else if (tb1Algorithm.equalsIgnoreCase("evolution")) {
        theAlgorithm = new EvolutionAlgorithm();
      } else if (tb1Algorithm.equalsIgnoreCase("joining")) {
        theAlgorithm = new JoiningAlgorithm();
      } else if (tb1Algorithm.equalsIgnoreCase("UPGMA")) {
        theAlgorithm = new UPGMAAlgorithm();
      } else if (tb1Algorithm.equalsIgnoreCase("likelihood")) {
        theAlgorithm = new LikelihoodAlgorithm();
      } else {
        theAlgorithm = new OtherAlgorithm()
      }
      theAlgorithm.setDescription(tb1Algorithm);
      ContextManager.getAlgorithmHome().save(theAlgorithm);
      theAnalysisStep.setAlgorithmInfo(theAlgorithm);
     
      { // handle INPUT_MATRIX and OUTPUT_TREE in each ANALYSIS section
        TreeBlock theTreeBlock = null;
        for (ValueSection ioSection : an.getIOSections()) {
          AnalyzedData theData;
          if (ioSection.label.equals("INPUT_MATRIX")) {
            AnalyzedMatrix theMatrix = new AnalyzedMatrix();
            theMatrix.setInput(true);
            String matrixID = ioSection.getsval("matrix_id");
           
            Matrix matrixData = matrices.get(matrixID);
                 
            if (matrixData == null) {
              warn("Matrix " + matrixID + "is used in analysis " + an.getString("analysis_id") + " but is not listed in any MATRIX section for its study");
              return new ValueNone();
            }

            matrixData.setStudy(theStudy);
            ContextManager.getTaxonLabelService().updateStudyForAllLabels(matrixData, theStudy);
            matrixData.setTB1MatrixID(matrixID);
            ContextManager.getMatrixService().save(matrixData);
            theSubmission.addMatrixIfNecessary(matrixData);
            ContextManager.getSubmissionService().save(theSubmission);
            theMatrix.setMatrix(matrixData);
            theData = theMatrix;
          } else if (ioSection.label.equals("OUTPUT_TREE")) {
         
            if (theTreeBlock == null) {
              theTreeBlock = new TreeBlock();
              ContextManager.getStudyService().save(theTreeBlock); // XXX should be some treeblock-specific service
              theSubmission.addPhyloTreeBlock(theTreeBlock);
              ContextManager.getSubmissionService().save(theSubmission);
            }     
           
            AnalyzedTree theTree = new AnalyzedTree();
            theTree.setInput(false);
            String treeID = ioSection.getsval("tree_id");
            PhyloTree treeData = trees.get(treeID);

            treeData.setStudy(theStudy);
            ContextManager.getTaxonLabelService().updateStudyForAllLabels(treeData, theStudy);
            treeData.setTB1TreeID(treeID);
            ContextManager.getPhyloTreeService().save(treeData);
            theTreeBlock.addPhyloTree(treeData);
            theSubmission.addPhyloTreeBlockIfNecessary(theTreeBlock);
            ContextManager.getSubmissionService().save(theSubmission);
            theTree.setTree(treeData);
            theData = theTree;
          } else {
            throw new Error("Unknown IO section '" + ioSection.label + "' in study " + aux.getString(null, "study_id"));
View Full Code Here

    String fileName = "wtset.nex";   
    long studyId = 100L;
    logger.info("study id: " + studyId);
    assertTrue(studyId > 0);
    Study s = (Study) hibernateTemplate.get(Study.class, studyId);
    Submission sub = s.getSubmission();
    if (fileName == null) {
      fileName = s.getNexusFiles().keySet().iterator().next();
    }
    logger.info("study found: " + s.getName() + "id = " + s.getId() + " fileName=" + fileName);
    logger.info("submission found: " + "id = " + sub.getId());

    // 2. test:
    long t1 = System.currentTimeMillis();
    assertTrue("Failed to refresh submission.", sub != null);
    String nexus = getFixture().generateReconstructedNexusFile(sub.getId(), fileName);
    assertTrue("empty nexus content", nexus != null);   
    long t2 = System.currentTimeMillis();
    logger.info("file generated: " + fileName + " Time =" + (t2 - t1));

    // 3. verify
View Full Code Here

  //Uncommenting the commitTransaction() call does not help much,
  //since then all trees and files are bundled into a huge transaction,
  //where a single failure scraps uploads of all prior trees and files (but not matrices!)
  public Study addFilesSimple(List<File> files, User aUser, Session session) throws IOException {
    //Transaction t = session.beginTransaction();
    Submission sub = getPseudoSubmission();
    Study study = sub.getStudy();
   
    log("submission ID = " + sub.getId() + " study ID " + study.getId());

    UploadFileResult uploadResult = ContextManager.getSubmissionService().addNexusFilesJDBC(sub, files, null);
//    commitTransaction();
    log("added " + uploadResult.getMatrixCount() + " matrices and " + uploadResult.getTreeCount() + " trees.");
View Full Code Here

    return study;
  }
 
  //VG 2010-02-18 This fixes the deficiency of addFilesSimple by committing each file upload.
  public Study addFilesOneByOne(List<File> files, User aUser) throws IOException {
    Submission sub = getPseudoSubmission();
    Study study = sub.getStudy();   
    log("submission ID = " + sub.getId() + " study ID " + study.getId());

    int countMatrices = 0, countTrees = 0;
    for (File f : files) {
      beginTransaction();
      List<File> theFile = new LinkedList<File> ();
View Full Code Here

  /**
   *
   * @see org.cipres.treebase.domain.study.SubmissionHome#findBySubmissionNumber(java.lang.String)
   */
  public Submission findBySubmissionNumber(String pSubmissionNumber) {
    Submission returnVal = null;

    if (!TreebaseUtil.isEmpty(pSubmissionNumber)) {
      Criteria c = getSession().createCriteria(Submission.class);
      c.add(Expression.eq("submissionNumber", pSubmissionNumber));

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.