use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class AddressPostalLookupDescriptor method getLookupValueFromLocation.
public IntegerLookupValue getLookupValueFromLocation(final I_C_Location locationRecord) {
final I_C_Postal postalRecord = locationRecord.getC_Postal();
if (postalRecord == null || postalRecord.getC_Postal_ID() <= 0) {
return null;
}
final LookupValue countryLookupValue = countryLookup.getLookupValueById(postalRecord.getC_Country_ID());
return buildPostalLookupValue(postalRecord.getC_Postal_ID(), postalRecord.getPostal(), postalRecord.getCity(), countryLookupValue.getDisplayNameTrl());
}
use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class AddressPostalLookupDescriptor method retrieveEntities.
@Override
public LookupValuesList retrieveEntities(final LookupDataSourceContext evalCtx) {
//
// Determine what we will filter
final String filter = evalCtx.getFilter();
String filterUC;
final int limit;
final int offset = evalCtx.getOffset(0);
if (filter == LookupDataSourceContext.FILTER_Any) {
// N/A
filterUC = "%";
limit = evalCtx.getLimit(Integer.MAX_VALUE);
} else if (Check.isEmpty(filter, true)) {
return LookupValuesList.EMPTY;
} else {
filterUC = filter.trim().toUpperCase();
if (!filterUC.startsWith("%")) {
filterUC = "%" + filterUC;
}
if (!filterUC.endsWith("%")) {
filterUC = filterUC + "%";
}
limit = evalCtx.getLimit(100);
}
final String sql = "SELECT " + "\n " + I_C_Postal.COLUMNNAME_C_Postal_ID + "\n, " + I_C_Postal.COLUMNNAME_Postal + "\n, " + I_C_Postal.COLUMNNAME_City + "\n, " + I_C_Postal.COLUMNNAME_C_Country_ID + "\n FROM " + I_C_Postal.Table_Name + "\n WHERE " + "\n " + I_C_Postal.COLUMNNAME_Postal + " ILIKE ?" + "\n OR " + I_C_Postal.COLUMNNAME_City + " ILIKE ?" + "\n ORDER BY " + I_C_Postal.COLUMNNAME_City + ", " + I_C_Postal.COLUMNNAME_Postal + ", " + I_C_Postal.COLUMNNAME_C_Postal_ID + "\n LIMIT ? OFFSET ?";
final Object[] sqlParams = new Object[] { filterUC, filterUC, limit, offset };
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, ITrx.TRXNAME_None);
DB.setParameters(pstmt, sqlParams);
rs = pstmt.executeQuery();
final List<LookupValue> lookupValues = new ArrayList<>();
while (rs.next()) {
final int postalId = rs.getInt(I_C_Postal.COLUMNNAME_C_Postal_ID);
final String postal = rs.getString(I_C_Postal.COLUMNNAME_Postal);
final String city = rs.getString(I_C_Postal.COLUMNNAME_City);
final int countryId = rs.getInt(I_C_Postal.COLUMNNAME_C_Country_ID);
final LookupValue countryLookupValue = countryLookup.getLookupValueById(countryId);
lookupValues.add(buildPostalLookupValue(postalId, postal, city, countryLookupValue.getDisplayNameTrl()));
}
return LookupValuesList.fromCollection(lookupValues);
} catch (final SQLException ex) {
throw new DBException(ex, sql, sqlParams);
} finally {
DB.close(rs, pstmt);
}
}
use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class ADProcessParametersRepository method extractParameterValue.
private static Object extractParameterValue(final Map<String, ProcessInfoParameter> processInfoParameters, final DocumentFieldDescriptor parameterDescriptor) {
final String fieldName = parameterDescriptor.getFieldName();
final ProcessInfoParameter processInfoParameter = processInfoParameters.get(fieldName);
if (processInfoParameter == null) {
return null;
}
final Object parameterValue = processInfoParameter.getParameter();
final String parameterDisplay = processInfoParameter.getInfo();
final Object parameterValueConv = parameterDescriptor.convertToValueClass(parameterValue, new LookupValueByIdSupplier() {
@Override
public DocumentZoomIntoInfo getDocumentZoomInto(final int id) {
throw new UnsupportedOperationException();
}
@Override
public LookupValue findById(final Object id) {
return LookupValue.fromObject(id, parameterDisplay);
}
});
return parameterValueConv;
}
use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause_LabelsWidget.
private final String buildSqlWhereClause_LabelsWidget(final DocumentFilterParam filterParam, final DocumentFilterParamDescriptor paramDescriptor, final SqlParamsCollector sqlParams, final SqlOptions sqlOpts) {
final LookupValuesList lookupValues = extractLookupValuesList(filterParam);
if (lookupValues.isEmpty()) {
return null;
}
final String tableAlias = sqlOpts.getTableNameOrAlias();
final LabelsLookup lookup = LabelsLookup.cast(paramDescriptor.getLookupDescriptor());
final String labelsTableName = lookup.getLabelsTableName();
final String labelsLinkColumnName = lookup.getLabelsLinkColumnName();
final String linkColumnName = lookup.getLinkColumnName();
final String labelsValueColumnName = lookup.getLabelsValueColumnName();
final StringBuilder sql = new StringBuilder();
for (final LookupValue lookupValue : lookupValues) {
if (sql.length() > 0) {
sql.append(" AND ");
}
final Object labelValue = lookup.isLabelsValuesUseNumericKey() ? lookupValue.getIdAsInt() : lookupValue.getIdAsString();
sql.append("EXISTS (SELECT 1 FROM " + labelsTableName + " labels " + " WHERE labels." + labelsLinkColumnName + "=" + tableAlias + "." + linkColumnName + " AND labels." + labelsValueColumnName + "=" + sqlParams.placeholder(labelValue) + ")");
}
return sql.toString();
}
use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class ForecastLineQuickInputDescriptorFactory method onProductChangedCallout.
private static void onProductChangedCallout(final ICalloutField calloutField) {
final QuickInput quickInput = QuickInput.getQuickInputOrNull(calloutField);
if (quickInput == null) {
return;
}
final IForecastLineQuickInput quickInputModel = quickInput.getQuickInputDocumentAs(IForecastLineQuickInput.class);
final LookupValue productLookupValue = quickInputModel.getM_Product_ID();
if (productLookupValue == null) {
return;
}
final ProductAndAttributes productAndAttributes = ProductLookupDescriptor.toProductAndAttributes(productLookupValue);
final I_M_Product quickInputProduct = load(productAndAttributes.getProductId(), I_M_Product.class);
final I_M_Forecast forecast = quickInput.getRootDocumentAs(I_M_Forecast.class);
Services.get(IHUOrderBL.class).findM_HU_PI_Item_ProductForForecast(forecast, quickInputProduct, quickInputModel::setM_HU_PI_Item_Product);
}
Aggregations