Search in sources :

Example 1 with LookupDataSourceContext

use of de.metas.ui.web.window.model.lookup.LookupDataSourceContext 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 LookupDataSourceContext

use of de.metas.ui.web.window.model.lookup.LookupDataSourceContext in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_Pick_ParametersFiller method getPickingSlotValues.

public LookupValuesList getPickingSlotValues(@NonNull final LookupDataSourceContext context) {
    if (shipmentScheduleId <= 0) {
        return LookupValuesList.EMPTY;
    }
    final IShipmentScheduleEffectiveBL shipmentScheduleEffectiveBL = Services.get(IShipmentScheduleEffectiveBL.class);
    final I_M_ShipmentSchedule shipmentSchedule = load(shipmentScheduleId, I_M_ShipmentSchedule.class);
    final PickingSlotQuery pickingSlotQuery = PickingSlotQuery.builder().availableForBPartnerId(shipmentScheduleEffectiveBL.getC_BP_Location_ID(shipmentSchedule)).availableForBPartnerLocationId(shipmentScheduleEffectiveBL.getC_BP_Location_ID(shipmentSchedule)).build();
    final List<I_M_PickingSlot> availablePickingSlots = Services.get(IPickingSlotDAO.class).retrievePickingSlots(pickingSlotQuery);
    return availablePickingSlots.stream().map(pickingSlot -> IntegerLookupValue.of(pickingSlot.getM_PickingSlot_ID(), createPickingSlotLabel(pickingSlot))).collect(LookupValuesList.collect());
}
Also used : IShipmentSchedulePA(de.metas.inoutcandidate.api.IShipmentSchedulePA) LookupDataSourceFactory(de.metas.ui.web.window.model.lookup.LookupDataSourceFactory) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) I_M_ShipmentSchedule(de.metas.inoutcandidate.model.I_M_ShipmentSchedule) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) DB(org.compiere.util.DB) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) ImmutableList(com.google.common.collect.ImmutableList) DisplayType(org.compiere.util.DisplayType) I_M_PickingSlot(de.metas.picking.model.I_M_PickingSlot) IPickingSlotDAO(de.metas.picking.api.IPickingSlotDAO) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) I_M_HU(de.metas.handlingunits.model.I_M_HU) IProcessDefaultParameter(de.metas.process.IProcessDefaultParameter) I_C_BPartner(org.compiere.model.I_C_BPartner) IShipmentScheduleEffectiveBL(de.metas.inoutcandidate.api.IShipmentScheduleEffectiveBL) LookupDataSource(de.metas.ui.web.window.model.lookup.LookupDataSource) LookupDataSourceContext(de.metas.ui.web.window.model.lookup.LookupDataSourceContext) NonNull(lombok.NonNull) IHUContextFactory(de.metas.handlingunits.IHUContextFactory) Services(org.adempiere.util.Services) List(java.util.List) Builder(lombok.Builder) AdempiereException(org.adempiere.exceptions.AdempiereException) IValidationRuleFactory(org.adempiere.ad.validationRule.IValidationRuleFactory) IProcessDefaultParametersProvider(de.metas.process.IProcessDefaultParametersProvider) InterfaceWrapperHelper.load(org.adempiere.model.InterfaceWrapperHelper.load) PickingSlotQuery(de.metas.picking.api.IPickingSlotDAO.PickingSlotQuery) IValidationRule(org.adempiere.ad.validationRule.IValidationRule) IHUProductStorage(de.metas.handlingunits.storage.IHUProductStorage) I_M_PickingSlot(de.metas.picking.model.I_M_PickingSlot) PickingSlotQuery(de.metas.picking.api.IPickingSlotDAO.PickingSlotQuery) IPickingSlotDAO(de.metas.picking.api.IPickingSlotDAO) IShipmentScheduleEffectiveBL(de.metas.inoutcandidate.api.IShipmentScheduleEffectiveBL) I_M_ShipmentSchedule(de.metas.inoutcandidate.model.I_M_ShipmentSchedule)

Example 3 with LookupDataSourceContext

use of de.metas.ui.web.window.model.lookup.LookupDataSourceContext in project metasfresh-webui-api by metasfresh.

the class WebuiProcessClassInfo method retriveLookupValues.

private static final LookupValuesList retriveLookupValues(final Method method, final List<Function<LookupDataSourceContext, Object>> parameterValueProviders, final LookupDataSourceContext evalCtx) {
    Check.assumeNotNull(method, "Parameter method is not null");
    final JavaProcess processClassInstance = JavaProcess.currentInstance();
    final Object[] methodParams = parameterValueProviders.stream().map(paramValueProvider -> paramValueProvider.apply(evalCtx)).toArray();
    try {
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        final LookupValuesList lookupValues = (LookupValuesList) method.invoke(processClassInstance, methodParams);
        return lookupValues;
    } catch (IllegalAccessException | InvocationTargetException e) {
        final Throwable cause = AdempiereException.extractCause(e);
        throw new AdempiereException("Failed invoking " + method + " using " + methodParams, cause);
    } catch (final Exception e) {
        throw AdempiereException.wrapIfNeeded(e);
    }
}
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) AdempiereException(org.adempiere.exceptions.AdempiereException) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AdempiereException(org.adempiere.exceptions.AdempiereException) JavaProcess(de.metas.process.JavaProcess)

Example 4 with LookupDataSourceContext

use of de.metas.ui.web.window.model.lookup.LookupDataSourceContext 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)4 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)4 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)4 LookupDataSourceContext (de.metas.ui.web.window.model.lookup.LookupDataSourceContext)4 List (java.util.List)4 Set (java.util.Set)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 Check (org.adempiere.util.Check)3 MoreObjects (com.google.common.base.MoreObjects)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 CacheLoader (com.google.common.cache.CacheLoader)2 LoadingCache (com.google.common.cache.LoadingCache)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 LogManager (de.metas.logging.LogManager)2 JavaProcess (de.metas.process.JavaProcess)2 ProcessClassInfo (de.metas.process.ProcessClassInfo)2 ProcessParamLookupValuesProvider (de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider)2 PanelLayoutType (de.metas.ui.web.window.datatypes.PanelLayoutType)2 ListLookupDescriptor (de.metas.ui.web.window.descriptor.ListLookupDescriptor)2 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)2