Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgonzalez committed May 9, 2020
1 parent d5822cc commit d56731d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
@@ -1,5 +1,5 @@
/*
* ACS AEM Commons
* ACS AEM Commons Bundle
*
* Copyright (C) 2020 Adobe
*
Expand Down
Expand Up @@ -30,21 +30,27 @@
import com.day.cq.workflow.collection.ResourceCollectionManager;
import com.day.cq.workflow.collection.ResourceCollectionUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.*;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* ACS AEM Commons - Workflow Package Manager.
Expand Down Expand Up @@ -79,13 +85,6 @@ public class WorkflowPackageManagerImpl implements WorkflowPackageManager {
private static final String[] DEFAULT_WF_PACKAGE_TYPES = {"cq:Page", "cq:PageContent", "dam:Asset"};

private String[] workflowPackageTypes = DEFAULT_WF_PACKAGE_TYPES;

private static final String SERVICE_NAME = "workflowpackagemanager-service";
private static final Map<String, Object> AUTH_INFO;

static {
AUTH_INFO = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_NAME);
}

@Property(label = "Workflow Package Types",
description = "Node Types allowed by the WF Package. Default: cq:Page, cq:PageContent, dam:Asset",
Expand All @@ -95,11 +94,6 @@ public class WorkflowPackageManagerImpl implements WorkflowPackageManager {

@Reference
private ResourceCollectionManager resourceCollectionManager;

@Reference
ResourceResolverFactory resourceResolverFactory;

private String bucketPath;

/**
* {@inheritDoc}
Expand All @@ -119,7 +113,7 @@ public final Page create(final ResourceResolver resourceResolver, String bucketS
final Session session = resourceResolver.adaptTo(Session.class);
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);


String bucketPath = getBucketPath(resourceResolver);

if (StringUtils.isNotBlank(bucketSegment)) {
bucketPath += "/" + bucketSegment;
Expand Down Expand Up @@ -164,7 +158,7 @@ public final List<String> getPaths(final ResourceResolver resourceResolver,
* {@inheritDoc}
*/
public final List<String> getPaths(final ResourceResolver resourceResolver,
final String path, final String[] nodeTypes) throws RepositoryException {
final String path, final String[] nodeTypes) throws RepositoryException {
final List<String> collectionPaths = new ArrayList<String>();

final Resource resource = resourceResolver.getResource(path);
Expand Down Expand Up @@ -280,14 +274,5 @@ private String getBucketPath(final ResourceResolver resourceResolver) {
protected final void activate(final Map<String, String> config) {
workflowPackageTypes =
PropertiesUtil.toStringArray(config.get(PROP_WF_PACKAGE_TYPES), DEFAULT_WF_PACKAGE_TYPES);
try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO)) {
bucketPath = getBucketPath(resolver);
log.debug("using {} as bucket path for wf packages",bucketPath);
} catch (LoginException e) {
log.error("Cannot determine bucket path for WorkflowPackageManager, do not activate this service",e);
// this service must not get activated
throw new IllegalStateException(e);
}

}
}
Expand Up @@ -75,17 +75,21 @@ public final void execute(WorkItem workItem, WorkflowSession workflowSession, Me
}

if (resourceResolver.hasChanges()) {
try {
resourceResolver.adaptTo(Session.class).getWorkspace().getObservationManager().setUserData(EVENT_DATA);
} catch (RepositoryException e) {
log.warn("Unable to set user-data to [ " + EVENT_DATA + " ]", e);
}
setJcrSessionUserData(resourceResolver);
}
} catch (RepositoryException e) {
throw new WorkflowException(String.format("Could not find the payload for '%s'", wfPayload), e);
}
}

protected void setJcrSessionUserData(ResourceResolver resourceResolver) {
try {
resourceResolver.adaptTo(Session.class).getWorkspace().getObservationManager().setUserData(EVENT_DATA);
} catch (RepositoryException e) {
log.warn("Unable to set user-data to [ " + EVENT_DATA + " ]", e);
}
}

protected void copyProperties(MetaDataMap metaDataMap, ResourceResolver resourceResolver, String payload) {
final Resource resource = workflowHelper.getPageOrAssetResource(resourceResolver, payload);

Expand Down Expand Up @@ -128,7 +132,7 @@ public PropertyResource(String mapProperty, String payload, ResourceResolver res

if (resource == null || StringUtils.isBlank(propertyName)) {
throw new WorkflowException(String.format("Unable to parse valid resource and property combination from [ %s + %s ]",
new String[]{payload, mapProperty}));
payload, mapProperty));
}
}

Expand Down
@@ -1,5 +1,5 @@
/*
* ACS AEM Commons
* ACS AEM Commons Bundle
*
* Copyright (C) 2020 Adobe
*
Expand Down

0 comments on commit d56731d

Please sign in to comment.