use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao 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.eao.UniqueUnitEao 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.eao.UniqueUnitEao in project dwoss by gg-net.
the class UnitProcessorOperation method validateReceipt.
private void validateReceipt(UniqueUnit receiptUnit) throws IllegalArgumentException {
if (receiptUnit.getId() > 0)
throw new IllegalArgumentException("UniqueUnit has already been persisted " + receiptUnit);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(Identifier.REFURBISHED_ID, receiptUnit.getIdentifier(Identifier.REFURBISHED_ID));
if (uniqueUnit != null)
throw new IllegalArgumentException("Unit with refurbishedId=" + receiptUnit.getRefurbishId() + " exists.\n- Supplied Unit:" + receiptUnit + "\n- Database Unit:" + uniqueUnit);
StockUnit stockUnit = new StockUnitEao(stockEm).findByRefurbishId(receiptUnit.getRefurbishId());
if (stockUnit != null)
throw new IllegalArgumentException(stockUnit + " exists");
}
use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.
the class UnitSupporterOperation method findRefurbishIdBySerial.
@Override
public String findRefurbishIdBySerial(String serial) {
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.SERIAL, serial);
if (uu != null)
return uu.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID);
return null;
}
use of eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao in project dwoss by gg-net.
the class UnitSupporterOperation method isRefurbishIdAvailable.
/**
* Returns true if supplied refurbishId is available, meaning not jet in the database.
*
* @param refurbishId the refubishedId
* @return true if available.
*/
@Override
public boolean isRefurbishIdAvailable(String refurbishId) {
UniqueUnit uniqueUnit = new UniqueUnitEao(uuEm).findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
if (uniqueUnit != null)
return false;
if (bridgeInstance.isUnsatisfied())
return true;
LegacyLocalBridge bridge = bridgeInstance.get();
L.info("Using LegacyBridge ({})", bridge.localName());
return bridge.isUnitIdentifierAvailable(refurbishId);
}
Aggregations