use of eu.ggnet.dwoss.stock.ee.emo.StockLocationDiscoverer in project dwoss by gg-net.
the class UnitProcessorOperation method transfer.
/**
* Transfers a UniqueUnits StockUnit to the supplied Stock.
* <p>
* <ul>
* <li>Validate, if a StockUnit for the UniqueUnit exists, and this StockUnit is in Stock</li>
* <li>Transfer StockUnit via {@link StockTransactionType#EXTERNAL_TRANSFER}</li>
* <li>Update the SopoUnit</li>
* </ul>
* <p/>
* @param uniqueUnit the uniqueUnit
* @param stockId the stockId
* @param arranger
* @return
*/
// TODO: Use StockTransactionEmo.resquestExternalTransfer and completeExternalTransfer
@Override
public UniqueUnit transfer(UniqueUnit uniqueUnit, int stockId, String arranger) {
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
if (stockUnit == null)
throw new IllegalArgumentException("No StockUnit for " + uniqueUnit);
if (stockUnit.isInTransaction())
throw new IllegalArgumentException(stockUnit + " is on Transaction");
Stock destination = new DefaultEao<>(Stock.class, stockEm).findById(stockId);
StockTransaction st = new StockTransaction(StockTransactionType.EXTERNAL_TRANSFER);
StockTransactionStatus status = new StockTransactionStatus(StockTransactionStatusType.COMPLETED, new Date());
status.addParticipation(new StockTransactionParticipation(StockTransactionParticipationType.ARRANGER, arranger));
st.addStatus(status);
st.setSource(stockUnit.getStock());
st.setDestination(destination);
st.addPosition(new StockTransactionPosition(stockUnit));
stockEm.persist(st);
stockUnit.setPosition(null);
new StockLocationDiscoverer(stockEm).discoverAndSetLocation(stockUnit, destination);
uniqueUnit = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
uniqueUnit.addHistory("External Stock change from " + stockUnit.getStock() + " to " + destination + " by " + arranger);
uniqueUnit.fetchEager();
return uniqueUnit;
}
use of eu.ggnet.dwoss.stock.ee.emo.StockLocationDiscoverer in project dwoss by gg-net.
the class SupportBean method changeStock.
public StockUnit changeStock(int uniqueUnitId, int target) {
StockUnit stockUnit1 = stockUnitEao.findByUniqueUnitId(uniqueUnitId);
StockLocationDiscoverer discoverer = new StockLocationDiscoverer(stockEm);
Stock notDestination = stockEm.find(Stock.class, target);
discoverer.discoverAndSetLocation(stockUnit1, notDestination);
return stockUnit1;
}
Aggregations