use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class LayoutFactory method layoutSingleRow.
/**
* Single row layout: sections list
*/
public DocumentLayoutSingleRow.Builder layoutSingleRow() {
// NOTE, according to (FRESH-686 #26), we are putting all elements in one list, one after another, no sections, no columns etc
final DocumentEntityDescriptor.Builder entityDescriptor = documentEntity();
logger.trace("Generating single row layout for {}", entityDescriptor);
// If the tab is never displayed then don't create the layout
final ILogicExpression tabDisplayLogic = descriptorsFactory.getTabDisplayLogic();
if (tabDisplayLogic.isConstantFalse()) {
logger.warn("Skip creating single row layout because it's never displayed: {}, tabDisplayLogic={}", entityDescriptor, tabDisplayLogic);
return null;
}
//
// Layout sections
List<DocumentLayoutSectionDescriptor.Builder> layoutSectionsList = layoutSectionsList();
// Usually this happens when generating the single row layout for included tabs.
if (!layoutSectionsList.stream().anyMatch(DocumentLayoutSectionDescriptor.Builder::isNotEmpty)) {
final DocumentLayoutSectionDescriptor.Builder oneLayoutSection = DocumentLayoutSectionDescriptor.builder().addColumn(layoutGridView().getElements());
layoutSectionsList = ImmutableList.of(oneLayoutSection);
}
return DocumentLayoutSingleRow.builder().setCaption(entityDescriptor.getCaption()).setDescription(entityDescriptor.getDescription()).addSections(layoutSectionsList);
}
use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method assertDeleteDocumentAllowed.
private void assertDeleteDocumentAllowed(final DocumentEntityDescriptor entityDescriptor) {
final Evaluatee evalCtx = Evaluatees.mapBuilder().put(WindowConstants.FIELDNAME_Processed, false).build().andComposeWith(userSession.toEvaluatee());
final ILogicExpression allowExpr = entityDescriptor.getAllowDeleteLogic();
final LogicExpressionResult allow = allowExpr.evaluateToResult(evalCtx, OnVariableNotFound.ReturnNoResult);
if (allow.isFalse()) {
throw new AdempiereException("Delete not allowed");
}
}
use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class GridTabVOBasedDocumentEntityDescriptorFactory method createAndAddDocumentField.
private final void createAndAddDocumentField(final DocumentEntityDescriptor.Builder entityDescriptor, final GridFieldVO gridFieldVO, final boolean keyColumn) {
// From entry data-binding:
final SqlDocumentEntityDataBindingDescriptor.Builder entityBindings = entityDescriptor.getDataBindingBuilder(SqlDocumentEntityDataBindingDescriptor.Builder.class);
// From GridFieldVO:
final String fieldName = gridFieldVO.getColumnName();
final String sqlColumnName = fieldName;
//
final boolean isParentLinkColumn = sqlColumnName.equals(entityBindings.getSqlParentLinkColumnName());
//
//
DocumentFieldWidgetType widgetType;
final Class<?> valueClass;
final Optional<IExpression<?>> defaultValueExpression;
final boolean alwaysUpdateable;
final LookupDescriptorProvider lookupDescriptorProvider;
final LookupDescriptor lookupDescriptor;
ILogicExpression readonlyLogic;
if (isParentLinkColumn) {
widgetType = DocumentFieldWidgetType.Integer;
valueClass = widgetType.getValueClass();
alwaysUpdateable = false;
lookupDescriptorProvider = LookupDescriptorProvider.NULL;
lookupDescriptor = null;
defaultValueExpression = Optional.empty();
readonlyLogic = ConstantLogicExpression.TRUE;
} else {
final int displayType = gridFieldVO.getDisplayType();
widgetType = DescriptorsFactoryHelper.extractWidgetType(sqlColumnName, displayType);
alwaysUpdateable = extractAlwaysUpdateable(gridFieldVO);
final String ctxTableName = Services.get(IADTableDAO.class).retrieveTableName(gridFieldVO.getAD_Table_ID());
lookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(ctxTableName).setCtxColumnName(sqlColumnName).setWidgetType(widgetType).setDisplayType(displayType).setAD_Reference_Value_ID(gridFieldVO.getAD_Reference_Value_ID()).setAD_Val_Rule_ID(gridFieldVO.getAD_Val_Rule_ID()).buildProvider();
lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupDescriptorProvider.LookupScope.DocumentField);
valueClass = DescriptorsFactoryHelper.getValueClass(widgetType, lookupDescriptor);
defaultValueExpression = defaultValueExpressionsFactory.extractDefaultValueExpression(gridFieldVO.getDefaultValue(), fieldName, widgetType, valueClass, gridFieldVO.isMandatory(), gridFieldVO.isUseDocSequence());
if (keyColumn) {
readonlyLogic = ConstantLogicExpression.TRUE;
} else if (gridFieldVO.isReadOnly()) {
readonlyLogic = ConstantLogicExpression.TRUE;
} else // and we want to allow the user setting it.
if (!gridFieldVO.isUpdateable() && !gridFieldVO.isParentLink()) {
readonlyLogic = ConstantLogicExpression.FALSE;
} else {
readonlyLogic = gridFieldVO.getReadOnlyLogic();
}
}
//
// Button action
final ButtonFieldActionDescriptor buttonAction;
if (!isParentLinkColumn && widgetType.isButton()) {
buttonAction = extractButtonFieldActionDescriptor(entityDescriptor.getTableNameOrNull(), fieldName, gridFieldVO.AD_Process_ID);
if (buttonAction != null) {
final ButtonFieldActionType actionType = buttonAction.getActionType();
if (actionType == ButtonFieldActionType.processCall) {
widgetType = DocumentFieldWidgetType.ProcessButton;
} else if (actionType == ButtonFieldActionType.genericZoomInto) {
widgetType = DocumentFieldWidgetType.ZoomIntoButton;
// allow pressing the button
readonlyLogic = ConstantLogicExpression.FALSE;
}
}
} else {
buttonAction = null;
}
//
// ORDER BY SortNo
int orderBySortNo = gridFieldVO.getSortNo();
if (orderBySortNo == 0 && keyColumn) {
orderBySortNo = Integer.MAX_VALUE;
}
final String sqlColumnSql = gridFieldVO.getColumnSQL(false);
final SqlDocumentFieldDataBindingDescriptor fieldBinding = SqlDocumentFieldDataBindingDescriptor.builder().setFieldName(sqlColumnName).setTableName(entityBindings.getTableName()).setTableAlias(entityBindings.getTableAlias()).setColumnName(sqlColumnName).setColumnSql(sqlColumnSql).setVirtualColumn(gridFieldVO.isVirtualColumn()).setMandatory(gridFieldVO.isMandatoryDB()).setWidgetType(widgetType).setValueClass(valueClass).setSqlValueClass(entityBindings.getPOInfo().getColumnClass(sqlColumnName)).setLookupDescriptor(lookupDescriptor).setKeyColumn(keyColumn).setEncrypted(gridFieldVO.isEncryptedColumn()).setDefaultOrderBy(orderBySortNo).build();
final DocumentFieldDescriptor.Builder fieldBuilder = DocumentFieldDescriptor.builder(sqlColumnName).setCaption(gridFieldVO.getHeaderTrls(), gridFieldVO.getHeader()).setDescription(gridFieldVO.getDescriptionTrls(), gridFieldVO.getDescription()).setKey(keyColumn).setParentLink(isParentLinkColumn).setWidgetType(widgetType).setButtonActionDescriptor(buttonAction).setLookupDescriptorProvider(lookupDescriptorProvider).setValueClass(fieldBinding.getValueClass()).setVirtualField(fieldBinding.isVirtualColumn()).setCalculated(gridFieldVO.isCalculated()).setDefaultValueExpression(defaultValueExpression).addCharacteristicIfTrue(keyColumn, Characteristic.SideListField).addCharacteristicIfTrue(keyColumn, Characteristic.GridViewField).setReadonlyLogic(readonlyLogic).setAlwaysUpdateable(alwaysUpdateable).setMandatoryLogic(extractMandatoryLogic(gridFieldVO)).setDisplayLogic(gridFieldVO.getDisplayLogic()).setDefaultFilterInfo(createDefaultFilterDescriptor(gridFieldVO.getDefaultFilterDescriptor(), sqlColumnName, widgetType)).setDataBinding(fieldBinding);
//
// Add Field builder to document entity
entityDescriptor.addField(fieldBuilder);
//
// Add Field's data binding to entity data binding
entityBindings.addField(fieldBinding);
//
// Collect special field
collectSpecialField(fieldBuilder);
}
use of org.adempiere.ad.expression.api.ILogicExpression in project metasfresh-webui-api by metasfresh.
the class GridTabVOBasedDocumentEntityDescriptorFactory method createDocumentEntityBuilder.
private DocumentEntityDescriptor.Builder createDocumentEntityBuilder(final GridTabVO gridTabVO, final GridTabVO parentTabVO, final boolean isSOTrx, final List<I_AD_UI_Element> labelsUIElements) {
final String tableName = gridTabVO.getTableName();
final DetailId detailId = parentTabVO == null ? null : DetailId.fromAD_Tab_ID(gridTabVO.getAD_Tab_ID());
// Entity Data binding
if (!Check.isEmpty(gridTabVO.getOrderByClause(), true)) {
logger.warn("Ignoring SQL order by for {}. See https://github.com/metasfresh/metasfresh/issues/412.", gridTabVO);
}
final SqlDocumentEntityDataBindingDescriptor.Builder dataBinding = SqlDocumentEntityDataBindingDescriptor.builder().setDocumentsRepository(documentsRepository).setTableName(tableName).setTableAliasFromDetailId(detailId).setChildToParentLinkColumnNames(extractChildParentLinkColumnNames(gridTabVO, parentTabVO)).setSqlWhereClause(gridTabVO.getWhereClause());
final ILogicExpression allowInsert = ConstantLogicExpression.of(gridTabVO.isInsertRecord());
final ILogicExpression allowDelete = ConstantLogicExpression.of(gridTabVO.isDeleteable());
final ILogicExpression readonlyLogic = extractTabReadonlyLogic(gridTabVO);
final ILogicExpression allowCreateNewLogic = allowInsert.andNot(readonlyLogic);
final ILogicExpression allowDeleteLogic = allowDelete.andNot(readonlyLogic);
//
final ILogicExpression displayLogic = gridTabVO.getDisplayLogic().evaluatePartial(Evaluatees.mapBuilder().put(WebRestApiContextProvider.CTXNAME_IsWebUI, DisplayType.toBooleanString(true)).build());
//
// Entity descriptor
final DocumentEntityDescriptor.Builder entityDescriptorBuilder = DocumentEntityDescriptor.builder().setDocumentType(DocumentType.Window, gridTabVO.getAD_Window_ID()).setDetailId(detailId).setCaption(gridTabVO.getNameTrls(), gridTabVO.getName()).setDescription(gridTabVO.getDescriptionTrls(), gridTabVO.getDescription()).setReadonlyLogic(readonlyLogic).setAllowCreateNewLogic(allowCreateNewLogic).setAllowDeleteLogic(allowDeleteLogic).setDisplayLogic(displayLogic).setDataBinding(dataBinding).setHighVolume(gridTabVO.IsHighVolume).setAD_Tab_ID(// legacy
gridTabVO.getAD_Tab_ID()).setTableName(// legacy
tableName).setIsSOTrx(// legacy
isSOTrx).setPrintAD_Process_ID(gridTabVO.getPrint_Process_ID());
final Predicate<GridFieldVO> isKeyColumn;
if (gridTabVO.getFields().stream().anyMatch(GridFieldVO::isKey)) {
isKeyColumn = GridFieldVO::isKey;
} else {
isKeyColumn = GridFieldVO::isParentLink;
}
//
// Fields descriptor
gridTabVO.getFields().stream().forEach(gridFieldVO -> createAndAddDocumentField(entityDescriptorBuilder, gridFieldVO, isKeyColumn.test(gridFieldVO)));
//
// Labels field descriptors
labelsUIElements.forEach(labelUIElement -> createAndAddLabelsDocumentField(entityDescriptorBuilder, labelUIElement));
return entityDescriptorBuilder;
}
use of org.adempiere.ad.expression.api.ILogicExpression 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);
}
Aggregations