Search in sources :

Example 1 with DescriptiveConsumer

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());
}
Also used : StockTransactionProcessor(eu.ggnet.dwoss.stock.ee.StockTransactionProcessor) DescriptiveConsumer(eu.ggnet.saft.core.ops.DescriptiveConsumer) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) Ui(eu.ggnet.saft.Ui) Collectors(java.util.stream.Collectors) Dl(eu.ggnet.saft.Dl) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) Guardian(eu.ggnet.saft.core.auth.Guardian) List(java.util.List) ReplyUtil(eu.ggnet.dwoss.common.ReplyUtil) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) DescriptiveConsumerFactory(eu.ggnet.saft.core.ops.DescriptiveConsumerFactory) CREATE_TRANSACTION_FOR_SINGLE_UNIT(eu.ggnet.dwoss.rights.api.AtomicRight.CREATE_TRANSACTION_FOR_SINGLE_UNIT) Collections(java.util.Collections) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) Guardian(eu.ggnet.saft.core.auth.Guardian) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 2 with DescriptiveConsumer

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;
}
Also used : DescriptiveConsumer(eu.ggnet.saft.core.ops.DescriptiveConsumer) DescriptiveConsumerRunner(eu.ggnet.saft.core.ops.DescriptiveConsumerRunner)

Example 3 with DescriptiveConsumer

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);
}
Also used : DescriptiveConsumer(eu.ggnet.saft.core.ops.DescriptiveConsumer) DefaultAction(eu.ggnet.saft.api.ops.DefaultAction)

Aggregations

DescriptiveConsumer (eu.ggnet.saft.core.ops.DescriptiveConsumer)3 ReplyUtil (eu.ggnet.dwoss.common.ReplyUtil)1 CREATE_TRANSACTION_FOR_SINGLE_UNIT (eu.ggnet.dwoss.rights.api.AtomicRight.CREATE_TRANSACTION_FOR_SINGLE_UNIT)1 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)1 StockTransactionProcessor (eu.ggnet.dwoss.stock.ee.StockTransactionProcessor)1 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)1 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)1 PicoUnit (eu.ggnet.dwoss.uniqueunit.api.PicoUnit)1 Dl (eu.ggnet.saft.Dl)1 Ui (eu.ggnet.saft.Ui)1 DefaultAction (eu.ggnet.saft.api.ops.DefaultAction)1 Guardian (eu.ggnet.saft.core.auth.Guardian)1 DescriptiveConsumerFactory (eu.ggnet.saft.core.ops.DescriptiveConsumerFactory)1 DescriptiveConsumerRunner (eu.ggnet.saft.core.ops.DescriptiveConsumerRunner)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1