Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
import com.adobe.forms.common.service.FileAttachmentWrapper;
import com.adobe.cq.forms.core.components.it.servlets.FileAttachmentServlet;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
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.Iterator;
import java.util.Map;
import java.util.UUID;

Expand All @@ -39,7 +40,9 @@
)
public class CustomAFSubmitService implements FormSubmitActionService {
private static final String serviceName = "Core Custom AF Submit";
private static Logger logger = LoggerFactory.getLogger(CustomAFSubmitService.class);
private static final Logger logger = LoggerFactory.getLogger(CustomAFSubmitService.class);

private static final String LOG_PREFIX = "[AF2Submit]";

@Reference
DataManager dataManager;
Expand All @@ -53,8 +56,20 @@ public String getServiceName() {
public Map<String, Object> submit(FormSubmitInfo formSubmitInfo) {
Map<String, Object> result = new HashMap<>();
result.put(GuideConstants.FORM_SUBMISSION_COMPLETE, Boolean.FALSE);
String guideContainerPath = formSubmitInfo.getFormContainerPath();
String formPath = StringUtils.substringBefore(guideContainerPath, "/jcr:content");
String submissionId = formSubmitInfo.getSubmissionId();
String actionType = null;
String submitType = null;

Resource formContainerResource = formSubmitInfo.getFormContainerResource();
if (formContainerResource != null) {
ValueMap valueMap = formContainerResource.getValueMap();
actionType = valueMap.get("actionType", String.class);
submitType = resolveSubmitTypeName(formContainerResource.getResourceResolver(), actionType);
}

try {
String guideContainerPath = formSubmitInfo.getFormContainerPath();
String data = formSubmitInfo.getData();
String uniqueID = UUID.randomUUID().toString();
if(formSubmitInfo.getFileAttachments() != null && formSubmitInfo.getFileAttachments().size() > 0) {
Expand All @@ -80,7 +95,8 @@ public Map<String, Object> submit(FormSubmitInfo formSubmitInfo) {
dataManager.put(DataManager.getFileAttachmentMapKey(uniqueID), formSubmitInfo.getFileAttachments());
}
}
logger.info("AF Submission successful using custom submit service for: {}", guideContainerPath);
logger.info("{} Submission successful - formPath: {}, submissionId: {}, submitType: {}",
LOG_PREFIX, formPath, submissionId, submitType);
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
Expand All @@ -90,7 +106,8 @@ public Map<String, Object> submit(FormSubmitInfo formSubmitInfo) {
// todo: move this to constant, once forms SDK is released
result.put("fd:redirectParameters", redirectParamMap);
} catch (Exception ex) {
logger.error("Error while using the AF Submit service", ex);
logger.error("{} Submission failed - formPath: {}, submissionId: {}, submitType: {}",
LOG_PREFIX, formPath, submissionId, submitType, ex);
GuideValidationResult guideValidationResult = new GuideValidationResult();
guideValidationResult.setOriginCode("500");
guideValidationResult.setErrorMessage("Internal server error");
Expand All @@ -99,4 +116,28 @@ public Map<String, Object> submit(FormSubmitInfo formSubmitInfo) {
return result;
}

/**
* Resolves the human-readable submit type name from the actionType resource type.
* Looks up the resource at the actionType path and reads its jcr:description
* (e.g. "Submit to REST endpoint", "Invoke an AEM workflow", "Core Custom AF Submit").
* Falls back to the raw actionType path if the resource or description is unavailable.
*/
private String resolveSubmitTypeName(ResourceResolver resourceResolver, String actionType) {
if (StringUtils.isBlank(actionType)) {
return "unknown";
}
try {
Resource actionResource = resourceResolver.getResource(actionType);
if (actionResource != null) {
String description = actionResource.getValueMap().get("jcr:description", String.class);
if (StringUtils.isNotBlank(description)) {
return description;
}
}
} catch (Exception e) {
logger.debug("{} Could not resolve submit type name for actionType: {}", LOG_PREFIX, actionType, e);
}
return actionType;
}

}
Loading