use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.
the class Document method updateFieldDisplayed.
private final void updateFieldDisplayed(final IDocumentField documentField) {
// default false, i.e. not displayed
LogicExpressionResult displayed = LogicExpressionResult.FALSE;
final ILogicExpression displayLogic = documentField.getDescriptor().getDisplayLogic();
try {
displayed = displayLogic.evaluateToResult(asEvaluatee(), OnVariableNotFound.Fail);
} catch (final Exception e) {
logger.warn("Failed evaluating display logic {} for {}. Preserving {}", displayLogic, documentField, documentField.getDisplayed(), e);
displayed = LogicExpressionResult.FALSE;
}
documentField.setDisplayed(displayed);
}
use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.
the class Document method computeFieldReadOnly.
private final LogicExpressionResult computeFieldReadOnly(final IDocumentField documentField) {
// Check document's readonly logic
final DocumentReadonly documentReadonlyLogic = getReadonly();
if (documentReadonlyLogic.computeFieldReadonly(documentField.getFieldName(), documentField.isAlwaysUpdateable())) {
return LogicExpressionResult.TRUE;
}
// Check field's readonly logic
final ILogicExpression fieldReadonlyLogic = documentField.getDescriptor().getReadonlyLogic();
try {
final LogicExpressionResult readonly = fieldReadonlyLogic.evaluateToResult(asEvaluatee(), OnVariableNotFound.Fail);
return readonly;
} catch (final Exception e) {
logger.warn("Failed evaluating readonly logic {} for {}. Preserving {}", fieldReadonlyLogic, documentField, documentField.getReadonly(), e);
return null;
}
}
use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.
the class Document method updateOnDependencyChanged.
/**
* Updates document or fields characteristics (e.g. readonly, mandatory, displayed, lookupValuesStaled etc).
*
* @param propertyName
* @param documentField
* @param triggeringFieldName optional field name which triggered this update
* @param triggeringDependencyType
* @param documentChangesCollector events collector (where to collect the change events)
* @param collectEventsEventIfNoChange true if we shall collect the change event even if there was no change
*/
private void updateOnDependencyChanged(final String propertyName, final IDocumentField documentField, final String triggeringFieldName, final DependencyType triggeringDependencyType) {
final ReasonSupplier reason = () -> "TriggeringField=" + triggeringFieldName + ", DependencyType=" + triggeringDependencyType;
if (DependencyType.DocumentReadonlyLogic == triggeringDependencyType) {
if (DocumentFieldDependencyMap.DOCUMENT_Readonly.equals(propertyName)) {
updateReadonlyAndPropagate(reason);
}
} else if (DependencyType.ReadonlyLogic == triggeringDependencyType) {
updateFieldReadOnlyAndCollect(documentField, reason);
} else if (DependencyType.MandatoryLogic == triggeringDependencyType) {
final LogicExpressionResult valueOld = documentField.getMandatory();
final ILogicExpression mandatoryLogic = documentField.getDescriptor().getMandatoryLogic();
try {
final LogicExpressionResult mandatory = mandatoryLogic.evaluateToResult(asEvaluatee(), OnVariableNotFound.Fail);
documentField.setMandatory(mandatory, changesCollector);
} catch (final Exception e) {
logger.warn("Failed evaluating mandatory logic {} for {}. Preserving {}", mandatoryLogic, documentField, documentField.getMandatory(), e);
}
changesCollector.collectMandatoryIfChanged(documentField, valueOld, reason);
} else if (DependencyType.DisplayLogic == triggeringDependencyType) {
final LogicExpressionResult valueOld = documentField.getDisplayed();
updateFieldDisplayed(documentField);
changesCollector.collectDisplayedIfChanged(documentField, valueOld, reason);
} else if (DependencyType.LookupValues == triggeringDependencyType) {
final boolean lookupValuesStaledOld = documentField.isLookupValuesStale();
final boolean lookupValuesStaled = documentField.setLookupValuesStaled(triggeringFieldName);
if (lookupValuesStaled && !lookupValuesStaledOld) {
// https://github.com/metasfresh/metasfresh-webui-api/issues/551 check if we can leave the old value as it is
final Object valueOld = documentField.getValue();
if (valueOld != null) {
final boolean currentValueStillValid = // because we did setLookupValuesStaled(), this causes a reload
documentField.getLookupValues().stream().anyMatch(// check if the current value is still value after we reloaded the list
value -> Objects.equals(value, valueOld));
if (!currentValueStillValid) {
documentField.setValue(null, changesCollector);
changesCollector.collectValueIfChanged(documentField, valueOld, reason);
}
}
// https://github.com/metasfresh/metasfresh-webui-frontend/issues/1165 - the value was not stale, but now it is => notify the frontend so it shall invalidate its cache
changesCollector.collectLookupValuesStaled(documentField, reason);
}
} else if (DependencyType.FieldValue == triggeringDependencyType) {
final IDocumentFieldValueProvider valueProvider = documentField.getDescriptor().getVirtualFieldValueProvider().orElse(null);
if (valueProvider != null) {
try {
final Object valueOld = documentField.getValue();
final Object valueNew = valueProvider.calculateValue(this);
documentField.setInitialValue(valueNew, changesCollector);
documentField.setValue(valueNew, changesCollector);
changesCollector.collectValueIfChanged(documentField, valueOld, reason);
} catch (final Exception ex) {
logger.warn("Failed updating virtual field {} for {}", documentField, this, ex);
}
}
} else {
new AdempiereException("Unknown dependency type: " + triggeringDependencyType).throwIfDeveloperModeOrLogWarningElse(logger);
}
}
use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.
the class Document method updateFieldReadOnlyAndCollect.
private final void updateFieldReadOnlyAndCollect(final IDocumentField documentField, final ReasonSupplier reason) {
final LogicExpressionResult readonlyOld = documentField.getReadonly();
final LogicExpressionResult readonlyNew = computeFieldReadOnly(documentField);
if (readonlyNew != null) {
documentField.setReadonly(readonlyNew);
changesCollector.collectReadonlyIfChanged(documentField, readonlyOld, reason);
}
}
use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.
the class IncludedDocumentsCollectionActions method updateAndGetAllowDeleteDocument.
public LogicExpressionResult updateAndGetAllowDeleteDocument(final IncludedDocumentsCollectionActionsContext context) {
final LogicExpressionResult allowDeleteOld = allowDelete;
final LogicExpressionResult allowDelete = computeAllowDeleteDocument(context);
this.allowDelete = allowDelete;
if (!allowDeleteOld.equalsByNameAndValue(allowDelete)) {
context.collectAllowDelete(parentDocumentPath, detailId, allowDelete);
}
return allowDelete;
}
Aggregations