OptimizePdfProcess.java 3.67 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.granite.workflow.WorkflowException
 *  com.adobe.granite.workflow.WorkflowSession
 *  com.adobe.granite.workflow.exec.WorkItem
 *  com.adobe.granite.workflow.metadata.MetaDataMap
 *  com.adobe.pdfg.result.OptimizePDFResult
 *  com.adobe.pdfg.service.api.GeneratePDFService
 *  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.pdfg;

import com.adobe.aemfd.docmanager.Document;
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 com.adobe.pdfg.result.OptimizePDFResult;
import com.adobe.pdfg.service.api.GeneratePDFService;
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={"OptimizePdfProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"OptimizePdfProcess"})})
public class OptimizePdfProcess
extends AEMFDWorkflowProcess {
    private static Logger LOGGER = LoggerFactory.getLogger(OptimizePdfProcess.class);
    private static final String INDOC_PARAM = "inDoc";
    private static final String FILETYPE_SETTINGS_PARAM = "filetypeSettings";
    private static final String SETTINGS_DOC_PARAM = "settingsDoc";
    private static final String OUT_DOC_PARAM = "outDoc";
    @Reference
    GeneratePDFService generatePdfService;

    @Override
    protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        try {
            OptimizePDFResult result;
            Document inputDoc = DocumentUtils.getInputDocument(workItem, "inDoc");
            String fileTypeSettings = null;
            Document settingsDoc = null;
            if (metaDataMap.get("filetypeSettings", String.class) != null) {
                fileTypeSettings = (String)metaDataMap.get("filetypeSettings", String.class);
                LOGGER.debug("filetypeSettings= " + fileTypeSettings);
            }
            if (metaDataMap.get("settingsDoc", Document.class) != null) {
                settingsDoc = (Document)metaDataMap.get("settingsDoc", Document.class);
            }
            if ((result = this.generatePdfService.optimizePDF(inputDoc, fileTypeSettings, settingsDoc)) != null && result.getConvertedDocument() != null) {
                DocumentUtils.saveOutputDocument(workItem, workflowSession, "outDoc", result.getConvertedDocument());
            }
        }
        catch (Exception e) {
            throw new WorkflowException((Throwable)e);
        }
    }

    protected void bindGeneratePdfService(GeneratePDFService generatePDFService) {
        this.generatePdfService = generatePDFService;
    }

    protected void unbindGeneratePdfService(GeneratePDFService generatePDFService) {
        if (this.generatePdfService == generatePDFService) {
            this.generatePdfService = null;
        }
    }
}