Class JsonOperationsHttpService
- java.lang.Object
-
- jmri.server.json.JsonHttpService
-
- jmri.server.json.operations.JsonOperationsHttpService
-
public class JsonOperationsHttpService extends JsonHttpService
-
-
Field Summary
-
Fields inherited from class jmri.server.json.JsonHttpService
mapper
-
-
Constructor Summary
Constructors Constructor Description JsonOperationsHttpService(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CarManager
carManager()
void
deleteCar(java.lang.String name, java.util.Locale locale, int id)
void
deleteEngine(java.lang.String name, java.util.Locale locale, int id)
void
deleteLocation(java.lang.String name, java.util.Locale locale, int id)
void
deleteTrack(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
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)
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.com.fasterxml.jackson.databind.JsonNode
doSchema(java.lang.String type, boolean server, JsonRequest request)
Get the JSON Schema for thedata
property of the requested type of JSON object.protected EngineManager
engineManager()
protected Car
getCarByName(java.lang.String name, java.util.Locale locale, int id)
com.fasterxml.jackson.databind.node.ArrayNode
getCars(java.util.Locale locale, int id)
protected Engine
getEngineByName(java.lang.String name, java.util.Locale locale, int id)
com.fasterxml.jackson.databind.node.ArrayNode
getEngines(java.util.Locale locale, int id)
protected Location
getLocationByName(java.lang.String name, java.util.Locale locale, int id)
com.fasterxml.jackson.databind.JsonNode
getLocations(java.util.Locale locale, int id)
protected Track
getTrackByName(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
com.fasterxml.jackson.databind.JsonNode
getTrains(java.util.Locale locale, int id)
protected LocationManager
locationManager()
com.fasterxml.jackson.databind.node.ObjectNode
postCar(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
Set the properties in the data parameter for the given car.com.fasterxml.jackson.databind.node.ObjectNode
postCar(Car car, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
Set the properties in the data parameter for the given car.com.fasterxml.jackson.databind.node.ObjectNode
postEngine(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
Set the properties in the data parameter for the given engine.com.fasterxml.jackson.databind.node.ObjectNode
postEngine(Engine engine, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
Set the properties in the data parameter for the given engine.com.fasterxml.jackson.databind.node.ObjectNode
postLocation(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
com.fasterxml.jackson.databind.node.ObjectNode
postLocation(Location location, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
com.fasterxml.jackson.databind.node.ObjectNode
postRollingStock(RollingStock rs, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
Set the properties in the data parameter for the given rolling stock.com.fasterxml.jackson.databind.node.ObjectNode
postTrack(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
com.fasterxml.jackson.databind.node.ObjectNode
postTrack(Track track, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
void
setTrain(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id)
Set the properties in the data parameter for the train with the given id.protected TrainManager
trainManager()
-
Methods inherited from class jmri.server.json.JsonHttpService
acceptForceDeleteToken, doSchema, doSchema, getObjectMapper, message, message, message, message, message, throwDeleteConflictException
-
-
-
-
Constructor Detail
-
JsonOperationsHttpService
public JsonOperationsHttpService(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 classJsonHttpService
- Parameters:
type
- the type of the requested objectname
- the system name of the requested objectdata
- JSON data set of attributes of the requested objectrequest
- 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
Description copied from class:JsonHttpService
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 classJsonHttpService
- Parameters:
type
- the type of the requested objectname
- the system name of the requested objectdata
- JSON data set of attributes of the requested object to be updatedrequest
- 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(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 classJsonHttpService
- Parameters:
type
- the type of the requested objectname
- the system name of the requested objectdata
- JSON data set of attributes of the requested object to be created or updatedrequest
- the JSON request- Returns:
- a JSON description of the requested object
- Throws:
JsonException
- if the 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 theJsonTimeHttpService
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 classJsonHttpService
- Parameters:
type
- the type of the requested listdata
- JSON data set of attributes of the requested objectsrequest
- 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
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 classJsonHttpService
- Parameters:
type
- the type of the deleted objectname
- the system name of the deleted objectdata
- additional datarequest
- the JSON request- Throws:
JsonException
- if this method is not allowed or other error occurs
-
getCars
public com.fasterxml.jackson.databind.node.ArrayNode getCars(java.util.Locale locale, int id)
-
getEngines
public com.fasterxml.jackson.databind.node.ArrayNode getEngines(java.util.Locale locale, int id)
-
getLocations
public com.fasterxml.jackson.databind.JsonNode getLocations(java.util.Locale locale, int id)
-
getTrains
public com.fasterxml.jackson.databind.JsonNode getTrains(java.util.Locale locale, int id)
-
setTrain
public void setTrain(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
Set the properties in the data parameter for the train with the given id.Currently only moves the train to the location given with the key "location". If the move cannot be completed, throws error code 428.
- Parameters:
name
- id of the traindata
- train data to changelocale
- locale to throw exceptions inid
- message id set by client- Throws:
JsonException
- if the train cannot move to the location in data.
-
postLocation
public com.fasterxml.jackson.databind.node.ObjectNode postLocation(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
postLocation
public com.fasterxml.jackson.databind.node.ObjectNode postLocation(Location location, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
postTrack
public com.fasterxml.jackson.databind.node.ObjectNode postTrack(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
postTrack
public com.fasterxml.jackson.databind.node.ObjectNode postTrack(Track track, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
postCar
public com.fasterxml.jackson.databind.node.ObjectNode postCar(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
Set the properties in the data parameter for the given car.Note returns the modified car because changing the road or number of a car changes its name in the JSON representation.
- Parameters:
name
- the operations id of the car to changedata
- car data to changelocale
- locale to throw exceptions inid
- message id set by client- Returns:
- the JSON representation of the car
- Throws:
JsonException
- if a car by name cannot be found
-
postCar
public com.fasterxml.jackson.databind.node.ObjectNode postCar(@Nonnull Car car, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
Set the properties in the data parameter for the given car.Note returns the modified car because changing the road or number of a car changes its name in the JSON representation.
- Parameters:
car
- the car to changedata
- car data to changelocale
- locale to throw exceptions inid
- message id set by client- Returns:
- the JSON representation of the car
- Throws:
JsonException
- if unable to set location
-
postEngine
public com.fasterxml.jackson.databind.node.ObjectNode postEngine(java.lang.String name, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
Set the properties in the data parameter for the given engine.Note returns the modified engine because changing the road or number of an engine changes its name in the JSON representation.
- Parameters:
name
- the operations id of the engine to changedata
- engine data to changelocale
- locale to throw exceptions inid
- message id set by client- Returns:
- the JSON representation of the engine
- Throws:
JsonException
- if a engine by name cannot be found
-
postEngine
public com.fasterxml.jackson.databind.node.ObjectNode postEngine(@Nonnull Engine engine, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
Set the properties in the data parameter for the given engine.Note returns the modified engine because changing the road or number of an engine changes its name in the JSON representation.
- Parameters:
engine
- the engine to changedata
- engine data to changelocale
- locale to throw exceptions inid
- message id set by client- Returns:
- the JSON representation of the engine
- Throws:
JsonException
- if unable to set location
-
postRollingStock
public com.fasterxml.jackson.databind.node.ObjectNode postRollingStock(@Nonnull RollingStock rs, com.fasterxml.jackson.databind.JsonNode data, java.util.Locale locale, int id) throws JsonException
Set the properties in the data parameter for the given rolling stock.Note returns the modified rolling stock because changing the road or number of a rolling stock changes its name in the JSON representation.
- Parameters:
rs
- the rolling stock to changedata
- rolling stock data to changelocale
- locale to throw exceptions inid
- message id set by client- Returns:
- the JSON representation of the rolling stock
- Throws:
JsonException
- if unable to set location
-
deleteCar
public void deleteCar(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
deleteEngine
public void deleteEngine(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
deleteLocation
public void deleteLocation(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
deleteTrack
public void deleteTrack(@Nonnull java.lang.String name, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
getCarByName
@Nonnull protected Car getCarByName(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
getEngineByName
@Nonnull protected Engine getEngineByName(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
getLocationByName
@Nonnull protected Location getLocationByName(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
getTrackByName
@Nonnull protected Track getTrackByName(@Nonnull java.lang.String name, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull java.util.Locale locale, int id) throws JsonException
- Throws:
JsonException
-
carManager
protected CarManager carManager()
-
engineManager
protected EngineManager engineManager()
-
locationManager
protected LocationManager locationManager()
-
trainManager
protected TrainManager trainManager()
-
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 thedata
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 classJsonHttpService
- Parameters:
type
- the type for which a schema is requestedserver
- true if the schema is for a message from the server; false if the schema is for a message from the clientrequest
- 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
-
-