From 6405dd0a89b7fdb214b97ece4639f0e71934b46b Mon Sep 17 00:00:00 2001 From: Muskan Gupta Date: Wed, 1 Apr 2026 14:54:22 +0530 Subject: [PATCH] Adding logs for AF2 Submit API --- .../it/service/CustomAFSubmitService.java | 53 ++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/it/core/src/main/java/com/adobe/cq/forms/core/components/it/service/CustomAFSubmitService.java b/it/core/src/main/java/com/adobe/cq/forms/core/components/it/service/CustomAFSubmitService.java index 613c5b29f0..dd8e9ade79 100644 --- a/it/core/src/main/java/com/adobe/cq/forms/core/components/it/service/CustomAFSubmitService.java +++ b/it/core/src/main/java/com/adobe/cq/forms/core/components/it/service/CustomAFSubmitService.java @@ -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; @@ -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; @@ -53,8 +56,20 @@ public String getServiceName() { public Map submit(FormSubmitInfo formSubmitInfo) { Map 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) { @@ -80,7 +95,8 @@ public Map 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 @@ -90,7 +106,8 @@ public Map 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"); @@ -99,4 +116,28 @@ public Map 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; + } + }