Package org.dspace.app.rest.repository
Class DSpaceRestRepository<T extends RestAddressableModel,ID extends Serializable>
- java.lang.Object
-
- org.dspace.app.rest.repository.AbstractDSpaceRestRepository
-
- org.dspace.app.rest.repository.DSpaceRestRepository<T,ID>
-
- All Implemented Interfaces:
org.springframework.data.repository.CrudRepository<T,ID>,org.springframework.data.repository.PagingAndSortingRepository<T,ID>,org.springframework.data.repository.Repository<T,ID>
- Direct Known Subclasses:
AuthorizationFeatureRestRepository,AuthorizationRestRepository,BitstreamFormatRestRepository,BrowseIndexRestRepository,ClaimedTaskRestRepository,ConfigurationRestRepository,DSpaceObjectRestRepository,EntityTypeRestRepository,ExternalSourceRestRepository,MetadataFieldRestRepository,MetadataSchemaRestRepository,PoolTaskRestRepository,ProcessRestRepository,RegistrationRestRepository,RelationshipRestRepository,RelationshipTypeRestRepository,ResourcePolicyRestRepository,ScriptRestRepository,StatisticsRestRepository,SubmissionCCLicenseRestRepository,SubmissionCCLicenseUrlRepository,SubmissionDefinitionRestRepository,SubmissionFormRestRepository,SubmissionPanelRestRepository,SubmissionUploadRestRepository,TemplateItemRestRepository,VersionHistoryRestRepository,VersionRestRepository,VocabularyEntryDetailsRestRepository,VocabularyRestRepository,WorkflowActionRestRepository,WorkflowDefinitionRestRepository,WorkflowItemRestRepository,WorkflowStepRestRepository,WorkspaceItemRestRepository
public abstract class DSpaceRestRepository<T extends RestAddressableModel,ID extends Serializable> extends AbstractDSpaceRestRepository implements org.springframework.data.repository.PagingAndSortingRepository<T,ID>
Base class for any Rest Repository. Adds a DSpaceContext to the normal Spring Data Repository methods signature.- Author:
- Andrea Bollini (andrea.bollini at 4science.it)
-
-
Field Summary
-
Fields inherited from class org.dspace.app.rest.repository.AbstractDSpaceRestRepository
converter, requestService, utils
-
-
Constructor Summary
Constructors Constructor Description DSpaceRestRepository()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Taction(javax.servlet.http.HttpServletRequest request, ID id)protected Taction(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, ID id)longcount()TcreateAndReturn()Create and return a new instance.TcreateAndReturn(List<String> list)Create and return a new instance.TcreateAndReturn(UUID uuid)Create and return a new instance after adding to the parent.protected TcreateAndReturn(org.dspace.core.Context context)Method to implement to support the creation of a new instance.protected TcreateAndReturn(org.dspace.core.Context context, List<String> list)Method to implement to support the creation of a new instance.protected TcreateAndReturn(org.dspace.core.Context context, UUID uuid)Method to implement to support the creation of a new instance.protected voiddelete(org.dspace.core.Context context, ID id)Method to implement to support delete of a single object instancevoiddelete(T entity)voiddeleteAll()voiddeleteAll(Iterable<? extends T> entities)voiddeleteById(ID id)booleanexistsById(ID id)Iterable<T>findAll()abstract org.springframework.data.domain.Page<T>findAll(org.dspace.core.Context context, org.springframework.data.domain.Pageable pageable)Method to implement to support scroll of entity instances from the collection resource endpointorg.springframework.data.domain.Page<T>findAll(org.springframework.data.domain.Pageable pageable)Iterable<T>findAll(org.springframework.data.domain.Sort sort)Iterable<T>findAllById(Iterable<ID> ids)Optional<T>findById(ID id)abstract TfindOne(org.dspace.core.Context context, ID id)Method to implement to support retrieval of a specific REST object instanceabstract Class<T>getDomainClass()The REST model supported by the repositoryTpatch(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, Patch patch)Apply a partial update to the REST object via JSON Patchprotected voidpatch(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, Patch patch)Method to implement to allow partial update of the REST object via JSON PatchTput(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID uuid, com.fasterxml.jackson.databind.JsonNode jsonNode)This method will fully replace the REST object with the given UUID with the REST object that is described in the JsonNode parameterTput(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, List<String> stringList)Method to support updating a DSpace instance.protected Tput(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, com.fasterxml.jackson.databind.JsonNode jsonNode)Implement this method in the subclass to support updating a REST object.protected Tput(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, List<String> stringList)Implement this method in the subclass to support updating a DSpace instance.protected <S extends T>
Ssave(org.dspace.core.Context context, S entity)Method to implement to support full update of a REST object.<S extends T>
Ssave(S entity)<S extends T>
Iterable<S>saveAll(Iterable<S> entities)Tupload(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, org.springframework.web.multipart.MultipartFile file)Method to implement to attach/upload a file to a specific REST objectIterable<T>upload(javax.servlet.http.HttpServletRequest request, List<org.springframework.web.multipart.MultipartFile> uploadfile)Bulk create object instances from an uploaded fileprotected Iterable<T>upload(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, List<org.springframework.web.multipart.MultipartFile> uploadfile)Method to implement to support bulk creation of objects from a file-
Methods inherited from class org.dspace.app.rest.repository.AbstractDSpaceRestRepository
getRequestService, obtainContext
-
-
-
-
Method Detail
-
save
public <S extends T> S save(S entity)
- Specified by:
savein interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
save
protected <S extends T> S save(org.dspace.core.Context context, S entity) throws org.dspace.authorize.AuthorizeException, RepositoryMethodNotImplementedException
Method to implement to support full update of a REST object. This is usually required by a PUT request.- Parameters:
context- the dspace contextentity- the REST object to update- Returns:
- the new state of the REST object after persistence
- Throws:
org.dspace.authorize.AuthorizeExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
saveAll
public <S extends T> Iterable<S> saveAll(Iterable<S> entities)
- Specified by:
saveAllin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findById
public Optional<T> findById(ID id)
- Specified by:
findByIdin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findOne
@PreAuthorize("hasAuthority(\'ADMIN\')") public abstract T findOne(org.dspace.core.Context context, ID id)Method to implement to support retrieval of a specific REST object instance- Parameters:
context- the dspace contextid- the rest object id- Returns:
- the REST object identified by its ID
-
existsById
public boolean existsById(ID id)
- Specified by:
existsByIdin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findAll
public final Iterable<T> findAll()
- Specified by:
findAllin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findAllById
public Iterable<T> findAllById(Iterable<ID> ids)
- Specified by:
findAllByIdin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
count
public long count()
- Specified by:
countin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
deleteById
public void deleteById(ID id)
- Specified by:
deleteByIdin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
delete
protected void delete(org.dspace.core.Context context, ID id) throws org.dspace.authorize.AuthorizeException, RepositoryMethodNotImplementedExceptionMethod to implement to support delete of a single object instance- Parameters:
context- the dspace contextid- the id of the rest object to delete- Throws:
org.dspace.authorize.AuthorizeExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
delete
public void delete(T entity)
- Specified by:
deletein interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
deleteAll
public void deleteAll(Iterable<? extends T> entities)
- Specified by:
deleteAllin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
deleteAll
public void deleteAll()
- Specified by:
deleteAllin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findAll
public final Iterable<T> findAll(org.springframework.data.domain.Sort sort)
- Specified by:
findAllin interfaceorg.springframework.data.repository.PagingAndSortingRepository<T extends RestAddressableModel,ID extends Serializable>
-
findAll
public org.springframework.data.domain.Page<T> findAll(org.springframework.data.domain.Pageable pageable)
- Specified by:
findAllin interfaceorg.springframework.data.repository.PagingAndSortingRepository<T extends RestAddressableModel,ID extends Serializable>
-
findAll
public abstract org.springframework.data.domain.Page<T> findAll(org.dspace.core.Context context, org.springframework.data.domain.Pageable pageable)
Method to implement to support scroll of entity instances from the collection resource endpoint- Parameters:
context- the dspace contextpageable- object embedding the requested pagination info- Returns:
-
createAndReturn
public T createAndReturn()
Create and return a new instance. Data are usually retrieved from the thread bound http request- Returns:
- the created REST object
-
createAndReturn
public T createAndReturn(UUID uuid)
Create and return a new instance after adding to the parent. Data are usually retrieved from the thread bound http request.- Parameters:
uuid- the id of the parent object- Returns:
- the created REST object
-
createAndReturn
public T createAndReturn(List<String> list)
Create and return a new instance. Data is recovered from the thread bound HTTP request and the list of DSpaceObjects provided in the uri-list body- Parameters:
list- The list of Strings to be used in the createAndReturn method- Returns:
- The created REST object
-
createAndReturn
protected T createAndReturn(org.dspace.core.Context context, UUID uuid) throws org.dspace.authorize.AuthorizeException, SQLException, RepositoryMethodNotImplementedException
Method to implement to support the creation of a new instance. Usually require to retrieve the http request from the thread bound attribute- Parameters:
context- the dspace contextuuid- The uuid of the parent object retrieved from the query param.- Returns:
- the created REST object
- Throws:
org.dspace.authorize.AuthorizeExceptionSQLExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
createAndReturn
protected T createAndReturn(org.dspace.core.Context context, List<String> list) throws org.dspace.authorize.AuthorizeException, SQLException, RepositoryMethodNotImplementedException
Method to implement to support the creation of a new instance. Usually require to retrieve the http request from the thread bound attribute- Parameters:
context- the dspace contextlist- The list of Strings that will be used as data for the object that's to be created This list is retrieved from the uri-list body- Returns:
- the created REST object
- Throws:
org.dspace.authorize.AuthorizeExceptionSQLExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
createAndReturn
protected T createAndReturn(org.dspace.core.Context context) throws org.dspace.authorize.AuthorizeException, SQLException, RepositoryMethodNotImplementedException
Method to implement to support the creation of a new instance. Usually require to retrieve the http request from the thread bound attribute- Parameters:
context- the dspace context- Returns:
- the created REST object
- Throws:
org.dspace.authorize.AuthorizeExceptionSQLExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
upload
public T upload(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, org.springframework.web.multipart.MultipartFile file) throws SQLException, FileNotFoundException, IOException, org.dspace.authorize.AuthorizeException
Method to implement to attach/upload a file to a specific REST object- Parameters:
request- the http requestapiCategory-model-id- the ID of the target REST objectfile- the uploaded file- Returns:
- the new state of the REST object
- Throws:
SQLExceptionFileNotFoundExceptionIOExceptionorg.dspace.authorize.AuthorizeException
-
patch
public T patch(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, Patch patch) throws UnprocessableEntityException, DSpaceBadRequestException
Apply a partial update to the REST object via JSON Patch- Parameters:
request- the http requestapiCategory-model-id- the ID of the target REST objectpatch- the JSON Patch (https://tools.ietf.org/html/rfc6902) operation- Returns:
- Throws:
UnprocessableEntityExceptionDSpaceBadRequestException
-
patch
protected void patch(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, Patch patch) throws RepositoryMethodNotImplementedException, SQLException, org.dspace.authorize.AuthorizeExceptionMethod to implement to allow partial update of the REST object via JSON Patch- Parameters:
request- the http requestapiCategory-model-id- the ID of the target REST objectpatch- the JSON Patch (https://tools.ietf.org/html/rfc6902) operation- Throws:
RepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entitySQLExceptionorg.dspace.authorize.AuthorizeException
-
action
public T action(javax.servlet.http.HttpServletRequest request, ID id) throws SQLException, IOException
- Throws:
SQLExceptionIOException
-
action
protected T action(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, ID id) throws SQLException, IOException
- Throws:
SQLExceptionIOException
-
upload
public Iterable<T> upload(javax.servlet.http.HttpServletRequest request, List<org.springframework.web.multipart.MultipartFile> uploadfile) throws SQLException, FileNotFoundException, IOException, org.dspace.authorize.AuthorizeException
Bulk create object instances from an uploaded file- Parameters:
request- the http requestuploadfile- the file to process- Returns:
- the created objects
- Throws:
SQLExceptionFileNotFoundExceptionIOExceptionorg.dspace.authorize.AuthorizeException
-
upload
protected Iterable<T> upload(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, List<org.springframework.web.multipart.MultipartFile> uploadfile) throws SQLException, FileNotFoundException, IOException, org.dspace.authorize.AuthorizeException
Method to implement to support bulk creation of objects from a file- Parameters:
request- the http requestuploadfile- the file to process- Returns:
- the created objects
- Throws:
SQLExceptionFileNotFoundExceptionIOExceptionorg.dspace.authorize.AuthorizeExceptionRepositoryMethodNotImplementedException
-
put
public T put(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID uuid, com.fasterxml.jackson.databind.JsonNode jsonNode)
This method will fully replace the REST object with the given UUID with the REST object that is described in the JsonNode parameter- Parameters:
request- the http requestapiCategory- the API category e.g. "api"model- the DSpace model e.g. "metadatafield"uuid- the ID of the target REST objectjsonNode- the part of the request body representing the updated rest object- Returns:
- the updated REST object
-
put
public T put(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, List<String> stringList)
Method to support updating a DSpace instance.- Parameters:
request- the http requestapiCategory- the API category e.g. "api"model- the DSpace model e.g. "metadatafield"id- the ID of the target REST objectstringList- The list of Strings that will be used as data for the put- Returns:
- the updated REST object
-
put
protected T put(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, com.fasterxml.jackson.databind.JsonNode jsonNode) throws RepositoryMethodNotImplementedException, SQLException, org.dspace.authorize.AuthorizeException
Implement this method in the subclass to support updating a REST object.- Parameters:
context- the dspace contextapiCategory- the API category e.g. "api"model- the DSpace model e.g. "metadatafield"id- the ID of the target REST objectjsonNode- the part of the request body representing the updated rest object- Returns:
- the updated REST object
- Throws:
org.dspace.authorize.AuthorizeException- if the context user is not authorized to perform this operationSQLException- when the database returns an errorRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
put
protected T put(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, List<String> stringList) throws RepositoryMethodNotImplementedException, SQLException, org.dspace.authorize.AuthorizeException
Implement this method in the subclass to support updating a DSpace instance.- Parameters:
context- the dspace contextapiCategory- the API category e.g. "api"model- the DSpace model e.g. "metadatafield"id- the ID of the target REST objectstringList- The list of Strings that will be used as data for the put- Returns:
- the updated REST object
- Throws:
org.dspace.authorize.AuthorizeException- if the context user is not authorized to perform this operationSQLException- when the database returns an errorRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
-