Class RESTGenericController<Type extends IridaRepresentationModel & IridaThing & java.lang.Comparable<Type>>

    • 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
    • Constructor Detail

      • RESTGenericController

        protected RESTGenericController()
        The type used to serialize/de-serialize the Type to the client.
      • RESTGenericController

        protected RESTGenericController​(CRUDService<java.lang.Long,​Type> crudService,
                                        java.lang.Class<Type> type)
        Construct an instance of RESTGenericController. 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 of Links for a specific resource. Each resource may have custom links that refer to other controllers, but not all will. This method is called by the getResource 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 of Type in the database, then respond to the client with the location of the resource.
        Parameters:
        resource - the Type that we should de-serialize to get an instance of Type 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 by listAllResources(). 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