mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
stub: introduce PATCH try to manage as https://tools.ietf.org/html/rfc6902
This commit is contained in:
@@ -41,6 +41,8 @@ import org.springframework.data.domain.PageImpl;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
|
import org.springframework.data.rest.webmvc.json.patch.JsonPatchPatchConverter;
|
||||||
|
import org.springframework.data.rest.webmvc.json.patch.Patch;
|
||||||
import org.springframework.data.web.PagedResourcesAssembler;
|
import org.springframework.data.web.PagedResourcesAssembler;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.hateoas.PagedResources;
|
import org.springframework.hateoas.PagedResources;
|
||||||
@@ -52,6 +54,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the main entry point of the new REST API. Its responsibility is to
|
* This is the main entry point of the new REST API. Its responsibility is to
|
||||||
* provide a consistent behaviors for all the exposed resources in terms of
|
* provide a consistent behaviors for all the exposed resources in terms of
|
||||||
@@ -73,6 +77,9 @@ public class RestResourceController implements InitializingBean {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RestRepositoryUtils repositoryUtils;
|
RestRepositoryUtils repositoryUtils;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
JsonPatchPatchConverter patchConverter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
@@ -155,6 +162,29 @@ public class RestResourceController implements InitializingBean {
|
|||||||
return findRelEntryInternal(request, apiCategory, model, id, rel, relid, page, assembler, projection);
|
return findRelEntryInternal(request, apiCategory, model, id, rel, relid, page, assembler, projection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.PATCH, value = "/{id:\\d+}")
|
||||||
|
public ResourceSupport patch(HttpServletRequest request, @PathVariable String apiCategory,
|
||||||
|
@PathVariable String model, @PathVariable Integer id, @RequestParam(required = false) JsonNode jsonNode) {
|
||||||
|
Patch patch = patchConverter.convert(jsonNode);
|
||||||
|
return patchInternal(request, apiCategory, model, id, patch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <ID extends Serializable> ResourceSupport patchInternal(HttpServletRequest request, String apiCategory,
|
||||||
|
String model, ID id, Patch patch) {
|
||||||
|
checkModelPluralForm(apiCategory, model);
|
||||||
|
DSpaceRestRepository<RestModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
||||||
|
RestModel modelObject = null;
|
||||||
|
try {
|
||||||
|
modelObject = repository.patch(patch);
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
}
|
||||||
|
if (modelObject == null) {
|
||||||
|
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
|
||||||
|
}
|
||||||
|
DSpaceResource result = repository.wrapResource(modelObject);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private <ID extends Serializable> ResourceSupport findRelEntryInternal(HttpServletRequest request, String apiCategory, String model,
|
private <ID extends Serializable> ResourceSupport findRelEntryInternal(HttpServletRequest request, String apiCategory, String model,
|
||||||
String id, String rel, String relid, Pageable page, PagedResourcesAssembler assembler, String projection) {
|
String id, String rel, String relid, Pageable page, PagedResourcesAssembler assembler, String projection) {
|
||||||
checkModelPluralForm(apiCategory, model);
|
checkModelPluralForm(apiCategory, model);
|
||||||
|
@@ -22,6 +22,7 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
|
import org.springframework.data.rest.webmvc.json.patch.Patch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base class for any Rest Repository. It add a DSpaceContext to the
|
* This is the base class for any Rest Repository. It add a DSpaceContext to the
|
||||||
@@ -117,4 +118,9 @@ extends AbstractDSpaceRestRepository
|
|||||||
public abstract Class<T> getDomainClass();
|
public abstract Class<T> getDomainClass();
|
||||||
|
|
||||||
public abstract DSpaceResource<T> wrapResource(T model, String... rels);
|
public abstract DSpaceResource<T> wrapResource(T model, String... rels);
|
||||||
|
|
||||||
|
public RestModel patch(Patch patch) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user