Search in sources :

Example 1 with StockTransactionPosition

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition 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;
}
Also used : StockTransactionParticipation(eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation) StockLocationDiscoverer(eu.ggnet.dwoss.stock.ee.emo.StockLocationDiscoverer) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 2 with StockTransactionPosition

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition in project dwoss by gg-net.

the class StockUnitEaoIT method testSumByTransaction.

@Test
public void testSumByTransaction() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s0 = new Stock(0, "1111111111111111111111111111");
    Stock s1 = new Stock(1, "2222222222222222222222222222");
    em.persist(s0);
    em.persist(s1);
    StockLocation s0l0 = new StockLocation("Lagerplatz");
    s0.addStockLocation(s0l0);
    StockUnit su0 = new StockUnit("g1", 1);
    su0.setRefurbishId("23");
    su0.setName("Name");
    StockUnit su1 = new StockUnit("g2", 2);
    su1.setRefurbishId("42");
    su1.setName("Name");
    StockUnit su2 = new StockUnit("g3", 3);
    su2.setRefurbishId("42");
    su2.setName("Name");
    s0.addUnit(su0, s0l0);
    s0.addUnit(su1, s0l0);
    s0.addUnit(su2, s0l0);
    em.persist(su0);
    em.persist(su1);
    em.persist(su2);
    StockTransaction st = new StockTransaction(StockTransactionType.TRANSFER);
    st.setDestination(s1);
    st.setSource(s0);
    st.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    em.persist(st);
    st.addPosition(new StockTransactionPosition(su0));
    st.addPosition(new StockTransactionPosition(su1));
    utx.commit();
    assertThat(sus.countByTransaction(s0.getId(), StockTransactionType.TRANSFER, StockTransactionStatusType.PREPARED)).isEqualTo(2);
}
Also used : StockLocation(eu.ggnet.dwoss.stock.ee.entity.StockLocation) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 3 with StockTransactionPosition

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition 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;
}
Also used : StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 4 with StockTransactionPosition

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition 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();
}
Also used : StockTransactionEao(eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 5 with StockTransactionPosition

use of eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition in project dwoss by gg-net.

the class StockUnitEaoIT method testFindByNoTransaction.

@Test
public void testFindByNoTransaction() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0, "TEEEEEEEEEEEEEEST");
    em.persist(s);
    StockLocation sl = new StockLocation("Lagerplatz");
    s.addStockLocation(sl);
    StockUnit s1 = new StockUnit("G1", 1);
    StockUnit s2 = new StockUnit("G2", 2);
    StockUnit s3 = new StockUnit("G3", 3);
    StockUnit s4 = new StockUnit("G4", 4);
    s.addUnit(s1, sl);
    s.addUnit(s2, sl);
    s.addUnit(s3, sl);
    s.addUnit(s4, sl);
    em.persist(s);
    em.persist(new Stock(1, "TEEEEEEEEEST2"));
    LogicTransaction lt = new LogicTransaction();
    lt.setDossierId(1);
    lt.add(s4);
    em.persist(lt);
    StockTransaction st = new StockTransaction(StockTransactionType.TRANSFER);
    st.setSource(s);
    st.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    em.persist(st);
    st.addPosition(new StockTransactionPosition(s1));
    utx.commit();
    List<StockUnit> sts = sus.findByNoTransaction();
    assertEquals(2, sts.size());
}
Also used : StockLocation(eu.ggnet.dwoss.stock.ee.entity.StockLocation) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Aggregations

StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)6 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)6 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)5 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)5 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)4 Date (java.util.Date)4 Test (org.junit.Test)4 StockTransactionEao (eu.ggnet.dwoss.stock.ee.eao.StockTransactionEao)2 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)2 StockLocation (eu.ggnet.dwoss.stock.ee.entity.StockLocation)2 StockLocationDiscoverer (eu.ggnet.dwoss.stock.ee.emo.StockLocationDiscoverer)1 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)1 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)1 StockTransactionParticipation (eu.ggnet.dwoss.stock.ee.entity.StockTransactionParticipation)1 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)1