Class DSpaceRestRepository<T extends RestAddressableModel,​ID extends Serializable>

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T action​(javax.servlet.http.HttpServletRequest request, ID id)  
      protected T action​(org.dspace.core.Context context, javax.servlet.http.HttpServletRequest request, ID id)  
      long count()  
      T createAndReturn()
      Create and return a new instance.
      T createAndReturn​(List<String> list)
      Create and return a new instance.
      T createAndReturn​(UUID uuid)
      Create and return a new instance after adding to the parent.
      protected T createAndReturn​(org.dspace.core.Context context)
      Method to implement to support the creation of a new instance.
      protected T createAndReturn​(org.dspace.core.Context context, List<String> list)
      Method to implement to support the creation of a new instance.
      protected T createAndReturn​(org.dspace.core.Context context, UUID uuid)
      Method to implement to support the creation of a new instance.
      protected void delete​(org.dspace.core.Context context, ID id)
      Method to implement to support delete of a single object instance
      void delete​(T entity)  
      void deleteAll()  
      void deleteAll​(Iterable<? extends T> entities)  
      void deleteById​(ID id)  
      boolean existsById​(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 endpoint
      org.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 T findOne​(org.dspace.core.Context context, ID id)
      Method to implement to support retrieval of a specific REST object instance
      abstract Class<T> getDomainClass()
      The REST model supported by the repository
      T patch​(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, Patch patch)
      Apply a partial update to the REST object via JSON Patch
      protected void patch​(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 Patch
      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
      T put​(javax.servlet.http.HttpServletRequest request, String apiCategory, String model, ID id, List<String> stringList)
      Method to support updating a DSpace instance.
      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)
      Implement this method in the subclass to support updating a REST object.
      protected T put​(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>
      S
      save​(org.dspace.core.Context context, S entity)
      Method to implement to support full update of a REST object.
      <S extends T>
      S
      save​(S entity)  
      <S extends T>
      Iterable<S>
      saveAll​(Iterable<S> entities)  
      T upload​(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 object
      Iterable<T> upload​(javax.servlet.http.HttpServletRequest request, List<org.springframework.web.multipart.MultipartFile> uploadfile)
      Bulk create object instances from an uploaded file
      protected 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
    • Constructor Detail

      • DSpaceRestRepository

        public DSpaceRestRepository()
    • Method Detail

      • 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​(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 context
        entity - the REST object to update
        Returns:
        the new state of the REST object after persistence
        Throws:
        org.dspace.authorize.AuthorizeException
        RepositoryMethodNotImplementedException - returned by the default implementation when the operation is not supported for the entity
      • 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 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>
      • 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​(org.dspace.core.Context context,
                              ID id)
                       throws org.dspace.authorize.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:
        org.dspace.authorize.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>
      • 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​(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 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​(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 context
        uuid - The uuid of the parent object retrieved from the query param.
        Returns:
        the created REST object
        Throws:
        org.dspace.authorize.AuthorizeException
        SQLException
        RepositoryMethodNotImplementedException - 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 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:
        org.dspace.authorize.AuthorizeException
        SQLException
        RepositoryMethodNotImplementedException - 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.AuthorizeException
        SQLException
        RepositoryMethodNotImplementedException - 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 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
        org.dspace.authorize.AuthorizeException
      • 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.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
        org.dspace.authorize.AuthorizeException
      • 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 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​(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 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​(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 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:
        org.dspace.authorize.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​(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 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:
        org.dspace.authorize.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