Search in sources :

Example 6 with IDocumentChangesCollector

use of de.metas.ui.web.window.model.IDocumentChangesCollector in project metasfresh-webui-api by metasfresh.

the class WindowRestController method patchDocument0.

private List<JSONDocument> patchDocument0(final DocumentPath documentPath, final List<JSONDocumentChangedEvent> events, final JSONOptions jsonOpts) {
    final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull();
    documentCollection.forDocumentWritable(documentPath, changesCollector, document -> {
        document.processValueChanges(events, REASON_Value_DirectSetFromCommitAPI);
        changesCollector.setPrimaryChange(document.getDocumentPath());
        // void
        return null;
    });
    // Extract and send websocket events
    final List<JSONDocument> jsonDocumentEvents = JSONDocument.ofEvents(changesCollector, jsonOpts);
    websocketPublisher.convertAndPublish(jsonDocumentEvents);
    return jsonDocumentEvents;
}
Also used : IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument)

Example 7 with IDocumentChangesCollector

use of de.metas.ui.web.window.model.IDocumentChangesCollector in project metasfresh-webui-api by metasfresh.

the class ProcessRestController method processParametersChangeEvents.

@RequestMapping(value = "/{processId}/{pinstanceId}", method = RequestMethod.PATCH)
public List<JSONDocument> processParametersChangeEvents(// 
@PathVariable("processId") final String processIdStr, // 
@PathVariable("pinstanceId") final String pinstanceIdStr, // 
@RequestBody final List<JSONDocumentChangedEvent> events) {
    userSession.assertLoggedIn();
    Check.assumeNotEmpty(events, "events is not empty");
    final ProcessId processId = ProcessId.fromJson(processIdStr);
    final DocumentId pinstanceId = DocumentId.of(pinstanceIdStr);
    final IProcessInstancesRepository instancesRepository = getRepository(processId);
    return Execution.callInNewExecution("", () -> {
        // get our collector to fill with the changes that we will record
        final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull();
        instancesRepository.forProcessInstanceWritable(pinstanceId, changesCollector, processInstance -> {
            processInstance.processParameterValueChanges(events, REASON_Value_DirectSetFromCommitAPI);
            // void
            return null;
        });
        return JSONDocument.ofEvents(changesCollector, newJSONOptions());
    });
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with IDocumentChangesCollector

use of de.metas.ui.web.window.model.IDocumentChangesCollector in project metasfresh-webui-api by metasfresh.

the class ASIRestController method processChanges.

@PatchMapping("/{asiDocId}")
public List<JSONDocument> processChanges(// 
@PathVariable("asiDocId") final String asiDocIdStr, // 
@RequestBody final List<JSONDocumentChangedEvent> events) {
    userSession.assertLoggedIn();
    final DocumentId asiDocId = DocumentId.of(asiDocIdStr);
    return Execution.callInNewExecution("processChanges", () -> {
        final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull();
        asiRepo.processASIDocumentChanges(asiDocId, events, changesCollector);
        return JSONDocument.ofEvents(changesCollector, newJsonOpts());
    });
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 9 with IDocumentChangesCollector

use of de.metas.ui.web.window.model.IDocumentChangesCollector 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

IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)9 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)4 JSONDocument (de.metas.ui.web.window.datatypes.json.JSONDocument)4 Document (de.metas.ui.web.window.model.Document)3 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 WindowId (de.metas.ui.web.window.datatypes.WindowId)2 JSONOptions (de.metas.ui.web.window.datatypes.json.JSONOptions)2 List (java.util.List)2 Set (java.util.Set)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 IMsgBL (de.metas.i18n.IMsgBL)1 ETagResponseEntityBuilder (de.metas.ui.web.cache.ETagResponseEntityBuilder)1