use of de.metas.ui.web.window.model.DocumentValidStatus 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.DocumentValidStatus in project metasfresh-webui-api by metasfresh.
the class ViewActionInstance method startProcess.
@Override
public ProcessInstanceResult startProcess(@NonNull final ProcessExecutionContext context) {
assertNotExecuted();
// Validate parameters, if any
if (parametersDocument != null) {
final DocumentValidStatus validStatus = parametersDocument.checkAndGetValidStatus();
if (!validStatus.isValid()) {
throw new AdempiereException(validStatus.getReason());
}
}
//
// Execute view action's method
final IView view = getView();
final Method viewActionMethod = viewActionDescriptor.getViewActionMethod();
final Object[] viewActionParams = viewActionDescriptor.extractMethodArguments(view, parametersDocument, selectedDocumentIds);
try {
final Object targetObject = Modifier.isStatic(viewActionMethod.getModifiers()) ? null : view;
final Object resultActionObj = viewActionMethod.invoke(targetObject, viewActionParams);
final ResultAction resultAction = viewActionDescriptor.convertReturnType(resultActionObj);
final ResultAction resultActionProcessed = processResultAction(resultAction, context.getViewsRepo());
final ProcessInstanceResult result = ProcessInstanceResult.builder(pinstanceId).action(resultActionProcessed).build();
this.result = result;
return result;
} catch (final Throwable ex) {
throw AdempiereException.wrapIfNeeded(ex);
}
}
use of de.metas.ui.web.window.model.DocumentValidStatus 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.DocumentValidStatus in project metasfresh-webui-api by metasfresh.
the class JSONDocumentField method ofDocumentFieldChangedEvent.
public static JSONDocumentField ofDocumentFieldChangedEvent(final DocumentFieldChange event, final JSONOptions jsonOpts) {
final JSONLayoutWidgetType widgetType = JSONLayoutWidgetType.fromNullable(event.getWidgetType());
final JSONDocumentField jsonField = new JSONDocumentField(event.getFieldName(), widgetType);
if (event.isValueSet()) {
jsonField.setValue(event.getValueAsJsonObject(), ReasonSupplier.toDebugString(event.getValueReason()));
}
final LogicExpressionResult readonly = event.getReadonly();
if (readonly != null) {
jsonField.setReadonly(readonly.booleanValue(), ReasonSupplier.toDebugString(event.getReadonlyReason()));
}
final LogicExpressionResult mandatory = event.getMandatory();
if (mandatory != null) {
jsonField.setMandatory(mandatory.booleanValue(), ReasonSupplier.toDebugString(event.getMandatoryReason()));
}
final LogicExpressionResult displayed = event.getDisplayed();
if (displayed != null) {
jsonField.setDisplayed(displayed.booleanValue(), ReasonSupplier.toDebugString(event.getDisplayedReason()));
}
final Boolean lookupValuesStale = event.getLookupValuesStale();
if (lookupValuesStale != null) {
jsonField.setLookupValuesStale(lookupValuesStale, ReasonSupplier.toDebugString(event.getLookupValuesStaleReason()));
}
final DocumentValidStatus validStatus = event.getValidStatus();
if (validStatus != null) {
jsonField.setValidStatus(validStatus);
}
jsonField.setFieldWarning(JSONDocumentFieldWarning.ofNullable(event.getFieldWarning(), jsonOpts.getAD_Language()));
jsonField.putDebugProperties(event.getDebugProperties());
return jsonField;
}
use of de.metas.ui.web.window.model.DocumentValidStatus 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