Esempio n. 1
0
  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);
    }
  }
Esempio n. 2
0
  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);
      }
    }
  }