Exemplo n.º 1
0
  /**
   * Returns the ID of ONE of the groups the user is a member of. If the user is an administrator,
   * the ID of the "administrators" group is returned. If the user is not a member of any group, 0
   * is returned
   *
   * @param user
   * @return
   * @throws SQLException
   */
  public static int getOneGroupId(User user) throws SQLException {

    Groups groups = Groups.getInstance();

    // If the user is an administrator return the ID of the administrators group
    if (groups.isMember(user.getResearcher().getID(), "administrators"))
      return groups.getGroupID("administrators");

    // Otherwise get a list of groups that this user is a member of.  Returns the
    // ID of the first group.
    List<String> groupMemberships = groups.getUserGroups(user.getResearcher().getID());
    if (groupMemberships != null && groupMemberships.size() > 0)
      return groups.getGroupID(groupMemberships.get(0));

    // If the user is not a member of any group return 0
    return 0;
  }
Exemplo n.º 2
0
  public static List<Integer> getAllGroupIds(User user) throws SQLException {

    Groups groups = Groups.getInstance();

    List<Integer> groupIds = new ArrayList<Integer>();

    // Get a list of groups that this user is a member of.
    List<String> groupMemberships = groups.getUserGroups(user.getResearcher().getID());
    if (groupMemberships != null && groupMemberships.size() > 0)
      groupIds.add(groups.getGroupID(groupMemberships.get(0)));

    return groupIds;
  }
Exemplo n.º 3
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    // The protein we're viewing
    int proteinID;

    // User making this request
    User user = UserUtils.getUser(request);
    if (user == null) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.login.notloggedin"));
      saveErrors(request, errors);
      return mapping.findForward("authenticate");
    }

    NRProtein protein = null;
    try {
      String strID = request.getParameter("id");

      if (strID == null || strID.equals("")) {
        ActionErrors errors = new ActionErrors();
        errors.add("protein", new ActionMessage("error.protein.invalidid"));
        saveErrors(request, errors);
        return mapping.findForward("Failure");
      }

      proteinID = Integer.parseInt(strID);

      // Load our protein
      NRProteinFactory nrpf = NRProteinFactory.getInstance();
      protein = (NRProtein) (nrpf.getProtein(proteinID));

      // Abundance information. Only for yeast
      // Ghaemmaghami, et al., Nature 425, 737-741 (2003)
      if (protein.getSpecies().getId() == TaxonomyUtils.SACCHAROMYCES_CEREVISIAE) {
        List<YeastOrfAbundance> abundances =
            ProteinAbundanceDao.getInstance().getAbundance(protein.getId());
        if (abundances == null || abundances.size() == 0)
          request.setAttribute("proteinAbundance", "NOT AVAILABLE");
        else {
          if (abundances.size() == 1) {
            request.setAttribute("proteinAbundance", abundances.get(0).getAbundanceString());
          } else {
            String aString = "";
            for (YeastOrfAbundance a : abundances) {
              aString += ", " + a.getAbundanceAndOrfNameString();
            }
            aString = aString.substring(1);
            request.setAttribute("proteinAbundance", aString);
          }
        }
      }

    } catch (NumberFormatException nfe) {
      ActionErrors errors = new ActionErrors();
      errors.add("protein", new ActionMessage("error.project.invalidid"));
      saveErrors(request, errors);
      return mapping.findForward("Failure");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.project.projectnotfound"));
      saveErrors(request, errors);
      return mapping.findForward("Failure");
    }

    Map goterms = protein.getGOAll();

    if (((Collection) goterms.get("P")).size() > 0)
      request.setAttribute("processes", goterms.get("P"));

    if (((Collection) goterms.get("C")).size() > 0)
      request.setAttribute("components", goterms.get("C"));

    if (((Collection) goterms.get("F")).size() > 0)
      request.setAttribute("functions", goterms.get("F"));

    // clean up
    goterms = null;

    YatesRunSearcher yrs = new YatesRunSearcher();
    yrs.setProtein(protein);
    Collection runs = yrs.search();

    // Make sure only runs belonging to projects this user has access to are listed.
    if (runs != null && runs.size() > 0) {
      Iterator iter = runs.iterator();
      while (iter.hasNext()) {
        YatesRun yr = (YatesRun) (iter.next());
        if (!yr.getProject().checkReadAccess(user.getResearcher())) iter.remove();
      }

      request.setAttribute("yatesdata", runs);
    }

    // Get the protein inference runs where this protein was listed
    // This is a bit convoluted
    // First get all the users' projects (projects the user has read access to)
    ProjectsSearcher projSearcher = new ProjectsSearcher();
    projSearcher.setResearcher(user.getResearcher());
    List<Project> projects = projSearcher.search();
    //		List<Project> projects = user.getProjects();

    List<Integer> pinferIds = new ArrayList<Integer>();
    for (Project project : projects) {
      List<Integer> experimentIds =
          ProjectExperimentDAO.instance().getExperimentIdsForProject(project.getID());

      for (int experimentId : experimentIds) {
        List<ProteinferJob> piJobs =
            ProteinInferJobSearcher.getInstance().getProteinferJobsForMsExperiment(experimentId);
        for (ProteinferJob job : piJobs) {
          pinferIds.add(job.getPinferId());
        }
      }
    }
    // We now have the protein inference runs for this user.
    // Find out which one of then has the protein of interest.
    List<ProteinferRun> piRuns = new ArrayList<ProteinferRun>(pinferIds.size());
    ProteinferRunDAO piRunDao = ProteinferDAOFactory.instance().getProteinferRunDao();
    ProteinferProteinDAO protDao = ProteinferDAOFactory.instance().getProteinferProteinDao();
    ArrayList<Integer> nrseqIds = new ArrayList<Integer>(1);
    nrseqIds.add(proteinID);
    for (int pinferId : pinferIds) {
      if (protDao.getProteinIdsForNrseqIds(pinferId, nrseqIds).size() > 0) {
        ProteinferRun piRun = piRunDao.loadProteinferRun(pinferId);
        piRuns.add(piRun);
      }
    }
    request.setAttribute("piRuns", piRuns);

    // Set this project in the request, as a bean to be displayed on the view
    request.setAttribute("protein", protein);
    return mapping.findForward("Success");
  }
Exemplo n.º 4
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // User making this request
    User user = UserUtils.getUser(request);
    if (user == null) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.login.notloggedin"));
      saveErrors(request, errors);
      return mapping.findForward("authenticate");
    }

    // Restrict access to researchers who are members of a group
    Groups groupMan = Groups.getInstance();
    if (!groupMan.isInAGroup(user.getResearcher().getID())) {
      ActionErrors errors = new ActionErrors();
      errors.add("access", new ActionMessage("error.access.invalidgroup"));
      saveErrors(request, errors);
      return mapping.findForward("standardHome");
    }

    UploadMSDataForm newForm = new UploadMSDataForm();
    if (groupMan.isMember(user.getResearcher().getID(), "administrators")) {
      newForm.setPipeline(Pipeline.TPP);
      newForm.setDataServer("local");
    } else if (groupMan.isMember(user.getResearcher().getID(), "MacCoss")) {
      newForm.setPipeline(Pipeline.MACOSS);
      newForm.setDataServer("local");
    } else {
      newForm.setPipeline(Pipeline.TPP);
      newForm.setDataServer("local");
    }

    try {
      int projectID = Integer.parseInt(request.getParameter("projectID"));
      newForm.setProjectID(projectID);
    } catch (Exception e) {
      newForm.setProjectID(0);
    }

    request.setAttribute("uploadMSDataForm", newForm);

    // get a list of projects on which this researcher is listed
    List<ProjectLite> projects =
        ProjectLiteDAO.instance().getResearcherWritableProjects(user.getResearcher().getID());
    Collections.sort(
        projects,
        new Comparator<ProjectLite>() {
          @Override
          public int compare(ProjectLite o1, ProjectLite o2) {
            return Integer.valueOf(o2.getId()).compareTo(o1.getId());
          }
        });

    request.getSession().setAttribute("researcherProjects", projects);

    // get a list of instruments available
    List<MsInstrument> instruments = DAOFactory.instance().getInstrumentDAO().loadAllInstruments();
    request.getSession().setAttribute("instrumentList", instruments);

    // Kick it to the view page
    return mapping.findForward("Success");
  }
Exemplo n.º 5
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // User making this request
    User user = UserUtils.getUser(request);
    if (user == null) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.login.notloggedin"));
      saveErrors(request, errors);
      return mapping.findForward("authenticate");
    }

    // Restrict access to yrc members
    Groups groupMan = Groups.getInstance();
    if (!groupMan.isInAGroup(user.getResearcher().getID())) {
      ActionErrors errors = new ActionErrors();
      errors.add("access", new ActionMessage("error.access.invalidgroup"));
      saveErrors(request, errors);
      return mapping.findForward("Failure");
    }

    try {
      Job job = MSJobFactory.getInstance().getJob(Integer.parseInt(request.getParameter("id")));

      if (job == null) {
        ActionErrors errors = new ActionErrors();
        errors.add(
            "general",
            new ActionMessage(
                "error.general.errorMessage",
                "No job found with ID " + request.getParameter("id")));
        saveErrors(request, errors);
        return mapping.findForward("Failure");
      }

      request.setAttribute("job", job);
      if (job instanceof MSJob) {
        int speciesId = ((MSJob) job).getTargetSpecies();
        Species species = Species.getInstance(speciesId);
        request.setAttribute("species", species);
        request.setAttribute("experimentUploadJob", true);
      } else if (job instanceof MsAnalysisUploadJob) {
        request.setAttribute("analysisUploadJob", true);
      } else if (job instanceof PercolatorJob) {
        request.setAttribute("percolatorJob", true);
      }

    } catch (Exception e) {

      log.error("Error loading job with ID: " + request.getParameter("id"), e);
      ActionErrors errors = new ActionErrors();
      errors.add(
          "general",
          new ActionMessage(
              "error.general.errorMessage",
              "Error reading job with ID: "
                  + request.getParameter("id")
                  + ". Error was: "
                  + e.getMessage()));
      saveErrors(request, errors);
      return mapping.findForward("Failure");
    }

    return mapping.findForward("Success");
  }
Exemplo n.º 6
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // User making this request
    User user = UserUtils.getUser(request);
    if (user == null) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.login.notloggedin"));
      saveErrors(request, errors);
      return mapping.findForward("authenticate");
    }

    // we need a projectID so that we can restrict access to researchers on a project
    int projectId = 0;
    try {
      projectId = Integer.parseInt(request.getParameter("projectId"));
    } catch (NumberFormatException e) {
      projectId = 0;
    }
    if (projectId == 0) {
      ActionErrors errors = new ActionErrors();
      errors.add(
          "payment", new ActionMessage("error.payment.invalidid", "Invalid projectID in request"));
      saveErrors(request, errors);
      return mapping.findForward("standardHome");
    }

    // user should be an admin OR a researcher on the project
    Project project = ProjectFactory.getProject(projectId);
    if (!project.checkAccess(user.getResearcher())) {
      ActionErrors errors = new ActionErrors();
      errors.add(
          "payment",
          new ActionMessage(
              "error.payment.invalidaccess",
              "User does not have access to view details of the payment method."));
      saveErrors(request, errors);
      ActionForward fwd = mapping.findForward("Failure");
      ActionForward newFwd =
          new ActionForward(fwd.getPath() + "?ID=" + projectId, fwd.getRedirect());
      return newFwd;
    }

    // we need a paymentMethodId
    int paymentMethodId = 0;
    try {
      paymentMethodId = Integer.parseInt(request.getParameter("paymentMethodId"));
    } catch (NumberFormatException e) {
      paymentMethodId = 0;
    }
    if (paymentMethodId == 0) {
      ActionErrors errors = new ActionErrors();
      errors.add(
          "payment",
          new ActionMessage("error.payment.invalidid", "Invalid paymentMethodID in request"));
      saveErrors(request, errors);
      ActionForward fwd = mapping.findForward("Failure");
      ActionForward newFwd =
          new ActionForward(fwd.getPath() + "?ID=" + projectId, fwd.getRedirect());
      return newFwd;
    }

    try {
      PaymentMethod paymentMethod =
          PaymentMethodDAO.getInstance().getPaymentMethod(paymentMethodId);
      request.setAttribute("paymentMethod", paymentMethod);
      request.setAttribute("projectId", projectId);
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("payment", new ActionMessage("error.payment.load", "ERROR: " + e.getMessage()));
      saveErrors(request, errors);
      log.error("Error loading payment method for ID: " + paymentMethodId, e);
      ActionForward fwd = mapping.findForward("Failure");
      ActionForward newFwd =
          new ActionForward(fwd.getPath() + "?ID=" + projectId, fwd.getRedirect());
      return newFwd;
    }

    return mapping.findForward("Success");
  }