use of eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo in project dwoss by gg-net.
the class StockTransactionEmoIT method testCompleteDestroy.
@Test
public void testCompleteDestroy() throws Exception {
List<Stock> stocks = gen.makeStocksAndLocations(2);
StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(em);
StockUnitEao stockUnitEao = new StockUnitEao(em);
utx.begin();
em.joinTransaction();
Stock s1 = em.find(Stock.class, stocks.get(0).getId());
for (int i = 1; i <= 10; i++) {
StockUnit su = new StockUnit(Integer.toString(i), i);
su.setStock(s1);
em.persist(su);
}
List<StockUnit> units = stockUnitEao.findAll();
assertNotNull(units);
for (StockUnit stockUnit : units) {
assertTrue(stockUnit.isInStock());
assertFalse(stockUnit.isInTransaction());
assertEquals(s1, stockUnit.getStock());
}
utx.commit();
utx.begin();
em.joinTransaction();
StockTransaction st1 = stockTransactionEmo.requestDestroyPrepared(stocks.get(0).getId(), "Hugo", "Ein toller Komentar");
for (StockUnit stockUnit : stockUnitEao.findAll()) {
st1.addUnit(stockUnit);
}
assertEquals(units.size(), st1.getPositions().size());
List<Integer> uids = stockTransactionEmo.completeDestroy("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.emo.StockTransactionEmo 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.emo.StockTransactionEmo 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.emo.StockTransactionEmo 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