Search in sources :

Example 6 with LookupDescriptor

use of de.metas.ui.web.window.descriptor.LookupDescriptor in project metasfresh-webui-api by metasfresh.

the class GridTabVOBasedDocumentEntityDescriptorFactory method createLabelsLookup.

private static final LabelsLookup createLabelsLookup(final I_AD_UI_Element labelsUIElement, final String tableName) {
    final I_AD_Tab labelsTab = labelsUIElement.getLabels_Tab();
    final String labelsTableName = labelsTab.getAD_Table().getTableName();
    final String linkColumnName;
    if (labelsTab.getParent_Column_ID() > 0) {
        linkColumnName = labelsTab.getParent_Column().getColumnName();
    } else {
        linkColumnName = InterfaceWrapperHelper.getKeyColumnName(tableName);
    }
    final String labelsLinkColumnName;
    if (labelsTab.getAD_Column_ID() > 0) {
        labelsLinkColumnName = labelsTab.getAD_Column().getColumnName();
    } else {
        labelsLinkColumnName = linkColumnName;
    }
    final I_AD_Column labelsValueColumn = labelsUIElement.getLabels_Selector_Field().getAD_Column();
    final String labelsValueColumnName = labelsValueColumn.getColumnName();
    final LookupDescriptor labelsValuesLookupDescriptor = SqlLookupDescriptor.builder().setCtxTableName(labelsTableName).setCtxColumnName(labelsValueColumnName).setDisplayType(labelsValueColumn.getAD_Reference_ID()).setWidgetType(DescriptorsFactoryHelper.extractWidgetType(labelsValueColumnName, labelsValueColumn.getAD_Reference_ID())).setAD_Reference_Value_ID(labelsValueColumn.getAD_Reference_Value_ID()).setAD_Val_Rule_ID(labelsValueColumn.getAD_Val_Rule_ID()).buildForDefaultScope();
    return LabelsLookup.builder().labelsTableName(labelsTableName).labelsValueColumnName(labelsValueColumnName).labelsValuesLookupDescriptor(labelsValuesLookupDescriptor).labelsLinkColumnName(labelsLinkColumnName).tableName(tableName).linkColumnName(linkColumnName).build();
}
Also used : I_AD_Tab(org.compiere.model.I_AD_Tab) I_AD_Column(org.compiere.model.I_AD_Column) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 7 with LookupDescriptor

use of de.metas.ui.web.window.descriptor.LookupDescriptor in project metasfresh-webui-api by metasfresh.

the class BoardDescriptorRepository method createBoardCardFieldDescriptor.

private final BoardCardFieldDescriptor createBoardCardFieldDescriptor(final I_WEBUI_Board_CardField cardFieldPO, final DocumentEntityDescriptor documentEntityDescriptor) {
    // TODO: might be not so performant, we just need the ColumnName
    final String fieldName = cardFieldPO.getAD_Column().getColumnName();
    final DocumentFieldDescriptor documentField = documentEntityDescriptor.getField(fieldName);
    final SqlDocumentFieldDataBindingDescriptor fieldBinding = documentField.getDataBindingNotNull(SqlDocumentFieldDataBindingDescriptor.class);
    final DocumentFieldWidgetType widgetType = documentField.getWidgetType();
    final boolean isDisplayColumnAvailable = fieldBinding.isUsingDisplayColumn();
    final ImmutableSet<String> sqlSelectValues;
    final BoardFieldLoader fieldLoader;
    if (widgetType == DocumentFieldWidgetType.Amount && documentEntityDescriptor.hasField(WindowConstants.FIELDNAME_C_Currency_ID)) {
        sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue(), WindowConstants.FIELDNAME_C_Currency_ID);
        fieldLoader = (rs, adLanguage) -> {
            final BigDecimal valueBD = rs.getBigDecimal(fieldBinding.getColumnName());
            if (valueBD == null) {
                return null;
            }
            final int currencyId = rs.getInt(WindowConstants.FIELDNAME_C_Currency_ID);
            final String currencyCode = Services.get(ICurrencyDAO.class).getISO_Code(Env.getCtx(), currencyId);
            if (currencyCode == null) {
                return valueBD;
            }
            return Amount.of(valueBD, currencyCode);
        };
    } else {
        sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue());
        final DocumentFieldValueLoader documentFieldValueLoader = fieldBinding.getDocumentFieldValueLoader();
        final LookupDescriptor lookupDescriptor = documentField.getLookupDescriptor(LookupScope.DocumentField);
        fieldLoader = (rs, adLanguage) -> documentFieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage, lookupDescriptor);
    }
    return BoardCardFieldDescriptor.builder().caption(documentField.getCaption()).fieldName(fieldBinding.getColumnName()).widgetType(widgetType).sqlSelectValues(sqlSelectValues).usingDisplayColumn(isDisplayColumnAvailable).sqlSelectDisplayValue(fieldBinding.getSqlSelectDisplayValue()).sqlOrderBy(fieldBinding.getSqlOrderBy()).fieldLoader(fieldLoader).build();
}
Also used : ICurrencyDAO(de.metas.currency.ICurrencyDAO) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) BoardFieldLoader(de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) DocumentFieldValueLoader(de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) DateTimeTranslatableString(de.metas.i18n.DateTimeTranslatableString) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) BigDecimal(java.math.BigDecimal)

Example 8 with LookupDescriptor

use of de.metas.ui.web.window.descriptor.LookupDescriptor in project metasfresh-webui-api by metasfresh.

the class WebuiProcessClassInfo method createParamLookupValuesProvider.

// 
// 
// ----
// 
// 
/**
 * @return parameterName and provider
 */
private static Map.Entry<String, LookupDescriptorProvider> createParamLookupValuesProvider(final Method method) {
    final ProcessParamLookupValuesProvider ann = method.getAnnotation(ProcessParamLookupValuesProvider.class);
    if (!LookupValuesList.class.isAssignableFrom(method.getReturnType())) {
        throw new AdempiereException("Method's return type shall be " + LookupValuesList.class + ": " + method);
    }
    final ImmutableList<Function<LookupDataSourceContext, Object>> parameterValueProviders = Stream.of(method.getParameterTypes()).map(parameterType -> {
        final Function<LookupDataSourceContext, Object> parameterValueProvider;
        if (LookupDataSourceContext.class.isAssignableFrom(parameterType)) {
            parameterValueProvider = evalCtx -> evalCtx;
        } else {
            throw new AdempiereException("Parameter " + parameterType + " not supported for " + method);
        }
        return parameterValueProvider;
    }).collect(ImmutableList.toImmutableList());
    // FIXME: holding a hard reference to method may introduce ClassLoader memory leaks
    final Method methodToInvoke = method;
    final LookupDescriptor lookupDescriptor = ListLookupDescriptor.builder().setLookupTableName(ann.lookupTableName()).setDependsOnFieldNames(ann.dependsOn()).setLookupSourceType(ann.lookupSource()).setLookupValues(ann.numericKey(), evalCtx -> retriveLookupValues(methodToInvoke, parameterValueProviders, evalCtx)).build();
    final LookupDescriptorProvider lookupDescriptorProvider = LookupDescriptorProvider.singleton(lookupDescriptor);
    return GuavaCollectors.entry(ann.parameterName(), lookupDescriptorProvider);
}
Also used : LogManager(de.metas.logging.LogManager) LoadingCache(com.google.common.cache.LoadingCache) GuavaCollectors(org.adempiere.util.GuavaCollectors) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) Function(java.util.function.Function) ProcessClassInfo(de.metas.process.ProcessClassInfo) ListLookupDescriptor(de.metas.ui.web.window.descriptor.ListLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) PanelLayoutType(de.metas.ui.web.window.datatypes.PanelLayoutType) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) LookupDataSourceContext(de.metas.ui.web.window.model.lookup.LookupDataSourceContext) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) MoreObjects(com.google.common.base.MoreObjects) JavaProcess(de.metas.process.JavaProcess) InvocationTargetException(java.lang.reflect.InvocationTargetException) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) Stream(java.util.stream.Stream) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) ProcessParamLookupValuesProvider(de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider) ReflectionUtils(org.reflections.ReflectionUtils) CacheBuilder(com.google.common.cache.CacheBuilder) LookupDataSourceContext(de.metas.ui.web.window.model.lookup.LookupDataSourceContext) Function(java.util.function.Function) ProcessParamLookupValuesProvider(de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider) AdempiereException(org.adempiere.exceptions.AdempiereException) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) Method(java.lang.reflect.Method) ListLookupDescriptor(de.metas.ui.web.window.descriptor.ListLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider)

Example 9 with LookupDescriptor

use of de.metas.ui.web.window.descriptor.LookupDescriptor in project metasfresh-webui-api by metasfresh.

the class ASIDescriptorFactory method createDocumentFieldDescriptor.

private DocumentFieldDescriptor.Builder createDocumentFieldDescriptor(final I_M_Attribute attribute) {
    final int attributeId = attribute.getM_Attribute_ID();
    final String fieldName = attribute.getValue();
    final String attributeValueType = attribute.getAttributeValueType();
    final Class<?> valueClass;
    final DocumentFieldWidgetType widgetType;
    final Function<I_M_AttributeInstance, Object> readMethod;
    final BiConsumer<I_M_AttributeInstance, IDocumentFieldView> writeMethod;
    LookupDescriptor lookupDescriptor = null;
    if (X_M_Attribute.ATTRIBUTEVALUETYPE_Date.equals(attributeValueType)) {
        valueClass = java.util.Date.class;
        widgetType = DocumentFieldWidgetType.Date;
        readMethod = I_M_AttributeInstance::getValueDate;
        writeMethod = (aiRecord, field) -> aiRecord.setValueDate(TimeUtil.asTimestamp(field.getValueAs(java.util.Date.class)));
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
        valueClass = StringLookupValue.class;
        widgetType = DocumentFieldWidgetType.List;
        readMethod = I_M_AttributeInstance::getValue;
        writeMethod = ASIAttributeFieldBinding::writeValueFromLookup;
        lookupDescriptor = getLookupDescriptor(attribute);
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
        valueClass = BigDecimal.class;
        widgetType = DocumentFieldWidgetType.Number;
        readMethod = I_M_AttributeInstance::getValueNumber;
        writeMethod = (aiRecord, field) -> aiRecord.setValueNumber(field.getValueAs(BigDecimal.class));
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_StringMax40.equals(attributeValueType)) {
        valueClass = String.class;
        widgetType = DocumentFieldWidgetType.Text;
        readMethod = I_M_AttributeInstance::getValue;
        writeMethod = (aiRecord, field) -> aiRecord.setValue(field.getValueAs(String.class));
    } else {
        throw new IllegalArgumentException("@NotSupported@ @AttributeValueType@=" + attributeValueType + ", @M_Attribute_ID@=" + attribute);
    }
    final ILogicExpression readonlyLogic = ConstantLogicExpression.FALSE;
    final ILogicExpression displayLogic = ConstantLogicExpression.TRUE;
    final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(attribute.isMandatory());
    final Optional<IExpression<?>> defaultValueExpr = Optional.empty();
    return DocumentFieldDescriptor.builder(fieldName).setCaption(attribute.getName()).setDescription(attribute.getDescription()).setValueClass(valueClass).setWidgetType(widgetType).setLookupDescriptorProvider(lookupDescriptor).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField).setDataBinding(new ASIAttributeFieldBinding(attributeId, fieldName, attribute.isMandatory(), readMethod, writeMethod));
}
Also used : X_M_Attribute(org.compiere.model.X_M_Attribute) ArrayKey(org.compiere.util.Util.ArrayKey) CCache(org.compiere.util.CCache) IExpression(org.adempiere.ad.expression.api.IExpression) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) TimeUtil(org.compiere.util.TimeUtil) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) Function(java.util.function.Function) DocumentLayoutElementDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor) BigDecimal(java.math.BigDecimal) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) I_M_AttributeSet(org.compiere.model.I_M_AttributeSet) Characteristic(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) BiConsumer(java.util.function.BiConsumer) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) I_M_Attribute(org.compiere.model.I_M_Attribute) DocumentsRepository(de.metas.ui.web.window.model.DocumentsRepository) ConstantLogicExpression(org.adempiere.ad.expression.api.ConstantLogicExpression) DocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor) MAttribute(org.compiere.model.MAttribute) ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) DocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor) DocumentLayoutElementFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor) List(java.util.List) Component(org.springframework.stereotype.Component) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) DocumentEntityDataBindingDescriptorBuilder(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) Optional(java.util.Optional) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) I_M_AttributeSetInstance(org.compiere.model.I_M_AttributeSetInstance) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) IExpression(org.adempiere.ad.expression.api.IExpression) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 10 with LookupDescriptor

use of de.metas.ui.web.window.descriptor.LookupDescriptor in project metasfresh-webui-api by metasfresh.

the class UserQueryDocumentFilterDescriptorsProvider method createFilterDescriptor0.

private static final DocumentFilterDescriptor createFilterDescriptor0(@NonNull final IUserQuery userQuery) {
    final DocumentFilterDescriptor.Builder filter = DocumentFilterDescriptor.builder().setFilterId("userquery-" + userQuery.getId()).setDisplayName(userQuery.getCaption()).setFrequentUsed(false);
    if (WindowConstants.isProtocolDebugging()) {
        filter.putDebugProperty("userQuery", userQuery.toString());
    }
    for (final IUserQueryRestriction queryRestriction : userQuery.getRestrictions()) {
        final Join join = queryRestriction.getJoin();
        final UserQueryField searchField = UserQueryField.cast(queryRestriction.getSearchField());
        final String fieldName = searchField.getColumnName();
        final Operator operator = MQueryDocumentFilterHelper.fromMQueryOperator(queryRestriction.getOperator());
        final Object value = queryRestriction.getValue();
        final Object valueTo = queryRestriction.getValueTo();
        final boolean isParameter;
        if (operator.isRangeOperator()) {
            isParameter = value == null || valueTo == null;
        } else {
            isParameter = value == null;
        }
        if (isParameter) {
            final ITranslatableString displayName = searchField.getDisplayName();
            final DocumentFieldWidgetType widgetType = searchField.getWidgetType();
            final LookupDescriptor lookupDescriptor = searchField.getLookupDescriptor();
            filter.addParameter(DocumentFilterParamDescriptor.builder().setJoinAnd(join == Join.AND).setDisplayName(displayName).setFieldName(fieldName).setWidgetType(widgetType).setOperator(operator).setDefaultValue(value).setDefaultValueTo(valueTo).setMandatory(// mandatory if there is no default value
            value == null).setLookupDescriptor(lookupDescriptor));
        } else {
            filter.addInternalParameter(DocumentFilterParam.builder().setJoinAnd(join == Join.AND).setFieldName(fieldName).setOperator(operator).setValue(value).setValueTo(valueTo).build());
        }
    }
    return filter.build();
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ITranslatableString(de.metas.i18n.ITranslatableString) Join(org.compiere.apps.search.IUserQueryRestriction.Join) IUserQueryField(org.compiere.apps.search.IUserQueryField) ITranslatableString(de.metas.i18n.ITranslatableString) IUserQueryRestriction(org.compiere.apps.search.IUserQueryRestriction) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Aggregations

LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)10 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)6 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)6 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)4 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)4 ITranslatableString (de.metas.i18n.ITranslatableString)3 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)3 Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)2 ActionType (de.metas.ui.web.handlingunits.process.WebuiHUTransformCommand.ActionType)2 LookupDataSource (de.metas.ui.web.window.model.lookup.LookupDataSource)2 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 Function (java.util.function.Function)2 IExpression (org.adempiere.ad.expression.api.IExpression)2 ILogicExpression (org.adempiere.ad.expression.api.ILogicExpression)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MoreObjects (com.google.common.base.MoreObjects)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1