Interface PlatformConverterService


  • @ProviderType
    public interface PlatformConverterService
    Service that provides common functionality that can be used by any Platform API based HypermediaConverter when serializing resources to Platform API style JSON.
    • Method Detail

      • populateHeaders

        void populateHeaders​(ConverterResponseBuilder builder,
                             ModelDescription description)
        Builds the response headers as defined in the model using the ApiHeader annotations and sets them in the response builder.
        Parameters:
        builder - The ConverterResponseBuilder responsible for building the response.
        description - The metadata description of the model.
      • populateLinkHeader

        void populateLinkHeader​(ConverterResponseBuilder builder,
                                ConverterContext context,
                                Resource resource,
                                ModelDescription description,
                                ApiLink.SCOPE scope)
                         throws java.net.URISyntaxException,
                                java.io.UnsupportedEncodingException
        Builds the link header for the response based on the ApiHeader annotations in the model, filtered by the scope parameter supplied.
        Parameters:
        builder - The ConverterResponseBuilder responsible for building the response.
        context - The ConverterContext providing information about the request.
        resource - The resource being serialized.
        description - The metadata description of the model.
        scope - The scope a link should satisfy in order to be serialized into the link header.
        Throws:
        java.io.UnsupportedEncodingException - If encoding is not supported.
        java.net.URISyntaxException
      • buildLinksObject

        @Nonnull
        JSONObject buildLinksObject​(ConverterContext context,
                                    Resource resource,
                                    ModelDescription description)
                             throws JSONException,
                                    java.net.URISyntaxException,
                                    java.io.UnsupportedEncodingException
        Builds the links JSONObject that can be added to the response body.
        Parameters:
        context - The ConverterContext providing information about the request.
        resource - The resource being serialized.
        description - The metadata description of the model.
        Returns:
        The JSONObject that is the links object.
        Throws:
        JSONException - If an error occurs when creating the links object.
        java.net.URISyntaxException - If an error occurs building the URL.
        java.io.UnsupportedEncodingException - If encoding is not supported.
      • buildProps

        @Nonnull
        java.util.Map<java.lang.String,​java.lang.Object> buildProps​(Resource resource,
                                                                          ModelDescription description,
                                                                          ApiProperty.SCOPE scope)
        Build a map of the properties to be serialized into the response body, filtered by the provided scope.
        Parameters:
        resource - The resource being serialized.
        description - The metadata description of the model.
        scope - The scope a property should satisfy in order to be serialized into the Map.
        Returns:
        The Map of properties to be serialized.
      • buildChildren

        @Nonnull
        JSONArray buildChildren​(ConverterContext context,
                                ModelDescription description,
                                HypermediaConverter converter)
        Build the children JSONArray that can be added to the response body.
        Parameters:
        context - The ConverterContext providing information about the request.
        description - The metadata description of the model.
        converter - The HypermediaConverter to be used to render the children resources as sub entities.
        Returns:
        The JSONArray that represents the children to be serialized.
      • buildPageObject

        @CheckForNull
        JSONObject buildPageObject​(ConverterContext context,
                                   java.lang.String nextValue,
                                   java.lang.String resourcePath,
                                   java.lang.String category,
                                   int count)
                            throws JSONException
        Build the page JSONObject that can be added to the response body.
        Parameters:
        context - The ConverterContext providing information about the request.
        nextValue - The value to be used to get the next page.
        resourcePath - The path to the resource.
        category - The API category.
        count - The number of resources contained in the children array.
        Returns:
        The JSONObject that is the page object.
        Throws:
        JSONException - If an error occurs when creating the JSONObject.
      • buildURL

        @Nonnull
        java.lang.String buildURL​(ConverterContext context,
                                  java.lang.String resourcePath)
                           throws java.net.URISyntaxException,
                                  java.io.UnsupportedEncodingException
        Builds a URL for a resource that can be used in the response.
        Parameters:
        context - The ConverterContext providing information about the request.
        resourcePath - The path to the resource.
        Returns:
        The URL to the resource.
        Throws:
        java.net.URISyntaxException - If an error occurs building the URL.
        java.io.UnsupportedEncodingException - If encoding is not supported.
      • getApiPrefix

        @Nonnull
        java.lang.String getApiPrefix​(ConverterContext context,
                                      java.lang.String category)
        Get the API prefix that can be used when building URLs for API managed resources.
        Parameters:
        context - The ConverterContext providing information about the request.
        category - The API category the resource is being managed under.
        Returns:
        The API prefix string.
      • getPaginationStartValue

        @CheckForNull
        java.lang.String getPaginationStartValue​(HttpServletRequest request)
        Get the pagination start value that will be used to build a paginated child entity list.
        Parameters:
        request - The HTTPServletRequest.
        Returns:
        The pagination start value.
      • getPaginationLimitValue

        int getPaginationLimitValue​(HttpServletRequest request)
        Get the pagination limit value that will be used to build a paginated child entity list.
        Parameters:
        request - The HTTPServletRequest.
        Returns:
        The pagination limit value.
      • getOrderBy

        @Nonnull
        java.util.List<OrderByDetails> getOrderBy​(HttpServletRequest request)
        Get the ordering parameters from the request that will be used to build a paginated child entity list.
        Parameters:
        request - The HTTPServletRequest.
        Returns:
        The pagination ordering parameters.