Search in sources :

Example 6 with LookupDescriptorProvider

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

LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)6 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)5 ImmutableList (com.google.common.collect.ImmutableList)3 LogManager (de.metas.logging.LogManager)3 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)3 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)3 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 Logger (org.slf4j.Logger)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 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)2 JavaProcess (de.metas.process.JavaProcess)2 ProcessClassInfo (de.metas.process.ProcessClassInfo)2