/** * Claim-tasks action. * * @param redirector unused. * @param resolver unused. * @param objectModel Cocoon's object model. * @param source unused. * @param parameters unused. * @return null. * @throws java.lang.Exception passed through. */ @Override public Map act( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { Request request = ObjectModelHelper.getRequest(objectModel); Context context = ContextUtil.obtainContext(objectModel); // Or the user selected a checkbox full of workflow IDs String[] workflowIDs = request.getParameterValues("workflowID"); if (workflowIDs != null) { for (String workflowID : workflowIDs) { BasicWorkflowItem workflowItem = basicWorkflowItemService.find(context, Integer.valueOf(workflowID)); int state = workflowItem.getState(); // Only unclaim tasks that are already claimed. if (state == BasicWorkflowServiceImpl.WFSTATE_STEP1POOL || state == BasicWorkflowServiceImpl.WFSTATE_STEP2POOL || state == BasicWorkflowServiceImpl.WFSTATE_STEP3POOL) { basicWorkflowService.claim(context, workflowItem, context.getCurrentUser()); } } } return null; }
/** * Obtains the submission info for the current submission process. If a submissionInfo object has * already been created for this HTTP request, it is re-used, otherwise it is created. * * @param objectModel the cocoon Objectmodel * @param workspaceID the workspaceID of the submission info to obtain * @return a SubmissionInfo object */ public static SubmissionInfo obtainSubmissionInfo(Map objectModel, String workspaceID) throws SQLException, IOException, AuthorizeException { Request request = ObjectModelHelper.getRequest(objectModel); Context context = ContextUtil.obtainContext(objectModel); // try loading subInfo from HTTP request SubmissionInfo subInfo = (SubmissionInfo) request.getAttribute(DSPACE_SUBMISSION_INFO); // get the submission represented by the WorkspaceID InProgressSubmission submission = findSubmission(context, workspaceID); // if no submission info, or wrong submission info, reload it! if ((subInfo == null && submission != null) || (subInfo != null && submission != null && subInfo.getSubmissionItem().getID() != submission.getID())) { try { final HttpServletRequest httpRequest = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT); // load submission info subInfo = SubmissionInfo.load(httpRequest, submission); // Set the session ID context.setExtraLogInfo("session_id=" + request.getSession().getId()); // Store the submissionInfo in the request request.setAttribute(DSPACE_SUBMISSION_INFO, subInfo); } catch (Exception e) { throw new SQLException("Error loading Submission Info: " + e.getMessage(), e); } } else if (subInfo == null && submission == null) { throw new SQLException( "Unable to load Submission Information, since WorkspaceID (ID:" + workspaceID + ") is not a valid in-process submission."); } return subInfo; }
/** * Query DSpace for a list of all items / collections / or communities that match the given search * query. */ protected void performSearch() throws SQLException, IOException, UIException { if (queryResults != null) { return; } Context context = ContextUtil.obtainContext(objectModel); String query = getQuery(); DSpaceObject scope = getScope(); int page = getParameterPage(); queryArgs = new QueryArgs(); queryArgs.setPageSize(getParameterRpp()); try { queryArgs.setSortOption(SortOption.getSortOption(getParameterSortBy())); } catch (SortException se) { } queryArgs.setSortOrder(getParameterOrder()); queryArgs.setQuery(query); if (page > 1) { queryArgs.setStart((Integer.valueOf(page) - 1) * queryArgs.getPageSize()); } else { queryArgs.setStart(0); } QueryResults qResults = null; if (scope instanceof Community) { qResults = DSQuery.doQuery(context, queryArgs, (Community) scope); } else if (scope instanceof Collection) { qResults = DSQuery.doQuery(context, queryArgs, (Collection) scope); } else { qResults = DSQuery.doQuery(context, queryArgs); } this.queryResults = qResults; }
/** * Get the results of the browse. If the results haven't been generated yet, then this will * perform the browse. * * @return * @throws SQLException * @throws UIException */ private BrowseInfo getBrowseInfo() throws SQLException, UIException { if (this.browseInfo != null) return this.browseInfo; Context context = ContextUtil.obtainContext(objectModel); // Get the parameters we will use for the browse // (this includes a browse scope) BrowseParams params = getUserParams(); try { // Create a new browse engine, and perform the browse BrowseEngine be = new BrowseEngine(context); this.browseInfo = be.browse(params.scope); // figure out the setting for author list truncation if (params.etAl < 0) { // there is no limit, or the UI says to use the default int etAl = ConfigurationManager.getIntProperty("webui.browse.author-limit"); if (etAl != 0) { this.browseInfo.setEtAl(etAl); } } else if (params.etAl == 0) // 0 is the user setting for unlimited { this.browseInfo.setEtAl(-1); // but -1 is the application // setting for unlimited } else // if the user has set a limit { this.browseInfo.setEtAl(params.etAl); } } catch (BrowseException bex) { throw new UIException("Unable to process browse", bex); } return this.browseInfo; }
public Map act( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { Request request = ObjectModelHelper.getRequest(objectModel); String requesterName = request.getParameter("requesterName"); String requesterEmail = request.getParameter("requesterEmail"); String allFiles = request.getParameter("allFiles"); String message = request.getParameter("message"); String bitstreamId = request.getParameter("bitstreamId"); // User email from context Context context = ContextUtil.obtainContext(objectModel); EPerson loggedin = context.getCurrentUser(); String eperson = null; if (loggedin != null) { eperson = loggedin.getEmail(); } // Check all data is there if (StringUtils.isEmpty(requesterName) || StringUtils.isEmpty(requesterEmail) || StringUtils.isEmpty(allFiles) || StringUtils.isEmpty(message)) { // Either the user did not fill out the form or this is the // first time they are visiting the page. Map<String, String> map = new HashMap<String, String>(); map.put("bitstreamId", bitstreamId); if (StringUtils.isEmpty(requesterEmail)) { map.put("requesterEmail", eperson); } else { map.put("requesterEmail", requesterEmail); } map.put("requesterName", requesterName); map.put("allFiles", allFiles); map.put("message", message); return map; } DSpaceObject dso = HandleUtil.obtainHandle(objectModel); if (!(dso instanceof Item)) { throw new Exception("Invalid DspaceObject at ItemRequest."); } Item item = (Item) dso; String title = ""; Metadatum[] titleDC = item.getDC("title", null, Item.ANY); if (titleDC == null || titleDC.length == 0) { titleDC = item.getDC("title", Item.ANY, Item.ANY); // dc.title with qualifier term } if (titleDC != null && titleDC.length > 0) { title = titleDC[0].value; } RequestItemAuthor requestItemAuthor = new DSpace() .getServiceManager() .getServiceByName( RequestItemAuthorExtractor.class.getName(), RequestItemAuthorExtractor.class) .getRequestItemAuthor(context, item); RequestItem requestItem = new RequestItem( item.getID(), Integer.parseInt(bitstreamId), requesterEmail, requesterName, message, Boolean.getBoolean(allFiles)); // All data is there, send the email Email email = Email.getEmail( I18nUtil.getEmailFilename(context.getCurrentLocale(), "request_item.author")); email.addRecipient(requestItemAuthor.getEmail()); email.addArgument(requesterName); email.addArgument(requesterEmail); email.addArgument( allFiles.equals("true") ? I18nUtil.getMessage("itemRequest.all") : Bitstream.find(context, Integer.parseInt(bitstreamId)).getName()); email.addArgument(HandleManager.getCanonicalForm(item.getHandle())); email.addArgument(title); // request item title email.addArgument(message); // message email.addArgument(getLinkTokenEmail(context, requestItem)); email.addArgument(requestItemAuthor.getFullName()); // corresponding author name email.addArgument(requestItemAuthor.getEmail()); // corresponding author email email.addArgument(ConfigurationManager.getProperty("dspace.name")); email.addArgument(ConfigurationManager.getProperty("mail.helpdesk")); email.setReplyTo(requesterEmail); email.send(); // Finished, allow to pass. return null; }
/** * Get the query parameters supplied to the browse. * * @return * @throws SQLException * @throws UIException */ private BrowseParams getUserParams() throws SQLException, UIException { if (this.userParams != null) return this.userParams; Context context = ContextUtil.obtainContext(objectModel); Request request = ObjectModelHelper.getRequest(objectModel); BrowseParams params = new BrowseParams(); params.month = request.getParameter(BrowseParams.MONTH); params.year = request.getParameter(BrowseParams.YEAR); params.etAl = RequestUtils.getIntParameter(request, BrowseParams.ETAL); params.scope = new BrowserScope(context); // Are we in a community or collection? DSpaceObject dso = HandleUtil.obtainHandle(objectModel); if (dso instanceof Community) params.scope.setCommunity((Community) dso); if (dso instanceof Collection) params.scope.setCollection((Collection) dso); try { String type = request.getParameter(BrowseParams.TYPE); int sortBy = RequestUtils.getIntParameter(request, BrowseParams.SORT_BY); BrowseIndex bi = BrowseIndex.getBrowseIndex(type); if (bi == null) { throw new BrowseException("There is no browse index of the type: " + type); } // If we don't have a sort column if (sortBy == -1) { // Get the default one SortOption so = bi.getSortOption(); if (so != null) { sortBy = so.getNumber(); } } else if (bi.isItemIndex() && !bi.isInternalIndex()) { // If a default sort option is specified by the index, but it isn't // the same as sort option requested, attempt to find an index that // is configured to use that sort by default // This is so that we can then highlight the correct option in the navigation SortOption bso = bi.getSortOption(); SortOption so = SortOption.getSortOption(sortBy); if (bso != null && bso != so) { BrowseIndex newBi = BrowseIndex.getBrowseIndex(so); if (newBi != null) { bi = newBi; type = bi.getName(); } } } params.scope.setBrowseIndex(bi); params.scope.setSortBy(sortBy); params.scope.setJumpToItem(RequestUtils.getIntParameter(request, BrowseParams.JUMPTO_ITEM)); params.scope.setOrder(request.getParameter(BrowseParams.ORDER)); params.scope.setResultsPerPage( RequestUtils.getIntParameter(request, BrowseParams.RESULTS_PER_PAGE)); params.scope.setStartsWith(request.getParameter(BrowseParams.STARTS_WITH)); params.scope.setFilterValue(request.getParameter(BrowseParams.FILTER_VALUE)); params.scope.setJumpToValue(request.getParameter(BrowseParams.JUMPTO_VALUE)); params.scope.setJumpToValueLang(request.getParameter(BrowseParams.JUMPTO_VALUE_LANG)); params.scope.setFilterValueLang(request.getParameter(BrowseParams.FILTER_VALUE_LANG)); // Filtering to a value implies this is a second level browse if (params.scope.getFilterValue() != null) params.scope.setBrowseLevel(1); // if year and perhaps month have been selected, we translate these // into "startsWith" // if startsWith has already been defined then it is overwritten if (params.year != null && !"".equals(params.year) && !"-1".equals(params.year)) { String startsWith = params.year; if ((params.month != null) && !"-1".equals(params.month) && !"".equals(params.month)) { // subtract 1 from the month, so the match works // appropriately if ("ASC".equals(params.scope.getOrder())) { params.month = Integer.toString((Integer.parseInt(params.month) - 1)); } // They've selected a month as well if (params.month.length() == 1) { // Ensure double-digit month number params.month = "0" + params.month; } startsWith = params.year + "-" + params.month; } params.scope.setStartsWith(startsWith); } } catch (BrowseException bex) { throw new UIException("Unable to create browse parameters", bex); } this.userParams = params; return params; }