Search in sources :

Example 1 with SalesChannelChange

use of eu.ggnet.dwoss.event.SalesChannelChange in project dwoss by gg-net.

the class StockTransactionProcessorOperation method rollIn.

/**
 * Rolls all StockTransaction in, completing them and setting the Stock.
 *
 * @param detachtedTransactions the transactions
 * @param arranger              the arranger
 */
@Override
public List<Integer> rollIn(List<StockTransaction> detachtedTransactions, String arranger) {
    SubMonitor m = monitorFactory.newSubMonitor("RollIn", detachtedTransactions.size() * 2);
    StockTransactionEao stockTransactionEao = new StockTransactionEao(stockEm);
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
    List<StockTransaction> transactions = new ArrayList<>();
    m.message("loading Transactions");
    for (StockTransaction detachedTransaction : detachtedTransactions) {
        transactions.add(stockTransactionEao.findById(detachedTransaction.getId()));
        m.worked(1);
    }
    m.setWorkRemaining(3);
    m.message("rolling in");
    List<StockUnit> stockUnits = stockTransactionEmo.completeRollIn(arranger, transactions);
    m.worked(2, "adding History");
    for (StockUnit stockUnit : stockUnits) {
        if (mandator.isApplyDefaultChannelOnRollIn()) {
            SalesChannel channel = stockUnit.getStock().getPrimaryChannel();
            channelChanger.fire(new SalesChannelChange(stockUnit.getUniqueUnitId(), channel));
            history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName() + " with " + channel.getName(), arranger));
        } else {
            history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName(), arranger));
        }
    }
    m.finish();
    return stockUnits.stream().map(x -> x.getId()).collect(Collectors.toList());
}
Also used : SalesChannel(eu.ggnet.dwoss.rules.SalesChannel) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) java.util(java.util) UnitHistory(eu.ggnet.dwoss.event.UnitHistory) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LoggerFactory(org.slf4j.LoggerFactory) eu.ggnet.dwoss.stock.ee.emo(eu.ggnet.dwoss.stock.ee.emo) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) Mandator(eu.ggnet.dwoss.mandator.api.value.Mandator) ConstraintViolationFormater(eu.ggnet.dwoss.util.validation.ConstraintViolationFormater) StockTransactionParticipationType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipationType) Stocks(eu.ggnet.dwoss.stock.ee.assist.Stocks) Inject(javax.inject.Inject) SalesChannelChange(eu.ggnet.dwoss.event.SalesChannelChange) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) Event(javax.enterprise.event.Event) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) SalesChannel(eu.ggnet.dwoss.rules.SalesChannel) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) DateUtils(org.apache.commons.lang3.time.DateUtils) eu.ggnet.dwoss.stock.ee.entity(eu.ggnet.dwoss.stock.ee.entity) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) MonitorFactory(eu.ggnet.dwoss.progress.MonitorFactory) StockTransactionStatusType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType) javax.validation(javax.validation) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) SalesChannelChange(eu.ggnet.dwoss.event.SalesChannelChange) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)

Aggregations

SalesChannelChange (eu.ggnet.dwoss.event.SalesChannelChange)1 UnitHistory (eu.ggnet.dwoss.event.UnitHistory)1 Mandator (eu.ggnet.dwoss.mandator.api.value.Mandator)1 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)1 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)1 SalesChannel (eu.ggnet.dwoss.rules.SalesChannel)1 Stocks (eu.ggnet.dwoss.stock.ee.assist.Stocks)1 StockTransactionEao (eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)1 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)1 eu.ggnet.dwoss.stock.ee.emo (eu.ggnet.dwoss.stock.ee.emo)1 eu.ggnet.dwoss.stock.ee.entity (eu.ggnet.dwoss.stock.ee.entity)1 StockTransactionParticipationType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipationType)1 StockTransactionStatusType (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1 ConstraintViolationFormater (eu.ggnet.dwoss.util.validation.ConstraintViolationFormater)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stateless (javax.ejb.Stateless)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1