<%-- ADOBE CONFIDENTIAL Copyright 2015 Adobe Systems Incorporated All Rights Reserved. NOTICE: All information contained herein is, and remains the property of Adobe Systems Incorporated and its suppliers, if any. The intellectual and technical concepts contained herein are proprietary to Adobe Systems Incorporated and its suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from Adobe Systems Incorporated. --%><%@page session="false" contentType="text/html; charset=utf-8"%><% %><%@page import="com.adobe.granite.security.user.UserProperties, com.adobe.granite.security.user.UserPropertiesManager, com.adobe.granite.security.user.UserPropertiesService, com.adobe.granite.workflow.WorkflowException, com.adobe.granite.workflow.WorkflowSession, com.adobe.granite.workflow.exec.HistoryItem, com.adobe.granite.workflow.exec.Participant, com.adobe.granite.workflow.exec.Route, com.adobe.granite.workflow.exec.WorkItem, com.adobe.granite.workflow.exec.Workflow, com.adobe.granite.workflow.exec.WorkflowData, com.adobe.granite.workflow.model.WorkflowNode, com.day.cq.i18n.I18n, org.apache.commons.collections.iterators.EmptyIterator, org.apache.jackrabbit.JcrConstants, org.apache.jackrabbit.vault.fs.api.FilterSet, org.apache.jackrabbit.vault.fs.api.PathFilter, org.apache.jackrabbit.vault.fs.api.PathFilterSet, org.apache.jackrabbit.vault.packaging.JcrPackage, org.apache.jackrabbit.vault.packaging.JcrPackageManager, org.apache.jackrabbit.vault.packaging.Packaging, org.apache.sling.api.resource.Resource, org.apache.sling.api.resource.ResourceResolver, javax.jcr.Node, javax.jcr.RepositoryException, javax.jcr.Session, java.util.ArrayList, java.util.Iterator, java.util.List"%><% %><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><% %><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><% %><%@taglib prefix="ui" uri="http://www.adobe.com/taglibs/granite/ui/1.0" %><% %><% ResourceResolver resolver = resource.getResourceResolver(); I18n i18n = new I18n(slingRequest); UserPropertiesManager userPropertiesManager = resolver.adaptTo(UserPropertiesManager.class); WorkflowSession workflowSession = resolver.adaptTo(WorkflowSession.class); Session session = resourceResolver.adaptTo(Session.class); JcrPackageManager packageManager = sling.getService(Packaging.class).getPackageManager(session); // get the selected resource Resource item = null; if (slingRequest.getRequestParameter("item") != null) { String path = slingRequest.getRequestParameter("item").getString("UTF-8") ; item = resourceResolver.getResource(path); } if (item == null) { %>
<%= i18n.get("Cannot locate the resource data. Please refresh the page.") %>
<% return; } String resourcePath = item.getPath(); String contentResourcePath = resourcePath + "/" + JcrConstants.JCR_CONTENT; // loop through all active work items of the current user for (WorkItem workItem : workflowSession.getActiveWorkItems()) { // skip workflows whose payload is not a JCR path or is null Workflow workflow = workItem.getWorkflow(); WorkflowData data = workflow.getWorkflowData(); if (!PAYLOAD_TYPE_PATH.equals(data.getPayloadType()) || data.getPayload() == null) { continue; } // get the resource referenced in the payload if(!session.nodeExists(data.getPayload().toString())) { log.warn("Resource referenced by payload doesn't exist for workflow instance {}", workflow.getId()); continue; } Node payload = session.getNode(data.getPayload().toString()); String payloadPath = payload.getPath(); // skip workflows whose payload either references: // - a workflow package that doesn't include the resource // - or a resource which doesn't match the selected resource (or resources below and including "jcr:content") if (payloadPath.startsWith(PACKAGES_ROOT_ETC + "/") || payloadPath.startsWith(PACKAGES_ROOT_VAR + "/")) { JcrPackage workflowPackage = packageManager.open(payload); if (!matches(resourcePath, workflowPackage)) { continue; } } else if (!(resourcePath.equals(payloadPath) || contentResourcePath.equals(payloadPath) || payloadPath.startsWith(contentResourcePath + "/"))) { continue; } String encodedId = xssAPI.encodeForHTMLAttr(workItem.getId()); String alertText = i18n.getVar(workItem.getNode().getTitle()); Iterator delegates = null; List backRoutes = null; List routes = null; try { delegates = workflowSession.getDelegates(workItem); } catch (WorkflowException we) { delegates = EmptyIterator.INSTANCE; } try { backRoutes = workflowSession.getBackRoutes(workItem, true); } catch (WorkflowException we) { backRoutes = new ArrayList(); } try { routes = workflowSession.getRoutes(workItem, true); } catch (WorkflowException we) { routes = new ArrayList(); } %>
<%-- ribbon --%>
<%= xssAPI.encodeForHTML(alertText) %>
<%-- action buttons --%> <% // // action back (Roll back) // if (backRoutes.size() > 0) { %> <% } // // action delegate (Change Assignee) // if (delegates.hasNext()) { %> <% } // // action advance (Complete) // %>
<% } %><%! /** * Type of payloads containing JCR paths. */ private static final String PAYLOAD_TYPE_PATH = "JCR_PATH"; /** * Locations of the workflow packages. */ private static final String PACKAGES_ROOT_ETC = "/etc/workflow/packages"; private static final String PACKAGES_ROOT_VAR = "/var/workflow/packages"; /** * Get the display name of the user of the given id. * @param userPropertiesManager * @param id * @return The display name or the id if not available */ private String getDisplayName(UserPropertiesManager userPropertiesManager, String id) { try { UserProperties profile = userPropertiesManager.getUserProperties(id, UserPropertiesService.PROFILE_PATH); if (profile == null) return id; return profile.getDisplayName(); } catch (RepositoryException re) { return id; } } /** * Get value and text for a dropdown option of a route. value will be the id of the route plus the id of the * participant e.g. "12356@admin". text will be the name of the route plus the display name of the participant * e.g. "Validate (Administrator)" * @param route The route * @param userPropertiesManager The user properties managager * @return new String[]{value, text} */ private String[] getRouteValueAndText(Route route, UserPropertiesManager userPropertiesManager, I18n i18n) { WorkflowNode wfNode = route.getDestinations().get(0).getTo(); String value = route.getId(); String text = i18n.getVar(route.getName()); String participant = ""; if (wfNode.getType().equals("PARTICIPANT")) { participant = wfNode.getMetaDataMap().get("PARTICIPANT", String.class); value += "@" + participant; // add participant's display name text = i18n.get("{0} ({1})", "name of a workflow route, in brackets a user name; sample: Validate Content (Alison Parker)", text, getDisplayName(userPropertiesManager, participant)); } return new String[]{value, text, participant}; } // copied from com.adobe.granite.workflow.core.util.WorkflowUtil because package is not public available /** * This method returns the userId of the user who completed the previous step. * * @param session workflow session * @param workflow workflow instance * @param nodeId node id of workflow node in question * @return user id as string or null if no user could be matched * @throws WorkflowException */ public static String getAuthorizableFromLastStep(WorkflowSession session, Workflow workflow, String nodeId) { try { List historyList = session.getHistory(workflow); for (int i = historyList.size(); i > 0; i--) { HistoryItem item = historyList.get(i - 1); if (item.getWorkItem() != null && item.getWorkItem().getNode().getId().equals(nodeId)) { return item.getUserId(); } } return null; } catch (WorkflowException we) { return null; } } /** * Checks if the specified package includes the {@code path}. * * @param path a path to check * @param pkg a package * @return {@code true} if the package matches the path, {@code false} otherwise * @throws RepositoryException */ private boolean matches(String path, JcrPackage pkg) throws RepositoryException { if (pkg == null) { return false; } // iterate over all filters and check if any of them matches the path for (PathFilterSet filterSet : pkg.getDefinition().getMetaInf().getFilter().getFilterSets()) { for (FilterSet.Entry filter : filterSet.getEntries()) { if (filter.getFilter().matches(path)) { return true; } } } return false; } %>