Search in sources :

Example 1 with LogicTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo in project dwoss by gg-net.

the class LogicTransactionEmoIT method testEquilibrate.

@Test
public void testEquilibrate() throws Exception {
    L.info("starting test equilibrate");
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0);
    s.setName("Test-0");
    L.debug("Persisted {}", s);
    em.persist(s);
    // StockEntityHelper.createOrUpdateMasterData(em);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    s = em.merge(s);
    L.debug("Merged {}", s);
    LogicTransaction logicTransaction = new LogicTransaction();
    LogicTransaction logicTransaction1 = new LogicTransaction();
    LogicTransaction logicTransaction2 = new LogicTransaction();
    StockUnit stockUnit1 = new StockUnit("Unit1", "Unit1", 1);
    StockUnit stockUnit2 = new StockUnit("Unit2", "Unit2", 2);
    StockUnit stockUnit3 = new StockUnit("Unit3", "Unit3", 3);
    StockUnit stockUnit4 = new StockUnit("Unit4", "Unit4", 4);
    StockUnit stockUnit5 = new StockUnit("Unit5", "Unit5", 5);
    StockUnit stockUnit6 = new StockUnit("Unit6", "Unit6", 6);
    StockUnit stockUnit7 = new StockUnit("Unit7", "Unit7", 7);
    StockUnit stockUnit8 = new StockUnit("Unit8", "Unit8", 8);
    stockUnit1.setStock(s);
    stockUnit2.setStock(s);
    stockUnit3.setStock(s);
    stockUnit4.setStock(s);
    stockUnit5.setStock(s);
    stockUnit6.setStock(s);
    stockUnit7.setStock(s);
    stockUnit8.setStock(s);
    logicTransaction.setDossierId(1l);
    logicTransaction1.setDossierId(1l);
    logicTransaction2.setDossierId(1l);
    em.persist(logicTransaction);
    em.persist(logicTransaction1);
    em.persist(logicTransaction2);
    em.persist(stockUnit1);
    em.persist(stockUnit2);
    em.persist(stockUnit3);
    em.persist(stockUnit4);
    em.persist(stockUnit5);
    em.persist(stockUnit6);
    em.persist(stockUnit7);
    em.persist(stockUnit8);
    logicTransaction.add(stockUnit1);
    logicTransaction.add(stockUnit2);
    logicTransaction1.add(stockUnit3);
    logicTransaction1.add(stockUnit4);
    logicTransaction2.add(stockUnit5);
    logicTransaction2.add(stockUnit6);
    L.debug("pre commit");
    utx.commit();
    L.debug("Post Commit");
    utx.begin();
    em.joinTransaction();
    LogicTransaction find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 2. find=" + find, find.getUnits().size() == 2);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2 })));
    utx.commit();
    LogicTransactionEmo emo = new LogicTransactionEmo(em);
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] { 1, 2, 7, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 4. find=" + find, find.getUnits().size() == 4);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2, stockUnit7, stockUnit8 })));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] { 1, 2, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 3. find=" + find, find.getUnits().size() == 3);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2, stockUnit8 })));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] { 1, 7, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("Size was not 3. find=" + find, find.getUnits().size() == 3);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit7, stockUnit8 })));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(1l, Arrays.asList(new Integer[] {}));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = em.find(LogicTransaction.class, 1l);
    assertTrue("LT was not null. find=" + find, find == null);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    emo.equilibrate(5l, Arrays.asList(new Integer[] { 1, 2, 7, 8 }));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    find = new LogicTransactionEao(em).findByDossierId(5l);
    assertTrue("LT was Null.", find != null);
    assertTrue("Size was not 4. find=" + find, find.getUnits().size() == 4);
    assertTrue("It wasnt All Units correctly in the Transaction. find=" + find, find.getUnits().containsAll(Arrays.asList(new StockUnit[] { stockUnit1, stockUnit2, stockUnit7, stockUnit8 })));
    utx.commit();
    L.info("stopping test equilibrate");
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Example 2 with LogicTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo in project dwoss by gg-net.

the class UnitDestroyerOperation method scrapDelete.

private void scrapDelete(final long targetCustomerId, final String operation, final UniqueUnit uniqueUnit, final String reason, final String arranger) {
    UniqueUnit uu = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
    Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) targetCustomerId, "Blockaddresse KundenId " + targetCustomerId, "Erzeugung durch " + operation, arranger);
    Dossier dos = doc.getDossier();
    doc.append(Position.builder().type(PositionType.UNIT).amount(1).bookingAccount(postLedger.get(PositionType.UNIT, doc.getTaxType()).orElse(null)).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).build());
    doc.append(Position.builder().type(PositionType.COMMENT).amount(1).name(operation).description(reason + " by " + arranger).build());
    LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dos.getId());
    // Implicit removes it from an existing LogicTransaction
    lt.add(stockUnit);
    StockTransaction st = stockTransactionEmo.requestDestroyPrepared(stockUnit.getStock().getId(), arranger, reason);
    st.addUnit(stockUnit);
    stockTransactionEmo.completeDestroy(arranger, Arrays.asList(st));
    uu.addHistory(operation + " of Unit via " + st);
    uu.setInternalComment(uu.getInternalComment() + ", " + operation + " of Unit.");
    uu.setSalesChannel(UNKNOWN);
    L.info("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), dos.getIdentifier());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 3 with LogicTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo in project dwoss by gg-net.

the class UnitProcessorOperation method executeOperation.

private void executeOperation(UniqueUnit uniqueUnit, StockUnit stockUnit, ReceiptOperation operation, String operationComment, String arranger) {
    long customerId = receiptCustomers.getCustomerId(uniqueUnit.getContractor(), operation);
    Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) customerId, "Blockaddresse KundenId " + customerId, "Erzeugung durch " + operation, arranger);
    L.debug("requestActiveDocumentBlock = {} with dossier = {}", doc, doc.getDossier());
    redTapeEm.flush();
    redTapeEm.refresh(doc, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
    L.debug("Refreshed requestActiveDocumentBlock to = {} with dossier = {}", doc, doc.getDossier());
    if (!doc.isActive())
        throw new RuntimeException("The Document(id={}) has changed to inactive while locking, this was very unlikely, inform Administrator");
    doc.append(toPosition(uniqueUnit, operationComment, doc.getTaxType()));
    LogicTransaction lt = new LogicTransactionEmo(stockEm).request(doc.getDossier().getId(), LockModeType.PESSIMISTIC_FORCE_INCREMENT);
    // Implicit removes it from an existing LogicTransaction
    lt.add(stockUnit);
    L.debug("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), doc.getDossier().getIdentifier());
    uniqueUnit.addHistory("RecepitOeration:" + operation + ", " + operationComment + " by " + arranger);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)

Example 4 with LogicTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo in project dwoss by gg-net.

the class RedTapeWorkerOperation method revertCreate.

/**
 * This method handles necessary cleanups if creation or update is canceled.
 * <p/>
 * If stock.LogicTransaction differs form Dossier.Document.Positions &rArr; change LogicTransaction.
 * <ul><li>Only LogicTransaction > Dossier.Document.Positions should be possible</li></ul>
 * If Dossier.isEmpty &rarr; delete.
 * If stock.LogicTransaction is empty &rarr; delete.
 */
@Override
public Document revertCreate(Document detached) throws UserInfoException {
    Document original = new DocumentEao(redTapeEm).findById(detached.getId());
    if (original.isActive() != detached.isActive())
        throw new UserInfoException("Das Document wurde durch jemand anderen inzwischen geändert, bitte neu laden.\n" + "Hint: original(" + original.getId() + ").active=" + original.isActive() + ", detached(" + detached.getId() + ").active=" + detached.isActive());
    if (original.getOptLock() != detached.getOptLock())
        throw new UserInfoException("Das Document wurde durch jemand anderen inzwischen geändert, bitte neu laden.\n" + "Hint: original(" + original.getId() + ").optLock=" + original.getOptLock() + ", detached(" + detached.getId() + ").optLock=" + detached.getOptLock());
    LogicTransactionEmo ltEmo = new LogicTransactionEmo(stockEm);
    if (!detached.isClosed())
        ltEmo.equilibrate(original.getDossier().getId(), original.getPositionsUniqueUnitIds());
    if (original.getDossier().getDocuments().size() == 1 && original.getPositions().isEmpty()) {
        redTapeEm.remove(original.getDossier());
        return null;
    }
    return original;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)

Example 5 with LogicTransactionEmo

use of eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo in project dwoss by gg-net.

the class RedTapeWorkerOperation method delete.

/**
 * Deletes a {@link Dossier}, cleaning up the Stock.
 * <p/>
 * @param dos the Dossier to be deleted.
 */
@Override
public void delete(Dossier dos) {
    new LogicTransactionEmo(stockEm).equilibrate(dos.getId(), new ArrayList<>());
    Dossier attachedDossier = new DossierEao(redTapeEm).findById(dos.getId());
    redTapeEm.remove(attachedDossier);
}
Also used : LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao)

Aggregations

LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)8 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)5 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)3 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)3 DossierEmo (eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)2 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)2 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)2 Test (org.junit.Test)2 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)1 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)1 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)1 CustomerDocument (eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)1 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)1 EquilibrationResult (eu.ggnet.dwoss.stock.ee.emo.EquilibrationResult)1 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)1 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)1 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1 ArrayList (java.util.ArrayList)1