ScriptedPayloadMapper.java 5.52 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.granite.workflow.exec.Workflow
 *  javax.jcr.Binary
 *  javax.jcr.Node
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.scripting.SlingBindings
 *  org.apache.sling.api.scripting.SlingScript
 */
package com.adobe.aemfd.watchfolder.workflow;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.aemfd.watchfolder.util.SessionUtil;
import com.adobe.aemfd.watchfolder.workflow.api.payload.PayloadMapper;
import com.adobe.aemfd.watchfolder.workflow.api.payload.WorkflowExecutionContext;
import com.adobe.aemfd.watchfolder.workflow.api.payload.WorkflowInitializationContext;
import com.adobe.aemfd.watchfolder.workflow.api.payload.WorkflowVariable;
import com.adobe.granite.workflow.exec.Workflow;
import java.util.Collection;
import java.util.Map;
import javax.jcr.Binary;
import javax.jcr.Node;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScript;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component(immediate=1)
@Service(value={PayloadMapper.class})
public class ScriptedPayloadMapper
implements PayloadMapper {
    @Reference
    private SessionUtil sessionUtil;

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    protected /* varargs */ Object doExecute(WorkflowInitializationContext wfInitContext, String method, Object ... args) throws Exception {
        Object object;
        String scriptPath = (String)wfInitContext.getConfigParameters().get("payload.mapper.script.path");
        ResourceResolver rr = this.sessionUtil.getServiceResolver("scripts");
        try {
            SlingBindings sb = new SlingBindings();
            SlingScript script = null;
            Resource r = rr.getResource(scriptPath);
            if (r != null) {
                script = (SlingScript)r.adaptTo(SlingScript.class);
            }
            if (script == null) {
                throw new Exception("Failed to resolve script at path " + scriptPath + ". Verify that the resource exists, is an executable script and is accessible to the" + " service-user used for watch-folder script execution.");
            }
            object = script.call(sb, method, args);
            Object var11_10 = null;
        }
        catch (Throwable var10_12) {
            Object var11_11 = null;
            rr.close();
            throw var10_12;
        }
        rr.close();
        return object;
    }

    @Override
    public Node createPayload(WorkflowInitializationContext wfInitCtxt, Node stagingFolder, String uniquePayloadName, Map<String, Binary> inputs, Collection<WorkflowVariable> variableDefs) throws Exception {
        return (Node)this.doExecute(wfInitCtxt, "createPayload", new Object[]{wfInitCtxt, stagingFolder, uniquePayloadName, inputs, variableDefs});
    }

    @Override
    public Map<String, Document> getInputs(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, ResourceResolver resourceResolver) throws Exception {
        return (Map)this.doExecute(wfInitCtxt, "getInputs", new Object[]{wfInitCtxt, wfExecCtxt, payload, resourceResolver});
    }

    @Override
    public void setOutput(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, String fileName, Binary contents, int outputMode) throws Exception {
        this.doExecute(wfInitCtxt, "setOutput", new Object[]{wfInitCtxt, wfExecCtxt, payload, fileName, contents, outputMode});
    }

    @Override
    public Map<String, Document> getIntermediateOutputs(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, ResourceResolver resourceResolver) throws Exception {
        return (Map)this.doExecute(wfInitCtxt, "getIntermediateOutputs", new Object[]{wfInitCtxt, wfExecCtxt, payload, resourceResolver});
    }

    @Override
    public Map<String, Document> getFinalOutputs(WorkflowInitializationContext wfInitCtxt, Workflow workflow, Node payload, ResourceResolver resourceResolver) throws Exception {
        return (Map)this.doExecute(wfInitCtxt, "getFinalOutputs", new Object[]{wfInitCtxt, workflow, payload, resourceResolver});
    }

    @Override
    public void setVariable(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, WorkflowVariable variable) throws Exception {
        this.doExecute(wfInitCtxt, "setVariable", new Object[]{wfInitCtxt, wfExecCtxt, payload, variable});
    }

    @Override
    public Map<String, Object> getVariables(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload) throws Exception {
        return (Map)this.doExecute(wfInitCtxt, "getVariables", new Object[]{wfInitCtxt, wfExecCtxt, payload});
    }

    protected void bindSessionUtil(SessionUtil sessionUtil) {
        this.sessionUtil = sessionUtil;
    }

    protected void unbindSessionUtil(SessionUtil sessionUtil) {
        if (this.sessionUtil == sessionUtil) {
            this.sessionUtil = null;
        }
    }
}