Search in sources :

Example 6 with UnitHistory

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

the class StockTransactionProcessorOperation method cancel.

/**
 * Cancels a stock transaction.
 * <p/>
 * @param transaction the transaction to cancel.
 * @param arranger    the arranger
 * @param comment     a comment to describe why
 * @throws UserInfoException if the transaction is not in state prepared.
 */
@Override
public void cancel(StockTransaction transaction, final String arranger, final String comment) throws UserInfoException {
    transaction = stockEm.find(StockTransaction.class, transaction.getId());
    if (transaction.getStatus().getType() != PREPARED) {
        throw new UserInfoException("Supplied transaction is not in state prepared, but " + transaction.getStatus() + ", cancel not allowed");
    }
    StockTransactionStatus status = new StockTransactionStatus(CANCELLED, new Date(), comment);
    status.addParticipation(new StockTransactionParticipation(ARRANGER, arranger));
    transaction.addStatus(status);
    for (StockUnit stockUnit : transaction.getUnits()) {
        history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Unit returned to Stock(" + transaction.getSource().getId() + ") " + transaction.getSource().getName() + ", cancelled Transaction(" + transaction.getId() + ")", arranger));
        L.info("cancelTransaction(): Returning {} to Stock {} ", stockUnit, transaction.getSource());
        stockUnit.setPosition(null);
    // Nothing to do because of special case prepared transaction, which allows the unit to be on transaction and on stock
    }
}
Also used : UnitHistory(eu.ggnet.dwoss.event.UnitHistory) UserInfoException(eu.ggnet.dwoss.util.UserInfoException)

Aggregations

UnitHistory (eu.ggnet.dwoss.event.UnitHistory)6 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Event (javax.enterprise.event.Event)3 Inject (javax.inject.Inject)3 EntityManager (javax.persistence.EntityManager)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)2 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)2 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)2 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)2 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)2 UNIT (eu.ggnet.dwoss.rules.PositionType.UNIT)2 javax.validation (javax.validation)2