Search in sources :

Example 6 with ReplicationActionType

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

the class DispatcherFlushRulesImplTest method testConfigureReplicationActionType_DELETE.

@Test
public void testConfigureReplicationActionType_DELETE() throws Exception {
    final ReplicationActionType expected = ReplicationActionType.DELETE;
    final ReplicationActionType actual = dispatcherFlushRules.configureReplicationActionType("DELETE");
    assertEquals(expected, actual);
}
Also used : ReplicationActionType(com.day.cq.replication.ReplicationActionType) Test(org.junit.Test)

Example 7 with ReplicationActionType

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

the class DispatcherFlushRulesImplTest method testConfigureReplicationActionType_INHERIT.

@Test
public void testConfigureReplicationActionType_INHERIT() throws Exception {
    final ReplicationActionType expected = null;
    final ReplicationActionType actual = dispatcherFlushRules.configureReplicationActionType("INHERIT");
    assertEquals(expected, actual);
}
Also used : ReplicationActionType(com.day.cq.replication.ReplicationActionType) Test(org.junit.Test)

Example 8 with ReplicationActionType

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

the class DispatcherFlushRulesImpl method preprocess.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("squid:S3776")
public final void preprocess(final ReplicationAction replicationAction, final ReplicationOptions replicationOptions) throws ReplicationException {
    if (!this.accepts(replicationAction, replicationOptions)) {
        return;
    }
    // Path being replicated
    final String path = replicationAction.getPath();
    // Replication action type occurring
    final ReplicationActionType flushActionType = replicationActionType == null ? replicationAction.getType() : replicationActionType;
    ResourceResolver resourceResolver = null;
    try {
        resourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
        // Flush full content hierarchies
        for (final Map.Entry<Pattern, String[]> entry : this.hierarchicalFlushRules.entrySet()) {
            final Pattern pattern = entry.getKey();
            final Matcher m = pattern.matcher(path);
            if (m.matches()) {
                for (final String value : entry.getValue()) {
                    final String flushPath = m.replaceAll(value);
                    log.debug("Requesting hierarchical flush of associated path: {} ~> {}", path, flushPath);
                    dispatcherFlusher.flush(resourceResolver, flushActionType, false, HIERARCHICAL_FILTER, flushPath);
                }
            }
        }
        // Flush explicit resources using the CQ-Action-Scope ResourceOnly header
        for (final Map.Entry<Pattern, String[]> entry : this.resourceOnlyFlushRules.entrySet()) {
            final Pattern pattern = entry.getKey();
            final Matcher m = pattern.matcher(path);
            if (m.matches()) {
                for (final String value : entry.getValue()) {
                    final String flushPath = m.replaceAll(value);
                    log.debug("Requesting ResourceOnly flush of associated path: {} ~> {}", path, entry.getValue());
                    dispatcherFlusher.flush(resourceResolver, flushActionType, false, RESOURCE_ONLY_FILTER, flushPath);
                }
            }
        }
    } catch (LoginException e) {
        log.error("Error issuing  dispatcher flush rules do to repository login exception: {}", e.getMessage());
    } finally {
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) LoginException(org.apache.sling.api.resource.LoginException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ReplicationActionType(com.day.cq.replication.ReplicationActionType)

Example 9 with ReplicationActionType

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

the class DispatcherFlushRulesImpl method configureReplicationActionType.

/**
 * Derive the ReplicationActionType to be used for Flushes.
 *
 * @param replicationActionTypeName String name of ReplicationActionType to use
 * @return the ReplicationActionType to use, or null if the ReplicationActionType should be inherited from the
 * incoming ReplicationAction
 */
protected final ReplicationActionType configureReplicationActionType(final String replicationActionTypeName) {
    try {
        final ReplicationActionType repActionType = ReplicationActionType.valueOf(replicationActionTypeName);
        log.debug("Using replication action type: {}", repActionType.name());
        return repActionType;
    } catch (IllegalArgumentException ex) {
        log.debug("Using replication action type: {}", OPTION_INHERIT);
        return null;
    }
}
Also used : ReplicationActionType(com.day.cq.replication.ReplicationActionType)

Example 10 with ReplicationActionType

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

the class BrandPortalSyncProcess method execute.

public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
    ResourceResolver resourceResolver = null;
    final List<String> assetPaths = new ArrayList<String>();
    final ReplicationActionType replicationActionType = getReplicationActionType(metaDataMap);
    try {
        resourceResolver = workflowHelper.getResourceResolver(workflowSession);
        final List<String> payloads = workflowPackageManager.getPaths(resourceResolver, (String) workItem.getWorkflowData().getPayload());
        for (final String payload : payloads) {
            // Convert the payloads to Assets, in preparation for Brand Portal publication
            // Note that this only supports Assets as payloads and NOT Asset Folders
            final Asset asset = DamUtil.resolveToAsset(resourceResolver.getResource(payload));
            if (asset == null) {
                log.debug("Payload path [ {} ] does not resolve to an asset", payload);
            } else {
                assetPaths.add(asset.getPath());
            }
        }
        // Based on the WF Process activation/deactivation directive; leverage the DamSyncService to publish the the Asset
        if (ReplicationActionType.ACTIVATE.equals(replicationActionType)) {
            damSyncService.publishResourcesToMP(assetPaths, resourceResolver);
        } else if (ReplicationActionType.DEACTIVATE.equals(replicationActionType)) {
            damSyncService.unpublishResourcesFromMP(assetPaths, resourceResolver);
        } else {
            log.warn("Unknown replication action type [ {} ] for AEM Assets Brand Portal Sync", replicationActionType);
        }
    } catch (RepositoryException e) {
        log.error("Could not find the payload", e);
        throw new WorkflowException("Could not find the payload");
    } finally {
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
}
Also used : WorkflowException(com.adobe.granite.workflow.WorkflowException) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) Asset(com.day.cq.dam.api.Asset) RepositoryException(javax.jcr.RepositoryException) ReplicationActionType(com.day.cq.replication.ReplicationActionType)

Aggregations

ReplicationActionType (com.day.cq.replication.ReplicationActionType)10 Test (org.junit.Test)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Session (javax.jcr.Session)2 LoginException (org.apache.sling.api.resource.LoginException)2 WorkflowException (com.adobe.granite.workflow.WorkflowException)1 Asset (com.day.cq.dam.api.Asset)1 Agent (com.day.cq.replication.Agent)1 ReplicationException (com.day.cq.replication.ReplicationException)1 ReplicationOptions (com.day.cq.replication.ReplicationOptions)1 ReplicationResult (com.day.cq.replication.ReplicationResult)1 Page (com.day.cq.wcm.api.Page)1 PageManager (com.day.cq.wcm.api.PageManager)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 RepositoryException (javax.jcr.RepositoryException)1