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