@Override protected Map<String, Object> buildModel( WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) { Map<String, String> params = req.getServiceMatch().getTemplateVars(); // state is not included into filters list as it will be taken into account before filtering WorkflowState state = getState(req); // get filter param values Map<String, Object> filters = new HashMap<String, Object>(9); filters.put(PARAM_INITIATOR, req.getParameter(PARAM_INITIATOR)); filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY)); filters.put(PARAM_DEFINITION_NAME, req.getParameter(PARAM_DEFINITION_NAME)); String excludeParam = req.getParameter(PARAM_EXCLUDE); if (excludeParam != null && excludeParam.length() > 0) { filters.put(PARAM_EXCLUDE, new ExcludeFilter(excludeParam)); } // process all the date related parameters processDateFilter(req, PARAM_DUE_BEFORE, filters); processDateFilter(req, PARAM_DUE_AFTER, filters); processDateFilter(req, PARAM_STARTED_BEFORE, filters); processDateFilter(req, PARAM_STARTED_AFTER, filters); processDateFilter(req, PARAM_COMPLETED_BEFORE, filters); processDateFilter(req, PARAM_COMPLETED_AFTER, filters); // determine if there is a definition id to filter by String workflowDefinitionId = params.get(VAR_DEFINITION_ID); if (workflowDefinitionId == null) { workflowDefinitionId = req.getParameter(PARAM_DEFINITION_ID); } List<WorkflowInstance> workflows; // list workflows for specified workflow definition if (state == null) { workflows = workflowService.getWorkflows(workflowDefinitionId); } else if (state == WorkflowState.ACTIVE) { workflows = workflowService.getActiveWorkflows(workflowDefinitionId); } else { workflows = workflowService.getCompletedWorkflows(workflowDefinitionId); } // sort workflows by due date Collections.sort(workflows, workflowComparator); // filter result List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(workflows.size()); for (WorkflowInstance workflow : workflows) { if (matches(workflow, filters, modelBuilder)) { results.add(modelBuilder.buildSimple(workflow)); } } // create and return results, paginated if necessary return createResultModel(req, "workflowInstances", results); }
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { final String value = req.getParameter(P_VALUE); NodeRef nodeRef = null; if (null != value && NodeRef.isNodeRef(value)) { nodeRef = new NodeRef(value); } final String engine = req.getParameter(P_ENGINE); String mimetype = req.getParameter(P_MIMETYPE); mimetype = null == mimetype ? D_MIMETYPE : mimetype; final ByteArrayOutputStream output = new ByteArrayOutputStream(); if (req.getServerPath().contains("/new")) { final String reference = referenceProviderService.getNewReference(engine, null); generateBarcode(reference, output, mimetype); } else { String barcodeValue = value; if (null != nodeRef) { barcodeValue = referenceProviderService.getExistingReference(nodeRef); } if (null != value && !value.isEmpty()) { generateBarcode(barcodeValue, output, mimetype); } else { logger.debug(String.format("No barcode generated for value '%s'", value)); } } res.setContentType(mimetype); // res.setContentEncoding(reader.getEncoding()); res.setHeader("Content-Length", Long.toString(output.size())); // get the content and stream directly to the response output stream // assuming the repository is capable of streaming in chunks, this should allow large files // to be streamed directly to the browser response stream. try { res.getOutputStream().write(output.toByteArray()); } catch (SocketException e1) { // the client cut the connection - our mission was accomplished apart from a little error // message if (logger.isInfoEnabled()) logger.info("Client aborted stream read."); } catch (ContentIOException e2) { if (logger.isInfoEnabled()) logger.info("Client aborted stream read."); } }
/* * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache) */ @Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { // create model object with the lists model Map<String, Object> model = new HashMap<String, Object>(1); boolean extended = false; String result = "NONE"; // Get the nodeRef and confirm it is valid String nodeRef = req.getParameter(PARAM_NODEREF); if (nodeRef == null || nodeRef.length() == 0) { String type = req.getParameter(PARAM_TYPE); if (type != null && type.length() != 0 && type.indexOf(':') != -1) { Matcher m = QNAME_PATTERN.matcher(type); if (m.matches()) { QName qname = QName.createQName(type, namespaceService); FilePlanComponentKind kind = filePlanService.getFilePlanComponentKindFromType(qname); if (kind != null) { result = kind.toString(); } } } } else { // quick test before running slow match for full NodeRef pattern if (nodeRef.indexOf(':') != -1) { Matcher m = NODE_REF_PATTERN.matcher(nodeRef); if (m.matches()) { NodeRef nodeRefObj = new NodeRef(nodeRef); FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRefObj); if (kind != null) { result = kind.toString(); } String extendedValue = req.getParameter(PARAM_EXTENDED); if (extendedValue != null && extendedValue.length() != 0) { extended = Boolean.parseBoolean(extendedValue); if (extended) { // get the aspects of the node model.put("aspects", getAspects(nodeRefObj)); } } } } } model.put("kind", result); model.put("extended", extended); return model; }
/** * Chooses the correct writer to use based on the supplied "format" param * * @param req - the WebScriptRequest * @return ResourceMetaDataWriter - a matching writer - DEFAULT is this class. */ protected ResourceMetaDataWriter chooseWriter(WebScriptRequest req) { if (writers != null) { ResourceMetaDataWriter theWriter = writers.get(req.getParameter("format")); if (theWriter != null) return theWriter; } return this; }
/** * Gets the specified {@link WorkflowState}, null if not requested. * * @param req The WebScript request * @return The workflow state or null if not requested */ private WorkflowState getState(WebScriptRequest req) { String stateName = req.getParameter(PARAM_STATE); if (stateName != null) { try { return WorkflowState.valueOf(stateName.toUpperCase()); } catch (IllegalArgumentException e) { String msg = "Unrecognised State parameter: " + stateName; throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); } } return null; }
/** * Retrieves the named paramter as a date. * * @param req The WebScript request * @param paramName The name of parameter to look for * @return The request parameter value or null if the parameter is not present */ protected Date getDateParameter(WebScriptRequest req, String paramName) { String dateString = req.getParameter(paramName); if (dateString != null) { try { return ISO8601DateFormat.parse(dateString.replaceAll(" ", "+")); } catch (Exception e) { String msg = "Invalid date value: " + dateString; throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); } } return null; }
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); // get request parameters NodeRef nodeRef = parseRequestForNodeRef(req); String ruleType = req.getParameter("ruleType"); RuleType type = ruleService.getRuleType(ruleType); if (type == null) { ruleType = null; } RuleSet ruleset = new RuleSet(); // get all "owned" rules List<Rule> ownedRules = ruleService.getRules(nodeRef, false, ruleType); // get all rules (including inherited) List<Rule> inheritedRules = ruleService.getRules(nodeRef, true, ruleType); // remove "owned" rules inheritedRules.removeAll(ownedRules); List<RuleRef> rulesToSet = new ArrayList<RuleRef>(); for (Rule rule : ownedRules) { rulesToSet.add( new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule)))); } ruleset.setRules(rulesToSet); List<RuleRef> inheritedRulesToSet = new ArrayList<RuleRef>(); for (Rule rule : inheritedRules) { inheritedRulesToSet.add( new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule)))); } ruleset.setInheritedRules(inheritedRulesToSet); ruleset.setLinkedToRuleSet(ruleService.getLinkedToRuleNode(nodeRef)); ruleset.setLinkedFromRuleSets(ruleService.getLinkedFromRuleNodes(nodeRef)); ruleset.setRulesetNodeRef(nodeRef); model.put("ruleset", ruleset); return model; }
/** * @see * org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, * org.springframework.extensions.webscripts.Status, * org.springframework.extensions.webscripts.Cache) */ @Override public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); Set<Role> roles = null; // get the file plan NodeRef filePlan = getFilePlan(req); if (filePlan == null) { throw new WebScriptException(Status.STATUS_FOUND, "File plan does not exist."); } // get the includesystem parameter boolean includeSystem = false; String includeSystemValue = req.getParameter("is"); if (includeSystemValue != null && includeSystemValue.length() != 0) { includeSystem = Boolean.parseBoolean(includeSystemValue); } // get the user filter String user = req.getParameter("user"); if (user != null && user.length() != 0) { roles = filePlanRoleService.getRolesByUser(filePlan, user, includeSystem); } else { roles = filePlanRoleService.getRoles(filePlan, includeSystem); } // get the auths parameter boolean showAuths = false; String auths = req.getParameter("auths"); if (auths != null && auths.length() != 0) { showAuths = Boolean.parseBoolean(auths); } Set<RoleItem> items = createRoleItems(filePlan, roles, showAuths); model.put("roles", items); return model; }
/** {@inheritDoc} */ @Override protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status) { final String visibleStr = req.getParameter("visible"); final boolean visible = Boolean.parseBoolean(visibleStr); if (visible) { this.debugger.activate(); } else { this.debugger.shutdown(); } final Map<String, Object> model = new HashMap<String, Object>(7, 1.0f); model.put("visible", Boolean.valueOf(this.debugger.isActive())); return model; }
/** * Processes the given date filter parameter from the provided webscript request. * * <p>If the parameter is present but set to an empty string or to "null" the date is added to the * given filters Map as "", if the parameter contains an ISO8601 date it's added as a Date object * to the filters. * * @param req The WebScript request * @param paramName The name of the parameter to look for * @param filters Map of filters to add the date to */ protected void processDateFilter( WebScriptRequest req, String paramName, Map<String, Object> filters) { // TODO: support other keywords i.e. today, tomorrow String dateParam = req.getParameter(paramName); if (dateParam != null) { Object date = EMPTY; if (!EMPTY.equals(dateParam) && !NULL.equals(dateParam)) { date = getDateParameter(req, paramName); } filters.put(paramName, date); } }
/** * Retrieves the named parameter as an integer, if the parameter is not present the default value * is returned * * @param req The WebScript request * @param paramName The name of parameter to look for * @param defaultValue The default value that should be returned if parameter is not present in * request or if it is not positive * @return The request parameter or default value */ protected int getIntParameter(WebScriptRequest req, String paramName, int defaultValue) { String paramString = req.getParameter(paramName); if (paramString != null) { try { int param = Integer.valueOf(paramString); if (param > 0) { return param; } } catch (NumberFormatException e) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } } return defaultValue; }
/** * Gets the string parameter value. * * @param req The webscript request. * @param param The name of the string parameter value * @param defaultValue The value to return if the parameter isn't present * @return The value of the string parameter or the default value if parameter isn't present */ protected String getString(WebScriptRequest req, String param, String defaultValue) { String value = checkString(req.getParameter(param), param, false); return value != null ? value : defaultValue; }
/** * Gets a mandatory string parameter value of throws an exception if the parameter isn't present. * * @param req The webscript request * @param param The name of the string parameter value * @return The string parameter value * @throws WebScriptException if the parameter isn't present */ protected String getMandatoryString(WebScriptRequest req, String param) { return checkString(req.getParameter(param), param, true); }
/** * Gets the string parameter value. * * @param req The webscript request * @param param The name of the string parameter * @return The string parameter value or null if the parameter isn't present */ protected String getString(WebScriptRequest req, String param) { return checkString(req.getParameter(param), param, false); }
/** * Get parameters from the request. * * @param req * @return * @throws Exception */ private static final Map<String, Object> getParameters(WebScriptRequest req) throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); // Counter parameter. String counterParameter = req.getParameter(PARAMETER_COUNTER); if (counterParameter == null) { throw new Exception("Parameter '" + PARAMETER_COUNTER + "' not specified."); } counterParameter = counterParameter.trim(); if (counterParameter.isEmpty()) { throw new Exception("Parameter '" + PARAMETER_COUNTER + "' cannot be empty."); } // Application parameter. String applicationParameter = req.getParameter(PARAMETER_APPLICATION); if (PARAMETER_COUNTER_AUDIT_TRAIL.equals(counterParameter)) { if (applicationParameter == null) { throw new Exception( "Parameter '" + PARAMETER_APPLICATION + "' requested in case of '" + PARAMETER_COUNTER + "=" + PARAMETER_COUNTER_AUDIT_TRAIL + "'."); } applicationParameter = applicationParameter.trim(); if (applicationParameter.isEmpty()) { throw new Exception( "Parameter '" + PARAMETER_APPLICATION + "' cannot be empty in case of '" + PARAMETER_COUNTER + "=" + PARAMETER_COUNTER_AUDIT_TRAIL + "'."); } } // Class array parameter. String classesParameter = req.getParameter(PARAMETER_CLASSES); if (PARAMETER_COUNTER_ASPECTS.equals(counterParameter)) { if (classesParameter == null) { throw new Exception( "Parameter '" + PARAMETER_CLASSES + "' requested in case of '" + PARAMETER_COUNTER + "=" + PARAMETER_COUNTER_ASPECTS + "'."); } classesParameter = classesParameter.trim(); } if (PARAMETER_COUNTER_TYPES.equals(counterParameter)) { if (classesParameter == null) { throw new Exception( "Parameter '" + PARAMETER_CLASSES + "' requested in case of '" + PARAMETER_COUNTER + "=" + PARAMETER_COUNTER_TYPES + "'."); } classesParameter = classesParameter.trim(); } parameters.put(PARAMETER_COUNTER, counterParameter); parameters.put(PARAMETER_APPLICATION, applicationParameter); parameters.put(PARAMETER_CLASSES, classesParameter); return parameters; }