use of org.springframework.web.bind.annotation.PatchMapping in project dhis2-core by dhis2.
the class AbstractCrudController method bulkSharing.
@ResponseBody
@PatchMapping(path = "/sharing", consumes = "application/json-patch+json", produces = APPLICATION_JSON_VALUE)
public WebMessage bulkSharing(@RequestParam(required = false, defaultValue = "false") boolean atomic, HttpServletRequest request) throws Exception {
final BulkJsonPatch bulkJsonPatch = jsonMapper.readValue(request.getInputStream(), BulkJsonPatch.class);
BulkPatchParameters patchParams = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = bulkPatchManager.applyPatch(bulkJsonPatch, patchParams);
if (patchedObjects.isEmpty() || (atomic && patchParams.hasErrorReports())) {
ImportReport importReport = new ImportReport();
importReport.addTypeReports(patchParams.getTypeReports());
importReport.setStatus(Status.ERROR);
return importReport(importReport);
}
Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
params.setUser(currentUserService.getCurrentUser()).setImportStrategy(ImportStrategy.UPDATE).addObjects(patchedObjects);
ImportReport importReport = importService.importMetadata(params);
if (patchParams.hasErrorReports()) {
importReport.addTypeReports(patchParams.getTypeReports());
importReport.setStatus(importReport.getStatus() == Status.OK ? Status.WARNING : importReport.getStatus());
}
return importReport(importReport);
}
use of org.springframework.web.bind.annotation.PatchMapping in project dhis2-core by dhis2.
the class AbstractCrudController method patchObject.
// --------------------------------------------------------------------------
// PATCH
// --------------------------------------------------------------------------
/**
* Adds support for HTTP Patch using JSON Patch (RFC 6902), updated object
* is run through normal metadata importer and internally looks like a
* normal PUT (after the JSON Patch has been applied).
*
* For now we only support the official mimetype
* "application/json-patch+json" but in future releases we might also want
* to support "application/json" after the old patch behavior has been
* removed.
*/
@ResponseBody
@PatchMapping(path = "/{uid}", consumes = "application/json-patch+json")
public WebMessage patchObject(@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()) {
return notFound(getEntityClass(), pvUid);
}
final T persistedObject = entities.get(0);
if (!aclService.canUpdate(currentUser, persistedObject)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
manager.resetNonOwnerProperties(persistedObject);
prePatchEntity(persistedObject);
final JsonPatch patch = jsonMapper.readValue(request.getInputStream(), JsonPatch.class);
final T patchedObject = jsonPatchManager.apply(patch, persistedObject);
// we don't allow changing IDs
((BaseIdentifiableObject) patchedObject).setId(persistedObject.getId());
// we don't allow changing UIDs
((BaseIdentifiableObject) patchedObject).setUid(persistedObject.getUid());
// Only supports new Sharing format
((BaseIdentifiableObject) patchedObject).clearLegacySharingCollections();
prePatchEntity(persistedObject, patchedObject);
Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
if (!parameterValuesMap.containsKey("importReportMode")) {
parameterValuesMap.put("importReportMode", Collections.singletonList("ERRORS_NOT_OWNER"));
}
MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
params.setUser(currentUser).setImportStrategy(ImportStrategy.UPDATE).addObject(patchedObject);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postPatchEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
return webMessage;
}
use of org.springframework.web.bind.annotation.PatchMapping in project scoold by Erudika.
the class ApiController method updateTag.
@PatchMapping("/tags/{id}")
public Tag updateTag(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Map<String, Object> entity = readEntity(req);
if (entity.isEmpty()) {
badReq("Missing request body.");
}
Model model = new ExtendedModelMap();
tagsController.rename(id, (String) entity.get("tag"), req, res, model);
if (!model.containsAttribute("tag")) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
return (Tag) model.getAttribute("tag");
}
use of org.springframework.web.bind.annotation.PatchMapping in project scoold by Erudika.
the class ApiController method updateWebhook.
@PatchMapping("/webhooks/{id}")
public Webhook updateWebhook(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
if (!utils.isWebhooksEnabled()) {
res.setStatus(HttpStatus.FORBIDDEN.value());
return null;
}
Webhook webhook = pc.read(id);
if (webhook == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
Map<String, Object> entity = readEntity(req);
return pc.update(ParaObjectUtils.setAnnotatedFields(webhook, entity, Locked.class));
}
use of org.springframework.web.bind.annotation.PatchMapping in project open-kilda by telstra.
the class LinkController method updateLinkEnableBfd.
/**
* Update "enable bfd" flag in the link.
*
* @return updated link.
*/
@ApiOperation(value = "Update \"enable bfd\" flag for the link.", response = LinkDto.class, responseContainer = "List")
@PatchMapping(path = "/links/enable-bfd", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseStatus(HttpStatus.OK)
public CompletableFuture<List<LinkDto>> updateLinkEnableBfd(@RequestBody LinkEnableBfdDto link) {
NetworkEndpoint source = makeSourceEndpoint(new SwitchId(link.getSrcSwitch()), link.getSrcPort());
NetworkEndpoint destination = makeDestinationEndpoint(new SwitchId(link.getDstSwitch()), link.getDstPort());
return linkService.writeBfdProperties(source, destination, link.isEnableBfd());
}
Aggregations