Search in sources :

Example 1 with DocumentFieldDescriptor

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

the class SqlDocumentQueryBuilder method extractSingleKeyColumnName.

/**
 * @return SQL key column name; never returns null
 */
private static final String extractSingleKeyColumnName(final DocumentEntityDescriptor entityDescriptor) {
    final DocumentFieldDescriptor idField = entityDescriptor.getSingleIdField();
    final SqlDocumentFieldDataBindingDescriptor idFieldBinding = SqlDocumentFieldDataBindingDescriptor.castOrNull(idField.getDataBinding());
    if (idFieldBinding == null) {
        throw new AdempiereException("Entity's ID field does not have SQL bindings: " + idField);
    }
    return idFieldBinding.getColumnName();
}
Also used : SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 2 with DocumentFieldDescriptor

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

the class Document method initializeField.

/**
 * Set field's initial value
 *
 * @param documentField
 * @param mode initialization mode
 * @param fieldValueSupplier initial value supplier
 */
private void initializeField(final IDocumentField documentField, final FieldInitializationMode mode, final DocumentValuesSupplier fieldValueSupplier) {
    boolean valueSet = false;
    Object valueOld = null;
    try {
        final DocumentFieldDescriptor fieldDescriptor = documentField.getDescriptor();
        // 
        // Get the initialization value
        final Object initialValue = fieldValueSupplier.getValue(fieldDescriptor);
        // Update field's initial value
        if (initialValue != DocumentValuesSupplier.NO_VALUE) {
            valueOld = documentField.getValue();
            documentField.setInitialValue(initialValue, changesCollector);
        }
        valueSet = true;
    } catch (final Exception e) {
        valueSet = false;
        if (FieldInitializationMode.NewDocument == mode) {
            logger.warn("Failed initializing {}, mode={} using {}. Keeping current initial value.", documentField, mode, fieldValueSupplier, e);
        } else {
            throw AdempiereException.wrapIfNeeded(e);
        }
    }
    // After field was initialized, based on "mode", trigger events, update other fields etc
    if (FieldInitializationMode.NewDocument == mode) {
        // Collect the change event, even if there was no change because we just set the initial value
        changesCollector.collectValueChanged(documentField, REASON_Value_NewDocument);
    // NOTE: don't update fields flags which depend on this field because we will do it all together after all fields are initialized
    // NOTE: don't call callouts because we will do it all together after all fields are initialized
    } else if (FieldInitializationMode.Load == mode) {
    // NOTE: don't collect field changes because we are just initializing a new Document instance from an existing database record.
    // NOTE: don't update fields flags which depend on this field because we will do it all together after all fields are initialized
    // NOTE: don't call callouts because this was not a user change.
    } else if (FieldInitializationMode.Refresh == mode) {
        if (valueSet) {
            changesCollector.collectValueIfChanged(documentField, valueOld, REASON_Value_Refreshing);
        }
    }
}
Also used : DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) 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)

Example 3 with DocumentFieldDescriptor

use of de.metas.ui.web.window.descriptor.DocumentFieldDescriptor 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)

Example 4 with DocumentFieldDescriptor

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

the class DocumentFilterDescriptorsProviderFactory method createFiltersProvider_Defaults.

/**
 * Creates standard filters, i.e. from document fields which are flagged with {@link Characteristic#AllowFiltering}.
 *
 * @param fields
 */
private ImmutableDocumentFilterDescriptorsProvider createFiltersProvider_Defaults(final Collection<DocumentFieldDescriptor> fields) {
    final DocumentFilterDescriptor.Builder defaultFilter = DocumentFilterDescriptor.builder().setFilterId(FILTER_ID_Default).setDisplayName(msgBL.getTranslatableMsgText(MSG_DefaultFilterName)).setFrequentUsed(false);
    final DocumentFilterDescriptor.Builder defaultDateFilter = DocumentFilterDescriptor.builder().setFilterId(FILTER_ID_DefaultDate).setFrequentUsed(true);
    final List<DocumentFieldDescriptor> filteringFields = fields.stream().filter(DocumentFieldDescriptor::isDefaultFilterField).sorted(Ordering.natural().onResultOf(field -> field.getDefaultFilterInfo().getSeqNo())).collect(ImmutableList.toImmutableList());
    for (final DocumentFieldDescriptor field : filteringFields) {
        final DocumentFilterParamDescriptor.Builder filterParam = createFilterParam(field);
        if (!defaultDateFilter.hasParameters() && filterParam.getWidgetType().isDateOrTime()) {
            defaultDateFilter.setDisplayName(filterParam.getDisplayName());
            defaultDateFilter.addParameter(filterParam);
        } else {
            defaultFilter.addParameter(filterParam);
        }
    }
    return Stream.of(defaultDateFilter, defaultFilter).filter(filterBuilder -> filterBuilder.hasParameters()).map(filterBuilder -> filterBuilder.build()).collect(ImmutableDocumentFilterDescriptorsProvider.collector());
}
Also used : ITranslatableString(de.metas.i18n.ITranslatableString) DocumentFieldDefaultFilterDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDefaultFilterDescriptor) Collection(java.util.Collection) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) Services(org.adempiere.util.Services) List(java.util.List) Stream(java.util.stream.Stream) Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Ordering(com.google.common.collect.Ordering) Characteristic(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IMsgBL(de.metas.i18n.IMsgBL) Nullable(javax.annotation.Nullable) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)

Aggregations

DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)4 ITranslatableString (de.metas.i18n.ITranslatableString)2 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)2 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)2 SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 ImmutableList (com.google.common.collect.ImmutableList)1 Ordering (com.google.common.collect.Ordering)1 ICurrencyDAO (de.metas.currency.ICurrencyDAO)1 DocumentProcessingException (de.metas.document.exceptions.DocumentProcessingException)1 DateTimeTranslatableString (de.metas.i18n.DateTimeTranslatableString)1 IMsgBL (de.metas.i18n.IMsgBL)1 ImmutableTranslatableString (de.metas.i18n.ImmutableTranslatableString)1 NumberTranslatableString (de.metas.i18n.NumberTranslatableString)1 BoardFieldLoader (de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader)1 Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)1 DocumentFieldDefaultFilterDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDefaultFilterDescriptor)1 Characteristic (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic)1 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)1 DocumentFieldValueLoader (de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader)1