use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class UnitProcessorOperation method receiptAndAddStockUnit.
private StockUnit receiptAndAddStockUnit(UniqueUnit uniqueUnit, StockTransaction transaction) {
StockUnit stockUnit = new StockUnit();
stockUnit.setUniqueUnitId(uniqueUnit.getId());
stockUnit.setRefurbishId(uniqueUnit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
stockUnit.setName(uniqueUnit.getProduct().getTradeName().getName() + " " + uniqueUnit.getProduct().getName());
transaction = new StockTransactionEao(stockEm).findById(transaction.getId());
transaction.addPosition(new StockTransactionPosition(stockUnit));
// implies persist on transaction commit
L.debug("adding {} to {}", stockUnit, transaction);
return stockUnit;
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.
the class LogicTransactionEaoIT method testFindByUniqueUnitId.
@Test
public void testFindByUniqueUnitId() throws Exception {
utx.begin();
em.joinTransaction();
Stock s1 = new Stock(0, "TEEEEEEEST");
Stock s2 = new Stock(1, "TEEEEEEEST");
em.persist(s1);
em.persist(s2);
StockUnit su1 = new StockUnit("1", 1);
s1.addUnit(su1);
em.persist(su1);
StockUnit su2 = new StockUnit("2", 5);
s1.addUnit(su2);
em.persist(su2);
StockUnit su3 = new StockUnit("3", 5);
s1.addUnit(su3);
em.persist(su3);
StockUnit su4 = new StockUnit("4", 5);
s1.addUnit(su4);
em.persist(su4);
StockUnit su5 = new StockUnit("5", 5);
s1.addUnit(su5);
em.persist(su5);
StockUnit su6 = new StockUnit("6", 6);
s2.addUnit(su6);
StockUnit su7 = new StockUnit("7", 7);
s1.addUnit(su7);
StockUnit su8 = new StockUnit("8", 8);
s2.addUnit(su8);
em.persist(su6);
em.persist(su7);
em.persist(su8);
LogicTransaction lt1 = new LogicTransaction();
lt1.setDossierId(1);
lt1.add(su6);
lt1.add(su7);
em.persist(lt1);
long lt1Id = lt1.getId();
LogicTransaction lt2 = new LogicTransaction();
lt2.setDossierId(2);
lt2.add(su8);
em.persist(lt2);
long lt2Id = lt2.getId();
utx.commit();
lt1 = ltEao.findByUniqueUnitId(1);
assertNull(lt1);
lt1 = ltEao.findByUniqueUnitId(-1);
assertNull(lt1);
lt1 = ltEao.findByUniqueUnitId(6);
assertNotNull(lt1);
assertEquals(lt1Id, lt1.getId());
lt2 = ltEao.findByUniqueUnitId(8);
assertNotNull(lt2);
assertEquals(lt2Id, lt2.getId());
}
use of eu.ggnet.dwoss.stock.ee.entity.StockUnit 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.entity.StockUnit 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.entity.StockUnit 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();
}
Aggregations