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);
}
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;
}
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);
}
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());
}
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();
}
Aggregations