Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: update links to dspace-spring-rest to refer to new dspace-server-webapp path

...

Coding the REST object

...

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

  1. 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.) 
    1. https://github.com/DSpace/DSpace/blob/master/dspace-springserver-restwebapp/src/main/java/org/dspace/app/rest/model/hateoas/DSpaceResource.java#L58
      This give a chance to add custom logic for extra links in specific resource
  2. put the wrapper in the embedded section 
  3. clean the attribute (not sure if useful/required/right): 
    1.  https://github.com/DSpace/DSpace/blob/master/dspace-springserver-restwebapp/src/main/java/org/dspace/app/rest/model/hateoas/DSpaceResource.java#L64

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

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

...