Search in sources :

Example 1 with SqlEntityFieldBinding

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

the class SqlDocumentQueryBuilder method extractComposedKey.

/**
 * @return map of (keyColumnName, value) pairs
 */
public static Map<String, Object> extractComposedKey(final DocumentId recordId, final List<? extends SqlEntityFieldBinding> keyFields) {
    final int count = keyFields.size();
    if (count < 1) {
        throw new AdempiereException("Invalid composed key: " + keyFields);
    }
    final List<Object> composedKeyParts = recordId.toComposedKeyParts();
    if (composedKeyParts.size() != count) {
        throw new AdempiereException("Invalid composed key '" + recordId + "'. Expected " + count + " parts but it has " + composedKeyParts.size());
    }
    final ImmutableMap.Builder<String, Object> composedKey = ImmutableMap.builder();
    for (int i = 0; i < count; i++) {
        final SqlEntityFieldBinding keyField = keyFields.get(i);
        final String keyColumnName = keyField.getColumnName();
        final Object valueObj = composedKeyParts.get(i);
        final Object valueConv = DocumentFieldDescriptor.convertToValueClass(keyColumnName, valueObj, keyField.getWidgetType(), keyField.getSqlValueClass(), (LookupValueByIdSupplier) null);
        composedKey.put(keyColumnName, valueConv);
    }
    return composedKey.build();
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with SqlEntityFieldBinding

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

the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause_StandardWidget.

private final String buildSqlWhereClause_StandardWidget(final SqlParamsCollector sqlParams, final DocumentFilterParam filterParam, final SqlOptions sqlOpts) {
    final SqlEntityFieldBinding paramBinding = getParameterBinding(filterParam.getFieldName());
    final DocumentFieldWidgetType widgetType = paramBinding.getWidgetType();
    // 
    // Regular filter
    final IQueryFilterModifier fieldModifier = extractFieldModifier(widgetType);
    final IQueryFilterModifier valueModifier = extractValueModifier(widgetType);
    final String columnSql = extractColumnSql(paramBinding, fieldModifier, sqlOpts);
    final Operator operator = filterParam.getOperator();
    switch(operator) {
        case EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
            }
        case NOT_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
            }
        case IN_ARRAY:
            {
                final List<Object> sqlValuesList = filterParam.getValueAsList(itemObj -> convertToSqlValue(itemObj, paramBinding, valueModifier));
                return buildSqlWhereClause_InArray(columnSql, sqlValuesList, sqlParams);
            }
        case GREATER:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, ">", sqlValue, sqlParams);
            }
        case GREATER_OR_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, ">=", sqlValue, sqlParams);
            }
        case LESS:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, "<", sqlValue, sqlParams);
            }
        case LESS_OR_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, "<=", sqlValue, sqlParams);
            }
        case LIKE:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                final boolean ignoreCase = false;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case NOT_LIKE:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                final boolean ignoreCase = false;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case LIKE_I:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                final boolean ignoreCase = true;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case NOT_LIKE_I:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                final boolean ignoreCase = true;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case BETWEEN:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final Object sqlValueTo = convertToSqlValue(filterParam.getValueTo(), paramBinding, valueModifier);
                return buildSqlWhereClause_Between(columnSql, sqlValue, sqlValueTo, sqlParams);
            }
        default:
            {
                throw new IllegalArgumentException("Operator not supported: " + operator);
            }
    }
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) DateTruncQueryFilterModifier(org.adempiere.ad.dao.impl.DateTruncQueryFilterModifier) NonNull(lombok.NonNull) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor) SqlDocumentsRepository(de.metas.ui.web.window.model.sql.SqlDocumentsRepository) DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam) IQueryFilterModifier(org.adempiere.ad.dao.IQueryFilterModifier) MoreObjects(com.google.common.base.MoreObjects) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) ArrayList(java.util.ArrayList) List(java.util.List) DB(org.compiere.util.DB) Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup) AdempiereException(org.adempiere.exceptions.AdempiereException) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) SqlEntityBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityBinding) DBConstants(org.adempiere.db.DBConstants) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) NullQueryFilterModifier(org.adempiere.ad.dao.impl.NullQueryFilterModifier) IQueryFilterModifier(org.adempiere.ad.dao.IQueryFilterModifier) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ArrayList(java.util.ArrayList) List(java.util.List) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding)

Example 3 with SqlEntityFieldBinding

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

the class SqlViewKeyColumnNamesMap method buildWebuiSelectionColumnNamesByKeyColumnName.

private static ImmutableMap<String, String> buildWebuiSelectionColumnNamesByKeyColumnName(final List<SqlEntityFieldBinding> keyFields) {
    final List<String> availableIntKeys = new ArrayList<>(I_T_WEBUI_ViewSelection.COLUMNNAME_IntKeys);
    final List<String> availableStringKeys = new ArrayList<>(I_T_WEBUI_ViewSelection.COLUMNNAME_StringKeys);
    final ImmutableMap.Builder<String, String> keyColumnName2selectionColumnName = ImmutableMap.builder();
    for (SqlEntityFieldBinding keyField : keyFields) {
        final List<String> availableKeys;
        final Class<?> sqlValueClass = keyField.getSqlValueClass();
        if (Integer.class.equals(sqlValueClass) || int.class.equals(sqlValueClass)) {
            availableKeys = availableIntKeys;
        } else if (String.class.equals(sqlValueClass)) {
            availableKeys = availableStringKeys;
        } else {
            throw new AdempiereException("Only integer or string types are supported for key columns: " + keyField);
        }
        if (availableKeys.isEmpty()) {
            throw new AdempiereException("No more available key columns found in " + I_T_WEBUI_ViewSelection.Table_Name + " for " + keyField);
        }
        final String webuiSelectionColumnName = availableKeys.remove(0);
        keyColumnName2selectionColumnName.put(keyField.getColumnName(), webuiSelectionColumnName);
    }
    return keyColumnName2selectionColumnName.build();
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) ToString(lombok.ToString) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) PlainSqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.PlainSqlEntityFieldBinding) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

SqlEntityFieldBinding (de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 MoreObjects (com.google.common.base.MoreObjects)1 Check (de.metas.printing.esb.base.util.Check)1 DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)1 DocumentFilterParam (de.metas.ui.web.document.filter.DocumentFilterParam)1 Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)1 DocumentFilterParamDescriptor (de.metas.ui.web.document.filter.DocumentFilterParamDescriptor)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)1 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)1 PlainSqlEntityFieldBinding (de.metas.ui.web.window.descriptor.sql.PlainSqlEntityFieldBinding)1 SqlEntityBinding (de.metas.ui.web.window.descriptor.sql.SqlEntityBinding)1 LabelsLookup (de.metas.ui.web.window.model.lookup.LabelsLookup)1 SqlDocumentsRepository (de.metas.ui.web.window.model.sql.SqlDocumentsRepository)1 SqlOptions (de.metas.ui.web.window.model.sql.SqlOptions)1 List (java.util.List)1 NonNull (lombok.NonNull)1