Search in sources :

Example 1 with SQLNamePairIterator

use of org.adempiere.ad.service.impl.LookupDAO.SQLNamePairIterator in project metasfresh-webui-api by metasfresh.

the class GenericSqlLookupDataSourceFetcher method retrieveEntities.

/**
 * @param evalCtx
 * @return lookup values list
 * @see #getRetrieveEntriesParameters()
 */
@Override
public LookupValuesList retrieveEntities(final LookupDataSourceContext evalCtx) {
    final String sqlForFetching = sqlForFetchingExpression.evaluate(evalCtx, OnVariableNotFound.Fail);
    final String adLanguage = isTranslatable ? evalCtx.getAD_Language() : null;
    try (final SQLNamePairIterator data = new SQLNamePairIterator(sqlForFetching, numericKey, entityTypeIndex)) {
        Map<String, String> debugProperties = null;
        if (WindowConstants.isProtocolDebugging()) {
            debugProperties = new LinkedHashMap<>();
            debugProperties.put("debug-sql", sqlForFetching);
            debugProperties.put("debug-params", evalCtx.toString());
        }
        final LookupValuesList values = data.fetchAll().stream().filter(evalCtx::acceptItem).map(namePair -> LookupValue.fromNamePair(namePair, adLanguage)).collect(LookupValuesList.collect(debugProperties));
        logger.trace("Returning values={} (executed sql: {})", values, sqlForFetching);
        return values;
    }
}
Also used : LogManager(de.metas.logging.LogManager) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LinkedHashMap(java.util.LinkedHashMap) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) DB(org.compiere.util.DB) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) INamePairPredicate(org.adempiere.ad.validationRule.INamePairPredicate) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) Logger(org.slf4j.Logger) WindowConstants(de.metas.ui.web.window.WindowConstants) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) MoreObjects(com.google.common.base.MoreObjects) WindowId(de.metas.ui.web.window.datatypes.WindowId) CCacheStats(org.compiere.util.CCache.CCacheStats) SQLNamePairIterator(org.adempiere.ad.service.impl.LookupDAO.SQLNamePairIterator) List(java.util.List) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) SQLNamePairIterator(org.adempiere.ad.service.impl.LookupDAO.SQLNamePairIterator) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) ITranslatableString(de.metas.i18n.ITranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString)

Aggregations

MoreObjects (com.google.common.base.MoreObjects)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 ImmutableTranslatableString (de.metas.i18n.ImmutableTranslatableString)1 LogManager (de.metas.logging.LogManager)1 WindowConstants (de.metas.ui.web.window.WindowConstants)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)1 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)1 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)1 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 NonNull (lombok.NonNull)1 OnVariableNotFound (org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound)1