/**
   * Grabs the appropriate stuff from a request and returns a list of case_ids
   *
   * @param request
   * @return
   * @throws ProtocolException
   * @throws DaoException
   */
  public static ArrayList<String> getSampleIds(HttpServletRequest request)
      throws ProtocolException, DaoException {
    String samples = request.getParameter(WebService.CASE_LIST);
    String sampleSetId = request.getParameter(WebService.CASE_SET_ID);
    String sampleIdsKey = request.getParameter(WebService.CASE_IDS_KEY);

    if (sampleIdsKey != null) {
      samples = SampleSetUtil.getSampleIds(sampleIdsKey);
    }

    ArrayList<String> sampleList = new ArrayList<String>();
    if (sampleSetId != null && !(sampleSetId.equals("-1"))) {
      DaoSampleList dao = new DaoSampleList();
      SampleList selectedSampleList = dao.getSampleListByStableId(sampleSetId);
      if (selectedSampleList == null) {
        throw new ProtocolException(
            "Invalid " + WebService.CASE_SET_ID + ":  " + sampleSetId + ".");
      }
      sampleList = selectedSampleList.getSampleList();
    } else if (samples != null) {
      for (String _sample : samples.split("[\\s,]+")) {
        _sample = _sample.trim();
        if (_sample.length() == 0) continue;
        sampleList.add(_sample);
      }
    } else if (samples != null) { // todo: this is a hack, samples is just another word for patients
      return new ArrayList(Arrays.asList(samples.split(" ")));
    } else {
      throw new ProtocolException(
          WebService.CASE_SET_ID + " or " + WebService.CASE_LIST + " must be specified.");
    }
    return sampleList;
  }
  /**
   * Given an HttpServletRequest, determine all cancer_study_ids associated with it. cancer study
   * identifiers can be inferred from profile_ids, case_list_ids, or case_ids. this returns the set
   * of ALL POSSIBLE cancer study identifiers
   *
   * @param request
   * @return the cancer_study_ids associated with the request, which will be empty if none can be
   *     determined; or empty set if a problem arises.
   * @throws DaoException
   * @throws ProtocolException
   */
  public static HashSet<String> getCancerStudyIDs(HttpServletRequest request)
      throws DaoException, ProtocolException {

    HashSet<String> cancerStudies = new HashSet<String>();

    // a CANCER_STUDY_ID is explicitly provided, as in getGeneticProfiles, getCaseLists, etc.
    // make sure the cancer_study_id provided in the request points to a real study
    String studyIDstring = getCancerStudyId(request);
    if (studyIDstring != null) {
      if (DaoCancerStudy.doesCancerStudyExistByStableId(studyIDstring)) {
        cancerStudies.add(studyIDstring);
      }

      return cancerStudies;
    }

    // a genetic_profile_id is explicitly provided, as in getProfileData
    if (null != request.getParameter(WebService.GENETIC_PROFILE_ID)) {
      ArrayList<String> geneticProfileIds = getGeneticProfileId(request);
      for (String geneticProfileId : geneticProfileIds) {

        // that's the point of this code??
        //                if (geneticProfileId == null) {
        //                    return cancerStudies;
        //                }

        GeneticProfile aGeneticProfile =
            DaoGeneticProfile.getGeneticProfileByStableId(geneticProfileId);
        if (aGeneticProfile != null
            && DaoCancerStudy.doesCancerStudyExistByInternalId(
                aGeneticProfile.getCancerStudyId())) {
          cancerStudies.add(
              DaoCancerStudy.getCancerStudyByInternalId(aGeneticProfile.getCancerStudyId())
                  .getCancerStudyStableId());
        }
      }

      return cancerStudies;
    }

    // a patient_set_id is explicitly provided, as in getProfileData, getMutationData,
    // getClinicalData, etc.
    String sampleSetId = request.getParameter(WebService.CASE_SET_ID);
    if (sampleSetId != null) {
      DaoSampleList aDaoSampleList = new DaoSampleList();
      SampleList aSampleList = aDaoSampleList.getSampleListByStableId(sampleSetId);

      if (aSampleList != null
          && DaoCancerStudy.doesCancerStudyExistByInternalId(aSampleList.getCancerStudyId())) {
        cancerStudies.add(
            DaoCancerStudy.getCancerStudyByInternalId(aSampleList.getCancerStudyId())
                .getCancerStudyStableId());
      }

      return cancerStudies;
    }

    return cancerStudies;
  }
Exemplo n.º 3
0
  private boolean validate(HttpServletRequest request) throws DaoException {
    String cancerStudyID = request.getParameter(ID);
    if (cancerStudyID == null) {
      cancerStudyID = request.getParameter(QueryBuilder.CANCER_STUDY_ID);
    }

    CancerStudy cancerStudy = DaoCancerStudy.getCancerStudyByStableId(cancerStudyID);
    if (cancerStudy == null) {
      try {
        cancerStudy = DaoCancerStudy.getCancerStudyByInternalId(Integer.parseInt(cancerStudyID));
      } catch (NumberFormatException ex) {
      }
    }
    if (cancerStudy == null) {
      request.setAttribute(ERROR, "No such cancer study");
      return false;
    }
    String cancerStudyIdentifier = cancerStudy.getCancerStudyStableId();

    if (accessControl.isAccessibleCancerStudy(cancerStudyIdentifier).size() != 1) {
      request.setAttribute(
          ERROR,
          "You are not authorized to view the cancer study with id: '"
              + cancerStudyIdentifier
              + "'. ");
      return false;
    } else {
      UserDetails ud = accessControl.getUserDetails();
      if (ud != null) {
        logger.info("CancerStudyView.validate: Query initiated by user: "******"_all";
      request.setAttribute(QueryBuilder.CASE_SET_ID, sampleListId);
    }

    SampleList sampleList = daoSampleList.getSampleListByStableId(sampleListId);
    if (sampleList == null) {
      request.setAttribute(ERROR, "Could not find sample list of '" + sampleListId + "'. ");
      return false;
    }

    request.setAttribute(QueryBuilder.CASE_IDS, sampleList.getSampleList());

    request.setAttribute(CANCER_STUDY, cancerStudy);
    request.setAttribute(QueryBuilder.HTML_TITLE, cancerStudy.getName());
    return true;
  }