예제 #1
0
  /**
   * Method submittal
   *
   * @param ActionMapping mapping
   * @param ActionForm form
   * @param HttpServletRequest request
   * @param HttpServletResponse response
   * @return ActionForward
   * @throws Exception
   */
  public ActionForward submit(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    GpIntegrationForm gpForm = (GpIntegrationForm) form;
    String sessionId = request.getSession().getId();
    HttpSession session = request.getSession();
    ISPYGPIntegrationQueryDTO ispyGPIntegrationQueryDTO =
        createGPIntegrationQueryDTO(gpForm, session);

    // to filter id with time points
    ISPYFindingsFactory findingFactory = new ISPYFindingsFactory();
    try {
      findingFactory.createGPIntegrationSampleIds(ispyGPIntegrationQueryDTO, sessionId);
    } catch (FrameworkException fwe) {
      logger.error(fwe.getMessage());
      fwe.printStackTrace();
    }
    SampleGroup[] sampleGroups = ispyGPIntegrationQueryDTO.getSampleGroups();
    // Now let's check id overlapping problem.
    if (isIdOverlap(sampleGroups)) {
      ActionErrors errors = new ActionErrors();
      errors.add(
          "selectedGroups1",
          new ActionMessage("gov.nih.nci.nautilus.ui.struts.form.groups.intersect.error"));
      this.saveErrors(request, errors);
      return setup(mapping, form, request, response);
    }

    List<List<String>> allStringList = new ArrayList<List<String>>();
    List<String> fileNameList = new ArrayList<String>();
    List<String> idStringList = new ArrayList<String>();
    List<String> reportIdStringList = new ArrayList<String>();

    String gpModule = System.getProperty("gov.nih.nci.caintegrator.gp.modulename");
    String analysisResultName =
        (gpForm.getAnalysisResultName() != null && !gpForm.getAnalysisResultName().equals(""))
            ? (String) gpForm.getAnalysisResultName()
            : "unnamed_task";

    // for sample Id file
    for (SampleGroup sampleGroup : sampleGroups) {
      idStringList.add(getIdsAsDelimitedString(sampleGroup, "\t"));
    }
    allStringList.add(idStringList);
    fileNameList.add("labIdsFile");

    // for reporter id file
    ReporterGroup reporterGroup = ispyGPIntegrationQueryDTO.getReporterGroup();
    if (reporterGroup != null && reporterGroup.size() > 0) {
      reportIdStringList.add(getIdsAsDelimitedString(reporterGroup, "\t"));
      allStringList.add(reportIdStringList);
      fileNameList.add("reproterIdsFile");
    } else {
      reportIdStringList.add("reporter=NONE");
      allStringList.add(reportIdStringList);
      fileNameList.add("reproterIdsFile");
    }
    // For class file
    // makeClassFile(classStringList, sampleGroups);
    // allStringList.add(classStringList);
    // fileNameList.add("ispyClassFile");

    // Now let's write them to files
    List<String> filePathList = new ArrayList<String>();
    writeGPFile(filePathList, allStringList, fileNameList);

    // Now get the R-binary file name:
    String r_fileName = null;
    String a_fileName = null;
    if (ispyGPIntegrationQueryDTO.getArrayPlatformDE().getValueObjectAsArrayPlatformType()
        == ArrayPlatformType.AGILENT) {
      r_fileName = System.getProperty("gov.nih.nci.ispyportal.agilent_data_matrix");
      a_fileName = System.getProperty("gov.nih.nci.ispyportal.agilent_data_annotation");
    } else {
      r_fileName = System.getProperty("gov.nih.nci.ispyportal.cdna_data_matrix");
      a_fileName = System.getProperty("gov.nih.nci.ispyportal.cdna_data_annotation");
    }

    // *** RUN TASK ON THE GP SERVER
    String tid = "209";

    String gpserverURL =
        System.getProperty("gov.nih.nci.caintegrator.gp.server") != null
            ? (String) System.getProperty("gov.nih.nci.caintegrator.gp.server")
            : "localhost:8080"; // default to localhost
    try {
      String ispyUser = (String) session.getAttribute("name");
      String publicUser = System.getProperty("gov.nih.nci.caintegrator.gp.publicuser.name");
      String password = System.getProperty("gov.nih.nci.caintegrator.gp.publicuser.password");

      // Check to see the user is already created otherwise create one.

      GPServer gpServer = null;
      if (ispyUser.equals(publicUser)) {
        String gpUser = (String) session.getAttribute(GenePatternPublicUserPool.PUBLIC_USER_NAME);
        if (gpUser == null) {
          PublicUserPool pool = GenePatternPublicUserPool.getInstance();
          gpUser = pool.borrowPublicUser();
          session.setAttribute(GenePatternPublicUserPool.PUBLIC_USER_NAME, gpUser);
          session.setAttribute(GenePatternPublicUserPool.PUBLIC_USER_POOL, pool);
        }
        ispyUser = gpUser;
      }
      String encryptKey = System.getProperty("gov.nih.nci.caintegrator.gp.desencrypter.key");
      String urlString = EncryptionUtil.encrypt(ispyUser + gpPoolString, encryptKey);
      urlString = URLEncoder.encode(urlString, "UTF-8");
      String ticketString = gpserverURL + "gp?ticket=" + urlString;

      logger.debug(ticketString);
      URL url;
      try {
        url = new java.net.URL(ticketString);
        URLConnection conn = url.openConnection();
        final int size = conn.getContentLength();
        logger.debug(Integer.toString(size));

      } catch (Exception e) {
        logger.error(e.getMessage());
      }
      gpServer = new GPServer(gpserverURL, ispyUser, password);

      // GPServer gpServer = new GPServer(gpserverURL, gpuname, password);
      Parameter[] par = new Parameter[filePathList.size() + 3 + 3];
      int currpos = 1;
      for (int i = 0; i < filePathList.size(); i++) {
        par[i] = new Parameter("input.filename" + currpos++, filePathList.get(i));
      }
      par[--currpos] = new Parameter("project.name", "ispy");

      // r_fileName = "'/usr/local/genepattern/resources/DataMatrix_ISPY_306cDNA_17May07.Rda'";
      par[++currpos] = new Parameter("array.filename", r_fileName);
      par[++currpos] = new Parameter("annotation.filename", a_fileName);

      par[++currpos] = new Parameter("analysis.name", analysisResultName);

      // always just 2
      par[++currpos] = new Parameter("output.cls.file", analysisResultName + ".cls");
      par[++currpos] = new Parameter("output.gct.file", analysisResultName + ".gct");

      // JobResult preprocess = gpServer.runAnalysis(gpModule, par);
      int nowait = gpServer.runAnalysisNoWait(gpModule, par);

      tid = String.valueOf(nowait);
      request.setAttribute("jobId", tid);
      request.setAttribute("gpStatus", "running");
      session.setAttribute("genePatternServer", gpServer);
      request.setAttribute("genePatternURL", ticketString);
      request.getSession().setAttribute("gptid", tid);
      request.getSession().setAttribute("gpUserId", ispyUser);
      request.getSession().setAttribute("ticketString", ticketString);
      GPTask gpTask = new GPTask(tid, analysisResultName, FindingStatus.Running);
      PresentationTierCache _cacheManager = ApplicationFactory.getPresentationTierCache();
      _cacheManager.addNonPersistableToSessionCache(
          request.getSession().getId(), "latestGpTask", (Serializable) gpTask);

    } catch (Exception e) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      e.printStackTrace(pw);
      logger.error(sw.toString());
      logger.error(gpModule + " failed...." + e.getMessage());
      throw new Exception(e.getMessage());
    }
    return mapping.findForward("viewJob");
  }