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, newJsonDocumentOpts());
}
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 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);
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 DefaultView method patchViewRow.
@Override
public void patchViewRow(final RowEditingContext ctx, final List<JSONDocumentChangedEvent> fieldChangeRequests) {
final DocumentId rowId = ctx.getRowId();
final DocumentCollection documentsCollection = ctx.getDocumentsCollection();
final DocumentPath documentPath = getById(rowId).getDocumentPath();
Services.get(ITrxManager.class).runInThreadInheritedTrx(() -> documentsCollection.forDocumentWritable(documentPath, NullDocumentChangesCollector.instance, document -> {
patchDocument(document, fieldChangeRequests);
return null;
}));
invalidateRowById(rowId);
ViewChangesCollector.getCurrentOrAutoflush().collectRowChanged(this, rowId);
documentsCollection.invalidateRootDocument(documentPath);
}
use of de.metas.ui.web.window.model.Document 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;
}));
}
Aggregations