Search in sources :

Example 6 with JSONDocument

use of de.metas.ui.web.window.datatypes.json.JSONDocument 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)

Aggregations

JSONDocument (de.metas.ui.web.window.datatypes.json.JSONDocument)6 Document (de.metas.ui.web.window.model.Document)4 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)1 JSONOptions (de.metas.ui.web.window.datatypes.json.JSONOptions)1 InvalidDocumentPathException (de.metas.ui.web.window.exceptions.InvalidDocumentPathException)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1