Search in sources :

Example 1 with ProcessParamLookupValuesProvider

use of de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider in project metasfresh-webui-api by metasfresh.

the class WEBUI_Picking_PickQtyToNewHU method getM_HU_PI_Item_Products.

/**
 * @return a list of PI item products that match the selected shipment schedule's product and partner, sorted by name.
 */
@ProcessParamLookupValuesProvider(parameterName = PARAM_M_HU_PI_Item_Product_ID, dependsOn = {}, numericKey = true, lookupTableName = I_M_HU_PI_Item_Product.Table_Name)
private LookupValuesList getM_HU_PI_Item_Products() {
    final Properties ctx = getCtx();
    // can't be null
    final I_M_ShipmentSchedule shipmentSchedule = getView().getCurrentShipmentSchedule();
    return WEBUI_ProcessHelper.retrieveHUPIItemProducts(ctx, shipmentSchedule.getM_Product(), shipmentSchedule.getC_BPartner(), // includeVirtualItem = true..similar case as with production
    true);
}
Also used : I_M_ShipmentSchedule(de.metas.handlingunits.model.I_M_ShipmentSchedule) Properties(java.util.Properties) ProcessParamLookupValuesProvider(de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider)

Example 2 with ProcessParamLookupValuesProvider

use of de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider 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

ProcessParamLookupValuesProvider (de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider)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 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 I_M_ShipmentSchedule (de.metas.handlingunits.model.I_M_ShipmentSchedule)1 LogManager (de.metas.logging.LogManager)1 JavaProcess (de.metas.process.JavaProcess)1 ProcessClassInfo (de.metas.process.ProcessClassInfo)1 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)1 PanelLayoutType (de.metas.ui.web.window.datatypes.PanelLayoutType)1 ListLookupDescriptor (de.metas.ui.web.window.descriptor.ListLookupDescriptor)1 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)1 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)1 LookupDataSourceContext (de.metas.ui.web.window.model.lookup.LookupDataSourceContext)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 List (java.util.List)1