use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class StockTransactionEmoIT method testPrepare.
@Test
public void testPrepare() throws Exception {
List<Stock> stocks = gen.makeStocksAndLocations(2);
int transactionSize = 5;
utx.begin();
em.joinTransaction();
Stock s1 = em.find(Stock.class, stocks.get(0).getId());
for (int i = 1; i <= 15; i++) {
StockUnit su = new StockUnit(Integer.toString(i), i);
su.setStock(s1);
em.persist(su);
}
utx.commit();
utx.begin();
em.joinTransaction();
List<Integer> units = new StockUnitEao(em).findAll().stream().map(StockUnit::getId).collect(Collectors.toList());
assertEquals("Assert 15 persisted Stockunits", 15, units.size());
// prepare
new StockTransactionEmo(em).prepare(Transfer.builder().destinationStockId(stocks.get(1).getId()).stockUnitIds(units).arranger("UnitTest").comment("Test prepare").maxTransactionSize(transactionSize).build(), null);
utx.commit();
utx.begin();
em.joinTransaction();
StockTransactionEao stEao = new StockTransactionEao(em);
List<StockTransaction> findByDestination = stEao.findAll();
assertEquals("Assert three transactions", 3, findByDestination.size());
for (StockTransaction transaction : findByDestination) {
List<StockTransactionPosition> positions = transaction.getPositions();
assertEquals("Assert five posititons", 5, positions.size());
}
utx.commit();
}
use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class StockTransactionEmoIT method testCompleteRollInRollOut.
@Test
public void testCompleteRollInRollOut() throws Exception {
List<Stock> stocks = gen.makeStocksAndLocations(2);
StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(em);
utx.begin();
em.joinTransaction();
StockTransaction st1 = stockTransactionEmo.requestRollInPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
st1.addUnit(new StockUnit("1", 1));
st1.addUnit(new StockUnit("2", 2));
st1.addUnit(new StockUnit("3", 3));
st1.addUnit(new StockUnit("4", 4));
st1.addUnit(new StockUnit("5", 5));
st1.addUnit(new StockUnit("6", 6));
st1.addUnit(new StockUnit("7", 7));
st1.addUnit(new StockUnit("8", 8));
st1.addUnit(new StockUnit("9", 9));
List<StockUnit> units = stockTransactionEmo.completeRollIn("Hans", Arrays.asList(st1));
assertEquals(COMPLETED, st1.getStatus().getType());
assertNotNull(units);
assertEquals(st1.getPositions().size(), units.size());
for (StockUnit stockUnit : units) {
assertTrue(stockUnit.isInStock());
assertFalse(stockUnit.isInTransaction());
assertEquals(stocks.get(0), stockUnit.getStock());
}
utx.commit();
StockUnitEao stockUnitEao = new StockUnitEao(em);
utx.begin();
em.joinTransaction();
st1 = stockTransactionEmo.requestRollOutPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
for (StockUnit stockUnit : stockUnitEao.findAll()) {
st1.addUnit(stockUnit);
}
assertEquals(units.size(), st1.getPositions().size());
utx.commit();
utx.begin();
em.joinTransaction();
st1 = em.merge(st1);
List<Integer> uids = stockTransactionEmo.completeRollOut("Horst", Arrays.asList(st1));
assertNotNull(uids);
assertEquals(units.size(), uids.size());
utx.commit();
utx.begin();
em.joinTransaction();
List<StockUnit> stockUnits = stockUnitEao.findAll();
assertTrue(stockUnits.isEmpty());
utx.commit();
}
use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class StockTransactionProcessorOperation method removeFromPreparedTransaction.
/**
* Remove the stockUnit represented by the refurbishId from a stock transaction, if that transaction exists and is in state prepared.
* <p/>
* @param refurbishId the refurbishId
* @param arranger the arranger
* @param comment a optional comment
* @throws UserInfoException if no unit exists, the unit is not on a transaction or the transaction has another state then prepared.
*/
@Override
public void removeFromPreparedTransaction(final String refurbishId, final String arranger, final String comment) throws UserInfoException {
StockUnit stockUnit = new StockUnitEao(stockEm).findByRefurbishId(refurbishId);
if (stockUnit == null)
throw new UserInfoException("SopoNr: " + refurbishId + " existiert nicht.");
if (!stockUnit.isInTransaction())
throw new UserInfoException("SopoNr: " + refurbishId + " nicht in Transaction.");
StockTransaction transaction = stockUnit.getTransaction();
if (transaction.getStatus().getType() != PREPARED) {
throw new UserInfoException("SopoNr: " + refurbishId + " auf Transaction, aber Transaction(" + transaction.getId() + ") not in Status prepared");
}
// The one case we remove the position as well, but dont need to set the stock because of beeing in status prepared
StockTransactionPosition position = stockUnit.getPosition();
stockEm.remove(position);
transaction.setComment(transaction.getComment() + ", Unit " + stockUnit.getRefurbishId() + " removed by " + arranger + ", cause=" + comment);
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), "Unit returned to Stock(" + transaction.getSource().getId() + ") " + transaction.getSource().getName() + ", removed from Transaction, cause: " + comment, arranger));
L.info("{} removed from {}", stockUnit, transaction);
}
use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.
the class RedTapeUpdateRepaymentWorkflow method rollInMissingStockUnits.
/**
* If referenced Units are not in Stock, roll them in and append them to the instance variable (stockUnits).
*
* @return the list of rolled in StockUnits
*/
List<StockUnit> rollInMissingStockUnits(String dossierIdentifier, Collection<Position> positions, int destinationId) {
List<UniqueUnit> uniqueUnits = new ArrayList<>();
StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uniqueUnitEm);
for (Position position : positions) {
if (stockUnitEao.findByUniqueUnitId(position.getUniqueUnitId()) == null) {
uniqueUnits.add(uniqueUnitEao.findById(position.getUniqueUnitId()));
}
}
if (uniqueUnits.isEmpty())
return Collections.EMPTY_LIST;
StockTransactionEmo transactionEmo = new StockTransactionEmo(stockEm);
StockTransaction rollInTransaction = transactionEmo.requestRollInPrepared(destinationId, arranger, "RollIn durch Gutschrift " + dossierIdentifier);
for (UniqueUnit uu : uniqueUnits) {
StockUnit stockUnit = new StockUnit(uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID), uu.getProduct().getName(), uu.getId());
rollInTransaction.addUnit(stockUnit);
stockEm.persist(stockUnit);
}
List<StockUnit> rolledInUnits = transactionEmo.completeRollIn(arranger, Arrays.asList(rollInTransaction));
L.info("Missing Units rolled In: {}", toIds(rolledInUnits));
return rolledInUnits;
}
Aggregations