DocumentTimeStampService.java 4.18 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.fd.docassurance.client.api.DocAssuranceService
 *  com.adobe.fd.signatures.client.types.VerificationTime
 *  com.adobe.fd.signatures.pdf.inputs.UnlockOptions
 *  com.adobe.fd.signatures.pdf.inputs.ValidationPreferences
 *  com.adobe.granite.workflow.WorkflowException
 *  com.adobe.granite.workflow.WorkflowSession
 *  com.adobe.granite.workflow.exec.WorkItem
 *  com.adobe.granite.workflow.metadata.MetaDataMap
 *  javax.jcr.Session
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.jcr.api.SlingRepository
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.fd.workflow.docassurance;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.docassurance.client.api.DocAssuranceService;
import com.adobe.fd.signatures.client.types.VerificationTime;
import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;
import com.adobe.fd.signatures.pdf.inputs.ValidationPreferences;
import com.adobe.fd.workflow.docassurance.intrernal.utils.DocAssuranceObjectParser;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
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 javax.jcr.Session;
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.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service
public class DocumentTimeStampService
extends AEMFDWorkflowProcess {
    @Reference
    private DocAssuranceService docAssuranceService;
    @Reference
    private SlingRepository slingRepository;
    private static final Logger log = LoggerFactory.getLogger(DocumentTimeStampService.class);

    @Override
    public void internal_execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
        ResourceResolver resourceResolver = null;
        try {
            Document inDoc = DocAssuranceObjectParser.getInputDoc(item, args);
            Document outputDoc = null;
            if (inDoc == null) {
                log.debug("Input Document is null");
                throw new WorkflowException("Input Document can not be null");
            }
            resourceResolver = this.getResourceResolver((Session)session.adaptTo(Session.class));
            UnlockOptions unlockOptions = DocAssuranceObjectParser.getUnlockOptions(args, resourceResolver);
            VerificationTime verificationTime = DocAssuranceObjectParser.getVerificationTimeType(args);
            ValidationPreferences validationPreferences = DocAssuranceObjectParser.getValidationPreferences(args, resourceResolver);
            outputDoc = this.docAssuranceService.applyDocumentTimeStamp(inDoc, verificationTime, validationPreferences, resourceResolver, unlockOptions);
            DocAssuranceObjectParser.saveDoc(item, session, outputDoc);
        }
        catch (Exception e) {
            log.debug("Exception in Document TimeStamp Service", (Throwable)e);
            throw new WorkflowException("Exception in Document TimeStamp Service", (Throwable)e);
        }
    }

    protected void bindDocAssuranceService(DocAssuranceService docAssuranceService) {
        this.docAssuranceService = docAssuranceService;
    }

    protected void unbindDocAssuranceService(DocAssuranceService docAssuranceService) {
        if (this.docAssuranceService == docAssuranceService) {
            this.docAssuranceService = null;
        }
    }

    protected void bindSlingRepository(SlingRepository slingRepository) {
        this.slingRepository = slingRepository;
    }

    protected void unbindSlingRepository(SlingRepository slingRepository) {
        if (this.slingRepository == slingRepository) {
            this.slingRepository = null;
        }
    }
}