Search in sources :

Example 6 with SqlDocumentFieldDataBindingDescriptor

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

the class BoardDescriptorRepository method createBoardCardFieldDescriptor.

private final BoardCardFieldDescriptor createBoardCardFieldDescriptor(final I_WEBUI_Board_CardField cardFieldPO, final DocumentEntityDescriptor documentEntityDescriptor) {
    // TODO: might be not so performant, we just need the ColumnName
    final String fieldName = cardFieldPO.getAD_Column().getColumnName();
    final DocumentFieldDescriptor documentField = documentEntityDescriptor.getField(fieldName);
    final SqlDocumentFieldDataBindingDescriptor fieldBinding = documentField.getDataBindingNotNull(SqlDocumentFieldDataBindingDescriptor.class);
    final DocumentFieldWidgetType widgetType = documentField.getWidgetType();
    final boolean isDisplayColumnAvailable = fieldBinding.isUsingDisplayColumn();
    final ImmutableSet<String> sqlSelectValues;
    final BoardFieldLoader fieldLoader;
    if (widgetType == DocumentFieldWidgetType.Amount && documentEntityDescriptor.hasField(WindowConstants.FIELDNAME_C_Currency_ID)) {
        sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue(), WindowConstants.FIELDNAME_C_Currency_ID);
        fieldLoader = (rs, adLanguage) -> {
            final BigDecimal valueBD = rs.getBigDecimal(fieldBinding.getColumnName());
            if (valueBD == null) {
                return null;
            }
            final int currencyId = rs.getInt(WindowConstants.FIELDNAME_C_Currency_ID);
            final String currencyCode = Services.get(ICurrencyDAO.class).getISO_Code(Env.getCtx(), currencyId);
            if (currencyCode == null) {
                return valueBD;
            }
            return Amount.of(valueBD, currencyCode);
        };
    } else {
        sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue());
        final DocumentFieldValueLoader documentFieldValueLoader = fieldBinding.getDocumentFieldValueLoader();
        final LookupDescriptor lookupDescriptor = documentField.getLookupDescriptor(LookupScope.DocumentField);
        fieldLoader = (rs, adLanguage) -> documentFieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage, lookupDescriptor);
    }
    return BoardCardFieldDescriptor.builder().caption(documentField.getCaption()).fieldName(fieldBinding.getColumnName()).widgetType(widgetType).sqlSelectValues(sqlSelectValues).usingDisplayColumn(isDisplayColumnAvailable).sqlSelectDisplayValue(fieldBinding.getSqlSelectDisplayValue()).sqlOrderBy(fieldBinding.getSqlOrderBy()).fieldLoader(fieldLoader).build();
}
Also used : ICurrencyDAO(de.metas.currency.ICurrencyDAO) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) BoardFieldLoader(de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) DocumentFieldValueLoader(de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) DateTimeTranslatableString(de.metas.i18n.DateTimeTranslatableString) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) BigDecimal(java.math.BigDecimal)

Aggregations

SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)6 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)5 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)3 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)2 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)2 MoreObjects (com.google.common.base.MoreObjects)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ICurrencyDAO (de.metas.currency.ICurrencyDAO)1 DateTimeTranslatableString (de.metas.i18n.DateTimeTranslatableString)1 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 ImmutableTranslatableString (de.metas.i18n.ImmutableTranslatableString)1 NumberTranslatableString (de.metas.i18n.NumberTranslatableString)1 BoardFieldLoader (de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader)1 DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)1 SqlDocumentFilterConverters (de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverters)1 SqlParamsCollector (de.metas.ui.web.document.filter.sql.SqlParamsCollector)1