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);
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations