LCSubmitActionService.java 6.5 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemds.guide.model.FormSubmitInfo
 *  com.adobe.aemds.guide.service.FormSubmitActionService
 *  com.adobe.aemds.guide.service.GuideLCServiceConnector
 *  com.adobe.aemds.guide.utils.GuideUtils
 *  com.adobe.forms.common.service.FileAttachmentWrapper
 *  com.adobe.idp.Document
 *  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.resource.ResourceResolverFactory
 *  org.apache.sling.api.resource.ValueMap
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.addon.service.impl;

import com.adobe.aemds.guide.model.FormSubmitInfo;
import com.adobe.aemds.guide.service.FormSubmitActionService;
import com.adobe.aemds.guide.service.GuideLCServiceConnector;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.forms.common.service.FileAttachmentWrapper;
import com.adobe.idp.Document;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0, immediate=0)
@Service(value={FormSubmitActionService.class})
public class LCSubmitActionService
implements FormSubmitActionService {
    private static final String serviceName = "LC";
    protected static Logger logger = LoggerFactory.getLogger(LCSubmitActionService.class);
    @Reference
    protected ResourceResolverFactory resourceResolverFactory;
    @Reference
    protected GuideLCServiceConnector guideLCServiceConnector;

    public String getServiceName() {
        return "LC";
    }

    public Map<String, Object> submit(FormSubmitInfo formSubmitInfo) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        result.put("FormSubmissionComplete", Boolean.FALSE);
        ResourceResolver resourceResolver = null;
        Resource formContainerResource = formSubmitInfo.getFormContainerResource();
        if (formContainerResource == null) {
            resourceResolver = GuideUtils.getServiceResourceResolver((ResourceResolverFactory)this.resourceResolverFactory);
            formContainerResource = resourceResolver.getResource(formSubmitInfo.getFormContainerPath());
        }
        ValueMap properties = formContainerResource.getValueMap();
        String processName = (String)properties.get("processName", (Object)"");
        Boolean isDorSubmit = Boolean.valueOf((String)properties.get("enableDoRSubmission", (Object)""));
        if (processName != null && processName.length() > 0) {
            Set keys;
            List attachmentWrapperList;
            String dataXmlParamterName = this.guideLCServiceConnector.getXmlParameterName();
            String fileListParameterName = this.guideLCServiceConnector.getFileListParameterName();
            String documentOfRecordParameterName = this.guideLCServiceConnector.getDocumentOfRecordParameterName();
            HashMap<String, Object> inputParams = new HashMap<String, Object>();
            Document dataXml = null;
            if (formSubmitInfo.getData() != null) {
                dataXml = new Document(formSubmitInfo.getData().getBytes());
            }
            inputParams.put(dataXmlParamterName, dataXml);
            ArrayList<Document> fileAttachments = new ArrayList<Document>();
            FileAttachmentWrapper dorPdfWrapper = formSubmitInfo.getDocumentOfRecord();
            if (dorPdfWrapper != null && isDorSubmit.booleanValue()) {
                Document dorDoc = new Document(dorPdfWrapper.getInputStream());
                dorDoc.setContentType(dorPdfWrapper.getContentType());
                dorDoc.setAttribute("file", (Serializable)((Object)dorPdfWrapper.getFileName()));
                inputParams.put(documentOfRecordParameterName, (Object)dorDoc);
            }
            if ((attachmentWrapperList = formSubmitInfo.getFileAttachments()) != null) {
                for (FileAttachmentWrapper attachmentWrapper : attachmentWrapperList) {
                    Document doc = new Document(attachmentWrapper.getInputStream());
                    doc.setContentType(attachmentWrapper.getContentType());
                    doc.setAttribute("file", (Serializable)((Object)attachmentWrapper.getFileName()));
                    fileAttachments.add(doc);
                }
            }
            inputParams.put(fileListParameterName, fileAttachments);
            Map outputParams = this.guideLCServiceConnector.invokeProcess(processName, inputParams);
            if (outputParams != null && (keys = outputParams.keySet()) != null) {
                for (Object key : keys) {
                    Object value = outputParams.get(key);
                    if (value.getClass().isPrimitive()) {
                        result.put((String)key, value);
                        continue;
                    }
                    logger.info("Ignoring " + (String)key + " because the value is not primitive");
                }
            }
            result.put("FormSubmissionComplete", Boolean.TRUE);
        } else {
            logger.error("There is no Forms and Document Workflow associated with this Adaptive Form.");
        }
        return result;
    }

    protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        this.resourceResolverFactory = resourceResolverFactory;
    }

    protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
        if (this.resourceResolverFactory == resourceResolverFactory) {
            this.resourceResolverFactory = null;
        }
    }

    protected void bindGuideLCServiceConnector(GuideLCServiceConnector guideLCServiceConnector) {
        this.guideLCServiceConnector = guideLCServiceConnector;
    }

    protected void unbindGuideLCServiceConnector(GuideLCServiceConnector guideLCServiceConnector) {
        if (this.guideLCServiceConnector == guideLCServiceConnector) {
            this.guideLCServiceConnector = null;
        }
    }
}