Class GuideSubmitUtils


  • public class GuideSubmitUtils
    extends java.lang.Object
    Provides Utility API to build custom submit action
    • 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 already
      static 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 object
      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
      static 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 id
      static 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 id
      static 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 parent
      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.
      static java.lang.String getReqAttrPdfName​(javax.servlet.http.HttpServletRequest request)
      Returns the name of the PDF set in the request
      static java.lang.String getUserID​(SlingHttpServletRequest request)
      Returns the current user ID from the request
      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
      static 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 request
      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
      static void setRedirectUrl​(SlingHttpServletRequest req, java.lang.String redirectUrl)
      This API should be used to set the redirect url
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • GuideSubmitUtils

        public GuideSubmitUtils()
    • 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 request
        path - Path to forward the current request
        selector - Sling selector to use while forwarding the request to the path. Null if no selector to be used
        suffix - 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 request
        redirectUrl - 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 submission
        retainBoundDataHierarchy - 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 request
        value - 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 URL
        contextPath - 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 to
        contextPath - Context path for the application
        serverUrl - 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 object
        response - response object
        submitResult - 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 originMessage
        status - 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 request
        formContainerResourceProperties - Form container resource properties
        redirectUrl - Url to be redirected to on async submission (can be null)
        Returns:
        AfSuccessPayload containing the thankYouOption and the thankYouContent
        Throws:
        java.io.UnsupportedEncodingException