Search in sources :

Example 1 with JSONDocument

use of de.metas.ui.web.window.datatypes.json.JSONDocument in project metasfresh-webui-api by metasfresh.

the class WindowQuickInputRestController method complete.

@PostMapping("{quickInputId}/complete")
public JSONDocument complete(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr, // 
@PathVariable("tabId") final String tabIdStr, // 
@PathVariable("quickInputId") final String quickInputIdStr) {
    userSession.assertLoggedIn();
    final QuickInputPath quickInputPath = QuickInputPath.of(windowIdStr, documentIdStr, tabIdStr, quickInputIdStr);
    final IDocumentChangesCollector changesCollector = NullDocumentChangesCollector.instance;
    return Execution.callInNewExecution("quickInput-writable-" + quickInputPath, () -> {
        return forQuickInputWritable(quickInputPath, changesCollector, quickInput -> {
            final Document document = quickInput.complete();
            return JSONDocument.ofDocument(document, newJSONOptions());
        });
    });
}
Also used : IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) Document(de.metas.ui.web.window.model.Document) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with JSONDocument

use of de.metas.ui.web.window.datatypes.json.JSONDocument in project metasfresh-webui-api by metasfresh.

the class AddressRestController method getAddressDocument.

@RequestMapping(value = "/{docId}", method = RequestMethod.GET)
public JSONDocument getAddressDocument(@PathVariable("docId") final int docId) {
    userSession.assertLoggedIn();
    final Document addressDoc = addressRepo.getAddressDocumentForReading(docId);
    return JSONDocument.ofDocument(addressDoc, newJsonOpts());
}
Also used : JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) Document(de.metas.ui.web.window.model.Document) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with JSONDocument

use of de.metas.ui.web.window.datatypes.json.JSONDocument in project metasfresh-webui-api by metasfresh.

the class WindowRestController method duplicate.

@PostMapping("/{windowId}/{documentId}/duplicate")
public JSONDocument duplicate(@PathVariable("windowId") final String windowIdStr, @PathVariable("documentId") final String documentIdStr, @RequestParam(name = PARAM_Advanced, required = false, defaultValue = PARAM_Advanced_DefaultValue) final boolean advanced) {
    userSession.assertLoggedIn();
    final DocumentPath fromDocumentPath = DocumentPath.rootDocumentPath(WindowId.fromJson(windowIdStr), DocumentId.of(documentIdStr));
    final Document documentCopy = documentCollection.duplicateDocument(fromDocumentPath);
    return JSONDocument.ofDocument(documentCopy, newJSONOptions().setShowAdvancedFields(advanced).build());
}
Also used : DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) Document(de.metas.ui.web.window.model.Document) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with JSONDocument

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

use of de.metas.ui.web.window.datatypes.json.JSONDocument in project metasfresh-webui-api by metasfresh.

the class WindowRestController method getData.

private List<JSONDocument> getData(final DocumentPath documentPath, final String fieldsListStr, final boolean advanced, final List<DocumentQueryOrderBy> orderBys) {
    userSession.assertLoggedIn();
    final JSONOptions jsonOpts = newJSONOptions().setShowAdvancedFields(advanced).setDataFieldsList(fieldsListStr).build();
    return documentCollection.forRootDocumentReadonly(documentPath, rootDocument -> {
        List<Document> documents;
        if (documentPath.isRootDocument()) {
            documents = ImmutableList.of(rootDocument);
        } else if (documentPath.isAnyIncludedDocument()) {
            documents = rootDocument.getIncludedDocuments(documentPath.getDetailId(), orderBys).toList();
        } else if (documentPath.isSingleIncludedDocument()) {
            documents = ImmutableList.of(rootDocument.getIncludedDocument(documentPath.getDetailId(), documentPath.getSingleRowId()));
        } else {
            throw new InvalidDocumentPathException(documentPath);
        }
        return JSONDocument.ofDocumentsList(documents, jsonOpts);
    });
}
Also used : JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) Document(de.metas.ui.web.window.model.Document) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException)

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