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)
  • Constructor Details

    • DSpaceRestRepository

      public DSpaceRestRepository()
  • Method Details

    • setBeanName

      public void setBeanName(String beanName)
      From BeanNameAware. Allows us to capture the name of the bean, so we can load it into thisRepository. See getThisRepository() method.
      Specified by:
      setBeanName in interface BeanNameAware
      Parameters:
      beanName - name of ourselves
    • save

      public <S extends T> S save(S entity)
      Specified by:
      save in interface org.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 context
      entity - the REST object to update
      Returns:
      the new state of the REST object after persistence
      Throws:
      AuthorizeException
      RepositoryMethodNotImplementedException - 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:
      saveAll in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • findById

      public Optional<T> findById(ID id)
      Specified by:
      findById in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • findOne

      public abstract T findOne(Context context, ID id)
      Method to implement to support retrieval of a specific REST object instance
      Parameters:
      context - the dspace context
      id - the rest object id
      Returns:
      the REST object identified by its ID
    • existsById

      public boolean existsById(ID id)
      Specified by:
      existsById in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • findAll

      public final Iterable<T> findAll()
      Specified by:
      findAll in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • findAllById

      public Iterable<T> findAllById(Iterable<ID> ids)
      Specified by:
      findAllById in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • count

      public long count()
      Specified by:
      count in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • deleteById

      public void deleteById(ID id)
      Specified by:
      deleteById in interface org.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 context
      id - the id of the rest object to delete
      Throws:
      AuthorizeException
      RepositoryMethodNotImplementedException - returned by the default implementation when the operation is not supported for the entity
    • delete

      public void delete(T entity)
      Specified by:
      delete in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • deleteAll

      public void deleteAll(Iterable<? extends T> entities)
      Specified by:
      deleteAll in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • deleteAllById

      public void deleteAllById(Iterable<? extends ID> ids)
      Specified by:
      deleteAllById in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • deleteAll

      public void deleteAll()
      Specified by:
      deleteAll in interface org.springframework.data.repository.CrudRepository<T extends RestAddressableModel,ID extends Serializable>
    • findAll

      public final Iterable<T> findAll(org.springframework.data.domain.Sort sort)
      Specified by:
      findAll in interface org.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:
      findAll in interface org.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 context
      pageable - object embedding the requested pagination info
      Returns:
    • getDomainClass

      public abstract Class<T> getDomainClass()
      The REST model supported by the repository
    • 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(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 context
      uuid - The uuid of the parent object retrieved from the query param.
      Returns:
      the created REST object
      Throws:
      AuthorizeException
      SQLException
      RepositoryMethodNotImplementedException - 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 context
      list - 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:
      AuthorizeException
      SQLException
      RepositoryMethodNotImplementedException - returned by the default implementation when the operation is not supported for the entity
    • createAndReturn

      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:
      AuthorizeException
      SQLException
      RepositoryMethodNotImplementedException - 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 request
      apiCategory -
      model -
      id - the ID of the target REST object
      file - the uploaded file
      Returns:
      the new state of the REST object
      Throws:
      SQLException
      FileNotFoundException
      IOException
      AuthorizeException
    • 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 request
      apiCategory -
      model -
      id - the ID of the target REST object
      patch - the JSON Patch (https://tools.ietf.org/html/rfc6902) operation
      Returns:
      Throws:
      UnprocessableEntityException
      DSpaceBadRequestException
    • 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 request
      apiCategory -
      model -
      id - the ID of the target REST object
      patch - 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 entity
      SQLException
      AuthorizeException
    • action

      public T action(jakarta.servlet.http.HttpServletRequest request, ID id) throws SQLException, IOException
      Throws:
      SQLException
      IOException
    • action

      protected T action(Context context, jakarta.servlet.http.HttpServletRequest request, ID id) throws SQLException, IOException
      Throws:
      SQLException
      IOException
    • 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 request
      uploadfile - the file to process
      Returns:
      the created objects
      Throws:
      SQLException
      FileNotFoundException
      IOException
      AuthorizeException
    • 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 request
      uploadfile - the file to process
      Returns:
      the created objects
      Throws:
      SQLException
      FileNotFoundException
      IOException
      AuthorizeException
      RepositoryMethodNotImplementedException
    • 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 request
      apiCategory - the API category e.g. "api"
      model - the DSpace model e.g. "metadatafield"
      uuid - the ID of the target REST object
      jsonNode - 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 request
      apiCategory - the API category e.g. "api"
      model - the DSpace model e.g. "metadatafield"
      id - the ID of the target REST object
      stringList - 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 context
      apiCategory - the API category e.g. "api"
      model - the DSpace model e.g. "metadatafield"
      id - the ID of the target REST object
      jsonNode - 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 operation
      SQLException - when the database returns an error
      RepositoryMethodNotImplementedException - 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 context
      apiCategory - the API category e.g. "api"
      model - the DSpace model e.g. "metadatafield"
      id - the ID of the target REST object
      stringList - 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 operation
      SQLException - when the database returns an error
      RepositoryMethodNotImplementedException - returned by the default implementation when the operation is not supported for the entity