Search in sources :

Example 1 with LookupValue

use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.

the class AddressRegionLookupDescriptor method retrieveLookupValueById.

@Override
public LookupValue retrieveLookupValueById(final LookupDataSourceContext evalCtx) {
    final int id = evalCtx.getIdToFilterAsInt(-1);
    if (id <= 0) {
        throw new IllegalStateException("No ID provided in " + evalCtx);
    }
    final LookupValue region = regionsByCountryId.values().stream().map(regions -> regions.getById(id)).filter(r -> r != null).findFirst().orElse(null);
    if (region != null) {
        return region;
    }
    final I_C_Region regionRecord = InterfaceWrapperHelper.create(Env.getCtx(), id, I_C_Region.class, ITrx.TRXNAME_None);
    if (regionRecord == null) {
        return LOOKUPVALUE_NULL;
    }
    return createLookupValue(regionRecord);
}
Also used : CCache(org.compiere.util.CCache) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) CtxName(org.compiere.util.CtxName) CtxNames(org.compiere.util.CtxNames) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) ImmutableList(com.google.common.collect.ImmutableList) I_C_Region(org.compiere.model.I_C_Region) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) ImmutableSet(com.google.common.collect.ImmutableSet) Builder(de.metas.ui.web.window.model.lookup.LookupDataSourceContext.Builder) LookupSource(de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor.LookupSource) LookupDataSourceContext(de.metas.ui.web.window.model.lookup.LookupDataSourceContext) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) CCacheStats(org.compiere.util.CCache.CCacheStats) ICountryDAO(de.metas.adempiere.service.ICountryDAO) Services(org.adempiere.util.Services) List(java.util.List) Check(org.adempiere.util.Check) I_C_Location(org.compiere.model.I_C_Location) Optional(java.util.Optional) LookupDataSourceFetcher(de.metas.ui.web.window.model.lookup.LookupDataSourceFetcher) I_C_Region(org.compiere.model.I_C_Region) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 2 with LookupValue

use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.

the class ProductLookupDescriptor method retrieveEntities.

@Override
public LookupValuesList retrieveEntities(final LookupDataSourceContext evalCtx) {
    final SqlParamsCollector sqlParams = SqlParamsCollector.newInstance();
    final String sql = buildSql(sqlParams, evalCtx);
    if (sql == null) {
        return LookupValuesList.EMPTY;
    }
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, ITrx.TRXNAME_None);
        DB.setParameters(pstmt, sqlParams.toList());
        rs = pstmt.executeQuery();
        final Map<Integer, LookupValue> valuesById = new LinkedHashMap<>();
        while (rs.next()) {
            final LookupValue value = loadLookupValue(rs);
            valuesById.putIfAbsent(value.getIdAsInt(), value);
        }
        final LookupValuesList unexplodedLookupValues = LookupValuesList.fromCollection(valuesById.values());
        final Date stockdateOrNull = getEffectiveStockDateOrNull(evalCtx);
        if (stockdateOrNull == null || availableToPromiseAdapter == null) {
            return unexplodedLookupValues;
        }
        return explodeRecordsWithStockQuantities(unexplodedLookupValues, stockdateOrNull);
    } catch (final SQLException ex) {
        throw new DBException(ex, sql, sqlParams.toList());
    } finally {
        DB.close(rs, pstmt);
    }
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) PreparedStatement(java.sql.PreparedStatement) ITranslatableString(de.metas.i18n.ITranslatableString) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector) Date(java.util.Date) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with LookupValue

use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.

the class ProductLookupDescriptor method createLookupValuesFromAvailableStockGroups.

private LookupValuesList createLookupValuesFromAvailableStockGroups(@NonNull final LookupValuesList initialLookupValues, @NonNull final List<Group> availableStockGroups) {
    final boolean addOnlyPositiveATP = addOnlyPositiveATP();
    final List<LookupValue> explodedProductValues = new ArrayList<>();
    for (final Group availableStockGroup : availableStockGroups) {
        if (addOnlyPositiveATP && availableStockGroup.getQty().signum() <= 0) {
            continue;
        }
        final int productId = availableStockGroup.getProductId();
        final LookupValue productLookupValue = initialLookupValues.getById(productId);
        final ITranslatableString displayName = createDisplayName(productLookupValue.getDisplayNameTrl(), availableStockGroup);
        final ImmutableMap<String, Object> attributeMap = availableStockGroup.getLookupAttributesMap();
        final IntegerLookupValue integerLookupValue = IntegerLookupValue.builder().id(productId).displayName(displayName).attribute(ATTRIBUTE_ASI, attributeMap).build();
        explodedProductValues.add(integerLookupValue);
    }
    if (explodedProductValues.isEmpty()) {
        // fallback
        return initialLookupValues;
    }
    return LookupValuesList.fromCollection(explodedProductValues);
}
Also used : Group(de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group) ArrayList(java.util.ArrayList) ITranslatableString(de.metas.i18n.ITranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 4 with LookupValue

use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.

the class DocumentField method getValueAsJsonObject.

@Override
public Object getValueAsJsonObject(final String adLanguage) {
    Object value = getValue();
    if (value == null) {
        return null;
    }
    // 
    // If we are dealing with a lookup value, make, sure it's translated (see https://github.com/metasfresh/metasfresh-webui-api/issues/311 )
    final LookupDataSource lookupDataSource = getLookupDataSourceOrNull();
    if (lookupDataSource != null && value instanceof LookupValue) {
        final LookupValue lookupValue = (LookupValue) value;
        final ITranslatableString displayNameTrl = lookupValue.getDisplayNameTrl();
        if (!displayNameTrl.isTranslatedTo(adLanguage)) {
            final LookupValue lookupValueNew = lookupDataSource.findById(lookupValue.getId());
            value = lookupValueNew;
        }
    }
    return Values.valueToJsonObject(value);
}
Also used : LookupDataSource(de.metas.ui.web.window.model.lookup.LookupDataSource) ITranslatableString(de.metas.i18n.ITranslatableString) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 5 with LookupValue

use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.

the class ADProcessParametersRepository method createProcessInfoParameter.

private static ProcessInfoParameter createProcessInfoParameter(final IDocumentFieldView field) {
    final String parameterName = field.getFieldName();
    final Object fieldValue = field.getValue();
    final Object parameter;
    final String info;
    final Object parameterTo;
    final String infoTo;
    if (fieldValue instanceof LookupValue) {
        final LookupValue lookupValue = (LookupValue) fieldValue;
        parameter = lookupValue.getId();
        info = lookupValue.getDisplayName();
        parameterTo = null;
        infoTo = null;
    } else if (fieldValue instanceof DateRangeValue) {
        final DateRangeValue dateRange = (DateRangeValue) fieldValue;
        parameter = dateRange.getFrom();
        info = parameter == null ? null : parameter.toString();
        parameterTo = dateRange.getTo();
        infoTo = parameterTo == null ? null : parameterTo.toString();
    } else if (fieldValue instanceof Password) {
        final Password password = Password.cast(fieldValue);
        parameter = password.getAsString();
        info = Password.OBFUSCATE_STRING;
        parameterTo = null;
        infoTo = null;
    } else {
        parameter = fieldValue;
        info = fieldValue == null ? null : fieldValue.toString();
        parameterTo = null;
        infoTo = null;
    }
    return new ProcessInfoParameter(parameterName, parameter, parameterTo, info, infoTo);
}
Also used : DateRangeValue(de.metas.ui.web.window.datatypes.DateRangeValue) ProcessInfoParameter(de.metas.process.ProcessInfoParameter) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) Password(de.metas.ui.web.window.datatypes.Password)

Aggregations

LookupValue (de.metas.ui.web.window.datatypes.LookupValue)31 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)25 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)7 JSONLookupValue (de.metas.ui.web.window.datatypes.json.JSONLookupValue)6 ITranslatableString (de.metas.i18n.ITranslatableString)5 AdempiereException (org.adempiere.exceptions.AdempiereException)4 Map (java.util.Map)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 IHUOrderBL (de.metas.handlingunits.order.api.IHUOrderBL)2 NumberTranslatableString (de.metas.i18n.NumberTranslatableString)2 BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)2 ProcessInfoParameter (de.metas.process.ProcessInfoParameter)2 QuickInput (de.metas.ui.web.quickinput.QuickInput)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)2 Password (de.metas.ui.web.window.datatypes.Password)2 JSONDate (de.metas.ui.web.window.datatypes.json.JSONDate)2 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)2 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)2