use of org.springframework.web.bind.annotation.PatchMapping in project metasfresh-webui-api by metasfresh.
the class WindowQuickInputRestController method processChanges.
@PatchMapping("/{quickInputId}")
public List<JSONDocument> processChanges(//
@PathVariable("windowId") final String windowIdStr, //
@PathVariable("documentId") final String documentIdStr, //
@PathVariable("tabId") final String tabIdStr, //
@PathVariable("quickInputId") final String quickInputIdStr, @RequestBody final List<JSONDocumentChangedEvent> events) {
userSession.assertLoggedIn();
final QuickInputPath quickInputPath = QuickInputPath.of(windowIdStr, documentIdStr, tabIdStr, quickInputIdStr);
return Execution.callInNewExecution("quickInput-writable-" + quickInputPath, () -> {
final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull();
forQuickInputWritable(quickInputPath, changesCollector, quickInput -> {
quickInput.processValueChanges(events);
changesCollector.setPrimaryChange(quickInput.getDocumentPath());
// void
return null;
});
// Extract and send websocket events
final List<JSONDocument> jsonDocumentEvents = JSONDocument.ofEvents(changesCollector, newJSONOptions());
websocketPublisher.convertAndPublish(jsonDocumentEvents);
return jsonDocumentEvents;
});
}
use of org.springframework.web.bind.annotation.PatchMapping in project metasfresh-webui-api by metasfresh.
the class ViewRowAttributesRestController method processChanges.
@PatchMapping
public List<JSONDocument> processChanges(//
@PathVariable(PARAM_WindowId) final String windowIdStr, //
@PathVariable(PARAM_ViewId) final String viewIdStr, //
@PathVariable(PARAM_RowId) final String rowIdStr, //
@RequestBody final List<JSONDocumentChangedEvent> events) {
userSession.assertLoggedIn();
final ViewId viewId = ViewId.of(windowIdStr, viewIdStr);
final DocumentId rowId = DocumentId.of(rowIdStr);
return Execution.callInNewExecution("processChanges", () -> {
viewsRepo.getView(viewId).getById(rowId).getAttributes().processChanges(events);
return JSONDocument.ofEvents(Execution.getCurrentDocumentChangesCollectorOrNull(), newJSONOptions());
});
}
use of org.springframework.web.bind.annotation.PatchMapping in project spring-boot-jpa by ssherwood.
the class PatientController method updatePatientExcludingNulls.
/**
* Applies changes to an existing resource as described by the JSON Merge Patch RFC
* (https://tools.ietf.org/html/rfc7386).
* <p>
* Unlike PUT, the PATCH operation is intended apply delta changes as opposed to a complete
* resource replacement. Like PUT this operation verifies that a resource exists by first
* loading it and then copies the properties from the RequestBody Map (i.e. any property that is
* in the map -- null values can be set using this technique).
* <p>
* TODO needs more testing to verify that it complies with the RFC
*
* @param patientId the UUID of the Patient to patch
* @param patientMap a JSON map of properties to use as the merge patch source
* @return the Patient as modified by the merge patch
*/
@PatchMapping("/{id}")
public Patient updatePatientExcludingNulls(@PathVariable("id") final UUID patientId, @RequestBody final Map<String, Object> patientMap) {
Patient originalPatient = this.getPatient(patientId);
updateProperties(patientId, originalPatient, patientMap);
return this.patientRepository.save(originalPatient);
}
use of org.springframework.web.bind.annotation.PatchMapping in project scoold by Erudika.
the class ApiController method updatePost.
@PatchMapping("/posts/{id}")
public Post updatePost(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Map<String, Object> entity = readEntity(req);
if (entity.isEmpty()) {
badReq("Missing request body.");
}
String editorid = (String) entity.get("lasteditby");
if (!StringUtils.isBlank(editorid)) {
Profile authUser = pc.read(Profile.id(editorid));
if (authUser != null) {
req.setAttribute(AUTH_USER_ATTRIBUTE, authUser);
}
}
String space = (String) entity.get("space");
String title = (String) entity.get("title");
String body = (String) entity.get("body");
String location = (String) entity.get("location");
String latlng = (String) entity.get("latlng");
List<String> spaces = readSpaces(space);
space = spaces.iterator().hasNext() ? spaces.iterator().next() : null;
Model model = new ExtendedModelMap();
questionController.edit(id, title, body, String.join(",", (List<String>) entity.get("tags")), location, latlng, space, req, res, model);
Post post = (Post) model.getAttribute("post");
if (post == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
} else if (!utils.canEdit(post, utils.getAuthUser(req))) {
badReq("Update failed - user " + editorid + " is not allowed to update post.");
}
return post;
}
use of org.springframework.web.bind.annotation.PatchMapping in project scoold by Erudika.
the class ApiController method updateUser.
@PatchMapping("/users/{id}")
public Profile updateUser(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Map<String, Object> entity = readEntity(req);
if (entity.isEmpty()) {
badReq("Missing request body.");
}
String name = (String) entity.get("name");
String location = (String) entity.get("location");
String latlng = (String) entity.get("latlng");
String website = (String) entity.get("website");
String aboutme = (String) entity.get("aboutme");
String picture = (String) entity.get("picture");
Model model = new ExtendedModelMap();
profileController.edit(id, name, location, latlng, website, aboutme, picture, req, model);
Profile profile = (Profile) model.getAttribute("user");
if (profile == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
if (entity.containsKey("spaces")) {
profile.setSpaces(new HashSet<>(readSpaces(((List<String>) entity.getOrDefault("spaces", Collections.emptyList())).toArray(new String[0]))));
pc.update(profile);
}
return profile;
}
Aggregations