use of org.adempiere.ad.expression.api.ILogicExpression 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.ILogicExpression 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.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class ADProcessDescriptorsFactory method createProcessParaDescriptor.
private DocumentFieldDescriptor.Builder createProcessParaDescriptor(final WebuiProcessClassInfo webuiProcesClassInfo, final I_AD_Process_Para adProcessParam) {
final IModelTranslationMap adProcessParaTrlsMap = InterfaceWrapperHelper.getModelTranslationMap(adProcessParam);
final String parameterName = adProcessParam.getColumnName();
//
// Ask the provider if it has some custom lookup descriptor
LookupDescriptorProvider lookupDescriptorProvider = webuiProcesClassInfo.getLookupDescriptorProviderOrNull(parameterName);
// Fallback: create an SQL lookup descriptor based on adProcessParam
if (lookupDescriptorProvider == null) {
lookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(null).setCtxColumnName(parameterName).setDisplayType(adProcessParam.getAD_Reference_ID()).setAD_Reference_Value_ID(adProcessParam.getAD_Reference_Value_ID()).setAD_Val_Rule_ID(adProcessParam.getAD_Val_Rule_ID()).setReadOnlyAccess().buildProvider();
}
//
final LookupDescriptor lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupDescriptorProvider.LookupScope.DocumentField);
final DocumentFieldWidgetType widgetType = extractWidgetType(parameterName, adProcessParam.getAD_Reference_ID(), lookupDescriptor, adProcessParam.isRange());
final Class<?> valueClass = DescriptorsFactoryHelper.getValueClass(widgetType, lookupDescriptor);
// process parameters shall always allow displaying the password
final boolean allowShowPassword = widgetType == DocumentFieldWidgetType.Password ? true : false;
final ILogicExpression readonlyLogic = expressionFactory.compileOrDefault(adProcessParam.getReadOnlyLogic(), ConstantLogicExpression.FALSE, ILogicExpression.class);
final ILogicExpression displayLogic = expressionFactory.compileOrDefault(adProcessParam.getDisplayLogic(), ConstantLogicExpression.TRUE, ILogicExpression.class);
final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(adProcessParam.isMandatory());
final Optional<IExpression<?>> defaultValueExpr = defaultValueExpressions.extractDefaultValueExpression(adProcessParam.getDefaultValue(), parameterName, widgetType, valueClass, mandatoryLogic.isConstantTrue(), // don't allow using auto sequence
false);
final DocumentFieldDescriptor.Builder paramDescriptor = DocumentFieldDescriptor.builder(parameterName).setCaption(adProcessParaTrlsMap.getColumnTrl(I_AD_Process_Para.COLUMNNAME_Name, adProcessParam.getName())).setDescription(adProcessParaTrlsMap.getColumnTrl(I_AD_Process_Para.COLUMNNAME_Description, adProcessParam.getDescription())).setValueClass(valueClass).setWidgetType(widgetType).setAllowShowPassword(allowShowPassword).setLookupDescriptorProvider(lookupDescriptorProvider).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField);
// Add a callout to forward process parameter value (UI) to current process instance
if (webuiProcesClassInfo.isForwardValueToJavaProcessInstance(parameterName)) {
paramDescriptor.addCallout(ProcessParametersCallout::forwardValueToCurrentProcessInstance);
}
return paramDescriptor;
}
use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method assertNewDocumentAllowed.
private void assertNewDocumentAllowed(final DocumentEntityDescriptor entityDescriptor) {
final ILogicExpression allowExpr = entityDescriptor.getAllowCreateNewLogic();
final LogicExpressionResult allow = allowExpr.evaluateToResult(userSession.toEvaluatee(), OnVariableNotFound.ReturnNoResult);
if (allow.isFalse()) {
throw new AdempiereException("Create not allowed");
}
}
use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class LayoutFactory method layoutDetail.
/**
* @return included entity grid layout
*/
public DocumentLayoutDetailDescriptor.Builder layoutDetail() {
final DocumentEntityDescriptor.Builder entityDescriptor = documentEntity();
logger.trace("Generating layout detail for {}", entityDescriptor);
// If the detail is never displayed then don't add it to layout
final ILogicExpression tabDisplayLogic = descriptorsFactory.getTabDisplayLogic();
if (tabDisplayLogic.isConstantFalse()) {
logger.trace("Skip adding detail tab to layout because it's never displayed: {}, tabDisplayLogic={}", entityDescriptor, tabDisplayLogic);
return null;
}
final DocumentLayoutDetailDescriptor.Builder layoutDetail = DocumentLayoutDetailDescriptor.builder(entityDescriptor.getWindowId(), entityDescriptor.getDetailId()).setGridLayout(layoutGridView()).setSingleRowLayout(layoutSingleRow()).setQueryOnActivate(entityDescriptor.isQueryIncludedTabOnActivate());
//
// Quick input
{
final boolean supportQuickInput = quickInputDescriptors.hasQuickInputEntityDescriptor(entityDescriptor.getDocumentType(), entityDescriptor.getDocumentTypeId(), entityDescriptor.getTableNameOrNull(), entityDescriptor.getDetailId(), entityDescriptor.getIsSOTrx());
layoutDetail.setSupportQuickInput(supportQuickInput);
}
return layoutDetail;
}
Aggregations