AfterMovePageProcess.java 4.03 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.replication.ReplicationActionType
 *  com.day.cq.replication.ReplicationException
 *  com.day.cq.replication.Replicator
 *  com.day.cq.workflow.WorkflowException
 *  com.day.cq.workflow.WorkflowSession
 *  com.day.cq.workflow.exec.WorkItem
 *  com.day.cq.workflow.exec.WorkflowData
 *  com.day.cq.workflow.exec.WorkflowProcess
 *  com.day.cq.workflow.metadata.MetaDataMap
 *  javax.jcr.Session
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.jcr.resource.JcrResourceResolverFactory
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.workflow.process;

import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.Replicator;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowData;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import javax.jcr.Session;
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.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service(value={WorkflowProcess.class})
@Property(name="process.label", value={"Replicate After Page Move"})
public class AfterMovePageProcess
implements WorkflowProcess {
    @Reference
    protected JcrResourceResolverFactory jcrResourceResolverFactory;
    @Reference
    protected Replicator replicator;
    private static final Logger log = LoggerFactory.getLogger(AfterMovePageProcess.class);

    public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
        try {
            MetaDataMap metaDataMap = workItem.getWorkflowData().getMetaDataMap();
            String srcPath = (String)metaDataMap.get("srcPath", String.class);
            ReplicationActionType replicationType = ReplicationActionType.valueOf((String)((String)metaDataMap.get("replicationType", String.class)));
            String[] publishReferences = (String[])metaDataMap.get("publishReferences", String[].class);
            Session session = workflowSession.getSession();
            ResourceResolver resolver = this.jcrResourceResolverFactory.getResourceResolver(session);
            log.debug("Replicate page in workflow " + srcPath);
            this.replicator.replicate(session, replicationType, srcPath);
            if (publishReferences != null) {
                for (String ref : publishReferences) {
                    log.debug("Replicate reference of page (" + srcPath + ") in workflow " + ref);
                    this.replicator.replicate(session, ReplicationActionType.ACTIVATE, ref);
                }
            }
        }
        catch (ReplicationException e) {
            throw new WorkflowException((Throwable)e);
        }
    }

    protected void bindJcrResourceResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
        this.jcrResourceResolverFactory = jcrResourceResolverFactory;
    }

    protected void unbindJcrResourceResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
        if (this.jcrResourceResolverFactory == jcrResourceResolverFactory) {
            this.jcrResourceResolverFactory = null;
        }
    }

    protected void bindReplicator(Replicator replicator) {
        this.replicator = replicator;
    }

    protected void unbindReplicator(Replicator replicator) {
        if (this.replicator == replicator) {
            this.replicator = null;
        }
    }
}