Package com.adobe.aemds.guide.utils
Class GuideSubmitUtils
- java.lang.Object
-
- com.adobe.aemds.guide.utils.GuideSubmitUtils
-
public class GuideSubmitUtils extends java.lang.Object
Provides Utility API to build custom submit action
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
REQ_ATTR_FORWARD_OPTIONS
static java.lang.String
REQ_ATTR_FORWARD_PATH
static java.lang.String
REQ_ATTR_GUIDE_SUBMIT_OPTIONS
static java.lang.String
REQUEST_ATTR_PDF_NAME
static java.lang.String
REQUEST_ATTR_REDIRECT_PARAMETER_MAP
-
Constructor Summary
Constructors Constructor Description GuideSubmitUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
addContextPath(java.lang.String url, java.lang.String contextPath)
This method will prepend context path to the URL if it starts with a /, provided url and context path is not blank.static java.lang.String
addContextPathWithServerUrl(java.lang.String url, java.lang.String contextPath, java.lang.String serverUrl)
A wrapper function for prepending context path and server url in case given url is not absolute alreadystatic void
addValidationErrorToResult(java.util.Map<java.lang.String,java.lang.Object> result, GuideSubmitErrorCause errorCause, java.lang.String errorMessage, java.lang.String originCode)
static java.util.Map<java.lang.String,java.lang.String>
getAFSuccessPayload(SlingHttpServletRequest request, ValueMap formContainerResourceProperties, java.lang.String redirectUrl)
When aemFormResource is null.static GuideValidationResult
getDefaultGuideValidationResult()
This method will return default guideValidation objectstatic GuideValidationResult
getGuideValidationResultFromString(java.lang.String errorMessage, java.lang.String status)
This method will check error in Map corresponding to key "FormSubmissioneError" If this key is present and value is Object of @link GuideValidationResult, error will be sent in responsestatic java.util.Map<java.lang.String,java.lang.String>
getGuideValueMap(FormSubmitInfo formSubmitInfo)
This API returns guideValueMap, that is, Map of all the fields and their values, and portal submit link and submit idstatic java.util.Map<java.lang.String,java.lang.String>
getGuideValueMap(FormSubmitInfo formSubmitInfo, boolean retainBoundDataHierarchy)
This API returns guideValueMap, that is, Map of all the fields and their values, and portal submit link and submit idstatic java.lang.String
getLocale(javax.servlet.http.HttpServletRequest request)
static java.util.Map<java.lang.String,java.lang.String>
getMappedFieldParameters(java.lang.String[] fieldParameterMapping)
Provides map of field name and parameter name pairs.static java.lang.String
getNameOfCompositeFieldFromChildResource(Resource resource)
Checks if the given resource is a child of composite field.static Resource
getParentResource(Resource resource, java.lang.String jcrPrimaryType)
Returns the closest parent with given jcrPrimaryType, if jcrPrimaryType is null or empty, then returns immediate parentstatic java.util.Map<java.lang.String,java.lang.String>
getRedirectParameters(javax.servlet.http.HttpServletRequest request)
This API returns redirect parameters set in the current request.static java.lang.String
getReqAttrPdfName(javax.servlet.http.HttpServletRequest request)
Returns the name of the PDF set in the requeststatic java.lang.String
getUserID(SlingHttpServletRequest request)
Returns the current user ID from the requeststatic void
handleValidationError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Map<java.lang.String,java.lang.Object> submitResult)
This method will check error in Map corresponding to key "FormSubmissioneError" If this key is present and value is Object of @link GuideValidationResult, error will be sent in responsestatic java.lang.String
prepareRedirectUrl(SlingHttpServletRequest request, java.lang.String redirectUrl)
static void
setForwardPath(SlingHttpServletRequest req, java.lang.String path, java.lang.String selector, java.lang.String suffix)
This API should be used to set the path to forward the current requeststatic void
setRedirectParameters(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.String> value)
Sets redirect parameters to the current requeststatic void
setRedirectUrl(SlingHttpServletRequest req, java.lang.String redirectUrl)
This API should be used to set the redirect url
-
-
-
Field Detail
-
REQUEST_ATTR_PDF_NAME
public static final java.lang.String REQUEST_ATTR_PDF_NAME
- See Also:
- Constant Field Values
-
REQUEST_ATTR_REDIRECT_PARAMETER_MAP
public static final java.lang.String REQUEST_ATTR_REDIRECT_PARAMETER_MAP
- See Also:
- Constant Field Values
-
REQ_ATTR_FORWARD_PATH
public static final java.lang.String REQ_ATTR_FORWARD_PATH
- See Also:
- Constant Field Values
-
REQ_ATTR_FORWARD_OPTIONS
public static final java.lang.String REQ_ATTR_FORWARD_OPTIONS
- See Also:
- Constant Field Values
-
REQ_ATTR_GUIDE_SUBMIT_OPTIONS
public static final java.lang.String REQ_ATTR_GUIDE_SUBMIT_OPTIONS
- See Also:
- Constant Field Values
-
-
Method Detail
-
setForwardPath
public static void setForwardPath(SlingHttpServletRequest req, java.lang.String path, java.lang.String selector, java.lang.String suffix)
This API should be used to set the path to forward the current request- Parameters:
req
- Sling http servlet requestpath
- Path to forward the current requestselector
- Sling selector to use while forwarding the request to the path. Null if no selector to be usedsuffix
- Suffix to use while forwarding the request to the path. Null if no selector to be used- See Also:
SlingHttpServletRequest
-
setRedirectUrl
public static void setRedirectUrl(SlingHttpServletRequest req, java.lang.String redirectUrl)
This API should be used to set the redirect url- Parameters:
req
- Sling http servlet requestredirectUrl
- redirect url to set in the current request object- See Also:
SlingHttpServletRequest
-
getUserID
public static java.lang.String getUserID(SlingHttpServletRequest request)
Returns the current user ID from the request- Parameters:
request
-SlingHttpServletRequest
sling http servlet request- Returns:
- string representing the user id
-
getParentResource
public static Resource getParentResource(Resource resource, java.lang.String jcrPrimaryType)
Returns the closest parent with given jcrPrimaryType, if jcrPrimaryType is null or empty, then returns immediate parent- Parameters:
resource
-jcrPrimaryType
-- Returns:
- parentResource
-
getRedirectParameters
public static java.util.Map<java.lang.String,java.lang.String> getRedirectParameters(javax.servlet.http.HttpServletRequest request)
This API returns redirect parameters set in the current request. To set the redirect parameters, check#setRedirectParameters(org.apache.sling.api.SlingHttpServletRequest, java.util.Map)
- Parameters:
request
- Sling http servlet request- Returns:
- Map containing parameter names with their corresponding values
- See Also:
SlingHttpServletRequest
-
getNameOfCompositeFieldFromChildResource
public static java.lang.String getNameOfCompositeFieldFromChildResource(@Nonnull Resource resource)
Checks if the given resource is a child of composite field. If it is a child of composite field, it would return the name of the composite field resource- Parameters:
resource
- reference to the child of the composite field resource- Returns:
- name of the composite field resource, null if not a child
-
getGuideValueMap
public static java.util.Map<java.lang.String,java.lang.String> getGuideValueMap(FormSubmitInfo formSubmitInfo) throws org.apache.sling.commons.json.JSONException
This API returns guideValueMap, that is, Map of all the fields and their values, and portal submit link and submit id- Parameters:
formSubmitInfo
-FormSubmitInfo
object containing the basic information required during form submission- Returns:
- Map of all the fields and their values, and portal submit link and submit id
- Throws:
org.apache.sling.commons.json.JSONException
- See Also:
FormSubmitInfo
-
getGuideValueMap
public static java.util.Map<java.lang.String,java.lang.String> getGuideValueMap(FormSubmitInfo formSubmitInfo, boolean retainBoundDataHierarchy) throws org.apache.sling.commons.json.JSONException
This API returns guideValueMap, that is, Map of all the fields and their values, and portal submit link and submit id- Parameters:
formSubmitInfo
-FormSubmitInfo
object containing the basic information required during form submissionretainBoundDataHierarchy
- boolean indicates if map should contain absolute path of data elements as key in case of bound data- Returns:
- Map of all the fields and their values, and portal submit link and submit id
- Throws:
org.apache.sling.commons.json.JSONException
- See Also:
FormSubmitInfo
-
getMappedFieldParameters
public static java.util.Map<java.lang.String,java.lang.String> getMappedFieldParameters(java.lang.String[] fieldParameterMapping)
Provides map of field name and parameter name pairs. In case of absence of parameter name, field name is used as parameter name.- Parameters:
fieldParameterMapping
- array of field mappings in the form of<=Parameter Name>. - Returns:
- map of field name and parameter name pairs.
-
setRedirectParameters
public static void setRedirectParameters(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.String> value)
Sets redirect parameters to the current request- Parameters:
request
- Sling http servlet requestvalue
- Map represent the redirect paramters to be set- See Also:
SlingHttpServletRequest
-
getReqAttrPdfName
public static java.lang.String getReqAttrPdfName(javax.servlet.http.HttpServletRequest request)
Returns the name of the PDF set in the request- Parameters:
request
- Sling http servlet request- Returns:
- name of the PDF from the request
-
addContextPath
public static java.lang.String addContextPath(java.lang.String url, java.lang.String contextPath)
This method will prepend context path to the URL if it starts with a /, provided url and context path is not blank. If URL starts with http/https, context path won't be added and the URL will be returned without any modification.- Parameters:
url
- Thank You page URLcontextPath
- Context path for the application.- Returns:
- context path added URL
-
addContextPathWithServerUrl
public static java.lang.String addContextPathWithServerUrl(java.lang.String url, java.lang.String contextPath, java.lang.String serverUrl)
A wrapper function for prepending context path and server url in case given url is not absolute already- Parameters:
url
- URL that user will be redirected tocontextPath
- Context path for the applicationserverUrl
- Server url (e.g localhost:4502)- Returns:
- URL prepended (with server url and context path) as appropriate
-
handleValidationError
public static void handleValidationError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Map<java.lang.String,java.lang.Object> submitResult)
This method will check error in Map corresponding to key "FormSubmissioneError" If this key is present and value is Object of @link GuideValidationResult, error will be sent in response- Parameters:
request
- request objectresponse
- response objectsubmitResult
- return value for submit() function
-
getDefaultGuideValidationResult
public static GuideValidationResult getDefaultGuideValidationResult()
This method will return default guideValidation object- Returns:
- GuideValidationResult default object
-
getGuideValidationResultFromString
public static GuideValidationResult getGuideValidationResultFromString(java.lang.String errorMessage, java.lang.String status)
This method will check error in Map corresponding to key "FormSubmissioneError" If this key is present and value is Object of @link GuideValidationResult, error will be sent in response- Parameters:
errorMessage
- strings to be parsed to get GuideValidationResult or else set as originMessagestatus
- response originCode that needs to be set in case parsing of errorMessage to GuideValidationResult fails- Returns:
- submitResult return value for submit() function
-
addValidationErrorToResult
public static void addValidationErrorToResult(java.util.Map<java.lang.String,java.lang.Object> result, GuideSubmitErrorCause errorCause, java.lang.String errorMessage, java.lang.String originCode)
-
getLocale
public static java.lang.String getLocale(javax.servlet.http.HttpServletRequest request)
-
prepareRedirectUrl
public static java.lang.String prepareRedirectUrl(SlingHttpServletRequest request, java.lang.String redirectUrl) throws java.io.UnsupportedEncodingException
- Throws:
java.io.UnsupportedEncodingException
-
getAFSuccessPayload
public static java.util.Map<java.lang.String,java.lang.String> getAFSuccessPayload(SlingHttpServletRequest request, ValueMap formContainerResourceProperties, java.lang.String redirectUrl) throws java.io.UnsupportedEncodingException
When aemFormResource is null. Creates a thankYou Configuration w.r.t GuideContainer. Use case e.g: normal async submission case.- Parameters:
request
- Sling http servlet requestformContainerResourceProperties
- Form container resource propertiesredirectUrl
- Url to be redirected to on async submission (can be null)- Returns:
- AfSuccessPayload containing the thankYouOption and the thankYouContent
- Throws:
java.io.UnsupportedEncodingException
-
-