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>
- Type Parameters:
T- a REST model class (e.g.ItemRest).ID- type used to identify an instance of the class (String, UUID, etc).
- All Implemented Interfaces:
Aware,BeanNameAware,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,BulkAccessConditionRestRepository,ClaimedTaskRestRepository,ConfigurationRestRepository,CorrectionTypeRestRepository,DSpaceObjectRestRepository,DuplicateRestRepository,EntityTypeRestRepository,ExternalSourceRestRepository,FeedbackRestRepository,IdentifierRestRepository,ItemFilterRestRepository,LDNMessageRestRepository,MetadataFieldRestRepository,MetadataSchemaRestRepository,NotifyServiceRestRepository,OrcidHistoryRestRepository,OrcidQueueRestRepository,PoolTaskRestRepository,ProcessRestRepository,QAEventRestRepository,QASourceRestRepository,QATopicRestRepository,RegistrationRestRepository,RelationshipRestRepository,RelationshipTypeRestRepository,RequestItemRepository,ResearcherProfileRestRepository,ResourcePolicyRestRepository,ScriptRestRepository,StatisticsRestRepository,SubmissionAccessOptionRestRepository,SubmissionCCLicenseRestRepository,SubmissionCCLicenseUrlRepository,SubmissionCoarNotifyRestRepository,SubmissionDefinitionRestRepository,SubmissionFormRestRepository,SubmissionPanelRestRepository,SubmissionUploadRestRepository,SubscriptionRestRepository,SuggestionRestRepository,SuggestionSourceRestRepository,SuggestionTargetRestRepository,SupervisionOrderRestRepository,SystemWideAlertRestRepository,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.CrudRepository<T,ID>, org.springframework.data.repository.PagingAndSortingRepository<T,ID>, BeanNameAware
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected Tlongcount()Create and return a new instance.createAndReturn(List<String> list) Create and return a new instance.createAndReturn(UUID uuid) Create and return a new instance after adding to the parent.protected TcreateAndReturn(Context context) Method to implement to support the creation of a new instance.protected TcreateAndReturn(Context context, List<String> list) Method to implement to support the creation of a new instance.protected TcreateAndReturn(Context context, UUID uuid) Method to implement to support the creation of a new instance.protected voidMethod to implement to support delete of a single object instancevoidvoidvoidvoiddeleteAllById(Iterable<? extends ID> ids) voiddeleteById(ID id) booleanexistsById(ID id) findAll()abstract org.springframework.data.domain.Page<T>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) findAll(org.springframework.data.domain.Sort sort) findAllById(Iterable<ID> ids) abstract TMethod to implement to support retrieval of a specific REST object instanceThe REST model supported by the repositorypatch(jakarta.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, Patch patch) Apply a partial update to the REST object via JSON Patchprotected voidpatch(Context context, jakarta.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 Patchput(jakarta.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 parameterput(jakarta.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, List<String> stringList) Method to support updating a DSpace instance.protected Tput(Context context, jakarta.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(Context context, jakarta.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>
SMethod to implement to support full update of a REST object.<S extends T>
Ssave(S entity) voidsetBeanName(String beanName) From BeanNameAware.upload(jakarta.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, MultipartFile file) Method to implement to attach/upload a file to a specific REST objectupload(jakarta.servlet.http.HttpServletRequest request, List<MultipartFile> uploadfile) Bulk create object instances from an uploaded fileupload(Context context, jakarta.servlet.http.HttpServletRequest request, List<MultipartFile> uploadfile) Method to implement to support bulk creation of objects from a fileMethods inherited from class org.dspace.app.rest.repository.AbstractDSpaceRestRepository
getRequestService, obtainContext
-
Constructor Details
-
DSpaceRestRepository
public DSpaceRestRepository()
-
-
Method Details
-
setBeanName
From BeanNameAware. Allows us to capture the name of the bean, so we can load it into thisRepository. See getThisRepository() method.- Specified by:
setBeanNamein interfaceBeanNameAware- Parameters:
beanName- name of ourselves
-
save
- Specified by:
savein interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
save
protected <S extends T> S save(Context context, S entity) throws 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:
AuthorizeExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
saveAll
- Specified by:
saveAllin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findById
- Specified by:
findByIdin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findOne
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
- Specified by:
existsByIdin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findAll
- Specified by:
findAllin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
findAllById
- 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
- Specified by:
deleteByIdin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
delete
protected void delete(Context context, ID id) throws AuthorizeException, RepositoryMethodNotImplementedException Method to implement to support delete of a single object instance- Parameters:
context- the dspace contextid- the id of the rest object to delete- Throws:
AuthorizeExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
delete
- Specified by:
deletein interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
deleteAll
- Specified by:
deleteAllin interfaceorg.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
-
deleteAllById
- Specified by:
deleteAllByIdin 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
- 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(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:
-
getDomainClass
The REST model supported by the repository -
createAndReturn
Create and return a new instance. Data are usually retrieved from the thread bound http request- Returns:
- the created REST object
-
createAndReturn
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
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(Context context, UUID uuid) throws 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:
AuthorizeExceptionSQLExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
createAndReturn
protected T createAndReturn(Context context, List<String> list) throws 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:
AuthorizeExceptionSQLExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
createAndReturn
protected T createAndReturn(Context context) throws 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:
AuthorizeExceptionSQLExceptionRepositoryMethodNotImplementedException- returned by the default implementation when the operation is not supported for the entity
-
upload
public T upload(jakarta.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, MultipartFile file) throws SQLException, FileNotFoundException, IOException, 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:
SQLExceptionFileNotFoundExceptionIOExceptionAuthorizeException
-
patch
public T patch(jakarta.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(Context context, jakarta.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, Patch patch) throws RepositoryMethodNotImplementedException, SQLException, AuthorizeException Method 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 entitySQLExceptionAuthorizeException
-
action
public T action(jakarta.servlet.http.HttpServletRequest request, ID id) throws SQLException, IOException - Throws:
SQLExceptionIOException
-
action
protected T action(Context context, jakarta.servlet.http.HttpServletRequest request, ID id) throws SQLException, IOException - Throws:
SQLExceptionIOException
-
upload
public Iterable<T> upload(jakarta.servlet.http.HttpServletRequest request, List<MultipartFile> uploadfile) throws SQLException, FileNotFoundException, IOException, AuthorizeException Bulk create object instances from an uploaded file- Parameters:
request- the http requestuploadfile- the file to process- Returns:
- the created objects
- Throws:
SQLExceptionFileNotFoundExceptionIOExceptionAuthorizeException
-
upload
protected Iterable<T> upload(Context context, jakarta.servlet.http.HttpServletRequest request, List<MultipartFile> uploadfile) throws SQLException, FileNotFoundException, IOException, 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:
SQLExceptionFileNotFoundExceptionIOExceptionAuthorizeExceptionRepositoryMethodNotImplementedException
-
put
public T put(jakarta.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(jakarta.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(Context context, jakarta.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, com.fasterxml.jackson.databind.JsonNode jsonNode) throws RepositoryMethodNotImplementedException, SQLException, 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:
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(Context context, jakarta.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, List<String> stringList) throws RepositoryMethodNotImplementedException, SQLException, 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:
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
-