use of eu.ggnet.saft.core.ops.DescriptiveConsumer in project dwoss by gg-net.
the class ConsumerFactoryOfStockTransactions method of.
@Override
public List<DescriptiveConsumer<PicoUnit>> of(PicoUnit t) {
StockAgent stockAgent = Dl.remote().lookup(StockAgent.class);
StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(t.uniqueUnitId);
if (su == null || su.isInTransaction())
return Collections.EMPTY_LIST;
Guardian guardian = Dl.local().lookup(Guardian.class);
if (!guardian.hasRight(CREATE_TRANSACTION_FOR_SINGLE_UNIT))
return Collections.EMPTY_LIST;
return stockAgent.findAll(Stock.class).stream().filter(s -> !s.equals(su.getStock())).map(destination -> {
return new DescriptiveConsumer<>("Umfuhr von " + su.getStock().getName() + " nach " + destination.getName(), (PicoUnit t1) -> {
Ui.exec(() -> {
Ui.build().dialog().eval(() -> new CreateQuestionModel(su, destination, "Umfuhr direkt durch Nutzer erzeugt"), () -> new CreateQuestionView()).opt().map(v -> ReplyUtil.wrap(() -> Dl.remote().lookup(StockTransactionProcessor.class).perpareTransfer(v.stockUnits, v.destination.getId(), Dl.local().lookup(Guardian.class).getUsername(), v.comment))).filter(Ui.failure()::handle).ifPresent(u -> Ui.build().alert("Umfuhr angelegt"));
});
});
}).collect(Collectors.toList());
}
use of eu.ggnet.saft.core.ops.DescriptiveConsumer in project dwoss by gg-net.
the class Ops method staticOf.
/**
* Returns all registered dependent actions for this instance as runners, or an empty list never null.
* <p>
* @param <T>
* @param t this instance as dependent reference
* @param enhancer an optional enhancer
* @return all registered dependent actions for this instance as runners, or an empty list never null.
*/
public static <T> List<DescriptiveConsumerRunner<?>> staticOf(T t, SelectionEnhancer<T> enhancer) {
Stream<DescriptiveConsumerRunner<T>> map = safeNull(REGISTERED_ACTIONS.get(t.getClass())).stream().map(d -> new DescriptiveConsumerRunner<T>(d, t));
List<DescriptiveConsumerRunner<?>> result = map.collect(Collectors.toList());
if (enhancer == null)
return result;
for (Object other : enhancer.enhance(t)) {
for (DescriptiveConsumer otherAction : safeNull(REGISTERED_ACTIONS.get(other.getClass()))) {
result.add(new DescriptiveConsumerRunner<>(otherAction, other));
}
}
return result;
}
use of eu.ggnet.saft.core.ops.DescriptiveConsumer in project dwoss by gg-net.
the class Ops method registerAction.
/**
* Register a Consumer as global action, possibly annotated for title and more.
* <p>
* @param <T> the type as key, what this action is for.
* @param consumer the consumer as action.
*/
public static <T> void registerAction(Consumer<T> consumer) {
Class clazz = extractSingleType(Consumer.class, consumer);
L.info("Registering action, key {} with {}", clazz, consumer);
DescriptiveConsumer descriptiveConsumer = new DescriptiveConsumer(consumer);
if (consumer.getClass().getAnnotation(DefaultAction.class) != null)
REGISTERED_DEFAULT_ACTIONS.put(clazz, descriptiveConsumer);
if (!REGISTERED_ACTIONS.containsKey(clazz))
REGISTERED_ACTIONS.put(clazz, new ArrayList<>());
REGISTERED_ACTIONS.get(clazz).add(descriptiveConsumer);
}
Aggregations