Search in sources :

Example 1 with Patch

use of org.hisp.dhis.patch.Patch in project dhis2-core by dhis2.

the class AbstractCrudController method partialUpdateObject.

// --------------------------------------------------------------------------
// OLD PATCH
// --------------------------------------------------------------------------
@PatchMapping(value = "/{uid}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void partialUpdateObject(@PathVariable("uid") String pvUid, @RequestParam Map<String, String> rpParameters, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
    WebOptions options = new WebOptions(rpParameters);
    List<T> entities = getEntity(pvUid, options);
    if (entities.isEmpty()) {
        throw new WebMessageException(notFound(getEntityClass(), pvUid));
    }
    T persistedObject = entities.get(0);
    if (!aclService.canUpdate(currentUser, persistedObject)) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
    }
    Patch patch = diff(request);
    prePatchEntity(persistedObject);
    patchService.apply(patch, persistedObject);
    validateAndThrowErrors(() -> schemaValidator.validate(persistedObject));
    manager.update(persistedObject);
    postPatchEntity(persistedObject);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) BulkJsonPatch(org.hisp.dhis.jsonpatch.BulkJsonPatch) Patch(org.hisp.dhis.patch.Patch) JsonPatch(org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Aggregations

JsonPatch (org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)1 BulkJsonPatch (org.hisp.dhis.jsonpatch.BulkJsonPatch)1 Patch (org.hisp.dhis.patch.Patch)1 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1