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

com.adobe.fd.fp.external.FPSubmitServiceImpl 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.external;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;

import com.adobe.aemds.guide.model.FormSubmitInfo;
import com.adobe.aemds.guide.service.FormSubmitActionService;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.fd.fp.common.AdaptiveFormSubmissionBase;
import com.adobe.fd.fp.exception.FormsPortalException;
import com.adobe.fd.fp.service.SubmitDataService;
import com.adobe.fd.fp.service.SubmitMetadataService;
import com.adobe.fd.fp.util.FormsPortalConstants;
import com.adobe.fd.fp.util.PortalUtils;

/**
 * @author sharoon
 *
 */
@Component(immediate=true)
@Service
public class FPSubmitServiceImpl extends AdaptiveFormSubmissionBase implements FormSubmitActionService{

	/**
	 * Serial Version UID 
	 */
	private static final long serialVersionUID = 3540542983992781935L;
	
	private static final String FORMS_PORTAl ="formsPortal";
	/* (non-Javadoc)
	 * @see com.adobe.aemds.guide.service.FormSubmitService#getServiceName()
	 */
	@Override
	public String getServiceName() {
		return FORMS_PORTAl;
	}

	/* (non-Javadoc)
	 * @see com.adobe.aemds.guide.service.FormSubmitService#submit(com.adobe.aemds.guide.model.FormSubmitInfo)
	 */
	@Override
	public Map submit(FormSubmitInfo formSubmitInfo) throws GuideException {
		return submit(formSubmitInfo, new HashMap());
	}
	
	public Map submit(FormSubmitInfo formSubmitInfo, Map options) throws GuideException {
		Map result = null;
		JSONObject jsonObj;
		try {
			jsonObj = submitFormInternal(formSubmitInfo, new HashMap());
			result = PortalUtils.convertJsonToMap(jsonObj);
			result.put(GuideConstants.FORM_SUBMISSION_COMPLETE, Boolean.TRUE);
		} catch (FormsPortalException e) {
			throw new GuideException(e);
		} catch (JSONException e) {
			throw new GuideException(e);
		}
		return result;
	}

	/* (non-Javadoc)
	 * @see com.adobe.fd.fp.common.FPSubmitHandler#saveData(byte[], java.util.Map)
	 */
	@Override
	protected String saveData(byte[] formData, Map options)
			throws Exception {
		String id = null;
		if (formData != null && options != null && !StringUtils.isEmpty((String)options.get(FormsPortalConstants.STR_OWNER))) {
			SubmitDataService fpSubmitDataService = (SubmitDataService)PortalUtils.getService(SubmitDataService.class, portalUtilsComponent.getSDSFilter());
			id = fpSubmitDataService.saveDataAsynchronusly(formData, options);
		}
		return id;
	}

	/* (non-Javadoc)
	 * @see com.adobe.fd.fp.common.FPSubmitHandler#saveAttachment(byte[], java.util.Map)
	 */
	@Override
	protected String saveAttachment(byte[] attachment,
			Map options) throws Exception {
		String id = null;
		if (attachment != null && options != null && !StringUtils.isEmpty((String)options.get(FormsPortalConstants.STR_OWNER))) {
			SubmitDataService fpSubmitDataService = (SubmitDataService)PortalUtils.getService(SubmitDataService.class, portalUtilsComponent.getSDSFilter());
			id = fpSubmitDataService.saveAttachmentAsynchronously(attachment, options);
		}
		return id;
	}

	/* (non-Javadoc)
	 * @see com.adobe.fd.fp.common.FPSubmitHandler#saveMetadata(java.util.Map, java.util.Map)
	 */
	@Override
	protected JSONObject saveMetadata(Map metadataProps,
			Map saveOptions) throws Exception {
		JSONObject json = null;
		if (metadataProps != null && saveOptions != null && !StringUtils.isEmpty((String)saveOptions.get(FormsPortalConstants.STR_OWNER))) {
			SubmitMetadataService fpSubmitMetadataService = (SubmitMetadataService)PortalUtils.getService(SubmitMetadataService.class, portalUtilsComponent.getSMSFilter());
			json = fpSubmitMetadataService.submitMetadataAsynchronously(metadataProps);
			json.put(FormsPortalConstants.STR_PATH, FormsPortalConstants.STR_PORTAL_RENDER_NODE + ".dor.pdf/" + json.getString(FormsPortalConstants.STR_SUBMIT_ID));
		}
		return json;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy