Search in sources :

Example 11 with PatchMapping

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;
    });
}
Also used : IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 12 with PatchMapping

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());
    });
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 13 with PatchMapping

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);
}
Also used : Patient(io.undertree.symptom.domain.Patient) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 14 with PatchMapping

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;
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Post(com.erudika.scoold.core.Post) Model(org.springframework.ui.Model) ParaObject(com.erudika.para.core.ParaObject) List(java.util.List) Profile(com.erudika.scoold.core.Profile) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 15 with PatchMapping

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;
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) ParaObject(com.erudika.para.core.ParaObject) Profile(com.erudika.scoold.core.Profile) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Aggregations

PatchMapping (org.springframework.web.bind.annotation.PatchMapping)18 List (java.util.List)5 ParaObject (com.erudika.para.core.ParaObject)4 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)4 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)4 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)3 Collections.singletonList (java.util.Collections.singletonList)3 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)3 BulkJsonPatch (org.hisp.dhis.jsonpatch.BulkJsonPatch)3 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)3 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)3 Model (org.springframework.ui.Model)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Profile (com.erudika.scoold.core.Profile)2 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)2 JsonPatch (org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 BulkPatchParameters (org.hisp.dhis.jsonpatch.BulkPatchParameters)2