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