use of de.metas.ui.web.window.model.Document 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.Document in project metasfresh-webui-api by metasfresh.
the class AddressRepository method createNewFrom.
public Document createNewFrom(final int fromC_Location_ID) {
final DocumentEntityDescriptor entityDescriptor = descriptorsFactory.getAddressDescriptor().getEntityDescriptor();
final Document addressDoc = Document.builder(entityDescriptor).initializeAsNewDocument(nextAddressDocId::getAndIncrement, VERSION_DEFAULT).build();
final I_C_Location fromLocation = fromC_Location_ID <= 0 ? null : InterfaceWrapperHelper.create(Env.getCtx(), fromC_Location_ID, I_C_Location.class, ITrx.TRXNAME_ThreadInherited);
if (fromLocation != null) {
addressDoc.getFieldViews().stream().forEach(field -> {
final Object value = field.getDescriptor().getDataBindingNotNull(AddressFieldBinding.class).readValue(fromLocation);
addressDoc.processValueChange(field.getFieldName(), value, () -> "update from " + fromLocation);
});
}
addressDoc.checkAndGetValidStatus();
logger.trace("Created from C_Location_ID={}: {}", fromC_Location_ID, addressDoc);
putAddressDocument(addressDoc);
return addressDoc;
}
use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.
the class AddressRepository method putAddressDocument.
private final void putAddressDocument(final Document addressDoc) {
final Document addressDocReadonly = addressDoc.copy(CopyMode.CheckInReadonly, NullDocumentChangesCollector.instance);
id2addressDoc.put(addressDoc.getDocumentId(), addressDocReadonly);
logger.trace("Added to repository: {}", addressDocReadonly);
}
use of de.metas.ui.web.window.model.Document 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());
}
use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.
the class JSONDocument method ofEventOrNull.
private static JSONDocument ofEventOrNull(final DocumentChanges documentChangedEvents, final JSONOptions jsonOpts) {
if (documentChangedEvents.isEmpty()) {
return null;
}
final DocumentPath documentPath = documentChangedEvents.getDocumentPath();
final JSONDocument jsonDocument = new JSONDocument(documentPath);
// If the document was deleted, we just need to export that flag. All the other changes are not relevant.
if (documentChangedEvents.isDeleted()) {
jsonDocument.setDeleted();
return jsonDocument;
}
//
// Fields
{
final List<JSONDocumentField> jsonFields = new ArrayList<>();
documentChangedEvents.getFieldChangesList().stream().filter(jsonOpts.documentFieldChangeFilter()).forEach((field) -> {
// Add the pseudo-field "ID" first
if (field.isKey()) {
jsonFields.add(0, JSONDocumentField.idField(field.getValueAsJsonObject()));
}
// Append the other fields
final JSONDocumentField jsonField = JSONDocumentField.ofDocumentFieldChangedEvent(field, jsonOpts);
// apply permissions
jsonOpts.getDocumentPermissions().apply(documentPath, jsonField);
jsonFields.add(jsonField);
});
jsonDocument.setFields(jsonFields);
}
//
// Valid status
final DocumentValidStatus documentValidStatus = documentChangedEvents.getDocumentValidStatus();
if (documentValidStatus != null) {
jsonDocument.setValidStatus(documentValidStatus);
}
//
// Save status
final DocumentSaveStatus documentSaveStatus = documentChangedEvents.getDocumentSaveStatus();
if (documentSaveStatus != null) {
jsonDocument.setSaveStatus(documentSaveStatus);
}
//
// Included tabs info
documentChangedEvents.getIncludedDetailInfos().stream().map(JSONDocument::createIncludedTabInfo).peek(jsonIncludedTabInfo -> jsonOpts.getDocumentPermissions().apply(documentPath, jsonIncludedTabInfo)).forEach(jsonDocument::addIncludedTabInfo);
return jsonDocument;
}
Aggregations