Search in sources :

Example 1 with ILogicExpression

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);
}
Also used : ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) DocumentLayoutSectionDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutSectionDescriptor) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 2 with ILogicExpression

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");
    }
}
Also used : ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) AdempiereException(org.adempiere.exceptions.AdempiereException) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) Evaluatee(org.compiere.util.Evaluatee)

Example 3 with ILogicExpression

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);
}
Also used : SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) IExpression(org.adempiere.ad.expression.api.IExpression) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) ButtonFieldActionDescriptor(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) ButtonFieldActionType(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor.ButtonFieldActionType) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 4 with ILogicExpression

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;
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) GridFieldVO(org.compiere.model.GridFieldVO) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 5 with ILogicExpression

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);
}
Also used : ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) DocumentFieldReadonlyException(de.metas.ui.web.window.exceptions.DocumentFieldReadonlyException) InvalidDocumentStateException(de.metas.ui.web.window.exceptions.InvalidDocumentStateException) DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) DocumentProcessingException(de.metas.document.exceptions.DocumentProcessingException) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentFieldNotFoundException(de.metas.ui.web.window.exceptions.DocumentFieldNotFoundException)

Aggregations

ILogicExpression (org.adempiere.ad.expression.api.ILogicExpression)12 AdempiereException (org.adempiere.exceptions.AdempiereException)7 LogicExpressionResult (org.adempiere.ad.expression.api.LogicExpressionResult)6 DocumentProcessingException (de.metas.document.exceptions.DocumentProcessingException)4 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)4 DocumentFieldNotFoundException (de.metas.ui.web.window.exceptions.DocumentFieldNotFoundException)4 DocumentFieldReadonlyException (de.metas.ui.web.window.exceptions.DocumentFieldReadonlyException)4 DocumentNotFoundException (de.metas.ui.web.window.exceptions.DocumentNotFoundException)4 InvalidDocumentStateException (de.metas.ui.web.window.exceptions.InvalidDocumentStateException)4 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)3 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)3 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)3 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)3 IExpression (org.adempiere.ad.expression.api.IExpression)3 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)2 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)2 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 Check (de.metas.printing.esb.base.util.Check)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 DocumentType (de.metas.ui.web.window.datatypes.DocumentType)1