ConvertToPDFAProcess.java 7.82 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.fd.assembler.client.PDFAConversionOptionSpec
 *  com.adobe.fd.assembler.client.PDFAConversionOptionSpec$ColorSpace
 *  com.adobe.fd.assembler.client.PDFAConversionOptionSpec$Compliance
 *  com.adobe.fd.assembler.client.PDFAConversionOptionSpec$OptionalContent
 *  com.adobe.fd.assembler.client.PDFAConversionOptionSpec$ResultLevel
 *  com.adobe.fd.assembler.client.PDFAConversionOptionSpec$Signatures
 *  com.adobe.fd.assembler.client.PDFAConversionResult
 *  com.adobe.fd.assembler.service.AssemblerService
 *  com.adobe.granite.workflow.WorkflowException
 *  com.adobe.granite.workflow.WorkflowSession
 *  com.adobe.granite.workflow.exec.WorkItem
 *  com.adobe.granite.workflow.metadata.MetaDataMap
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.fd.workflow.assembler;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.assembler.client.PDFAConversionOptionSpec;
import com.adobe.fd.assembler.client.PDFAConversionResult;
import com.adobe.fd.assembler.service.AssemblerService;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
import com.adobe.fd.workflow.utils.DocumentUtils;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import java.util.Collections;
import java.util.List;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service
@Properties(value={@Property(name="service.description", value={"ConvertToPDFAProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"ConvertToPDFAProcess"})})
public class ConvertToPDFAProcess
extends AEMFDWorkflowProcess {
    private static Logger LOGGER = LoggerFactory.getLogger(ConvertToPDFAProcess.class);
    private static final String INDOC_PARAM = "inDoc";
    private static final String PDFADOC_PARAM = "pdfaDoc";
    private static final String CONVERSION_LOG_PARAM = "conversionLog";
    private static final String COMPLIANCE_PARAM = "compliance";
    private static final String RESULT_LEVEL_PARAM = "resultLevel";
    private static final String SIGNATURES_PARAM = "signatures";
    private static final String COLOR_SPACE_PARAM = "colorspace";
    private static final String OPTIONAL_CONTENT_PARAM = "optionalContent";
    private static final String VERIFY_CONVERSION_PARAM = "verifyConversion";
    private static final String LOG_LEVEL_PARAM = "logLevelParam";
    private static final String METDATA_EXTENSION_SCHEMA_PARAM = "metadataExtensionSchema";
    @Reference
    AssemblerService assemblerService;

    @Override
    protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        try {
            Document inDoc = DocumentUtils.getInputDocument(workItem, "inDoc");
            PDFAConversionOptionSpec conversionOptions = this.createPDFAConversionOptions(workItem, workflowSession, metaDataMap);
            PDFAConversionResult conversionResult = this.assemblerService.toPDFA(inDoc, conversionOptions);
            if (!conversionResult.isPDFA()) {
                LOGGER.info("Conversion to PDFA unsuccessfull");
            } else {
                LOGGER.info("Conversion to PDFA successfull");
            }
            DocumentUtils.saveOutputDocument(workItem, workflowSession, "pdfaDoc", conversionResult.getPDFADocument());
            DocumentUtils.saveOutputDocument(workItem, workflowSession, "conversionLog", conversionResult.getConversionLog());
        }
        catch (Exception e) {
            throw new WorkflowException((Throwable)e);
        }
    }

    private PDFAConversionOptionSpec createPDFAConversionOptions(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) {
        String colorspace;
        PDFAConversionOptionSpec conversionOptions = new PDFAConversionOptionSpec();
        if (metaDataMap.get("compliance", String.class) != null) {
            String compliance = (String)metaDataMap.get("compliance", String.class);
            LOGGER.debug("compliance= " + compliance);
            conversionOptions.setCompliance(PDFAConversionOptionSpec.Compliance.valueOf((String)compliance));
        }
        if (metaDataMap.get("resultLevel", String.class) != null) {
            String resultLevel = (String)metaDataMap.get("resultLevel", String.class);
            LOGGER.debug("resultLevel= " + resultLevel);
            conversionOptions.setResultLevel(PDFAConversionOptionSpec.ResultLevel.valueOf((String)resultLevel));
        }
        if (metaDataMap.get("signatures", String.class) != null) {
            String signatures = (String)metaDataMap.get("signatures", String.class);
            LOGGER.debug("signatures= " + signatures);
            conversionOptions.setSignatures(PDFAConversionOptionSpec.Signatures.valueOf((String)signatures));
        }
        if (metaDataMap.get("colorspace", String.class) != null) {
            colorspace = (String)metaDataMap.get("colorspace", String.class);
            LOGGER.debug("colorspace= " + colorspace);
            conversionOptions.setColorSpace(PDFAConversionOptionSpec.ColorSpace.valueOf((String)colorspace));
        }
        if (metaDataMap.get("colorspace", String.class) != null) {
            colorspace = (String)metaDataMap.get("colorspace", String.class);
            LOGGER.debug("colorspace= " + colorspace);
            conversionOptions.setColorSpace(PDFAConversionOptionSpec.ColorSpace.valueOf((String)colorspace));
        }
        if (metaDataMap.get("optionalContent", String.class) != null) {
            String optionalContent = (String)metaDataMap.get("optionalContent", String.class);
            LOGGER.debug("optionalContent= " + optionalContent);
            conversionOptions.setOptionalContent(PDFAConversionOptionSpec.OptionalContent.valueOf((String)optionalContent));
        }
        if (metaDataMap.get("verifyConversion", Boolean.class) != null) {
            Boolean verifyConversion = (Boolean)metaDataMap.get("verifyConversion", Boolean.class);
            LOGGER.debug("verifyConversion= " + verifyConversion);
            conversionOptions.setVerify(verifyConversion.booleanValue());
        }
        if (metaDataMap.get("logLevelParam", String.class) != null) {
            String logLevel = (String)metaDataMap.get("logLevelParam", String.class);
            LOGGER.debug("logLevelParam= " + logLevel);
            conversionOptions.setLogLevel(logLevel);
        }
        if (metaDataMap.get("metadataExtensionSchema", String.class) != null) {
            String metadataSchemaPath = (String)metaDataMap.get("metadataExtensionSchema", String.class);
            LOGGER.debug("metadataExtensionSchema= " + metadataSchemaPath);
            if (!metadataSchemaPath.isEmpty()) {
                conversionOptions.setMetadataSchemaExtensions(Collections.singletonList(new Document(metadataSchemaPath)));
            }
        }
        return conversionOptions;
    }

    protected void bindAssemblerService(AssemblerService assemblerService) {
        this.assemblerService = assemblerService;
    }

    protected void unbindAssemblerService(AssemblerService assemblerService) {
        if (this.assemblerService == assemblerService) {
            this.assemblerService = null;
        }
    }
}