사용 사례를 충족하기 위해 제출된 데이터 및 첨부 파일을 Azure에 저장하는 사용자 지정 제출 서비스를 만들었습니다. 핵심 구성 요소 기반 양식을 제출하면 데이터는 다음 형식을 갖습니다
{
"Name": "Gloria Rios",
"EmailID": "grios@email.com",
"ExistingCustomer": [
"Yes"
],
"PhoneNumber": "1234567890",
"Solution": "Forms",
"contractcopy": {
"name": "annualcontract.pdf",
"size": 80194,
"mediaType": "application/pdf",
"data": "[object File]"
},
"Message": "We would like to renew our annual contract "
}
contractcopy 요소는 첨부 파일 구성 요소를 나타내며 양식과 함께 제출된 첨부 파일을 캡처하는 데 사용됩니다.
적응형 양식에 데이터 및 해당 첨부 파일을 미리 채울 수 있도록 제출된 첨부 파일이 Azure 포털에 저장되고 제출된 데이터에 있는 contractcopy 개체의 데이터 요소가 저장된 첨부 파일의 URL로 업데이트됩니다.
사용자 지정 제출 서비스는 Azure 포털에서 첨부 파일을 추출하여 저장합니다. 업데이트된 제출 데이터는 다음과 같이 표시됩니다
{
"Name": "Gloria Rios",
"EmailID": "grios@email.com",
"ExistingCustomer": [
"Yes"
],
"PhoneNumber": "1234567890",
"Solution": "Forms",
"contractcopy": {
"name": "annualcontract.pdf",
"size": 80194,
"mediaType": "application/pdf",
"data": "https://aemformstutorial.blob.core.windows.net/benefiitsenrollment/69d5a2?sv=2022-11-02&ss=bfqt&srt=KiHs0%3D"
},
"Message": "We would like to renew our annual contract "
}
``
package com.azuredemo.core;
import com.adobe.aemds.guide.common.GuideValidationResult;
import com.adobe.aemds.guide.model.FormSubmitInfo;
import com.adobe.aemds.guide.service.FormSubmitActionService;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.forms.common.service.FileAttachmentWrapper;
import com.azuredemo.core.SaveAndFetchFromAzure.StoreAndFetchDataFromAzureStorage;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Component(
service = FormSubmitActionService.class,
immediate = true
)
public class StoreFormDataWithAttachments implements FormSubmitActionService {
private static final String serviceName = "Store Submitted Form Data in Azure";
private static transient Logger logger = LoggerFactory.getLogger(StoreFormDataWithAttachments.class);
@Reference
DataManager dataManager;
@Reference
StoreAndFetchDataFromAzureStorage storeAndFetchDataFromAzureStorage;
@Override
public String getServiceName() {
return serviceName;
}
@Override
public Map < String, Object > submit(FormSubmitInfo formSubmitInfo) {
logger.debug("@@@@in my custom submit!!!");
Map < String, Object > result = new HashMap < > ();
result.put(GuideConstants.FORM_SUBMISSION_COMPLETE, Boolean.FALSE);
try {
String guideContainerPath = formSubmitInfo.getFormContainerPath();
String submittedFormName = formSubmitInfo.getFormContainerResource().getParent().getParent().getName();
logger.debug("The submitted form name is " + submittedFormName);
String data = formSubmitInfo.getData();
logger.debug("The submitted data is " + data);
JsonObject jsonData = new Gson().fromJson(data, JsonObject.class);
if (formSubmitInfo.getFileAttachments() != null && formSubmitInfo.getFileAttachments().size() > 0) {
logger.debug("#####The form submitted has file attachments");
for (int i = 0; i < formSubmitInfo.getFileAttachments().size(); i++) {
FileAttachmentWrapper fileAttachment = formSubmitInfo.getFileAttachments().get(i);
logger.debug("The url of the file attachment is " + fileAttachment.getUri());
logger.debug("The data ref of the file attachment is " + fileAttachment.getDataRef());
String fileName = fileAttachment.getFileName();
logger.debug("The fileName is " + fileName);
logger.debug("#### Writing " + fileName + " to azure");
String dataUrl = storeAndFetchDataFromAzureStorage.saveFormAttachmentinAzure(fileAttachment.getInputStream(), fileName, fileAttachment.getContentType());
jsonData.getAsJsonObject(fileAttachment.getDataRef()).addProperty("data", dataUrl);
logger.debug(jsonData.toString());
}
}
String uniqueID = UUID.randomUUID().toString();
logger.debug(storeAndFetchDataFromAzureStorage.saveFormDatainAzure(jsonData.toString(), "text/plain"));
if (dataManager != null) {
dataManager.put(uniqueID, data);
}
logger.info("AF Submission successful using custom submit service for: {}", guideContainerPath);
result.put(GuideConstants.FORM_SUBMISSION_COMPLETE, Boolean.TRUE);
result.put(DataManager.UNIQUE_ID, uniqueID);
// adding id here so that this available in redirect parameters in final thank you page
Map < String, Object > redirectParamMap = new HashMap < String, Object > () {
{
put(DataManager.UNIQUE_ID, uniqueID);
}
};
result.put("fd:redirectParameters", redirectParamMap);
} catch (Exception ex) {
logger.error("Error while using the AF Submit service", ex);
GuideValidationResult guideValidationResult = new GuideValidationResult();
guideValidationResult.setOriginCode("500");
guideValidationResult.setErrorMessage("Internal server error");
result.put(GuideConstants.FORM_SUBMISSION_ERROR, guideValidationResult);
}
return result;
}
}