/** * Save a single object to an existing bag. * * @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 */ @Override public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { int id = Integer.parseInt(request.getParameter("object")); HttpSession session = request.getSession(); final InterMineAPI im = SessionMethods.getInterMineAPI(request.getSession()); Profile profile = SessionMethods.getProfile(session); String bagName = request.getParameter("bag"); InterMineBag existingBag = profile.getSavedBags().get(bagName); if (existingBag != null) { // TODO add a warning when object already in bag ?? try { InterMineObject o = im.getObjectStore().getObjectById(id); existingBag.addIdToBag(id, DynamicUtil.getFriendlyName(o.getClass())); recordMessage(new ActionMessage("bag.addedToBag", existingBag.getName()), request); } catch (IncompatibleTypesException e) { recordError(new ActionMessage("bag.typesDontMatch"), request); } catch (ObjectStoreException e) { recordError(new ActionMessage("bag.error"), request, e); } } else { recordError(new ActionMessage("bag.noSuchBag"), request); } return mapping.findForward("report"); }
/** * Create a PathQuery to get the contents of an InterMineBag * * @param imBag the bag * @param webConfig the WebConfig * @param model the Model * @return a PathQuery */ public static PathQuery makePathQueryForBag( InterMineBag imBag, WebConfig webConfig, Model model) { PathQuery query = new PathQuery(model); query.addViews(getDefaultViewForClass(imBag.getType(), model, webConfig)); query.addConstraint(Constraints.in(imBag.getType(), imBag.getName())); return query; }
private ActionForward createBagAndGoToBagDetails( ActionMapping mapping, InterMineBag imBag, List<Integer> bagList) throws ObjectStoreException { imBag.addIdsToBag(bagList, imBag.getType()); return new ForwardParameters(mapping.findForward("bagDetails")) .addParameter("bagName", imBag.getName()) .forward(); }
private void delete(ActionForm form, HttpServletRequest request) throws Exception { HttpSession session = request.getSession(); Profile profile = SessionMethods.getProfile(session); ModifyBagForm mbf = (ModifyBagForm) form; for (int i = 0; i < mbf.getSelectedBags().length; i++) { String bagName = mbf.getSelectedBags()[i]; InterMineBag bag = profile.getSavedBags().get(bagName); if (bag != null) { deleteQueriesThatMentionBag(profile, bag.getName()); deleteBag(session, profile, bag); } else { bag = profile.getSharedBags().get(bagName); if (bag == null) { LOG.error("Asked to delete a bag this user does not have access to."); } else { unshareBag(session, profile, bag); } } } }
// Remove a bag from userprofile database and session cache private void deleteBag(HttpSession session, Profile profile, InterMineBag bag) throws ObjectStoreException { // removed a cached bag table from the session SessionMethods.invalidateBagTable(session, bag.getName()); profile.deleteBag(bag.getName()); }
/** * 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(); }