GuideLCServiceConnectorImpl.java 9.09 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemds.guide.service.GuideException
 *  com.adobe.aemds.guide.service.GuideLCServiceConnector
 *  com.adobe.idp.dsc.InvocationRequest
 *  com.adobe.idp.dsc.InvocationResponse
 *  com.adobe.idp.dsc.clientsdk.ServiceClient
 *  com.adobe.idp.dsc.clientsdk.ServiceClientFactory
 *  com.adobe.idp.dsc.filter.Condition
 *  com.adobe.idp.dsc.filter.FilterResult
 *  com.adobe.idp.dsc.filter.PagingFilter
 *  com.adobe.idp.dsc.registry.InputParameterNotFoundException
 *  com.adobe.idp.dsc.registry.OperationNotFoundException
 *  com.adobe.idp.dsc.registry.infomodel.InputParameter
 *  com.adobe.idp.dsc.registry.infomodel.Operation
 *  com.adobe.idp.dsc.registry.infomodel.ServiceConfiguration
 *  com.adobe.idp.dsc.registry.service.ServiceConfigurationFilter
 *  com.adobe.idp.dsc.registry.service.ServiceRegistry
 *  com.adobe.livecycle.dsc.clientsdk.ServiceClientFactoryProvider
 *  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.commons.osgi.PropertiesUtil
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.addon.service.impl;

import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideLCServiceConnector;
import com.adobe.idp.dsc.InvocationRequest;
import com.adobe.idp.dsc.InvocationResponse;
import com.adobe.idp.dsc.clientsdk.ServiceClient;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.dsc.filter.Condition;
import com.adobe.idp.dsc.filter.FilterResult;
import com.adobe.idp.dsc.filter.PagingFilter;
import com.adobe.idp.dsc.registry.InputParameterNotFoundException;
import com.adobe.idp.dsc.registry.OperationNotFoundException;
import com.adobe.idp.dsc.registry.infomodel.InputParameter;
import com.adobe.idp.dsc.registry.infomodel.Operation;
import com.adobe.idp.dsc.registry.infomodel.ServiceConfiguration;
import com.adobe.idp.dsc.registry.service.ServiceConfigurationFilter;
import com.adobe.idp.dsc.registry.service.ServiceRegistry;
import com.adobe.livecycle.dsc.clientsdk.ServiceClientFactoryProvider;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(label="Guide LiveCycle Process Locator and Invoker", description="Guide LC Process Locator and Invoker Service", immediate=1, metatype=1)
@Service(value={GuideLCServiceConnector.class})
public class GuideLCServiceConnectorImpl
implements GuideLCServiceConnector {
    @Reference
    private ServiceClientFactoryProvider serviceClientFactoryProvider;
    @Reference
    private ServiceRegistry serviceRegistry;
    @Property(value={"dataxml"}, label="Name of the data xml parameter", description="Name of the parameter corresponding to data xml")
    private static final String DATA_XML = "dataXml";
    private String dataXml;
    @Property(value={"fileAttachmentsList"}, label="Name of the file attachments parameter", description="Name of the parameter corresponding to the list of file attachments")
    private static final String FILE_ATTACHMENTS_LIST = "fileAttachmentsList";
    private String fileAttachmentsList;
    @Property(value={"documentOfRecord"}, label="Name of the document of record parameter", description="Name of the parameter corresponding to document of record")
    private static final String DOCUMENT_OF_RECORD = "documentOfRecord";
    private String documentOfRecord;
    private static final String INVOKE_METHOD = "invoke";
    private Logger logger = LoggerFactory.getLogger(GuideLCServiceConnectorImpl.class);

    protected void activate(ComponentContext context) {
        Dictionary props = context.getProperties();
        this.dataXml = PropertiesUtil.toString(props.get("dataXml"), (String)"dataXml");
        this.fileAttachmentsList = PropertiesUtil.toString(props.get("fileAttachmentsList"), (String)"fileAttachmentsList");
        this.documentOfRecord = PropertiesUtil.toString(props.get("documentOfRecord"), (String)"documentOfRecord");
    }

    public List<String> getServices() {
        try {
            ServiceConfigurationFilter filter = new ServiceConfigurationFilter();
            filter.addCondition("type", (Object)"WKF");
            FilterResult configs = this.serviceRegistry.getServiceConfigurations((PagingFilter)filter);
            ArrayList<String> serviceNames = new ArrayList<String>();
            for (Object config : configs) {
                ServiceConfiguration serviceConfig = (ServiceConfiguration)config;
                try {
                    Operation op = null;
                    try {
                        op = serviceConfig.getOperation("invoke");
                        if (op == null) continue;
                        InputParameter[] inParams = op.getInputParameters();
                        InputParameter data = null;
                        InputParameter files = null;
                        try {
                            data = op.getInputParameter(this.dataXml);
                            files = op.getInputParameter(this.fileAttachmentsList);
                        }
                        catch (InputParameterNotFoundException e) {
                            this.logger.info("No parameters found by the names " + this.dataXml + " and " + this.fileAttachmentsList, (Throwable)e);
                        }
                        if (data == null) continue;
                        serviceNames.add(serviceConfig.getServiceId());
                    }
                    catch (Exception e) {
                        this.logger.info("Ignoring process '" + serviceConfig.getServiceId() + "' - No operation found by the name '" + "invoke" + "'", (Throwable)e);
                    }
                    continue;
                }
                catch (Exception e) {
                    throw new GuideException(e);
                }
            }
            return serviceNames;
        }
        catch (Exception e) {
            throw new GuideException(e);
        }
    }

    public String getXmlParameterName() {
        return this.dataXml;
    }

    public String getFileListParameterName() {
        return this.fileAttachmentsList;
    }

    public String getDocumentOfRecordParameterName() {
        return this.documentOfRecord;
    }

    public Map invokeProcess(String process, Map inputParams) {
        return this.invokeProcess(process, "invoke", inputParams, false);
    }

    private Map invokeProcess(String process, String method, Map inputParams, boolean waitForResponse) {
        try {
            HashMap outputParams = null;
            boolean synchronous = false;
            long l1 = System.currentTimeMillis();
            try {
                ServiceConfiguration serviceConfiguration = this.serviceRegistry.getHeadActiveConfiguration(process);
                synchronous = !serviceConfiguration.getOperation(method).getLongLived();
            }
            catch (OperationNotFoundException e) {
                throw new GuideException((Exception)e);
            }
            long l2 = System.currentTimeMillis();
            ServiceClientFactory serviceClientFactory = this.serviceClientFactoryProvider.getDefaultServiceClientFactory();
            InvocationRequest request = serviceClientFactory.createInvocationRequest(process, method, inputParams, synchronous);
            request.setProperty("INVOKER_TYPE", (Object)"INVOKER_TYPE_SYSTEM");
            InvocationResponse response = null;
            response = serviceClientFactory.getServiceClient().invoke(request);
            if (synchronous) {
                outputParams = response.getOutputParameters();
            } else {
                outputParams = new HashMap();
                String invocationId = response.getInvocationId();
            }
            return outputParams;
        }
        catch (Exception e) {
            throw new GuideException(e);
        }
    }

    protected void bindServiceClientFactoryProvider(ServiceClientFactoryProvider serviceClientFactoryProvider) {
        this.serviceClientFactoryProvider = serviceClientFactoryProvider;
    }

    protected void unbindServiceClientFactoryProvider(ServiceClientFactoryProvider serviceClientFactoryProvider) {
        if (this.serviceClientFactoryProvider == serviceClientFactoryProvider) {
            this.serviceClientFactoryProvider = null;
        }
    }

    protected void bindServiceRegistry(ServiceRegistry serviceRegistry) {
        this.serviceRegistry = serviceRegistry;
    }

    protected void unbindServiceRegistry(ServiceRegistry serviceRegistry) {
        if (this.serviceRegistry == serviceRegistry) {
            this.serviceRegistry = null;
        }
    }
}