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
}
}
Aggregations