Coding the REST object
- Add private properties
- Add a get/set method
- Add get and set to the class DSpaceObjectRest
- To exclude a property from JSON representation, add @JsonIgnore to the get method or to the property
- the REST Object should not includes collections (List, Set, etc.) to maintain relations with other REST Objects unless it makes sense to load in memory all the linked objects, instead it should contains information (probably in form of annotation) to discovery linked entities. When a collection could be already available in the corresponding Hibernate object depending on the performed operation the collections should be annotated to provide a more efficient strategy to load the (paginated) information than the native (unpaginated) hibernate lazy-loading
The base class in this package uses reflection to identify attributes that are actual links to other REST resources.
If an attribute is of type RestModel, then the code will
- wrap the linked REST resource inside a DSpaceResource (so to have the identifier, self link, and links to other resources). The wrapper is actually created by the Repository responsible of the specific resource (ItemRepository, BitstreamRepository, etc.)
This give a chance to add custom logic for extra links in specific resource
- put the wrapper in the embedded section
- clean the attribute (not sure if useful/required/right):
Converter Object: org.dspace.app.rest.converter.DSpaceObjectConverter
Convert between the REST representation of an object and the hibernate Hibernate representation of an object.
Coding a converter object
- In the fromModel() function, map all object attributes from the persistence/hibernate Hibernate model to the rest REST model.
- In the toModel() method, map all attributes from the REST model to the persistence model.
Repository Object: org.dspace.app.rest.repository.DSpaceRestRepository
Provide repository interface functions that return and manage REST representations of DSpace objects. It should provides provide methods to
- get a specific instance of the object (findOne)
- get all the instances, paginated (findAll)
- save an instance (save)
- delete an instance (delete)
Any additional methods that return a subset of the collection exposed by the repository should be annotated with @SearchRestMethod annotation so to be discovered as "search" capabilities of the repository and automatically exposed over the /search endpoint sub-path of the resource type (i.e. /community/search/top).
The java method in the repository class can be named in any way, the sub-path used to build the rest endpoint is by default equals to the method name but can be forced to a specific value using the name parameter in the annotation
The java method must return a Page of rest resources or a single resource but can accept any kind of arguments. If the method has a Pageable argument it is automatically bind, the other argument are bind from HTTP parameters using the Spring Converter Framework but they need to be annotated with the @Param annotation where the name attribute define the name of the HTTP parameter (see an example here)
Repository Object: massive conditional update/deletion