use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class Document method computeReadonly.
private final DocumentReadonly computeReadonly() {
final ILogicExpression allFieldsReadonlyLogic = getEntityDescriptor().getReadonlyLogic();
LogicExpressionResult allFieldsReadonly;
try {
allFieldsReadonly = allFieldsReadonlyLogic.evaluateToResult(asEvaluatee(), OnVariableNotFound.Fail);
} catch (final Exception e) {
allFieldsReadonly = LogicExpressionResult.FALSE;
logger.warn("Failed evaluating entity readonly logic {} for {}. Considering {}", allFieldsReadonlyLogic, this, allFieldsReadonly, e);
}
final DocumentReadonly readonlyComputed = DocumentReadonly.builder().parentActive(parentReadonly.isActive()).active(isActive()).processed(parentReadonly.isProcessed() || isProcessed()).processing(parentReadonly.isProcessing() || isProcessing()).fieldsReadonly(allFieldsReadonly.booleanValue()).build();
return readonlyComputed;
}
use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class ASIDescriptorFactory method createDocumentFieldDescriptor.
private DocumentFieldDescriptor.Builder createDocumentFieldDescriptor(final I_M_Attribute attribute) {
final int attributeId = attribute.getM_Attribute_ID();
final String fieldName = attribute.getValue();
final String attributeValueType = attribute.getAttributeValueType();
final Class<?> valueClass;
final DocumentFieldWidgetType widgetType;
final Function<I_M_AttributeInstance, Object> readMethod;
final BiConsumer<I_M_AttributeInstance, IDocumentFieldView> writeMethod;
LookupDescriptor lookupDescriptor = null;
if (X_M_Attribute.ATTRIBUTEVALUETYPE_Date.equals(attributeValueType)) {
valueClass = java.util.Date.class;
widgetType = DocumentFieldWidgetType.Date;
readMethod = I_M_AttributeInstance::getValueDate;
writeMethod = (aiRecord, field) -> aiRecord.setValueDate(TimeUtil.asTimestamp(field.getValueAs(java.util.Date.class)));
} else if (X_M_Attribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
valueClass = StringLookupValue.class;
widgetType = DocumentFieldWidgetType.List;
readMethod = I_M_AttributeInstance::getValue;
writeMethod = ASIAttributeFieldBinding::writeValueFromLookup;
lookupDescriptor = getLookupDescriptor(attribute);
} else if (X_M_Attribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
valueClass = BigDecimal.class;
widgetType = DocumentFieldWidgetType.Number;
readMethod = I_M_AttributeInstance::getValueNumber;
writeMethod = (aiRecord, field) -> aiRecord.setValueNumber(field.getValueAs(BigDecimal.class));
} else if (X_M_Attribute.ATTRIBUTEVALUETYPE_StringMax40.equals(attributeValueType)) {
valueClass = String.class;
widgetType = DocumentFieldWidgetType.Text;
readMethod = I_M_AttributeInstance::getValue;
writeMethod = (aiRecord, field) -> aiRecord.setValue(field.getValueAs(String.class));
} else {
throw new IllegalArgumentException("@NotSupported@ @AttributeValueType@=" + attributeValueType + ", @M_Attribute_ID@=" + attribute);
}
final ILogicExpression readonlyLogic = ConstantLogicExpression.FALSE;
final ILogicExpression displayLogic = ConstantLogicExpression.TRUE;
final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(attribute.isMandatory());
final Optional<IExpression<?>> defaultValueExpr = Optional.empty();
return DocumentFieldDescriptor.builder(fieldName).setCaption(attribute.getName()).setDescription(attribute.getDescription()).setValueClass(valueClass).setWidgetType(widgetType).setLookupDescriptorProvider(lookupDescriptor).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField).setDataBinding(new ASIAttributeFieldBinding(attributeId, fieldName, attribute.isMandatory(), readMethod, writeMethod));
}
Aggregations