Class JsonNamedBeanHttpService<T extends NamedBean>

    • Constructor Summary

      Constructors 
      Constructor Description
      JsonNamedBeanHttpService​(com.fasterxml.jackson.databind.ObjectMapper mapper)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void deleteBean​(T bean, java.lang.String name, java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Delete the requested bean.
      void doDelete​(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Respond to an HTTP DELETE request for the requested name.
      protected void doDelete​(T bean, java.lang.String name, java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Delete the requested bean.
      com.fasterxml.jackson.databind.JsonNode doGet​(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Respond to an HTTP GET request for the requested name.
      protected abstract com.fasterxml.jackson.databind.node.ObjectNode doGet​(T bean, java.lang.String name, java.lang.String type, JsonRequest request)
      Respond to an HTTP GET request for the requested name.
      com.fasterxml.jackson.databind.JsonNode doGetList​(java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Respond to an HTTP GET request for a list of items of type.
      com.fasterxml.jackson.databind.JsonNode doPost​(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Respond to an HTTP POST request for the requested name.
      protected abstract com.fasterxml.jackson.databind.node.ObjectNode doPost​(T bean, java.lang.String name, java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Respond to an HTTP POST request for the requested name.
      com.fasterxml.jackson.databind.JsonNode doPut​(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Respond to an HTTP PUT request for the requested name.
      protected Manager<T> getManager()
      Get the expected manager for the supported JSON type.
      T getNamedBean​(java.lang.String type, java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, JsonRequest request)
      Get the NamedBean matching name and type.
      protected abstract ProvidingManager<T> getProvidingManager()
      Get the expected providing manager for the supported JSON type.
      protected abstract java.lang.String getType()
      Get the JSON type supported by this service.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • doGet

        @Nonnull
        public final com.fasterxml.jackson.databind.JsonNode doGet​(@Nonnull
                                                                   java.lang.String type,
                                                                   @Nonnull
                                                                   java.lang.String name,
                                                                   @Nonnull
                                                                   com.fasterxml.jackson.databind.JsonNode data,
                                                                   @Nonnull
                                                                   JsonRequest request)
                                                            throws JsonException
        Respond to an HTTP GET request for the requested name.

        If name is null, return a list of all objects for the given type, if appropriate.

        This method should throw a 500 Internal Server Error if type is not recognized.

        Specified by:
        doGet in class JsonHttpService
        Parameters:
        type - the type of the requested object
        name - the system name of the requested object
        data - JSON data set of attributes of the requested object
        request - the JSON request
        Returns:
        a JSON description of the requested object
        Throws:
        JsonException - if the named object does not exist or other error occurs
      • doPost

        @Nonnull
        public final com.fasterxml.jackson.databind.JsonNode doPost​(@Nonnull
                                                                    java.lang.String type,
                                                                    @Nonnull
                                                                    java.lang.String name,
                                                                    @Nonnull
                                                                    com.fasterxml.jackson.databind.JsonNode data,
                                                                    @Nonnull
                                                                    JsonRequest request)
                                                             throws JsonException
        Respond to an HTTP POST request for the requested name.

        This method should throw a 400 Invalid Request error if the named object does not exist.

        Specified by:
        doPost in class JsonHttpService
        Parameters:
        type - the type of the requested object
        name - the system name of the requested object
        data - JSON data set of attributes of the requested object to be updated
        request - the JSON request
        Returns:
        a JSON description of the requested object after updates have been applied
        Throws:
        JsonException - if the named object does not exist or other error occurs
      • doPut

        public com.fasterxml.jackson.databind.JsonNode doPut​(@Nonnull
                                                             java.lang.String type,
                                                             @Nonnull
                                                             java.lang.String name,
                                                             @Nonnull
                                                             com.fasterxml.jackson.databind.JsonNode data,
                                                             @Nonnull
                                                             JsonRequest request)
                                                      throws JsonException
        Respond to an HTTP PUT request for the requested name.

        Throw an HTTP 405 Method Not Allowed exception if new objects of the type are not intended to be addable. Override if the implementing class needs to prevent PUT methods from functioning or need to perform additional validation prior to creating the NamedBean.

        Overrides:
        doPut in class JsonHttpService
        Parameters:
        type - the type of the requested object
        name - the system name of the requested object
        data - JSON data set of attributes of the requested object to be created or updated
        request - the JSON request
        Returns:
        a JSON description of the requested object
        Throws:
        JsonException - if the method is not allowed or other error occurs
      • doGetList

        @Nonnull
        public final com.fasterxml.jackson.databind.JsonNode doGetList​(java.lang.String type,
                                                                       com.fasterxml.jackson.databind.JsonNode data,
                                                                       JsonRequest request)
                                                                throws JsonException
        Respond to an HTTP GET request for a list of items of type.

        This is called by the JsonServlet to handle get requests for a type, but no name. Services that do not have named objects, such as the JsonTimeHttpService should respond to this with a list containing a single JSON object. Services that can't return a list may throw a 400 Bad Request JsonException in this case.

        Specified by:
        doGetList in class JsonHttpService
        Parameters:
        type - the type of the requested list
        data - JSON data set of attributes of the requested objects
        request - the JSON request
        Returns:
        a JSON list or message containing type "list", the list as data, and the passed in id
        Throws:
        JsonException - may be thrown by concrete implementations
      • doDelete

        public void doDelete​(java.lang.String type,
                             java.lang.String name,
                             com.fasterxml.jackson.databind.JsonNode data,
                             JsonRequest request)
                      throws JsonException
        Respond to an HTTP DELETE request for the requested name.

        Throw an HTTP 405 Method Not Allowed exception if the object is not intended to be removable.

        Do not throw an error if the requested object does not exist.

        Overrides:
        doDelete in class JsonHttpService
        Parameters:
        type - the type of the deleted object
        name - the system name of the deleted object
        data - additional data
        request - the JSON request
        Throws:
        JsonException - if this method is not allowed or other error occurs
      • doGet

        @Nonnull
        protected abstract com.fasterxml.jackson.databind.node.ObjectNode doGet​(T bean,
                                                                                @Nonnull
                                                                                java.lang.String name,
                                                                                @Nonnull
                                                                                java.lang.String type,
                                                                                @Nonnull
                                                                                JsonRequest request)
                                                                         throws JsonException
        Respond to an HTTP GET request for the requested name.

        If name is null, return a list of all objects for the given type, if appropriate.

        This method should throw a 500 Internal Server Error if type is not recognized.

        Specified by:
        doGet in class JsonNonProvidedNamedBeanHttpService<T extends NamedBean>
        Parameters:
        bean - the requested object
        name - the name of the requested object
        type - the type of the requested object
        request - the JSON request
        Returns:
        a JSON description of the requested object
        Throws:
        JsonException - if the named object does not exist or other error occurs
      • getNamedBean

        @CheckForNull
        public T getNamedBean​(@Nonnull
                              java.lang.String type,
                              @Nonnull
                              java.lang.String name,
                              @Nonnull
                              com.fasterxml.jackson.databind.JsonNode data,
                              @Nonnull
                              JsonRequest request)
                       throws JsonException
        Get the NamedBean matching name and type. If the request has a method other than GET, this may modify or create the NamedBean requested. Note that name or data may be null, but it is an error to have both be null.
        Specified by:
        getNamedBean in class JsonNonProvidedNamedBeanHttpService<T extends NamedBean>
        Parameters:
        type - the type of the requested object
        name - the name of the requested object
        data - the JsonNode containing the JSON representation of the bean to get
        request - the JSON request
        Returns:
        the matching NamedBean or null if there is no match
        Throws:
        JsonException - if the name is invalid for the type
      • doPost

        @Nonnull
        protected abstract com.fasterxml.jackson.databind.node.ObjectNode doPost​(T bean,
                                                                                 @Nonnull
                                                                                 java.lang.String name,
                                                                                 @Nonnull
                                                                                 java.lang.String type,
                                                                                 @Nonnull
                                                                                 com.fasterxml.jackson.databind.JsonNode data,
                                                                                 @Nonnull
                                                                                 JsonRequest request)
                                                                          throws JsonException
        Respond to an HTTP POST request for the requested name.
        Parameters:
        bean - the requested object
        name - the name of the requested object
        type - the type of the requested object
        data - data describing the requested object
        request - the JSON request
        Returns:
        a JSON description of the requested object
        Throws:
        JsonException - if an error occurs
      • doDelete

        protected void doDelete​(@CheckForNull
                                T bean,
                                @Nonnull
                                java.lang.String name,
                                @Nonnull
                                java.lang.String type,
                                @Nonnull
                                com.fasterxml.jackson.databind.JsonNode data,
                                @Nonnull
                                JsonRequest request)
                         throws JsonException
        Delete the requested bean.

        This method must be overridden to allow a bean to be deleted. The simplest overriding method body is: deleteBean(bean, name, type, data, locale, id);

        Parameters:
        bean - the bean to delete
        name - the named of the bean to delete
        type - the type of the bean to delete
        data - data describing the named bean
        request - the JSON request
        Throws:
        JsonException - if an error occurs
      • getType

        @Nonnull
        protected abstract java.lang.String getType()
        Get the JSON type supported by this service.
        Returns:
        the JSON type
      • getManager

        @Nonnull
        protected Manager<TgetManager()
        Get the expected manager for the supported JSON type. This should normally be the default manager.
        Returns:
        the manager
      • getProvidingManager

        protected abstract ProvidingManager<TgetProvidingManager()
                                                            throws java.lang.UnsupportedOperationException
        Get the expected providing manager for the supported JSON type. This should normally be the default manager.
        Returns:
        the providing manager
        Throws:
        java.lang.UnsupportedOperationException - if a providing manager isn't available