Search in sources :

Example 26 with StockUnitEao

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();
}
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 27 with StockUnitEao

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();
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) 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 28 with StockUnitEao

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);
}
Also used : UnitHistory(eu.ggnet.dwoss.event.UnitHistory) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException)

Example 29 with StockUnitEao

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;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Aggregations

StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)29 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)25 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)19 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)16 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)9 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)6 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)6 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)5 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)5 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)4 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)3 ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)3 FileJacket (eu.ggnet.dwoss.util.FileJacket)3 Test (org.junit.Test)3 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)2 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)2