Package com.adobe.aemds.guide.utils
Class GuideSubmitUtils
- java.lang.Object
-
- com.adobe.aemds.guide.utils.GuideSubmitUtils
-
public class GuideSubmitUtils extends java.lang.ObjectProvides Utility API to build custom submit action
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringREQ_ATTR_FORWARD_OPTIONSstatic java.lang.StringREQ_ATTR_FORWARD_PATHstatic java.lang.StringREQ_ATTR_GUIDE_SUBMIT_OPTIONSstatic java.lang.StringREQUEST_ATTR_PDF_NAMEstatic java.lang.StringREQUEST_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.StringaddContextPath(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.StringaddContextPathWithServerUrl(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 voidaddValidationErrorToResult(java.util.Map<java.lang.String,java.lang.Object> result, GuideSubmitErrorCause errorCause, java.lang.String errorMessage, java.lang.String originCode)static GuideValidationResultgetDefaultGuideValidationResult()This method will return default guideValidation objectstatic GuideValidationResultgetGuideValidationResultFromString(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>getMappedFieldParameters(java.lang.String[] fieldParameterMapping)Provides map of field name and parameter name pairs.static java.lang.StringgetNameOfCompositeFieldFromChildResource(Resource resource)Checks if the given resource is a child of composite field.static ResourcegetParentResource(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(SlingHttpServletRequest request)This API returns redirect parameters set in the current request.static java.lang.StringgetReqAttrPdfName(SlingHttpServletRequest request)Returns the name of the PDF set in the requeststatic java.lang.StringgetUserID(SlingHttpServletRequest request)Returns the current user ID from the requeststatic voidhandleValidationError(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 voidsetForwardPath(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 voidsetRedirectParameters(SlingHttpServletRequest request, java.util.Map<java.lang.String,java.lang.String> value)Sets redirect parameters to the current requeststatic voidsetRedirectUrl(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-SlingHttpServletRequestsling 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(SlingHttpServletRequest request)
This API returns redirect parameters set in the current request. To set the redirect parameters, checksetRedirectParameters(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
-
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(SlingHttpServletRequest 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(SlingHttpServletRequest 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)
-
-