Class JsonConsistHttpService

    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      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.
      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)
      Change the properties and locomotives of a consist.
      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.
      com.fasterxml.jackson.databind.JsonNode doSchema​(java.lang.String type, boolean server, JsonRequest request)
      Get the JSON Schema for the data property of the requested type of JSON object.
      com.fasterxml.jackson.databind.JsonNode getConsist​(LocoAddress address, JsonRequest request)
      Get the JSON representation of a consist.
      • Methods inherited from class java.lang.Object

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

      • JsonConsistHttpService

        public JsonConsistHttpService​(com.fasterxml.jackson.databind.ObjectMapper mapper)
    • Method Detail

      • doGet

        public com.fasterxml.jackson.databind.JsonNode doGet​(java.lang.String type,
                                                             java.lang.String name,
                                                             com.fasterxml.jackson.databind.JsonNode data,
                                                             JsonRequest request)
                                                      throws JsonException
        Description copied from class: JsonHttpService
        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

        public com.fasterxml.jackson.databind.JsonNode doPost​(java.lang.String type,
                                                              java.lang.String name,
                                                              com.fasterxml.jackson.databind.JsonNode data,
                                                              JsonRequest request)
                                                       throws JsonException
        Change the properties and locomotives of a consist. This method takes as input the JSON representation of a consist as provided by getConsist(jmri.LocoAddress, jmri.server.json.JsonRequest). If present in the JSON, this method sets the following consist properties:
        • consistID
        • consistType
        • locomotives (engines in the JSON representation)
          NOTE Since this method adds, repositions, and deletes locomotives, the JSON representation must contain every locomotive that should be in the consist, if it contains the engines node.
        Specified by:
        doPost in class JsonHttpService
        Parameters:
        type - the JSON message type
        name - the consist address, ignored if data contains an "address" and "isLongAddress" nodes
        data - the consist as a JsonObject
        request - the JSON request
        Returns:
        the JSON representation of the Consist
        Throws:
        JsonException - if there is no consist manager (code 503), the consist does not exist (code 404), or the consist cannot be saved (code 500).
      • doPut

        public com.fasterxml.jackson.databind.JsonNode doPut​(java.lang.String type,
                                                             java.lang.String name,
                                                             com.fasterxml.jackson.databind.JsonNode data,
                                                             JsonRequest request)
                                                      throws JsonException
        Description copied from class: JsonHttpService
        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.

        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
      • doDelete

        public void doDelete​(java.lang.String type,
                             java.lang.String name,
                             com.fasterxml.jackson.databind.JsonNode data,
                             JsonRequest request)
                      throws JsonException
        Description copied from class: JsonHttpService
        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
      • doGetList

        public com.fasterxml.jackson.databind.JsonNode doGetList​(java.lang.String type,
                                                                 com.fasterxml.jackson.databind.JsonNode data,
                                                                 JsonRequest request)
                                                          throws JsonException
        Description copied from class: JsonHttpService
        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
      • getConsist

        public com.fasterxml.jackson.databind.JsonNode getConsist​(LocoAddress address,
                                                                  JsonRequest request)
                                                           throws JsonException
        Get the JSON representation of a consist. The JSON representation is an object with the following data attributes:
        • address - integer address
        • isLongAddress - boolean true if address is long, false if short
        • type - integer, see Consist.getConsistType()
        • id - string with consist Id
        • sizeLimit - the maximum number of locomotives the consist can contain
        • engines - array listing every locomotive in the consist. Each entry in the array contains the following attributes:
          • address - integer address
          • isLongAddress - boolean true if address is long, false if short
          • forward - boolean true if the locomotive running is forward in the consists
          • position - integer locomotive's position in the consist
        Parameters:
        address - The address of the consist to get
        request - the JSON request
        Returns:
        The JSON representation of the consist
        Throws:
        JsonException - This exception has code 404 if the consist does not exist
      • doSchema

        public com.fasterxml.jackson.databind.JsonNode doSchema​(java.lang.String type,
                                                                boolean server,
                                                                JsonRequest request)
                                                         throws JsonException
        Description copied from class: JsonHttpService
        Get the JSON Schema for the data property of the requested type of JSON object. It is a invalid for implementations to not return a valid schema that clients can use to validate a request to or response from the JSON services.

        Note that a schema must be contained in a standard object as:

        {"type":"schema", "data":{"schema":<em>schema</em>, "server":boolean}}

        If using JsonHttpService.doSchema(String, boolean, String, String, int), an implementation can be as simple as: return doSchema(type, server, "path/to/client/schema.json", "path/to/server/schema.json", id);

        Specified by:
        doSchema in class JsonHttpService
        Parameters:
        type - the type for which a schema is requested
        server - true if the schema is for a message from the server; false if the schema is for a message from the client
        request - the JSON request
        Returns:
        a JSON Schema valid for the type
        Throws:
        JsonException - if an error occurs preparing schema; if type is is not a type handled by this service, this must be thrown with an error code of 500 and the localized message ERROR_UNKNOWN_TYPE