use of de.metas.ui.web.window.model.IDocumentChangesCollector 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());
});
});
}
use of de.metas.ui.web.window.model.IDocumentChangesCollector in project metasfresh-webui-api by metasfresh.
the class AddressRestController method processChanges.
@RequestMapping(value = "/{docId}", method = RequestMethod.PATCH)
public List<JSONDocument> processChanges(//
@PathVariable("docId") final int docId, //
@RequestBody final List<JSONDocumentChangedEvent> events) {
userSession.assertLoggedIn();
return Execution.callInNewExecution("processChanges", () -> {
final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull();
addressRepo.processAddressDocumentChanges(docId, events, changesCollector);
return JSONDocument.ofEvents(changesCollector, newJsonOpts());
});
}
use of de.metas.ui.web.window.model.IDocumentChangesCollector in project metasfresh-webui-api by metasfresh.
the class JSONDocument method ofEvents.
public static List<JSONDocument> ofEvents(final IDocumentChangesCollector documentChangesCollector, final JSONOptions jsonOpts) {
final int MAX_SIZE = 100;
final List<JSONDocument> jsonChanges = documentChangesCollector.streamOrderedDocumentChanges().map(documentChanges -> ofEventOrNull(documentChanges, jsonOpts)).filter(jsonDocument -> jsonDocument != null).limit(MAX_SIZE + 1).collect(ImmutableList.toImmutableList());
// Prevent sending more then MAX_SIZE events because that will freeze the frontend application.
if (jsonChanges.size() > MAX_SIZE) {
throw new AdempiereException("Events count exceeded").setParameter("maxSize", MAX_SIZE).setParameter("documentChangesCollector", documentChangesCollector).setParameter("first events", jsonChanges);
}
return jsonChanges;
}
use of de.metas.ui.web.window.model.IDocumentChangesCollector in project metasfresh-webui-api by metasfresh.
the class WindowRestController method processRecord.
/**
* @task https://github.com/metasfresh/metasfresh/issues/1090
*/
@GetMapping("/{windowId}/{documentId}/processNewRecord")
public int processRecord(//
@PathVariable("windowId") final String windowIdStr, //
@PathVariable("documentId") final String documentIdStr) {
userSession.assertLoggedIn();
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentIdStr);
final IDocumentChangesCollector changesCollector = NullDocumentChangesCollector.instance;
return Execution.callInNewExecution("window.processTemplate", () -> documentCollection.forDocumentWritable(documentPath, changesCollector, document -> {
document.saveIfValidAndHasChanges();
if (document.hasChangesRecursivelly()) {
throw new AdempiereException("Not saved");
}
final int newRecordId = newRecordDescriptorsProvider.getNewRecordDescriptor(document.getEntityDescriptor()).getProcessor().processNewRecordDocument(document);
return newRecordId;
}));
}
use of de.metas.ui.web.window.model.IDocumentChangesCollector in project metasfresh-webui-api by metasfresh.
the class WindowRestController method deleteDocuments.
private List<JSONDocument> deleteDocuments(final List<DocumentPath> documentPaths) {
userSession.assertLoggedIn();
final JSONOptions jsonOpts = newJSONOptions().setShowAdvancedFields(false).build();
return Execution.callInNewExecution("window.delete", () -> {
final IDocumentChangesCollector changesCollector = Execution.getCurrentDocumentChangesCollectorOrNull();
documentCollection.deleteAll(documentPaths, changesCollector);
return JSONDocument.ofEvents(changesCollector, jsonOpts);
});
}
Aggregations