Class RESTGenericController<Type extends IridaRepresentationModel & IridaThing & java.lang.Comparable<Type>>
- java.lang.Object
-
- ca.corefacility.bioinformatics.irida.web.controller.api.RESTGenericController<Type>
-
- Type Parameters:
Type
- the type that this controller is working with.
- Direct Known Subclasses:
RESTAnalysisSubmissionController
,RESTProjectsController
,RESTSequencingRunController
,RESTUsersController
@Controller @RequestMapping("/api/generic") public abstract class RESTGenericController<Type extends IridaRepresentationModel & IridaThing & java.lang.Comparable<Type>> extends java.lang.Object
A controller that can serve any model from the database.
-
-
Field Summary
Fields Modifier and Type Field Description protected CRUDService<java.lang.Long,Type>
crudService
service used for working with classes in the database.static java.lang.String
REL_COLLECTION
Link back to the collection after deletion of a resource.static java.lang.String
REL_RELATIONSHIP
Rel used for terminating a relationship between resources.static java.lang.String
RELATED_RESOURCES_NAME
name of related resources sent back to the client.static java.lang.String
RESOURCE_NAME
name of the objects used to render the view classes.
-
Constructor Summary
Constructors Modifier Constructor Description protected
RESTGenericController()
The type used to serialize/de-serialize theType
to the client.protected
RESTGenericController(CRUDService<java.lang.Long,Type> crudService, java.lang.Class<Type> type)
Construct an instance ofRESTGenericController
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Collection<org.springframework.hateoas.Link>
constructCollectionResourceLinks(ResourceCollection<Type> list)
Get custom links to the ResourceCollection being called bylistAllResources()
.protected java.util.Collection<org.springframework.hateoas.Link>
constructCustomResourceLinks(Type resource)
Construct a collection ofLink
s for a specific resource.ResponseResource<Type>
create(Type resource, javax.servlet.http.HttpServletResponse response)
Create a new instance ofType
in the database, then respond to the client with the location of the resource.ResponseResource<RootResource>
delete(java.lang.Long identifier)
Delete the instance of the resource identified by a specific identifier.ResponseResource<Type>
getResource(java.lang.Long identifier)
Retrieve and serialize an individual instance of a resource by identifier.ResponseResource<ResourceCollection<Type>>
listAllResources()
Get all resources in the application.ResponseResource<RootResource>
update(java.lang.Long identifier, java.util.Map<java.lang.String,java.lang.Object> representation)
Update some of the fields of an individual resource in the database.
-
-
-
Field Detail
-
RESOURCE_NAME
public static final java.lang.String RESOURCE_NAME
name of the objects used to render the view classes.- See Also:
- Constant Field Values
-
RELATED_RESOURCES_NAME
public static final java.lang.String RELATED_RESOURCES_NAME
name of related resources sent back to the client.- See Also:
- Constant Field Values
-
REL_RELATIONSHIP
public static final java.lang.String REL_RELATIONSHIP
Rel used for terminating a relationship between resources.- See Also:
- Constant Field Values
-
REL_COLLECTION
public static final java.lang.String REL_COLLECTION
Link back to the collection after deletion of a resource.- See Also:
- Constant Field Values
-
crudService
protected CRUDService<java.lang.Long,Type extends IridaRepresentationModel & IridaThing & java.lang.Comparable<Type>> crudService
service used for working with classes in the database.
-
-
Constructor Detail
-
RESTGenericController
protected RESTGenericController()
The type used to serialize/de-serialize theType
to the client.
-
RESTGenericController
protected RESTGenericController(CRUDService<java.lang.Long,Type> crudService, java.lang.Class<Type> type)
Construct an instance ofRESTGenericController
.RESTGenericController
is an abstract type, and should only be used as a super-class.- Parameters:
crudService
- the service used to manage resources in the database.type
- the type of that this controller manages.
-
-
Method Detail
-
constructCustomResourceLinks
protected java.util.Collection<org.springframework.hateoas.Link> constructCustomResourceLinks(Type resource)
Construct a collection ofLink
s for a specific resource. Each resource may have custom links that refer to other controllers, but not all will. This method is called by thegetResource
method.- Parameters:
resource
- the resource to generate the links for.- Returns:
- a collection of links.
-
listAllResources
@RequestMapping(method=GET) public ResponseResource<ResourceCollection<Type>> listAllResources()
Get all resources in the application.- Returns:
- a model containing all resources of the specified type in the application.
-
getResource
@RequestMapping(value="/{identifier}", method=GET) public ResponseResource<Type> getResource(@PathVariable java.lang.Long identifier)
Retrieve and serialize an individual instance of a resource by identifier.- Parameters:
identifier
- the identifier of the resource to retrieve from the database.- Returns:
- the model and view for the individual resource.
-
create
@RequestMapping(method=POST, consumes="application/json") public ResponseResource<Type> create(@RequestBody Type resource, javax.servlet.http.HttpServletResponse response)
Create a new instance ofType
in the database, then respond to the client with the location of the resource.- Parameters:
resource
- theType
that we should de-serialize to get an instance ofType
to persist.response
- a reference to the servlet response.- Returns:
- a response containing the location of the newly persisted resource.
-
delete
@RequestMapping(value="/{identifier}", method=DELETE) public ResponseResource<RootResource> delete(@PathVariable java.lang.Long identifier)
Delete the instance of the resource identified by a specific identifier.- Parameters:
identifier
- the identifier that should be deleted from the database.- Returns:
- a response indicating that the resource was deleted.
-
update
@RequestMapping(value="/{identifier}", method=PATCH, consumes="application/json") public ResponseResource<RootResource> update(@PathVariable java.lang.Long identifier, @RequestBody java.util.Map<java.lang.String,java.lang.Object> representation)
Update some of the fields of an individual resource in the database. The client should only send the key-value pairs for the properties that are to be updated in the database.- Parameters:
identifier
- the identifier of the resource to be updated.representation
- the properties to be updated and their new values.- Returns:
- a response indicating that the resource was updated.
-
constructCollectionResourceLinks
protected java.util.Collection<org.springframework.hateoas.Link> constructCollectionResourceLinks(ResourceCollection<Type> list)
Get custom links to the ResourceCollection being called bylistAllResources()
. This method can be overridden by extending classes to add links to the returned list.- Parameters:
list
-ResourceCollection
to add links to- Returns:
- Collection of links to add to the
ResourceCollection
-
-