Class JsonNamedBeanHttpService<T extends NamedBean>
- java.lang.Object
-
- jmri.server.json.JsonHttpService
-
- jmri.server.json.JsonNonProvidedNamedBeanHttpService<T>
-
- jmri.server.json.JsonNamedBeanHttpService<T>
-
- Type Parameters:
T
- the type supported by this service
- Direct Known Subclasses:
JsonAudioHttpService
,JsonBlockHttpService
,JsonIdTagHttpService
,JsonLightHttpService
,JsonMemoryHttpService
,JsonOblockHttpService
,JsonReporterHttpService
,JsonRouteHttpService
,JsonSensorHttpService
,JsonSignalMastHttpService
,JsonTurnoutHttpService
public abstract class JsonNamedBeanHttpService<T extends NamedBean> extends JsonNonProvidedNamedBeanHttpService<T>
Abstract implementation of JsonHttpService with specific support forNamedBean
objects.Note: services requiring support for multiple classes of NamedBean cannot extend this class.
Note: NamedBeans must be managed by a
ProvidingManager
for this class to be used.
-
-
Field Summary
-
Fields inherited from class jmri.server.json.JsonHttpService
mapper
-
-
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 jmri.server.json.JsonNonProvidedNamedBeanHttpService
doGetList, doGetList, getNamedBean, postNamedBean
-
Methods inherited from class jmri.server.json.JsonHttpService
acceptForceDeleteToken, doSchema, doSchema, doSchema, getObjectMapper, message, message, message, message, message, throwDeleteConflictException
-
-
-
-
Constructor Detail
-
JsonNamedBeanHttpService
public JsonNamedBeanHttpService(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
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 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
@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 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(@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 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
@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 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
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
-
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 classJsonNonProvidedNamedBeanHttpService<T extends NamedBean>
- Parameters:
bean
- the requested objectname
- the name of the requested objecttype
- the type 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
-
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 classJsonNonProvidedNamedBeanHttpService<T extends NamedBean>
- Parameters:
type
- the type of the requested objectname
- the name of the requested objectdata
- the JsonNode containing the JSON representation of the bean to getrequest
- 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 objectname
- the name of the requested objecttype
- the type of the requested objectdata
- data describing the requested objectrequest
- 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 deletename
- the named of the bean to deletetype
- the type of the bean to deletedata
- data describing the named beanrequest
- the JSON request- Throws:
JsonException
- if an error occurs
-
deleteBean
protected final void deleteBean(@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 is the simplest method to delete a bean, and is likely to become the default implementation ofdoDelete(java.lang.String, java.lang.String, com.fasterxml.jackson.databind.JsonNode, jmri.server.json.JsonRequest)
in an upcoming release of JMRI.- Parameters:
bean
- the bean to deletename
- the named of the bean to deletetype
- the type of the bean to deletedata
- data describing the named beanrequest
- 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<T> getManager()
Get the expected manager for the supported JSON type. This should normally be the default manager.- Returns:
- the manager
-
getProvidingManager
protected abstract ProvidingManager<T> getProvidingManager() 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
-
-