Search in sources :

Example 1 with LogicTransactionEao

use of eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao in project dwoss by gg-net.

the class UnitProcessorOperation method findEditableUnit.

/**
 * Returns a editable UniqueUnit.
 * An Exception is thrown if:
 * <ul>
 * <li>No UniqueUnit with refurbishedId</li>
 * <li>No StockUnit for UniqueUnit</li>
 * <li>StockUnit is on Transaction</li>
 * <li>No SopoUnit with refurbishedId</li>
 * <li>No SopoUnit UniqueUnit miss match</li>
 * </ul>
 * The Operation is discovert via:
 * <ul>
 * <li>If on an AlphaAcount, and operation is allowed, returns appropriated operation</li>
 * <li>If on no Auftrag, returns Sales</li>
 * <li>If on any other Auftrag, returns null</li>
 * </ul>
 *
 * @param refurbishedIdOrSerial the refurbishedId or the serial, both are tried
 * @return a EditableUnit with, the editable UniqueUnit, the refrencing StockUnit, the Operation it is in, and the PartNo
 * @throws UserInfoException if refurbishedId is not ok.
 */
@Override
public EditableUnit findEditableUnit(String refurbishedIdOrSerial) throws UserInfoException {
    if (StringUtils.isBlank(refurbishedIdOrSerial))
        throw new UserInfoException("Keine SopoNr/Seriennummer eingegeben");
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(REFURBISHED_ID, refurbishedIdOrSerial);
    if (uniqueUnit == null)
        uniqueUnit = uniqueUnitEao.findByIdentifier(SERIAL, refurbishedIdOrSerial);
    if (uniqueUnit == null)
        throw new UserInfoException("Keine Gerät mit SopoNr/Seriennummer " + refurbishedIdOrSerial + " gefunden");
    StockUnit stockUnit;
    ReceiptOperation operation = ReceiptOperation.SALEABLE;
    stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        throw new UserInfoException("Keine Lagergerät für SopoNr " + uniqueUnit.getIdentifier(REFURBISHED_ID) + " gefunden, bearbeitung unzulässig");
    LogicTransaction lt = new LogicTransactionEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (lt != null) {
        operation = receiptCustomers.getOperation(new DossierEao(redTapeEm).findById(lt.getDossierId()).getCustomerId()).orElse(ReceiptOperation.IN_SALE);
    }
    // Lazyinit
    uniqueUnit.fetchEager();
    return new EditableUnit(uniqueUnit, stockUnit, operation, uniqueUnit.getProduct() == null ? "" : uniqueUnit.getProduct().getPartNo());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 2 with LogicTransactionEao

use of eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao 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 3 with LogicTransactionEao

use of eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao in project dwoss by gg-net.

the class PersistenceValidatorOperation method validateDatabase.

/**
 * This Method Validate all Databases.
 * It's validate:
 * - RedTape
 * - UniqueUnit
 * - Sopo
 * - Stock
 * <p/>
 * @return a Filejacket where a xls from the JExcel api is, that contains all Errors.
 */
@Override
public Optional<FileJacket> validateDatabase() {
    List<Vm> vms = new ArrayList<>();
    UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
    DossierEao dossierEao = new DossierEao(redTapeEm);
    LogicTransactionEao logicEao = new LogicTransactionEao(stockEm);
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    int uuMax = uuEao.count();
    int dossierMax = dossierEao.count();
    int logicMax = logicEao.count();
    int stockUnitMax = stockUnitEao.count();
    SubMonitor m = monitorFactory.newSubMonitor("DatenbankValidation", 100);
    // All Listen
    List<Dossier> dossiers;
    List<UniqueUnit> uniqueUnits;
    List<LogicTransaction> logicTransactions;
    List<StockUnit> stockUnits;
    m.message("Hole alle Unique Units. " + uuMax);
    uniqueUnits = uuEao.findAll();
    m.worked(10, "Hole Alle Dossiers. " + dossierMax);
    dossiers = dossierEao.findAll();
    m.worked(10, "Hole Alle LogicTransaction. " + logicMax);
    logicTransactions = logicEao.findAll();
    m.worked(10, "Hole Alle StockUnit. " + stockUnitMax);
    stockUnits = stockUnitEao.findAll();
    m.worked(10, "Validieren.");
    validateRedTape(vms, dossiers, convertUnitListToMap(uniqueUnits), m.newChild(10));
    validateUniqueUnit(vms, uniqueUnits, m.newChild(10));
    validateLogicTransaction(vms, logicTransactions, dossiers, m.newChild(10));
    // TODO: split:
    // 1. Sopo Validation <-> RedTape
    // 2. Sopo Only.
    m.finish();
    return createFileJacket(vms);
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 4 with LogicTransactionEao

use of eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao in project dwoss by gg-net.

the class MovementListingProducerOperation method generateList.

@Override
public JasperPrint generateList(ListType listType, Stock stock) {
    SubMonitor m = monitorFactory.newSubMonitor("Versand und Abholung", 100);
    m.message("lade Vorgänge");
    m.start();
    LogicTransactionEao ltEao = new LogicTransactionEao(stockEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    List<Document> documents = new DocumentEao(redTapeEm).findActiveByDirective(listType.getDirective());
    m.worked(5);
    m.setWorkRemaining(documents.size() + 2);
    List<MovementLine> lines = new ArrayList<>();
    List<String> dossierids = new ArrayList<>();
    List<Long> systemCustomers = customerService.allSystemCustomerIds();
    for (Document document : documents) {
        if (systemCustomers.contains(document.getDossier().getCustomerId()))
            continue;
        m.worked(1, "verarbeite " + document.getDossier().getIdentifier());
        LogicTransaction lt = ltEao.findByDossierId(document.getDossier().getId());
        // Filter by stock
        if (!hasUnitOnStock(lt, stock))
            continue;
        MovementLine line = new MovementLine();
        line.setCustomerId(document.getDossier().getCustomerId());
        line.setCustomerComment(customerService.findComment(document.getDossier().getCustomerId()));
        line.setComment(document.getDossier().getComment());
        line.setInvoiceAddress(document.getInvoiceAddress().getDescription());
        line.setDeliveryAddress(document.getShippingAddress().getDescription());
        line.setDossierIdentifier(document.getDossier().getIdentifier());
        dossierids.add(document.getDossier().getIdentifier());
        line.setPaymentMethod(document.getDossier().getPaymentMethod().getNote());
        for (StockUnit stockUnit : lt.getUnits()) {
            UniqueUnit uniqueUnit = uniqueUnitEao.findById(stockUnit.getUniqueUnitId());
            Product p = uniqueUnit.getProduct();
            MovementSubline elem = new MovementSubline(1, (p == null ? "Kein Produkt" : ProductFormater.toName(p) + " (" + p.getGroup().getNote() + ")"), uniqueUnit.getRefurbishId(), (stockUnit.getStock() == null ? stockUnit.getTransaction().toString() : stockUnit.getStock().getName()), uniqueUnit.getInternalComments().contains(UniqueUnit.StaticInternalComment.PREPARED_SHIPMENT));
            line.addMovementSubline(elem);
        }
        lines.add(line);
    }
    String title = listType.getName() + " - " + stock.getName();
    L.info("generateList {} containing {}", title, dossierids);
    m.message("erzeuge Report");
    Map<String, Object> reportParameter = new HashMap<>();
    reportParameter.put("TITLE", title);
    JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(lines);
    String name = "MovementList.jrxml";
    URL url = Objects.requireNonNull(getClass().getResource(name), "The Resource " + getClass().getPackage() + "/" + name + " not found.");
    try (InputStream is = url.openStream()) {
        JasperReport jasperReport = JasperCompileManager.compileReport(is);
        JasperPrint result = JasperFillManager.fillReport(jasperReport, reportParameter, datasource);
        return result;
    } catch (IOException | JRException e) {
        L.error("Exception during movementList", e);
        throw new RuntimeException(e);
    } finally {
        m.finish();
    }
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) URL(java.net.URL) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)

Example 5 with LogicTransactionEao

use of eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao in project dwoss by gg-net.

the class LogicTransactionEmo method optionalRemoveUnits.

/**
 * Removes StockUnits identified by UniqueUnitIds from a LogicTransaction, if it exists.
 *
 * @param dossierId     the dossierId of the LogicTransaction
 * @param uniqueUnitIds the uniqueUnitIds
 * @return the LogicTransaction after the removal, always returns a list.
 */
// TODO: Test
public List<StockUnit> optionalRemoveUnits(long dossierId, Collection<Integer> uniqueUnitIds) {
    if (uniqueUnitIds == null)
        throw new NullPointerException("uniqueUnitIds must not be null");
    // Null is possible
    LogicTransaction logicTransaction = new LogicTransactionEao(em).findByDossierId(dossierId);
    if (logicTransaction == null)
        return new ArrayList<>();
    List<StockUnit> stockUnits = new ArrayList<>();
    for (Integer uniqueUnitId : uniqueUnitIds) {
        // check stockunit if not in LogicTransaction.
        StockUnit unit = new StockUnitEao(em).findByUniqueUnitId(uniqueUnitId);
        if (unit == null)
            continue;
        if (unit.getLogicTransaction() == null)
            throw new IllegalStateException(unit + " is not on a LogicTransaction, shoud be on " + logicTransaction);
        if (!logicTransaction.equals(unit.getLogicTransaction()))
            throw new IllegalStateException(unit + " is on a different LogicTransaction than " + logicTransaction);
        logicTransaction.remove(unit);
        stockUnits.add(unit);
    }
    return stockUnits;
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Aggregations

LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)6 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)6 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)6 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)4 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)3 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)2 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)2 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)1 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)1 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1 URL (java.net.URL)1 JRBeanCollectionDataSource (net.sf.jasperreports.engine.data.JRBeanCollectionDataSource)1 Test (org.junit.Test)1