Search in sources :

Example 1 with SalesChannel

use of eu.ggnet.dwoss.core.common.values.SalesChannel 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) {
    L.info("rollIn(transactions.ids={}) starting", detachtedTransactions.stream().map(StockTransaction::getId).collect(Collectors.toList()));
    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.applyDefaultChannelOnRollIn()) {
            SalesChannel channel = stockUnit.getStock().getPrimaryChannel();
            channelChanger.fire(new SalesChannelChange.Builder().uniqueUnitId(stockUnit.getUniqueUnitId()).newChannel(channel).build());
            history.fire(UnitHistory.create(stockUnit.getUniqueUnitId(), "Rolled in " + stockUnit.getStock().getName() + " with " + channel.description, arranger));
        } else {
            history.fire(UnitHistory.create(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.core.common.values.SalesChannel) java.util(java.util) UserInfoException(eu.ggnet.dwoss.core.common.UserInfoException) LoggerFactory(org.slf4j.LoggerFactory) eu.ggnet.dwoss.stock.ee.emo(eu.ggnet.dwoss.stock.ee.emo) Mandator(eu.ggnet.dwoss.mandator.api.value.Mandator) StockTransactionParticipationType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipationType) Stocks(eu.ggnet.dwoss.stock.ee.assist.Stocks) Inject(javax.inject.Inject) SubMonitor(eu.ggnet.dwoss.core.system.progress.SubMonitor) LocalBean(javax.ejb.LocalBean) UnitHistory(eu.ggnet.dwoss.uniqueunit.api.event.UnitHistory) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) SalesChannel(eu.ggnet.dwoss.core.common.values.SalesChannel) Event(javax.enterprise.event.Event) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) MonitorFactory(eu.ggnet.dwoss.core.system.progress.MonitorFactory) 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) SalesChannelChange(eu.ggnet.dwoss.uniqueunit.api.event.SalesChannelChange) StockTransactionStatusType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType) ValidationUtil(eu.ggnet.dwoss.core.system.util.ValidationUtil) javax.validation(javax.validation) SubMonitor(eu.ggnet.dwoss.core.system.progress.SubMonitor) StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)

Aggregations

UserInfoException (eu.ggnet.dwoss.core.common.UserInfoException)1 SalesChannel (eu.ggnet.dwoss.core.common.values.SalesChannel)1 MonitorFactory (eu.ggnet.dwoss.core.system.progress.MonitorFactory)1 SubMonitor (eu.ggnet.dwoss.core.system.progress.SubMonitor)1 ValidationUtil (eu.ggnet.dwoss.core.system.util.ValidationUtil)1 Mandator (eu.ggnet.dwoss.mandator.api.value.Mandator)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 SalesChannelChange (eu.ggnet.dwoss.uniqueunit.api.event.SalesChannelChange)1 UnitHistory (eu.ggnet.dwoss.uniqueunit.api.event.UnitHistory)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 LocalBean (javax.ejb.LocalBean)1 Stateless (javax.ejb.Stateless)1 Event (javax.enterprise.event.Event)1