Public API v1
In preparation for making GG-CE API accessible for external users we need to implement a set of controllers that will allow for accessing only the public data.
Public data means records are filtered by the server for is_web_visible = 'Y'
.
AccessionController
Provides read access to Accession
records with list
, filter
and details
methods.
InventoryGroupController
Provides read access to AccessionInvGroup
records with list
, filter
and details
methods.
Trait controllers
CropController
, CropTraitController
, etc.
Implementation
The best approach would be to implement a new controller base class PublicController
(similar to FilteredCRUDController
) and an interface PublicService
:
public abstract class PublicController<E extends EmptyModel, S extends PublicService<E, F>, F extends EmptyModelFilter<F, E>> {
public FilteredPage<E, F> list(@Parameter(hidden = true) final Pagination page, @RequestBody(required = false) final F filter) throws SearchException, IOException {}
public FilteredPage<E, F> filter(@RequestParam(name = "f", required = false) String filterCode, @Parameter(hidden = true) final Pagination page, @RequestBody(required = false) F filter) throws IOException, SearchException {}
...
}
public interface PublicService<T extends EmptyModel, F extends EmptyModelFilter<F, T>> {
Page<T> listPublic(F filter, Pageable page) throws SearchException;
T loadPublic(long id);
}
We can add PublicService
to services that support public API and ensure that they only query for and return data that is publicly accessible (e.g. is_web_visible = 'Y'
).