
com.adobe.fd.fp.external.FormsPortalDraftDataProviderImpl Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2014 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.external;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
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.ReferencePolicyOption;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.Constants;
import com.adobe.aemds.guide.service.GuideDraftStateProvider;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.fd.fp.common.PortalUtilsComponent;
import com.adobe.fd.fp.config.FormsPortalDraftsandSubmissionConfigService;
import com.adobe.fd.fp.service.DraftAFDataService;
import com.adobe.fd.fp.service.DraftDataService;
import com.adobe.fd.fp.service.DraftMetadataService;
import com.adobe.fd.fp.util.FormsPortalConstants;
import com.adobe.fd.fp.util.PortalUtils;
import com.adobe.forms.common.service.DataOptions;
import com.adobe.forms.common.service.DataProvider;
import com.adobe.forms.common.service.FormsException;
import com.adobe.forms.common.service.PrefillData;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
@Component(metatype = false, immediate = true, label = "FormsPortalDraftDataProviderImpl")
@Service(value = {GuideDraftStateProvider.class, DataProvider.class})
public class FormsPortalDraftDataProviderImpl implements GuideDraftStateProvider, DataProvider {
@Property(intValue=2100)
static final String SERVICE_RANKING = Constants.SERVICE_RANKING;
@Reference(referenceInterface=PortalUtilsComponent.class)
private PortalUtilsComponent portalUtilsComponent;
@Reference(referenceInterface=DraftAFDataService.class, policy=ReferencePolicy.DYNAMIC, policyOption=ReferencePolicyOption.GREEDY, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private volatile DraftAFDataService fpAfDataService;
@Reference(referenceInterface=ResourceResolverHelper.class)
ResourceResolverHelper resourceResolverHelper;
@Reference(referenceInterface=FormsPortalDraftsandSubmissionConfigService.class)
private FormsPortalDraftsandSubmissionConfigService draftsandSubmissionConfiguration;
@Override
public String getGuideDraftState(String draftID) throws GuideException {
return getData(draftID);
}
private String getData(String draftID) {
String response = null;
try {
DraftMetadataService fpDraftMetadataService = (DraftMetadataService) PortalUtils.getService(DraftMetadataService.class, portalUtilsComponent.getDMSFilter());
DraftDataService fpDraftDataService = (DraftDataService) PortalUtils.getService(DraftDataService.class, portalUtilsComponent.getDDSFilter());
if(draftID.startsWith(FormsPortalConstants.STR_CONTENT_FORMS_FP)){
draftID = draftID.substring(draftID.lastIndexOf("/") + 1);
}
String userdataID = null;
// CQ-102852: Something like "//" will never be present in draft id. It comes in cases when prefill service is present using service:// protocol.
//So adding this check as it will never be a draft reload case if "//" is present in the dataref.
//for example - incase of prefill service it will be something like "service://randomprefillservice"
//and formsportal should not be bothered by it and should retrun null
if(StringUtils.isNotEmpty(draftID) && !draftID.contains("//")) {
userdataID = fpDraftMetadataService.getProperty(draftID, FormsPortalConstants.STR_USERDATA_ID)[0];
}
if(userdataID != null && !userdataID.trim().isEmpty()){
if(fpAfDataService != null){
response = new String(fpAfDataService.getAFDraftUserData(userdataID), "UTF-8");
} else {
response = new String(fpDraftDataService.getData(userdataID), "UTF-8");
}
} else {
return null;
}
} catch (Exception e) {
throw new GuideException(e.getMessage(),e);
}
return response;
}
@Override
public PrefillData getPrefillData(DataOptions options) throws FormsException {
String draftID = options.getDataRef();
PrefillData prefillData = null;
if(StringUtils.isNotEmpty(draftID)) {
String data = getData(draftID);
if(StringUtils.isNotEmpty(data)) {
InputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
prefillData = new PrefillData(is, options.getContentType());
}
}
return prefillData;
}
@Override
public String getServiceDescription() {
return null;
}
@Override
public String getServiceName() {
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy