Search in sources :

Example 26 with LookupValue

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());
}
Also used : I_C_Postal(de.metas.adempiere.model.I_C_Postal) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 27 with LookupValue

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);
    }
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ITranslatableString(de.metas.i18n.ITranslatableString) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 28 with LookupValue

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;
}
Also used : ProcessInfoParameter(de.metas.process.ProcessInfoParameter) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) LookupValueByIdSupplier(de.metas.ui.web.window.model.lookup.LookupValueByIdSupplier) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 29 with LookupValue

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();
}
Also used : LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 30 with LookupValue

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);
}
Also used : I_M_Product(org.compiere.model.I_M_Product) QuickInput(de.metas.ui.web.quickinput.QuickInput) IHUOrderBL(de.metas.handlingunits.order.api.IHUOrderBL) I_M_Forecast(org.compiere.model.I_M_Forecast) ProductAndAttributes(de.metas.ui.web.window.descriptor.sql.ProductLookupDescriptor.ProductAndAttributes) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

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