All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.fd.fp.external.FormPortalSubmitPreprocessorImpl Maven / Gradle / Ivy

package com.adobe.fd.fp.external;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.aemds.guide.service.external.FormPortalSubmitPreprocessor;
import com.adobe.aemds.guide.service.external.PortalRecordInfo;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.fd.fp.exception.ErrorMessages;
import com.adobe.fd.fp.exception.FormsPortalException;
import com.adobe.fd.fp.service.DraftAndSubmissionUtilService;
import com.adobe.fd.fp.service.FormsPortalProcessor;
import com.adobe.fd.fp.util.FormsPortalConstants;

@Component
@Service(value = FormPortalSubmitPreprocessor.class)
public class FormPortalSubmitPreprocessorImpl implements FormPortalSubmitPreprocessor{

    private final Logger log = LoggerFactory.getLogger(FormPortalSubmitPreprocessorImpl.class);

    @Reference(referenceInterface= DraftAndSubmissionUtilService.class)
    private DraftAndSubmissionUtilService dsUtil;
    
    @Reference(target="("+FormsPortalProcessor.PROCESSOR_TYPE + "="+FormsPortalProcessor.SUBMIT+")")
    private FormsPortalProcessor submitProcessor;
    
    @Reference(target="("+FormsPortalProcessor.PROCESSOR_TYPE + "="+FormsPortalProcessor.SIGN+")",
    		policy = ReferencePolicy.DYNAMIC,
    		cardinality = ReferenceCardinality.OPTIONAL_UNARY)
    private volatile FormsPortalProcessor signProcessor;
    
    @Override
    public PortalRecordInfo doPreProcess(Map options) {
    	PortalRecordInfo preProcessorResult = null;
        try {
        	
            String draftID = (String)options.get(FormsPortalConstants.STR_DRAFT_ID);
            try {
                if(!StringUtils.isEmpty(draftID)){
                    dsUtil.deleteDraft(draftID);
                }
            } catch(Exception e) {
               log.error("Draft is either deleted already or an error occured while deleting it" , e);
            }
            if (options.containsKey(GuideConstants.SIGN_AGREEMENT_INFO)) {
            	if (signProcessor == null) {
            		throw new FormsPortalException(ErrorMessages.ALC_FMP_001_053);
            	} else {
            		preProcessorResult = signProcessor.doPreProcess(options);
            	}
            } else if (options.containsKey(GuideConstants.ENABLE_PORTAL_SUBMIT) && (boolean)options.get(GuideConstants.ENABLE_PORTAL_SUBMIT)) {
            	preProcessorResult = submitProcessor.doPreProcess(options);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return preProcessorResult;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy