com.ibm.commerce.foundation.rest.resourcehandler

Class AbstractBaseResourceHandler

  • java.lang.Object
    • com.ibm.commerce.foundation.rest.resourcehandler.AbstractBaseResourceHandler
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM Copyright notice field.
        See Also:
        Constant Field Values
      • APPLICATION_ATOM_XML

        public static final java.lang.String APPLICATION_ATOM_XML
        atom format
        See Also:
        Constant Field Values
      • APPLICATION_JSON

        public static final java.lang.String APPLICATION_JSON
        json format
        See Also:
        Constant Field Values
      • APPLICATION_XHTML_XML

        public static final java.lang.String APPLICATION_XHTML_XML
        xhtml format
        See Also:
        Constant Field Values
      • APPLICATION_XML

        public static final java.lang.String APPLICATION_XML
        xml format
        See Also:
        Constant Field Values
      • PARAMETER_LANG_ID

        public static final java.lang.String PARAMETER_LANG_ID
        langId parameter
        See Also:
        Constant Field Values
      • PARAMETER_LANG_ID_DESCRIPTION

        public static final java.lang.String PARAMETER_LANG_ID_DESCRIPTION
        langId description
        See Also:
        Constant Field Values
      • PARAMETER_QUERY

        public static final java.lang.String PARAMETER_QUERY
        q
        See Also:
        Constant Field Values
      • PARAMETER_QUERY_DESCRIPTION

        public static final java.lang.String PARAMETER_QUERY_DESCRIPTION
        q description
        See Also:
        Constant Field Values
      • PARAMETER_PROFILE_NAME

        public static final java.lang.String PARAMETER_PROFILE_NAME
        profileName
        See Also:
        Constant Field Values
      • PARAMETER_PROFILE_NAME_DESCRIPTION

        public static final java.lang.String PARAMETER_PROFILE_NAME_DESCRIPTION
        profileName description
        See Also:
        Constant Field Values
      • PARAMETER_LOCALE

        public static final java.lang.String PARAMETER_LOCALE
        locale
        See Also:
        Constant Field Values
      • PARAMETER_LOCALE_DESCRIPTION

        public static final java.lang.String PARAMETER_LOCALE_DESCRIPTION
        locale description
        See Also:
        Constant Field Values
      • PARAMETER_CATALOG_ID

        public static final java.lang.String PARAMETER_CATALOG_ID
        catalogId
        See Also:
        Constant Field Values
      • PARAMETER_CATALOG_ID_DESCRIPTION

        public static final java.lang.String PARAMETER_CATALOG_ID_DESCRIPTION
        catalogId description
        See Also:
        Constant Field Values
      • PARAMETER_CURRENCY

        public static final java.lang.String PARAMETER_CURRENCY
        currency
        See Also:
        Constant Field Values
      • PARAMETER_CURRENCY_DESCRIPTION

        public static final java.lang.String PARAMETER_CURRENCY_DESCRIPTION
        currency description
        See Also:
        Constant Field Values
      • PARAMETER_STORE_ID

        public static final java.lang.String PARAMETER_STORE_ID
        store identifier
        See Also:
        Constant Field Values
      • PARAMETER_STORE_ID_DESCRIPTION

        public static final java.lang.String PARAMETER_STORE_ID_DESCRIPTION
        store identifier description
        See Also:
        Constant Field Values
      • PARAMETER_PAGE_SIZE

        public static final java.lang.String PARAMETER_PAGE_SIZE
        page size
        See Also:
        Constant Field Values
      • PARAMETER_PAGE_SIZE_DESCRIPTION

        public static final java.lang.String PARAMETER_PAGE_SIZE_DESCRIPTION
        page size description
        See Also:
        Constant Field Values
      • PARAMETER_PAGE_NUMBER

        public static final java.lang.String PARAMETER_PAGE_NUMBER
        page number
        See Also:
        Constant Field Values
      • PARAMETER_PAGE_NUMBER_DESCRIPTION

        public static final java.lang.String PARAMETER_PAGE_NUMBER_DESCRIPTION
        page number description
        See Also:
        Constant Field Values
      • PARAMETER_RESPONSE_FORMAT

        public static final java.lang.String PARAMETER_RESPONSE_FORMAT
        response format
        See Also:
        Constant Field Values
      • PARAMETER_RESPONSE_FORMAT_DESCRIPTION

        public static final java.lang.String PARAMETER_RESPONSE_FORMAT_DESCRIPTION
        response format description
        See Also:
        Constant Field Values
      • PARAMETER_FOR_USER

        public static final java.lang.String PARAMETER_FOR_USER
        forUser
        See Also:
        Constant Field Values
      • PARAMETER_FOR_USER_DESCRIPTION

        public static final java.lang.String PARAMETER_FOR_USER_DESCRIPTION
        forUser description
        See Also:
        Constant Field Values
      • PARAMETER_FOR_USER_ID

        public static final java.lang.String PARAMETER_FOR_USER_ID
        forUserId
        See Also:
        Constant Field Values
      • PARAMETER_FOR_USER_ID_DESCRIPTION

        public static final java.lang.String PARAMETER_FOR_USER_ID_DESCRIPTION
        forUserId description
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_IDENTIFIER

        public static final java.lang.String PARAMETER_WORKSPACE_IDENTIFIER
        workspace Identifier
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_IDENTIFIER_DESCRIPTION

        public static final java.lang.String PARAMETER_WORKSPACE_IDENTIFIER_DESCRIPTION
        workspace Identifier description
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_NAME

        public static final java.lang.String PARAMETER_WORKSPACE_NAME
        workspace name
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_NAME_DESCRIPTION

        public static final java.lang.String PARAMETER_WORKSPACE_NAME_DESCRIPTION
        workspace name description
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_TASKGROUP

        public static final java.lang.String PARAMETER_WORKSPACE_TASKGROUP
        workspace task group
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_TASKGROUP_DESCRIPTION

        public static final java.lang.String PARAMETER_WORKSPACE_TASKGROUP_DESCRIPTION
        workspace task group description
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_TASK

        public static final java.lang.String PARAMETER_WORKSPACE_TASK
        workspace task
        See Also:
        Constant Field Values
      • PARAMETER_WORKSPACE_TASK_DESCRIPTION

        public static final java.lang.String PARAMETER_WORKSPACE_TASK_DESCRIPTION
        workspace task description
        See Also:
        Constant Field Values
      • PARAMETER_ACTION

        public static final java.lang.String PARAMETER_ACTION
        action
        See Also:
        Constant Field Values
      • PARAMETER_ACTION_DESCRIPTION

        public static final java.lang.String PARAMETER_ACTION_DESCRIPTION
        action description
        See Also:
        Constant Field Values
      • PARAMETER_MODE

        public static final java.lang.String PARAMETER_MODE
        mode
        See Also:
        Constant Field Values
      • PARAMETER_MODE_DESCRIPTION

        public static final java.lang.String PARAMETER_MODE_DESCRIPTION
        mode description
        See Also:
        Constant Field Values
      • PARAMETER_RESET_PASSWORD_DESCRIPTION

        public static final java.lang.String PARAMETER_RESET_PASSWORD_DESCRIPTION
        Reset password description
        See Also:
        Constant Field Values
      • RESPONSE_200_DESCRIPTION

        public static final java.lang.String RESPONSE_200_DESCRIPTION
        200 return code description
        See Also:
        Constant Field Values
      • RESPONSE_201_DESCRIPTION

        public static final java.lang.String RESPONSE_201_DESCRIPTION
        201 return code description
        See Also:
        Constant Field Values
      • RESPONSE_204_DESCRIPTION

        public static final java.lang.String RESPONSE_204_DESCRIPTION
        204 return code description
        See Also:
        Constant Field Values
      • RESPONSE_400_DESCRIPTION

        public static final java.lang.String RESPONSE_400_DESCRIPTION
        400 return code description
        See Also:
        Constant Field Values
      • RESPONSE_401_DESCRIPTION

        public static final java.lang.String RESPONSE_401_DESCRIPTION
        401 return code description
        See Also:
        Constant Field Values
      • RESPONSE_403_DESCRIPTION

        public static final java.lang.String RESPONSE_403_DESCRIPTION
        403 return code description
        See Also:
        Constant Field Values
      • RESPONSE_404_DESCRIPTION

        public static final java.lang.String RESPONSE_404_DESCRIPTION
        404 return code description
        See Also:
        Constant Field Values
      • RESPONSE_500_DESCRIPTION

        public static final java.lang.String RESPONSE_500_DESCRIPTION
        500 return code description
        See Also:
        Constant Field Values
      • PROCESS_VERB

        public static final java.lang.String PROCESS_VERB
        The string constant of "Process".
        See Also:
        Constant Field Values
      • CHANGE_VERB

        public static final java.lang.String CHANGE_VERB
        The string constant of "Change".
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractBaseResourceHandler

        public AbstractBaseResourceHandler()
    • Method Detail

      • getInstrumentor

        public com.ibm.commerce.rest.utils.Instrumentor getInstrumentor()
        Return the instrumentor associated with this handler instance.
        Returns:
        Instrumentor
      • handleException

        public javax.ws.rs.core.Response handleException(java.lang.String responseFormat,
                                                         java.lang.Exception ex,
                                                         java.lang.String methodName)
        This method generates a special response for AbstractBusinessObjectDocumentException and re-throw the original exception.
        Parameters:
        responseFormat - response format
        ex - Exception
        methodName - method name that throws the exception ex.
        Returns:
        Response
      • addError

        public void addError(com.ibm.commerce.foundation.rest.resourcehandler.RestError errorToAdd)
        Add an error to the list of detected errors.
        Parameters:
        errorToAdd - the error to add.
      • getUriInfo

        public javax.ws.rs.core.UriInfo getUriInfo()
        Provides access to application and request URI information.
        Returns:
        the URI info
      • getRequest

        public javax.servlet.http.HttpServletRequest getRequest()
        Provides access to the servlet request object.
        Returns:
        the servlet request
      • getResponse

        public javax.servlet.http.HttpServletResponse getResponse()
        Provides access to the servlet response object.
        Returns:
        the servlet response
      • getFormattedMessage

        public static java.lang.String getFormattedMessage(java.lang.String errorKey,
                                                           java.lang.Object... parameters)
        Returns the message in the REST properties file named by the given key, and formatted with the given parameters. If the message could not be retrieved, this fact will be logged.
        Parameters:
        errorKey - The key for the error message. This value cannot be null or empty.
        parameters - The parameters to insert into the error message. A null array may not be specified, but no parameters need be given.
        Returns:
        The message. This value will not be null or empty.
      • getFormattedMessageWithLocale

        public static java.lang.String getFormattedMessageWithLocale(java.lang.String errorKey,
                                                                     java.util.Locale locale,
                                                                     java.lang.Object... parameters)
        Returns the message in the REST properties file named by the given key, and formatted with the given parameters. If the message could not be retrieved, this fact will be logged.
        Parameters:
        errorKey - The key for the error message. This value cannot be null or empty.
        locale - The request locale.
        parameters - The parameters to insert into the error message. A null array may not be specified, but no parameters need be given.
        Returns:
        The message. This value will not be null or empty.
      • getErrorCodeFromMessage

        public static java.lang.String getErrorCodeFromMessage(java.lang.String errorMessage)
        get the unique error code from a message
        Parameters:
        errorMessage - the error message
        Returns:
        the unique error code, if it can be isolated.
      • throwRestExceptionIfErrorsAreDetected

        public void throwRestExceptionIfErrorsAreDetected()
                                                   throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
        Throw a RestException only if errors were detected using the addError(RestError) method.
        Throws:
        RestException - The RestException containing all the detected errors.
      • isRequestInPreviewMode

        public abstract boolean isRequestInPreviewMode()
        Test if the request is executed in preview mode.
        Returns:
        True or false.
      • getParameterValue

        public java.lang.String getParameterValue(java.lang.String parameterName,
                                                  java.lang.String defaultValue,
                                                  boolean mandatory)
        A utility method that may be called by a sub-class to get the parameter value from request.
        Parameters:
        parameterName - The parameter name.
        defaultValue - The parameter's default value.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an exception.
        Returns:
        The value for parameter.
      • getParameterValue

        public java.lang.String getParameterValue(java.lang.String parameterName,
                                                  java.lang.String defaultValue,
                                                  boolean mandatory,
                                                  boolean allowEmptyValue)
        A utility method that may be called by a sub-class to get the parameter value from request.
        Parameters:
        parameterName - The parameter name.
        defaultValue - The parameter's default value.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an exception.
        allowEmptyValue - Flag to indicate if empty value is allowed for the parameter. If not but empty value is received, register an exception.
        Returns:
        The value for parameter.
      • getParameterValues

        public java.lang.String[] getParameterValues(java.lang.String parameterName,
                                                     java.lang.String[] defaultValues,
                                                     boolean mandatory)
        A utility method that may be called by a sub-class to get the parameter values from request.
        Parameters:
        parameterName - The parameter name.
        defaultValues - The parameter's default values.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an exception.
        Returns:
        The values for parameter.
      • getIntegerParameterValues

        public java.lang.Integer[] getIntegerParameterValues(java.lang.String parameterName,
                                                             java.lang.Integer[] defaultValues,
                                                             boolean mandatory)
        A utility method that may be called by a sub-class to get the Integer parameters values from request.
        Parameters:
        parameterName - The parameter name.
        defaultValues - The parameter's default values.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an exception.
        Returns:
        The Integer values for parameter.
      • getLongParameterValues

        public java.lang.Long[] getLongParameterValues(java.lang.String parameterName,
                                                       java.lang.Long[] defaultValues,
                                                       boolean mandatory)
        A utility method that may be called by a sub-class to get the Long parameters values from request.
        Parameters:
        parameterName - The parameter name.
        defaultValues - The parameter's default values.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an exception.
        Returns:
        The Long values for parameter.
      • getDoubleParameterValues

        public java.lang.Double[] getDoubleParameterValues(java.lang.String parameterName,
                                                           java.lang.Double[] defaultValues,
                                                           boolean mandatory)
        A utility method that may be called by a sub-class to get the Double parameters values from request.
        Parameters:
        parameterName - The parameter name.
        defaultValues - The parameter's default values.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an exception.
        Returns:
        The Double values for parameter.
      • getEnumeratedParameterValue

        public java.lang.String getEnumeratedParameterValue(java.lang.String parameterName,
                                                            java.lang.String defaultValue,
                                                            boolean mandatory,
                                                            java.util.Collection<java.lang.String> validValues)
        A utility method that may be called by a sub-class to get a String parameter from the request using a set of valid values. If the value is missing or invalid, the default value is returned. If the value isn't valid, an error is added about the invalid input.
        Parameters:
        parameterName - The parameter name.
        defaultValue - The parameter's default value.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an exception.
        validValues - the set of valid values.
        Returns:
        The value for parameter.
      • getBooleanParameterValue

        public boolean getBooleanParameterValue(java.lang.String parameterName,
                                                boolean defaultValue,
                                                boolean mandatory)
        A utility method to get the boolean parameter value. If the value isn't a valid boolean, an error is registered.
        Parameters:
        parameterName - The parameter name.
        defaultValue - The default value for the parameter.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an error.
        Returns:
        The boolean value for the parameter.
      • getIntegerParameterValue

        public int getIntegerParameterValue(java.lang.String parameterName,
                                            int defaultValue,
                                            boolean mandatory)
        A utility method to get the integer parameter value. If the value isn't a valid integer, an error is registered.
        Parameters:
        parameterName - The parameter name.
        defaultValue - The default value for parameter.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an error.
        Returns:
        The integer value of parameter.
      • getLongParameterValue

        public java.lang.Long getLongParameterValue(java.lang.String parameterName,
                                                    java.lang.Long defaultValue,
                                                    boolean mandatory)
        A utility method to get the Long parameter value. If the value isn't a valid Long, an error is registered.
        Parameters:
        parameterName - The parameter name.
        defaultValue - The default value for parameter.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an error.
        Returns:
        The Long value of parameter.
      • getDoubleParameterValue

        public java.lang.Double getDoubleParameterValue(java.lang.String parameterName,
                                                        java.lang.Double defaultValue,
                                                        boolean mandatory)
        A utility method to get the Double parameter value. If the value isn't a valid Double, an error is registered.
        Parameters:
        parameterName - The parameter name.
        defaultValue - The default value for parameter.
        mandatory - Flag to indicate if the parameter is mandatory. If the value is not provided for the mandatory parameter, register an error.
        Returns:
        The Double value of parameter.
      • throwInvalidQueryNameException

        public void throwInvalidQueryNameException(java.lang.String queryName,
                                                   java.util.Collection<java.lang.String> validNames)
                                            throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
        Throw an error if the query name isn't valid.
        Parameters:
        queryName - the query name.
        validNames - the collection of valid query names.
        Throws:
        RestException - the exception indicating that the query is invalid.
      • throwInvalidQueryNameException

        public void throwInvalidQueryNameException(java.lang.String queryName)
                                            throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
        Throw an error if the query name isn't valid.
        Parameters:
        queryName - the query name.
        Throws:
        RestException - the exception indicating that the query is invalid.
      • throwRestException

        public void throwRestException(com.ibm.commerce.foundation.rest.resourcehandler.RestError errorToThrow)
                                throws com.ibm.commerce.foundation.rest.resourcehandler.RestException
        Throw an exception right away due to a detected error.
        Parameters:
        errorToThrow - The detected error.
        Throws:
        RestException - the RestException that will contain the specified error as well as all the other errors detected so far.
      • createMapForProviderWithResultData

        public java.util.Map<java.lang.String,java.lang.Object> createMapForProviderWithResultData(java.util.Map<java.lang.String,java.lang.Object> resultData,
                                                                                                   java.lang.String resourceName)
        This method create a Map for entity providers using the result map instead of DataObject.
        Parameters:
        resultData - Result map from REST resource handler.
        resourceName - resource name
        Returns:
        A map to be passed to entity providers.
      • preProcess

        public void preProcess(java.util.Map<java.lang.String,java.lang.Object> responseMap)
        This method does the pre-processing of the response map before the entity provider is invoked passing the response map.

        Overwrite this method in your resource handler class to customize the response map.

        Specified by:
        preProcess in interface IResourceHandler
        Parameters:
        responseMap - the response map.
      • postProcess

        public void postProcess(java.util.Map<java.lang.String,java.lang.Object> responseMap)
        Method to provide post process in out of box JSON/XML entity providers after each DataObject has been converted to a Map and before constructing the REST response. By default, it does nothing. Overwrite this method in your resource handler class to perform any post process, for example, merge maps from multiple DataObjects into a single Map.
        Specified by:
        postProcess in interface IResourceHandler
        Parameters:
        responseMap - The response Map after each DataObject has been converted to a Map.
      • getFormattingGroupName

        public java.lang.String getFormattingGroupName()
        Returns the formatting group name for resolving the struts action of the formatting JSP. Overwrite this method in your resource handler class to return a formatting group name specific to your resource handler.
        Specified by:
        getFormattingGroupName in interface IResourceHandler
        Returns:
        the formatting group name.
      • generateResponseFromHttpStatusCodeAndRespData

        public javax.ws.rs.core.Response generateResponseFromHttpStatusCodeAndRespData(java.lang.String responseFormat,
                                                                                       java.util.Map<java.lang.String,java.lang.Object> responseData,
                                                                                       org.apache.wink.common.http.HttpStatus statusCode)
        This method generates REST response for a given response map.

        Use this method in your resource handler class when you want to pass name value pairs to the entity provider.

        Specified by:
        generateResponseFromHttpStatusCodeAndRespData in interface IResourceHandler
        Parameters:
        responseFormat - the response format shortcut. Response format is used to resolve the media type for the REST response. If response format is not provided, then Accept header is used to resolve the media type for the REST response. Refer to MediaTypeHelper.getResponseMediaType(String, Request) for more details on the response media type resolution.
        responseData - the response map to pass to the entity provider.
        statusCode - the HTTP status code to set in the REST response.
        Returns:
        the REST response.
      • getExternalResourceName

        public java.lang.String getExternalResourceName()
        Get the resource name to show externally. This defaults to the value returned by getResourceName if this method isn't overridden.
        Returns:
        The external resource name.
      • getClassDescription

        public java.lang.String getClassDescription(java.util.Locale locale)
        Description copied from interface: DocumentedResourceHandler
        Get the class description based on description annotations.
        Specified by:
        getClassDescription in interface DocumentedResourceHandler
        Parameters:
        locale - The locale to use.
        Returns:
        The class description.
      • getQueryRegistry

        public OperationRegistry getQueryRegistry()
        Get the query registry for this handler.
        Returns:
        The query registry.
      • initializeQueryRegistry

        public void initializeQueryRegistry(OperationRegistry registry)
        Initialize the query registry. Override this method to register
        Parameters:
        registry - The query registry to initialize.
      • getActionRegistry

        public OperationRegistry getActionRegistry()
        Get the action registry for this handler.
        Returns:
        The action registry.
      • initializeActionRegistry

        public void initializeActionRegistry(OperationRegistry registry)
        Initialize the action registry. Override this method to register
        Parameters:
        registry - The query registry to initialize.
      • registerOperationWithMethodSignature

        public void registerOperationWithMethodSignature(OperationRegistry registry,
                                                         java.lang.String operationName,
                                                         java.lang.String description,
                                                         java.lang.String methodName,
                                                         java.lang.Class<?>... parameterTypes)
        Register an operation with a method signature.
        Parameters:
        registry - The operation registry.
        operationName - The operation name to register.
        description - The operation description.
        methodName - The method name to call.
        parameterTypes - The parameters in the method to call.
      • runQuery

        public javax.ws.rs.core.Response runQuery(java.lang.String queryName,
                                                  java.lang.String responseFormat,
                                                  java.lang.Object... parameters)
        Run a query.
        Parameters:
        queryName - Name of the query to execute.
        responseFormat - The response format.
        parameters - The parameters to use while running the query.
        Returns:
        The response generated by the query.
      • performAction

        public javax.ws.rs.core.Response performAction(java.lang.String action,
                                                       java.lang.String responseFormat,
                                                       java.lang.Object... parameters)
        Performs an action.
        Parameters:
        action - Name of the action to perform.
        responseFormat - The response format.
        parameters - The parameters to use while performing the action.
        Returns:
        The response generated by the action.
      • staticConvertStreamToString

        public static java.lang.String staticConvertStreamToString(java.io.InputStream is)
                                                            throws java.io.IOException
        Convert a stream to a string using UTF-8 encoding.
        Parameters:
        is - The input stream to convert.
        Returns:
        The converted String.
        Throws:
        java.io.IOException - If reading the stream fails.
      • validatePageNumberPageSize

        public void validatePageNumberPageSize(int pageNumber,
                                               int pageSize)
        Validates the page number and page size parameters. The combination of page number and page size parameters can not exceed maximum value of integer.
        Parameters:
        pageNumber - The page number parameter.
        pageSize - The page size parameter.