Search in sources :

Example 51 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class UnitOverseerBean method createUnitPosition.

/**
 * Find a Unit by its refurbished id and returns it.
 * <p/>
 * This method will throw a UserInfoException describing, why the unit is not available.
 * <p/>
 * @param refurbishId The refurbished id of the UniqueUnit
 * @param documentId  the document as reference for tax and more.
 * @return a Unit by its refurbished id or null if nothing is found of the unit is not available.
 * @throws UserInfoException if the refurbishId is not available
 */
@Override
public Result<List<Position>> createUnitPosition(String refurbishId, long documentId) throws UserInfoException {
    UnitShard us = internalFind(refurbishId);
    if (!us.isAvailable())
        throwNotAvailable(refurbishId, us);
    Document doc = new DocumentEao(redTapeEm).findById(documentId);
    UniqueUnit uu = new UniqueUnitEao(uuEm).findByIdentifier(Identifier.REFURBISHED_ID, refurbishId);
    Position p = Position.builder().amount(1).price(0.).serialNumber(uu.getSerial()).refurbishedId(uu.getRefurbishId()).bookingAccount(postLedger.get(PositionType.UNIT, doc.getTaxType()).orElse(null)).type(PositionType.UNIT).tax(doc.getTaxType().getTax()).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).name(UniqueUnitFormater.toPositionName(uu)).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).build();
    // return Result
    if (redTapeHook.isUnsatisfied())
        return new Result(Arrays.asList(p));
    return redTapeHook.get().elaborateUnitPosition(p, documentId);
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) UnitShard(eu.ggnet.dwoss.uniqueunit.api.UnitShard) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) Result(eu.ggnet.dwoss.util.interactiveresult.Result)

Example 52 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class UniversalSearcherOperation method searchUnits.

/**
 * Returns a List of short descriptions of Units in Html.
 * Ensure to add the html start/end tags manually
 * <p/>
 * @param search a search string.
 * @return a List of short descriptions of Units in Html.
 */
// Used in Misc. Unversal Search
@Override
public List<Tuple2<Long, String>> searchUnits(String search) {
    List<UniqueUnit> uus = new UniqueUnitEao(uuEm).find(search);
    List<Tuple2<Long, String>> result = new ArrayList<>(uus.size());
    Set<Long> uurefurbishIds = new HashSet<>();
    for (UniqueUnit uu : uus) {
        // TODO: WARNING, if we start using letters in refurbhisIds, the search will not show any results.
        try {
            long sopoNr = Long.parseLong(uu.getRefurbishId());
            uurefurbishIds.add(sopoNr);
            result.add(new Tuple2(sopoNr, UniqueUnitFormater.toSimpleHtml(uu)));
        } catch (NumberFormatException e) {
            continue;
        }
    }
    if (bridgeInstance.isUnsatisfied())
        return result;
    for (LegacyUnit unit : bridgeInstance.get().findUnit(search)) {
        try {
            if (uurefurbishIds.contains(Long.parseLong(unit.getUnitIdentifier())))
                continue;
            String re = "<b>" + unit.getUnitIdentifier() + "</b> - ";
            re += unit.getSerial() + "<br />";
            re += unit.getManufacturerPartNo() + "<br />";
            re += "Status: <i>Nicht verfügbar (Legacy System:" + bridgeInstance.get().localName() + ")</i><br />";
            result.add(new Tuple2<>(Long.parseLong(unit.getUnitIdentifier()), re));
        } catch (NumberFormatException e) {
        // Ignore
        }
    }
    return result;
}
Also used : LegacyUnit(eu.ggnet.dwoss.redtape.ee.api.LegacyUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Tuple2(eu.ggnet.dwoss.util.Tuple2)

Example 53 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class ReceiptUnitOperationIT method testReceiptAndUpdate.

@Test
public void testReceiptAndUpdate() throws InterruptedException {
    customerGenerator.makeSystemCustomers(contractors.all().toArray(new TradeName[0]));
    // Constants ,later permutate throug all
    Stock stock = stockGenerator.makeStocksAndLocations(2).get(0);
    List<ReceiptOperation> operations = Arrays.asList(SALEABLE, INTERNAL_REWORK, MISSING_PARTS, REPAIR);
    // Receipt a Unit
    ProductSpec productSpec = receiptGenerator.makeProductSpec();
    Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
    StockTransaction stockTransaction = stockTransactionEmo.requestRollInPrepared(stock.getId(), "No User", "Rollin via ReceiptUnitOperationHelper.findOrCreateRollInTransaction");
    for (TradeName contractor : contractors.all()) {
        Shipment productShipment = stockAgent.persist(new Shipment("SHIPMENTNAME_" + contractor, contractor, TradeName.ACER, Shipment.Status.OPENED));
        for (ReceiptOperation receiptOperation : operations) {
            UniqueUnit receiptUnit = unitGenerator.makeUniqueUnit(contractor, product);
            unitProcessor.receipt(receiptUnit, product, productShipment, stockTransaction, receiptOperation, "Receipt Operation from Test", "Testuser");
            asserts(receiptUnit, stockTransaction, receiptOperation, contractor);
            for (ReceiptOperation updateOperation : operations) {
                UniqueUnit uniqueUnit = uniqueUnitAgent.findUnitByIdentifierEager(Identifier.REFURBISHED_ID, receiptUnit.getIdentifier(Identifier.REFURBISHED_ID));
                unitProcessor.update(uniqueUnit, product, updateOperation, "Update Operation from Test", "Testuser");
                assertsUpdate(receiptUnit, stockTransaction, updateOperation, contractor);
            }
        }
    }
    Thread.sleep(3000);
}
Also used : ReceiptOperation(eu.ggnet.dwoss.rules.ReceiptOperation) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Shipment(eu.ggnet.dwoss.stock.ee.entity.Shipment) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 54 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class ReceiptUnitOperationIT method asserts.

private void asserts(UniqueUnit receiptUnit, StockTransaction stockTransaction, ReceiptOperation receiptOperation, TradeName contractor) {
    String head = "(" + contractor + "," + receiptOperation + "):";
    // Verify the UniqueUnit
    UniqueUnit uniqueUnit = uniqueUnitAgent.findUnitByIdentifierEager(Identifier.REFURBISHED_ID, receiptUnit.getIdentifier(Identifier.REFURBISHED_ID));
    assertNotNull(head + "Receipt Unit should exist", uniqueUnit);
    assertEquals(head + "Serial not equal", receiptUnit.getIdentifier(Identifier.SERIAL), uniqueUnit.getIdentifier(Identifier.SERIAL));
    // Verify the StockUnit
    StockUnit stockUnit = stockAgent.findStockUnitByUniqueUnitIdEager(uniqueUnit.getId());
    assertNotNull(head + "StockUnit should exist", stockUnit);
    assertEquals(head + "RefurbishId of UniqueUnit and StockUnit must be equal", receiptUnit.getIdentifier(Identifier.REFURBISHED_ID), stockUnit.getRefurbishId());
    assertEquals(head + "StockTransaction must be the same", stockTransaction.getId(), stockUnit.getTransaction().getId());
    if (!ReceiptOperation.valuesBackedByCustomer().contains(receiptOperation)) {
        // If unspecial Operation, no more verification needed.
        assertNull(head + "StockUnit.logicTransaction for " + receiptOperation, stockUnit.getLogicTransaction());
        return;
    }
    // Verify RedTape
    LogicTransaction logicTransaction = stockUnit.getLogicTransaction();
    assertNotNull(head + "StockUnit.logicTransaction for " + receiptOperation, logicTransaction);
    Dossier dossier = redTapeAgent.findByIdEager(Dossier.class, stockUnit.getLogicTransaction().getDossierId());
    assertNotNull(head + "Dossier for LogicTransaction must exist", dossier);
    assertEquals(head + "Dossier.customerId for " + contractor + " with " + receiptOperation, receiptCustomers.getCustomerId(contractor, receiptOperation), dossier.getCustomerId());
    assertEquals(head + "Dossier.activeDocuments", 1, dossier.getActiveDocuments().size());
    Document document = dossier.getActiveDocuments().get(0);
    assertEquals(head + "Document.type", DocumentType.BLOCK, document.getType());
    assertEquals(head + "LogicTransaction.stockUnits and Document.positions.uniqueUnitIds", toUniqueUnitIds(logicTransaction), document.getPositionsUniqueUnitIds());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 55 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class ScrapUnitOperationIT method testScrap.

@Test
public void testScrap() throws UserInfoException {
    UniqueUnit unit = receiptGenerator.makeUniqueUnit();
    unit = unitDestroyer.verifyScarpOrDeleteAble(unit.getRefurbishId());
    unitDestroyer.scrap(unit, "Someone", "cause i can");
    assertThat(stockUnitEao.findByRefurbishId(unit.getRefurbishId())).isNull();
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Test(org.junit.Test)

Aggregations

UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)88 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)38 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)31 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)27 Test (org.junit.Test)21 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)20 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)16 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)13 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)8 UnitCollection (eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection)7 java.util (java.util)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)6 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)6 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)6 UniqueUnitAgent (eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent)6 FileJacket (eu.ggnet.dwoss.util.FileJacket)6 DocumentType (eu.ggnet.dwoss.rules.DocumentType)5 Collectors (java.util.stream.Collectors)5