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);
}
Aggregations