Search in sources :

Example 1 with HierarchyNodeInheritanceValueMap

use of com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class WorkflowDelegationStep method execute.

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metadata) throws WorkflowException {
    Map<String, String> args = getProcessArgsMap(metadata);
    String propertyName = args.get(WORKFLOW_PROPERTY_NAME);
    String defaultWorkflowModelId = args.get(DEFAULT_WORKFLOW_MODEL);
    boolean terminateOnDelegation = Boolean.parseBoolean(StringUtils.lowerCase(args.get(TERMINATE_ON_DELEGATION)));
    if (StringUtils.isBlank(propertyName)) {
        throw new WorkflowException("PROCESS_ARG [ " + WORKFLOW_PROPERTY_NAME + " ] not defined");
    }
    log.debug("Provided PROCESS_ARGS: propertyName = [ {} ], Default Workflow Model = [ {} ]", propertyName, defaultWorkflowModelId);
    ResourceResolver resolver = null;
    WorkflowData wfData = workItem.getWorkflowData();
    if (!workflowHelper.isPathTypedPayload(wfData)) {
        log.warn("Could not locate a JCR_PATH payload for this workflow. Skipping delegation.");
        return;
    }
    final String path = wfData.getPayload().toString();
    // Get the resource resolver
    resolver = workflowHelper.getResourceResolver(workflowSession);
    if (resolver == null) {
        throw new WorkflowException("Could not adapt the WorkflowSession to a ResourceResolver. Something has gone terribly wrong!");
    }
    // Derive the Page or Asset resource so we have a normalized entry-point for finding the /jcr:content resource
    final Resource pageOrAssetResource = workflowHelper.getPageOrAssetResource(resolver, path);
    if (pageOrAssetResource == null) {
        log.warn("Could not resolve [ {} ] to an Asset or Page. Skipping delegation.", path);
        return;
    }
    // Get the Asset or Page's jcr:content resource, so we have a common inherited property look-up scheme
    final Resource jcrContentResource = pageOrAssetResource.getChild(JcrConstants.JCR_CONTENT);
    if (jcrContentResource == null) {
        throw new WorkflowException(String.format("Could not find a child jcr:content resource for [ %s ]", pageOrAssetResource.getPath()));
    }
    // Look up the content-hierarchy for the delegate workflow model
    final InheritanceValueMap inheritance = new HierarchyNodeInheritanceValueMap(jcrContentResource);
    final String foundWorkflowModelId = StringUtils.trim(inheritance.getInherited(propertyName, String.class));
    final WorkflowModel delegateWorkflowModel = getDelegateWorkflowModel(workflowSession, foundWorkflowModelId, defaultWorkflowModelId);
    if (delegateWorkflowModel != null) {
        workflowSession.startWorkflow(delegateWorkflowModel, wfData);
        log.info("Delegating payload [ {} ] to Workflow Model [ {} ]", wfData.getPayload(), delegateWorkflowModel.getId());
        if (terminateOnDelegation) {
            log.info("Terminating current workflow due to PROCESS_ARGS[ {} ] = [ {} ]", TERMINATE_ON_DELEGATION, terminateOnDelegation);
            workflowSession.terminateWorkflow(workItem.getWorkflow());
        }
    } else {
        log.warn("No valid delegate Workflow Model could be located. Skipping workflow delegation.");
    }
}
Also used : HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) InheritanceValueMap(com.day.cq.commons.inherit.InheritanceValueMap) HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) WorkflowException(com.adobe.granite.workflow.WorkflowException) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) WorkflowModel(com.adobe.granite.workflow.model.WorkflowModel) WorkflowData(com.adobe.granite.workflow.exec.WorkflowData)

Example 2 with HierarchyNodeInheritanceValueMap

use of com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class SiteMapServlet method write.

@SuppressWarnings("squid:S1192")
private void write(Page page, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException {
    if (isHidden(page)) {
        return;
    }
    stream.writeStartElement(NS, "url");
    String loc = "";
    if (!extensionlessUrls) {
        loc = externalizer.externalLink(resolver, externalizerDomain, String.format("%s.html", page.getPath()));
    } else {
        String urlFormat = removeTrailingSlash ? "%s" : "%s/";
        loc = externalizer.externalLink(resolver, externalizerDomain, String.format(urlFormat, page.getPath()));
    }
    writeElement(stream, "loc", loc);
    if (includeLastModified) {
        Calendar cal = page.getLastModified();
        if (cal != null) {
            writeElement(stream, "lastmod", DATE_FORMAT.format(cal));
        }
    }
    if (includeInheritValue) {
        HierarchyNodeInheritanceValueMap hierarchyNodeInheritanceValueMap = new HierarchyNodeInheritanceValueMap(page.getContentResource());
        writeFirstPropertyValue(stream, "changefreq", changefreqProperties, hierarchyNodeInheritanceValueMap);
        writeFirstPropertyValue(stream, "priority", priorityProperties, hierarchyNodeInheritanceValueMap);
    } else {
        ValueMap properties = page.getProperties();
        writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties);
        writeFirstPropertyValue(stream, "priority", priorityProperties, properties);
    }
    stream.writeEndElement();
}
Also used : HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) Calendar(java.util.Calendar) ValueMap(org.apache.sling.api.resource.ValueMap) HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) InheritanceValueMap(com.day.cq.commons.inherit.InheritanceValueMap)

Example 3 with HierarchyNodeInheritanceValueMap

use of com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class SiteMapServlet method writeAsset.

private void writeAsset(Asset asset, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException {
    stream.writeStartElement(NS, "url");
    String loc = externalizer.externalLink(resolver, externalizerDomain, asset.getPath());
    writeElement(stream, "loc", loc);
    if (includeLastModified) {
        long lastModified = asset.getLastModified();
        if (lastModified > 0) {
            writeElement(stream, "lastmod", DATE_FORMAT.format(lastModified));
        }
    }
    Resource contentResource = asset.adaptTo(Resource.class).getChild(JcrConstants.JCR_CONTENT);
    if (contentResource != null) {
        if (includeInheritValue) {
            HierarchyNodeInheritanceValueMap hierarchyNodeInheritanceValueMap = new HierarchyNodeInheritanceValueMap(contentResource);
            writeFirstPropertyValue(stream, "changefreq", changefreqProperties, hierarchyNodeInheritanceValueMap);
            writeFirstPropertyValue(stream, "priority", priorityProperties, hierarchyNodeInheritanceValueMap);
        } else {
            ValueMap properties = contentResource.getValueMap();
            writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties);
            writeFirstPropertyValue(stream, "priority", priorityProperties, properties);
        }
    }
    stream.writeEndElement();
}
Also used : HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) ValueMap(org.apache.sling.api.resource.ValueMap) HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) InheritanceValueMap(com.day.cq.commons.inherit.InheritanceValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 4 with HierarchyNodeInheritanceValueMap

use of com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class TwitterAdapterFactory method findTwitterConfiguration.

private com.day.cq.wcm.webservicesupport.Configuration findTwitterConfiguration(Page page) {
    ConfigurationManager configurationManager = page.getContentResource().getResourceResolver().adaptTo(ConfigurationManager.class);
    final HierarchyNodeInheritanceValueMap pageProperties = new HierarchyNodeInheritanceValueMap(page.getContentResource());
    final String[] services = pageProperties.getInherited(ConfigurationConstants.PN_CONFIGURATIONS, new String[0]);
    return configurationManager.getConfiguration(CLOUD_SERVICE_NAME, services);
}
Also used : HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) ConfigurationManager(com.day.cq.wcm.webservicesupport.ConfigurationManager)

Example 5 with HierarchyNodeInheritanceValueMap

use of com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class ErrorPageHandlerImpl method findErrorsPath.

/**
 * Searches for a resource specific error page.
 *
 * @param errorResource
 * @return path to the default error page or "root" error page
 */
private String findErrorsPath(SlingHttpServletRequest request, Resource errorResource) {
    final String errorResourcePath = errorResource.getPath();
    Resource real = findFirstRealParentOrSelf(request, errorResource);
    String errorsPath = null;
    if (real != null) {
        log.trace("Found real resource at [ {} ]", real.getPath());
        if (!JcrConstants.JCR_CONTENT.equals(real.getName())) {
            Resource tmp = real.getChild(JcrConstants.JCR_CONTENT);
            if (tmp != null) {
                real = tmp;
            }
        }
        final InheritanceValueMap pageProperties = new HierarchyNodeInheritanceValueMap(real);
        errorsPath = pageProperties.getInherited(ERROR_PAGE_PROPERTY, String.class);
    } else {
        log.trace("No page found for [ {} ]", errorResource);
    }
    if (errorsPath == null) {
        log.trace("could not find inherited property for [ {} ]", errorResource);
        for (final Map.Entry<String, String> mapPage : pathMap.entrySet()) {
            if (errorResourcePath.startsWith(mapPage.getKey())) {
                log.trace("found error path in map [ {} ]", mapPage.getKey());
                errorsPath = mapPage.getValue();
                break;
            }
        }
    }
    log.debug("Best matching errors path for request is: {}", errorsPath);
    return errorsPath;
}
Also used : HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) InheritanceValueMap(com.day.cq.commons.inherit.InheritanceValueMap) HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) Resource(org.apache.sling.api.resource.Resource) Map(java.util.Map) HierarchyNodeInheritanceValueMap(com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap) InheritanceValueMap(com.day.cq.commons.inherit.InheritanceValueMap) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap)

Aggregations

HierarchyNodeInheritanceValueMap (com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap)5 InheritanceValueMap (com.day.cq.commons.inherit.InheritanceValueMap)4 Resource (org.apache.sling.api.resource.Resource)3 ValueMap (org.apache.sling.api.resource.ValueMap)2 WorkflowException (com.adobe.granite.workflow.WorkflowException)1 WorkflowData (com.adobe.granite.workflow.exec.WorkflowData)1 WorkflowModel (com.adobe.granite.workflow.model.WorkflowModel)1 ConfigurationManager (com.day.cq.wcm.webservicesupport.ConfigurationManager)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1