@Override
 protected void postInit() {
   profile = getPermission().getProfile();
   BagManager bagManager = im.getBagManager();
   lists = bagManager.getBags(profile);
   knownBags = lists.keySet();
 }
 @Override
 protected void postInit() {
   profile = getPermission().getProfile();
   BagManager bagManager = im.getBagManager();
   lists = bagManager.getBags(profile);
   knownBags.addAll(lists.keySet());
   output.setHeaderAttributes(getHeaderAttributes());
 }
  private Set<String> getTagsForSingleList(String name, Profile profile) {
    BagManager bagManager = im.getBagManager();

    Map<String, InterMineBag> lists = bagManager.getBags(profile);
    InterMineBag list = lists.get(name);
    if (list == null) {
      throw new ResourceNotFoundException("You do not have access to a list called " + name);
    }
    List<Tag> tags = bagManager.getTagsForBag(list, profile);
    @SuppressWarnings("unchecked")
    Collection<String> tagNames = collect(tags, invokerTransformer("getTagName"));
    return new HashSet<String>(tagNames);
  }
Exemple #4
0
 /**
  * Fill a map with intermine bags from the names in a parameter.
  *
  * @param map The map to fill.
  * @param param The parameter to read names from.
  */
 protected void populateListMap(Map<String, InterMineBag> map, String param) {
   String[] paramValues = request.getParameterValues(param);
   if (paramValues != null) {
     for (String value : paramValues) {
       String[] names = StringUtils.split(value, LIST_SEPARATOR);
       for (String name : names) {
         InterMineBag list = bagManager.getBag(profile, name);
         map.put(name, list);
       }
     }
   }
 }
 /**
  * Get the Objectstore Query to run to generate the list.
  *
  * @param pq The pathquery to generate the query from.
  * @param profile The profile to search for bags.
  * @return A query.
  */
 protected Query getQuery(PathQuery pq, Profile profile) {
   Query ret;
   try {
     ret =
         MainHelper.makeQuery(
             pq,
             bagManager.getBags(profile),
             new HashMap<String, QuerySelectable>(),
             im.getBagQueryRunner(),
             new HashMap<String, BagQueryResult>());
   } catch (ObjectStoreException e) {
     throw new InternalErrorException(e);
   }
   return ret;
 }
Exemple #6
0
  /** @return a name for the new list * */
  protected String produceName() {
    // Give the user a default name if none is provided.
    String nameParam = request.getParameter(NAME_PARAMETER);
    nameParam = StringUtils.isBlank(nameParam) ? request.getParameter(ALT_NAME_PARAM) : nameParam;
    String name;
    if (StringUtils.isBlank(nameParam)) {
      nameParam = DEFAULT_LIST_NAME;
      name = nameParam;
      Set<String> listNames = bagManager.getBags(profile).keySet();
      int counter = 2;

      while (listNames.contains(name)) {
        name = nameParam + "_" + counter;
        counter++;
      }
    } else {
      name = nameParam;
    }
    return name;
  }
 private void unshareBag(HttpSession session, Profile profile, InterMineBag bag) {
   InterMineAPI api = SessionMethods.getInterMineAPI(session);
   BagManager bm = api.getBagManager();
   bm.unshareBagWithUser(bag, profile);
 }
  private void combine(ActionForm form, HttpServletRequest request, String opText) {
    HttpSession session = request.getSession();
    final InterMineAPI im = SessionMethods.getInterMineAPI(session);
    Profile profile = SessionMethods.getProfile(session);
    ModifyBagForm mbf = (ModifyBagForm) form;

    BagManager bagManager = im.getBagManager();
    Map<String, InterMineBag> allBags = bagManager.getBags(profile);

    String[] selectedBagNames = mbf.getSelectedBags();

    Collection<InterMineBag> selectedBags = getSelectedBags(allBags, selectedBagNames);

    String newBagName = NameUtil.validateName(allBags.keySet(), mbf.getNewBagName());

    int newBagSize = 0;
    try {
      if (opText.equals(BagOperations.UNION)) {
        newBagSize = BagOperations.union(selectedBags, newBagName, profile, im.getClassKeys());
      } else if (opText.equals(BagOperations.INTERSECT)) {
        newBagSize = BagOperations.intersect(selectedBags, newBagName, profile, im.getClassKeys());
      } else if (opText.equals(BagOperations.SUBTRACT)) {
        newBagSize = BagOperations.subtract(selectedBags, newBagName, profile, im.getClassKeys());
      }
    } catch (IncompatibleTypesException e) {
      SessionMethods.recordError(
          "You can only perform operations on lists of the same type."
              + " Lists "
              + StringUtil.prettyList(Arrays.asList(selectedBagNames))
              + " do not match.",
          session);
      return;
    } catch (ObjectStoreException e) {
      LOG.error(e);
      ActionMessage actionMessage = new ActionMessage("An error occurred while saving the list");
      recordError(actionMessage, request);
      return;
    }

    if (newBagSize > 0) {
      SessionMethods.recordMessage(
          "Created list \""
              + newBagName
              + "\" as "
              + opText
              + " of  "
              + StringUtil.prettyList(Arrays.asList(selectedBagNames))
              + ".",
          session);
      // track the list creation
      im.getTrackerDelegate()
          .trackListCreation(
              BagOperations.getCommonBagType(selectedBags),
              newBagSize,
              ListBuildMode.OPERATION,
              profile,
              session.getId());
    } else {
      SessionMethods.recordError(
          opText
              + " operation on lists "
              + StringUtil.prettyList(Arrays.asList(selectedBagNames))
              + " produced no results.",
          session);
    }
  }
  private void copy(ActionForm form, HttpServletRequest request) throws ObjectStoreException {
    HttpSession session = request.getSession();
    final InterMineAPI im = SessionMethods.getInterMineAPI(session);
    Profile profile = SessionMethods.getProfile(session);
    ModifyBagForm frm = (ModifyBagForm) form;
    String[] selectedBagNames = frm.getSelectedBags();

    BagManager bagManager = im.getBagManager();
    Map<String, InterMineBag> allBags = bagManager.getBags(profile);

    String newNameTextBox = getNewNameTextBox(request, frm.getNewBagName());

    if (selectedBagNames.length == 1) {
      String selectedBagName = selectedBagNames[0];
      InterMineBag origBag = allBags.get(selectedBagName);

      if (origBag == null) {
        recordError(new ActionMessage("errors.bag.notfound"), request);
        return;
      }

      String newBagName = "";
      if (newNameTextBox != null) {
        newBagName = NameUtil.validateName(allBags.keySet(), newNameTextBox);
        if (newBagName.isEmpty()) {
          recordError(new ActionMessage("bag.createdlists.notvalidname", newNameTextBox), request);
          return;
        }
      }
      if (newNameTextBox == null) {
        newBagName = NameUtil.generateNewName(allBags.keySet(), selectedBagName);
      }

      if (createBag(origBag, newBagName, profile)) {
        recordMessage(new ActionMessage("bag.createdlists", newBagName), request);
        // track the list creation
        im.getTrackerDelegate()
            .trackListCreation(
                origBag.getType(),
                origBag.getSize(),
                ListBuildMode.OPERATION,
                profile,
                session.getId());
      }
    } else {
      if (newNameTextBox != null) {
        recordError(new ActionMessage("errors.bag.namecannotbespecified"), request);
        return;
      }
      String msg = "";
      for (int i = 0; i < selectedBagNames.length; i++) {

        String selectedBagName = selectedBagNames[i];
        InterMineBag origBag = allBags.get(selectedBagName);

        if (origBag == null) {
          recordError(new ActionMessage("errors.bag.notfound"), request);
          return;
        }

        String newBagName = NameUtil.generateNewName(allBags.keySet(), selectedBagName);
        if (createBag(origBag, newBagName, profile)) {
          msg += newBagName + ", ";
        }
      }
      if (msg.length() > 2) {
        msg = msg.substring(0, msg.length() - 2);
      }
      if (msg.length() > 0) {
        recordMessage(new ActionMessage("bag.createdlists", msg), request);
      }
    }
  }
  /**
   * Forward to the correct method based on the button pressed
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @return an ActionForward object defining where control goes next
   * @exception Exception if the application business logic throws an exception
   */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HttpSession session = request.getSession();
    final InterMineAPI im = SessionMethods.getInterMineAPI(session);
    Profile profile = SessionMethods.getProfile(session);

    Model model = im.getModel();
    ModifyBagDetailsForm mbdf = (ModifyBagDetailsForm) form;
    BagManager bagManager = im.getBagManager();

    InterMineBag imBag = bagManager.getBag(profile, mbdf.getBagName());
    String bagIdentifier = "bag." + imBag.getName();

    if (request.getParameter("removeFromBag") != null) {
      PagedTable pc = SessionMethods.getResultsTable(session, bagIdentifier);
      String msg = "";

      if (pc.isAllRowsSelected()) {
        // TODO these messages need to be moved to properties file
        msg = "You can't remove all items from your list.  Try deleting your list instead.";
      } else {
        int removed = pc.removeSelectedFromBag(imBag, session);
        msg = "You have removed " + removed + " items from your list.";
      }
      SessionMethods.recordMessage(msg, session);
      // return new ForwardParameters(mapping.findForward("bagDetails"))
      // .addParameter("bagName", mbdf.getBagName()).forward();

      // pass an extra parameter telling the JSP to open up the results table
      return new ForwardParameters(mapping.findForward("bagDetails"))
          .addParameter("bagName", mbdf.getBagName())
          .addParameter("table", "open")
          .forward();

    } else if (request.getParameter("addToBag") != null) {
      InterMineBag newBag = bagManager.getBag(profile, mbdf.getExistingBagName());
      String msg = "";
      if (newBag.getType().equals(imBag.getType())) {
        PagedTable pc = SessionMethods.getResultsTable(session, bagIdentifier);
        int oldSize = newBag.size();
        pc.addSelectedToBag(newBag);
        int newSize = newBag.size();
        int added = newSize - oldSize;
        msg =
            "You have added "
                + added
                + " items from list <strong>"
                + imBag.getName()
                + "</strong> to list <strong>"
                + newBag.getName()
                + "</strong>";
      } else {
        msg = "You can only add objects to other lists of the same type";
      }
      SessionMethods.recordMessage(msg, session);
      // orthologues form
    } else if (request.getParameter("convertToThing") != null) {
      BagQueryConfig bagQueryConfig = im.getBagQueryConfig();
      Set<AdditionalConverter> additionalConverters =
          bagQueryConfig.getAdditionalConverters(imBag.getType());
      if (additionalConverters != null && !additionalConverters.isEmpty()) {
        for (AdditionalConverter additionalConverter : additionalConverters) {
          BagConverter bagConverter =
              PortalHelper.getBagConverter(
                  im, SessionMethods.getWebConfig(request), additionalConverter.getClassName());
          List<Integer> converted =
              bagConverter.getConvertedObjectIds(
                  profile, imBag.getType(), imBag.getContentsAsIds(), mbdf.getExtraFieldValue());

          if (converted.size() == 1) {
            return goToReport(mapping, converted.get(0).toString());
          }

          String bagName =
              NameUtil.generateNewName(
                  profile.getSavedBags().keySet(),
                  mbdf.getExtraFieldValue() + " orthologues of " + imBag.getName());

          InterMineBag newBag = profile.createBag(bagName, imBag.getType(), "", im.getClassKeys());
          return createBagAndGoToBagDetails(mapping, newBag, converted);
        }
      }

      // "use in bag" link
    } else if (request.getParameter("useBag") != null) {
      PagedTable pc = SessionMethods.getResultsTable(session, bagIdentifier);
      PathQuery pathQuery = pc.getWebTable().getPathQuery().clone();
      SessionMethods.setQuery(session, pathQuery);
      session.setAttribute("path", imBag.getType());
      session.setAttribute("prefix", imBag.getType());
      String msg = "You can now create a query using your list " + imBag.getName();
      SessionMethods.recordMessage(msg, session);
      return mapping.findForward("query");

      // convert links
    } else if (request.getParameter("convert") != null && request.getParameter("bagName") != null) {
      String type2 = request.getParameter("convert");
      TemplateManager templateManager = im.getTemplateManager();
      PathQuery q =
          BagConversionHelper.getConvertedObjects(
              session,
              templateManager.getConversionTemplates(),
              TypeUtil.instantiate(model.getPackageName() + "." + imBag.getType()),
              TypeUtil.instantiate(model.getPackageName() + "." + type2),
              imBag);
      q.setTitle(type2 + "s from list '" + imBag.getName() + "'");
      SessionMethods.loadQuery(q, session, response);
      String qid = SessionMethods.startQueryWithTimeout(request, false, q);
      Thread.sleep(200); // slight pause in the hope of avoiding holding page
      final String trail = "|bag." + imBag.getName();
      return new ForwardParameters(mapping.findForward("waiting"))
          .addParameter("trail", trail)
          .addParameter("qid", qid)
          .forward();
    }
    return new ForwardParameters(mapping.findForward("bagDetails"))
        .addParameter("bagName", mbdf.getBagName())
        .forward();
  }