use of de.metas.ui.web.window.model.DocumentSaveStatus 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 -> {
//
// Process changes and the save the document
document.processValueChanges(fieldChangeRequests, ReasonSupplier.NONE);
document.saveIfValidAndHasChanges();
//
// Important: before allowing the document to be stored back in documents collection,
// we need to make sure it's valid and saved.
final DocumentValidStatus validStatus = document.getValidStatus();
if (!validStatus.isValid()) {
throw new AdempiereException(validStatus.getReason());
}
final DocumentSaveStatus saveStatus = document.getSaveStatus();
if (saveStatus.isNotSaved()) {
throw new AdempiereException(saveStatus.getReason());
}
// nothing/not important
return null;
}));
invalidateRowById(rowId);
ViewChangesCollector.getCurrentOrAutoflush().collectRowChanged(this, rowId);
documentsCollection.invalidateRootDocument(documentPath);
}
use of de.metas.ui.web.window.model.DocumentSaveStatus 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;
}
use of de.metas.ui.web.window.model.DocumentSaveStatus in project metasfresh-webui-api by metasfresh.
the class ADProcessInstanceController method saveIfValidAndHasChanges.
/* package */
boolean saveIfValidAndHasChanges(final boolean throwEx) {
final Document parametersDocument = getParametersDocument();
final DocumentSaveStatus parametersSaveStatus = parametersDocument.saveIfValidAndHasChanges();
final boolean saved = parametersSaveStatus.isSaved();
if (!saved && throwEx) {
throw new ProcessExecutionException(parametersSaveStatus.getReason());
}
return saved;
}
use of de.metas.ui.web.window.model.DocumentSaveStatus in project metasfresh-webui-api by metasfresh.
the class JSONDocument method ofDocument.
public static final JSONDocument ofDocument(final Document document, final JSONOptions jsonOpts) {
final JSONDocument jsonDocument = new JSONDocument(document.getDocumentPath());
//
// Fields
{
final List<JSONDocumentField> jsonFields = new ArrayList<>();
// Add pseudo "ID" field first
jsonFields.add(0, JSONDocumentField.idField(document.getDocumentIdAsJson()));
// Append the other fields
document.getFieldViews().stream().filter(jsonOpts.documentFieldFilter()).map(field -> JSONDocumentField.ofDocumentField(field, jsonOpts.getAD_Language())).peek(// apply permissions
jsonField -> jsonOpts.getDocumentPermissions().apply(document, jsonField)).forEach(jsonFields::add);
jsonDocument.setFields(jsonFields);
}
//
// Valid Status
final DocumentValidStatus documentValidStatus = document.getValidStatus();
if (documentValidStatus != null) {
jsonDocument.setValidStatus(documentValidStatus);
}
//
// Save Status
final DocumentSaveStatus documentSaveStatus = document.getSaveStatus();
if (documentSaveStatus != null) {
jsonDocument.setSaveStatus(documentSaveStatus);
}
//
// Included tabs info
document.getIncludedDocumentsCollections().stream().map(JSONDocument::createIncludedTabInfo).peek(jsonIncludedTabInfo -> jsonOpts.getDocumentPermissions().apply(document, jsonIncludedTabInfo)).forEach(jsonDocument::addIncludedTabInfo);
//
// Available standard actions
jsonDocument.setStandardActions(document.getStandardActions());
// Set debugging info
if (WindowConstants.isProtocolDebugging()) {
jsonDocument.putDebugProperty("tablename", document.getEntityDescriptor().getTableNameOrNull());
jsonDocument.putDebugProperty(JSONOptions.DEBUG_ATTRNAME, jsonOpts.toString());
jsonDocument.putDebugProperty("fields-count", jsonDocument.getFieldsCount());
}
return jsonDocument;
}
Aggregations