Search in sources :

Example 6 with DocumentFieldWidgetType

use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType 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;
}
Also used : IModelTranslationMap(de.metas.i18n.IModelTranslationMap) IExpression(org.adempiere.ad.expression.api.IExpression) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 7 with DocumentFieldWidgetType

use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.

the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause.

/**
 * Build document filter parameter where clause
 */
private String buildSqlWhereClause(final SqlParamsCollector sqlParams, final String filterId, final DocumentFilterParam filterParam, final SqlOptions sqlOpts) {
    // SQL filter
    if (filterParam.isSqlFilter()) {
        String sqlWhereClause = filterParam.getSqlWhereClause();
        if (sqlOpts.isUseTableAlias()) {
            sqlWhereClause = replaceTableNameWithTableAlias(sqlWhereClause, sqlOpts.getTableAlias());
        }
        final List<Object> sqlWhereClauseParams = filterParam.getSqlWhereClauseParams();
        sqlParams.collectAll(sqlWhereClauseParams);
        return sqlWhereClause;
    }
    // 
    // Labels filter
    final String parameterName = filterParam.getFieldName();
    final DocumentFieldWidgetType widgetType = getParameterWidgetType(parameterName);
    if (widgetType == DocumentFieldWidgetType.Labels) {
        final DocumentFilterParamDescriptor paramDescriptor = getParameterDescriptor(filterId, parameterName);
        return buildSqlWhereClause_LabelsWidget(filterParam, paramDescriptor, sqlParams, sqlOpts);
    } else // 
    // Standard filter
    {
        return buildSqlWhereClause_StandardWidget(sqlParams, filterParam, sqlOpts);
    }
}
Also used : DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor)

Example 8 with DocumentFieldWidgetType

use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.

the class SqlDefaultDocumentFilterConverter method convertToSqlValue.

private Object convertToSqlValue(final Object value, final SqlEntityFieldBinding fieldBinding, final IQueryFilterModifier modifier) {
    final String columnName = fieldBinding.getColumnName();
    final DocumentFieldWidgetType widgetType = fieldBinding.getWidgetType();
    final Class<?> targetClass = fieldBinding.getSqlValueClass();
    final Object sqlValue = SqlDocumentsRepository.convertValueToPO(value, columnName, widgetType, targetClass);
    return modifier.convertValue(columnName, sqlValue, null);
}
Also used : DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)

Example 9 with DocumentFieldWidgetType

use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.

the class DocumentFilterDescriptorsProviderFactory method createFilterParam.

private final DocumentFilterParamDescriptor.Builder createFilterParam(final DocumentFieldDescriptor field) {
    final ITranslatableString displayName = field.getCaption();
    final String fieldName = field.getFieldName();
    final DocumentFieldWidgetType widgetType = extractFilterWidgetType(field);
    final DocumentFieldDefaultFilterDescriptor filteringInfo = field.getDefaultFilterInfo();
    final LookupDescriptor lookupDescriptor = field.getLookupDescriptor(LookupDescriptorProvider.LookupScope.DocumentFilter);
    final Operator operator;
    if (widgetType.isText()) {
        operator = Operator.LIKE_I;
    } else if (filteringInfo.isRangeFilter()) {
        operator = Operator.BETWEEN;
    } else {
        operator = Operator.EQUAL;
    }
    return DocumentFilterParamDescriptor.builder().setDisplayName(displayName).setFieldName(fieldName).setWidgetType(widgetType).setOperator(operator).setLookupDescriptor(lookupDescriptor).setMandatory(false).setShowIncrementDecrementButtons(filteringInfo.isShowFilterIncrementButtons()).setAutoFilterInitialValue(filteringInfo.getAutoFilterInitialValue());
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) DocumentFieldDefaultFilterDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDefaultFilterDescriptor) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ITranslatableString(de.metas.i18n.ITranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 10 with DocumentFieldWidgetType

use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.

the class SqlDocumentQueryBuilder method buildSqlWhereClause.

private IPair<IStringExpression, List<Object>> buildSqlWhereClause() {
    final SqlParamsCollector sqlParams = SqlParamsCollector.newInstance();
    final CompositeStringExpression.Builder sqlWhereClauseBuilder = IStringExpression.composer();
    // 
    // Entity's WHERE clause
    {
        final IStringExpression entityWhereClauseExpression = entityBinding.getSqlWhereClause();
        if (!entityWhereClauseExpression.isNullExpression()) {
            sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
            sqlWhereClauseBuilder.append(" /* entity where clause */ (").append(entityWhereClauseExpression).append(")");
        }
    }
    // 
    // Key column
    // FIXME: handle AD_Reference/AD_Ref_List(s). In that case the recordId will be AD_Ref_List.Value,
    // so the SQL where clause which is currently build is AD_Ref_List_ID=<the AD_Ref_List.Value>.
    // The build SQL where clause shall be something like AD_Reference_ID=<the reference, i think we shall fetch it somehow from Lookup> AND Value=<the value, which currently is the recordId>
    final DocumentId recordId = getRecordId();
    if (recordId != null) {
        final List<SqlDocumentFieldDataBindingDescriptor> keyFields = entityBinding.getKeyFields();
        if (keyFields.isEmpty()) {
            throw new AdempiereException("Failed building where clause because there is no Key Column defined in " + entityBinding);
        } else // Single primary key
        if (keyFields.size() == 1) {
            final String keyColumnName = keyFields.get(0).getColumnName();
            sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
            sqlWhereClauseBuilder.append(" /* key */ ").append(keyColumnName).append("=").append(sqlParams.placeholder(recordId.toInt()));
        } else // Composed primary key
        {
            final Map<String, Object> keyColumnName2value = extractComposedKey(recordId, keyFields);
            keyColumnName2value.forEach((keyColumnName, value) -> {
                sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
                sqlWhereClauseBuilder.append(" /* key */ ").append(keyColumnName).append("=").append(sqlParams.placeholder(value));
            });
        }
    }
    // 
    // Parent link where clause (if any)
    final Document parentDocument = getParentDocument();
    if (parentDocument != null) {
        final String parentLinkColumnName = entityBinding.getParentLinkColumnName();
        final String linkColumnName = entityBinding.getLinkColumnName();
        if (parentLinkColumnName != null && linkColumnName != null) {
            final IDocumentFieldView parentLinkField = parentDocument.getFieldView(parentLinkColumnName);
            final Object parentLinkValue = parentLinkField.getValue();
            final DocumentFieldWidgetType parentLinkWidgetType = parentLinkField.getWidgetType();
            final Class<?> targetClass = entityBinding.getFieldByFieldName(linkColumnName).getSqlValueClass();
            final Object sqlParentLinkValue = SqlDocumentsRepository.convertValueToPO(parentLinkValue, parentLinkColumnName, parentLinkWidgetType, targetClass);
            sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
            sqlWhereClauseBuilder.append(" /* parent link */ ").append(linkColumnName).append("=").append(sqlParams.placeholder(sqlParentLinkValue));
        }
    }
    // 
    // Document filters
    {
        final String sqlFilters = SqlDocumentFilterConverters.createEntityBindingEffectiveConverter(entityBinding).getSql(sqlParams, getDocumentFilters(), SqlOptions.usingTableAlias(entityBinding.getTableAlias()));
        if (!Check.isEmpty(sqlFilters, true)) {
            sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
            sqlWhereClauseBuilder.append(" /* filters */ (\n").append(sqlFilters).append(")\n");
        }
    }
    // Build the final SQL where clause
    return ImmutablePair.of(sqlWhereClauseBuilder.build(), Collections.unmodifiableList(sqlParams.toList()));
}
Also used : IPair(org.adempiere.util.lang.IPair) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Env(org.compiere.util.Env) ArrayList(java.util.ArrayList) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) Evaluatee(org.compiere.util.Evaluatee) SqlDocumentFilterConverters(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverters) ImmutableList(com.google.common.collect.ImmutableList) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) Map(java.util.Map) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) DocumentQueryOrderBy(de.metas.ui.web.window.model.DocumentQueryOrderBy) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) Properties(java.util.Properties) WindowConstants(de.metas.ui.web.window.WindowConstants) UserRolePermissionsKey(org.adempiere.ad.security.UserRolePermissionsKey) Evaluatees(org.compiere.util.Evaluatees) ImmutableMap(com.google.common.collect.ImmutableMap) AccessSqlStringExpression(org.adempiere.ad.security.impl.AccessSqlStringExpression) MoreObjects(com.google.common.base.MoreObjects) Objects(java.util.Objects) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) List(java.util.List) ImmutablePair(org.adempiere.util.lang.ImmutablePair) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) DocumentQuery(de.metas.ui.web.window.model.DocumentQuery) LookupValueByIdSupplier(de.metas.ui.web.window.model.lookup.LookupValueByIdSupplier) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector) Collections(java.util.Collections) Document(de.metas.ui.web.window.model.Document) CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Document(de.metas.ui.web.window.model.Document) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) AdempiereException(org.adempiere.exceptions.AdempiereException) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector)

Aggregations

DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)20 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)6 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)6 ITranslatableString (de.metas.i18n.ITranslatableString)4 Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)3 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)3 SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)3 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)3 List (java.util.List)3 MoreObjects (com.google.common.base.MoreObjects)2 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)2 Check (de.metas.printing.esb.base.util.Check)2 DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)2 DocumentFilterParamDescriptor (de.metas.ui.web.document.filter.DocumentFilterParamDescriptor)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)2 SqlEntityFieldBinding (de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding)2 BigDecimal (java.math.BigDecimal)2 IExpression (org.adempiere.ad.expression.api.IExpression)2