
com.adobe.fd.fp.common.AdaptiveFormSubmissionBase Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2016 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.fd.fp.common;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.commons.json.JSONObject;
import com.adobe.aemds.guide.model.FormSubmitInfo;
import com.adobe.aemds.guide.service.external.PortalRecordInfo;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.fd.fp.exception.FormsPortalException;
import com.adobe.fd.fp.model.PendingSignMetadata;
import com.adobe.fd.fp.util.FormsPortalConstants;
import com.adobe.fd.fp.util.RepositoryUtils;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
/**
* Base class for handling of Adaptive Forms submission
* @author sharoon
*
*/
@Component
public abstract class AdaptiveFormSubmissionBase extends FPSubmitHandler {
/**
* Serial Version UID
*/
private static final long serialVersionUID = 4916445735602389229L;
@Reference
protected ResourceResolverHelper resourceResolverHelper;
protected Map getOptionsFromSubmitInfo(FormSubmitInfo formSubmitInfo, Map options) throws FormsPortalException {
if (options == null) {
options = new HashMap();
}
try {
options.put(FormsPortalConstants.STR_ATTACHMENTS, formSubmitInfo.getFileAttachments());
options.put(FormsPortalConstants.STR_OWNER, formSubmitInfo.getFormSubmitter());
if (formSubmitInfo.getDocumentOfRecord() != null) {
options.put(FormsPortalConstants.STR_PDF, getDorBytes(formSubmitInfo));
options.put(GuideConstants.PDF_NAME, formSubmitInfo.getDocumentOfRecord().getFileName());
}
options.put(FormsPortalConstants.STR_FORM_TYPE, FormsPortalConstants.STR_ADAPTIVE_FORM);
options.put(FormsPortalConstants.STR_FORM_CONTAINER_PATH, formSubmitInfo.getFormContainerPath());
options.put(FormsPortalConstants.STR_CONTENT_TYPE, formSubmitInfo.getContentType());
options.put(FormsPortalConstants.STR_FORM_DATA, formSubmitInfo.getData());
options.put(FormsPortalConstants.STR_FILE_ATTACHMENT_MAP, formSubmitInfo.getFileAttachmentMap());
options.put(FormsPortalConstants.STR_LOCALE, formSubmitInfo.getLocale());
String fpAllowedMetadata = (String)options.get(FormsPortalConstants.STR_FP_ALLOWED_METADATA);
if (!StringUtils.isEmpty(fpAllowedMetadata)) {
filterAllowedMetadata(options, options);
fpAllowedMetadata+=","+FormsPortalConstants.STR_FILE_ATTACHMENT_MAP;
} else {
fpAllowedMetadata = FormsPortalConstants.STR_FILE_ATTACHMENT_MAP;
}
PortalRecordInfo portalInfo = formSubmitInfo.getPortalRecordInfo();
if (portalInfo != null) {
if (StringUtils.isNotEmpty(portalInfo.getPendingSignId())) {
options.put(PendingSignMetadata.PENDING_SIGN_ID, portalInfo.getPendingSignId());
}
}
options.put(FormsPortalConstants.STR_FP_ALLOWED_METADATA, fpAllowedMetadata);
addAgreementsRelatedInfo(formSubmitInfo, options);
} catch (Exception e) {
throw new FormsPortalException(e);
}
return options;
}
private void addAgreementsRelatedInfo(FormSubmitInfo formSubmitInfo, Map options) {
if (formSubmitInfo != null) {
PortalRecordInfo portalRecordInfo = formSubmitInfo.getPortalRecordInfo();
if (portalRecordInfo != null && StringUtils.isNotEmpty(portalRecordInfo.getPendingSignId())) {
options.put(PendingSignMetadata.PENDING_SIGN_ID, portalRecordInfo.getPendingSignId());
}
if (StringUtils.isNotEmpty(formSubmitInfo.getAgreementId())) {
options.put(FormsPortalConstants.STR_AGREEMENT_ID, formSubmitInfo.getAgreementId());
}
if (formSubmitInfo.getSignData() != null) {
options.put(FormsPortalConstants.STR_AGREEMENT_DATA, new String(formSubmitInfo.getSignData()));
}
String fpAllowedMetadata = (String)options.get(FormsPortalConstants.STR_FP_ALLOWED_METADATA);
fpAllowedMetadata = fpAllowedMetadata + "," + PendingSignMetadata.PENDING_SIGN_ID
+ "," + FormsPortalConstants.STR_AGREEMENT_ID
+ "," + FormsPortalConstants.STR_AGREEMENT_DATA;
options.put(FormsPortalConstants.STR_FP_ALLOWED_METADATA, fpAllowedMetadata);
}
}
protected Node getFormNodeFromPath(String formPath) throws RepositoryException {
Node formNode = null;
RepositoryUtils repUtils = RepositoryUtils.getInstance(draftsandSubmissionConfiguration);
Session currentSession = resourceResolverHelper.getResourceResolverAs(Session.class);
//LC-8828 If this is an AF inside some CQ page not managed by FM, we need to find that CQ page and read it for name and description, unlike from metadata node in case of FM managed AFs
String parentCQPage = repUtils.findParentCQPage(formPath, currentSession);
formPath = parentCQPage != null? parentCQPage : formPath;
//If form path starts with /content/forms/af, this means it is an AF managed by FM which is supposed to have a metadata node so changing formpath to /content/dam/formsanddocuments/*
if (formPath != null && formPath.startsWith(FormsPortalConstants.STR_CONTENT_FORMS_AF)) {
formPath = FormsPortalConstants.STR_CONTENT_DAM_FORMSANDDOCUMENTS + formPath.substring(FormsPortalConstants.STR_CONTENT_FORMS_AF.length());
}
if (currentSession.nodeExists(formPath)) {
formNode = currentSession.getNode(formPath);
}
return formNode;
}
protected JSONObject submitFormInternal(FormSubmitInfo formSubmitInfo, Map options)
throws FormsPortalException {
try {
if (options == null) {
options = new HashMap();
}
return submitForm(getOptionsFromSubmitInfo(formSubmitInfo, options), getFormNodeFromPath(formSubmitInfo.getFormContainerPath()));
} catch (RepositoryException e) {
throw new FormsPortalException(e);
}
}
protected byte[] getDorBytes(FormSubmitInfo formSubmitInfo) throws Exception {
return IOUtils.toByteArray(formSubmitInfo.getDocumentOfRecord().getInputStream());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy