Search in sources :

Example 6 with StockUnitEao

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

the class LogicTransactionEmo method equilibrate.

/**
 * Brings the LogicTransaction identified by the dossierId and the supplied uniqueUnitIds in equilibrium.
 * <p/>
 * Handles the following states:
 * <ul>
 * <li>If uniqueUnitIds is empty a possible LogicTransaction is emptied and removed</li>
 * <li>Otherwise the LogicTransaction is synchronised with the uniqueUnitIds. possibly creating the LogicTransaction</li>
 * </ul>
 * TODO: Test (is Tested in RedTapeOperationTest)
 * <p/>
 * @param dossierId        the id of the dossier
 * @param newUniqueUnitIds List of uniqueUnitIds may not be null
 * @return a Result containing uniqueUnitIds which have been added an removed, or null if nothing happend.
 * @throws NullPointerException     if uniqueUnitIds is null
 * @throws IllegalArgumentException if a uniqueUnitId has no StockUnit
 * @throws IllegalStateException    if a StockUnit, that should be free, is already on a LogicTransaction.
 */
// TODO: Return removed, added.
public EquilibrationResult equilibrate(long dossierId, final Collection<Integer> newUniqueUnitIds) throws IllegalArgumentException, IllegalStateException, NullPointerException {
    L.debug("equilibrate dossierId={}, uniqueUnitIds={}", dossierId, newUniqueUnitIds);
    if (newUniqueUnitIds == null)
        throw new NullPointerException("uniqueUnitIds must not be null");
    // Null is possible
    LogicTransaction logicTransaction = new LogicTransactionEao(em).findByDossierId(dossierId, LockModeType.PESSIMISTIC_WRITE);
    if (logicTransaction == null && newUniqueUnitIds.isEmpty()) {
        L.debug("Both are empty, nothing to equilibrate");
        return null;
    }
    NavigableSet<Integer> adding = new TreeSet<>(newUniqueUnitIds);
    Map<Integer, StockUnit> oldStockUnits = new HashMap<>();
    NavigableSet<Integer> removal = new TreeSet<>();
    // Remove possible old stockuntis
    if (logicTransaction != null) {
        for (StockUnit stockUnit : logicTransaction.getUnits()) {
            oldStockUnits.put(stockUnit.getUniqueUnitId(), stockUnit);
        }
        removal.addAll(oldStockUnits.keySet());
        removal.removeAll(newUniqueUnitIds);
        // newUniqueUnitIds - oldUniqueUnitIds = notJetAdded
        adding.removeAll(oldStockUnits.keySet());
        L.debug("Removal: removing StockUnits with UniqueUnit.ids={} ", removal);
        for (Integer uniqueUnitId : removal) {
            logicTransaction.remove(oldStockUnits.get(uniqueUnitId));
        }
        if (newUniqueUnitIds.isEmpty()) {
            L.debug("Rqmoval: removing empty {}", logicTransaction);
            em.remove(logicTransaction);
            return null;
        }
    }
    // Non LT exists, but we need one.
    if (logicTransaction == null) {
        L.debug("Request: New LogicTransaction needed");
        logicTransaction = request(dossierId, LockModeType.PESSIMISTIC_WRITE);
        L.debug("Request: Result={}", logicTransaction);
    }
    L.debug("Adding: StockUnits with UniqueUnit.ids={}", adding);
    for (Integer uniqueUnitId : adding) {
        // check stockunit if not in LogicTransaction.
        StockUnit unit = new StockUnitEao(em).findByUniqueUnitId(uniqueUnitId);
        if (unit == null)
            throw new IllegalArgumentException("The supplied uniqueUnitId=" + uniqueUnitId + " has no StockUnit");
        if (unit.getLogicTransaction() != null)
            throw new IllegalStateException(unit + " is already in a LogicTransaction");
        else
            logicTransaction.add(unit);
    }
    L.debug("Adding: Result = {}", logicTransaction);
    return new EquilibrationResult(adding, removal, logicTransaction);
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 7 with StockUnitEao

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

the class UnitDestroyerOperation method scrapDelete.

private void scrapDelete(final long targetCustomerId, final String operation, final UniqueUnit uniqueUnit, final String reason, final String arranger) {
    UniqueUnit uu = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
    StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
    Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) targetCustomerId, "Blockaddresse KundenId " + targetCustomerId, "Erzeugung durch " + operation, arranger);
    Dossier dos = doc.getDossier();
    doc.append(Position.builder().type(PositionType.UNIT).amount(1).bookingAccount(postLedger.get(PositionType.UNIT, doc.getTaxType()).orElse(null)).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).build());
    doc.append(Position.builder().type(PositionType.COMMENT).amount(1).name(operation).description(reason + " by " + arranger).build());
    LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dos.getId());
    // Implicit removes it from an existing LogicTransaction
    lt.add(stockUnit);
    StockTransaction st = stockTransactionEmo.requestDestroyPrepared(stockUnit.getStock().getId(), arranger, reason);
    st.addUnit(stockUnit);
    stockTransactionEmo.completeDestroy(arranger, Arrays.asList(st));
    uu.addHistory(operation + " of Unit via " + st);
    uu.setInternalComment(uu.getInternalComment() + ", " + operation + " of Unit.");
    uu.setSalesChannel(UNKNOWN);
    L.info("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), dos.getIdentifier());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 8 with StockUnitEao

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

the class UnitDestroyerOperation method verifyScarpOrDeleteAble.

/**
 * Validates if a unit identified by refurbishedId is scrapable.
 * Throws Exception if:
 * <ul>
 * <li>No UniqueUnit,SopoUnit or StockUnit exists.</li>
 * <li>StockUnit is inTransaction</li>
 * <li>SopoUnit is in Auftrag or Balanced.</li>
 * </ul>
 *
 * @param refurbishId the refurbishedId
 * @return
 * @throws UserInfoException if not scrapable.
 */
@Override
public UniqueUnit verifyScarpOrDeleteAble(String refurbishId) throws UserInfoException {
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
    if (uniqueUnit == null)
        throw new UserInfoException("Keine Gerät mit SopoNr " + refurbishId + " gefunden");
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    StockUnit stockUnit = stockUnitEao.findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        throw new UserInfoException("Keine Lagergerät für SopoNr " + refurbishId + " gefunden, Verschrottung/Löschung unnötig");
    if (stockUnit.isInTransaction())
        throw new UserInfoException("StockUnit ist auf einer Transaktion, Verschrottung/Löschung unzulässig");
    uniqueUnit.fetchEager();
    return uniqueUnit;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 9 with StockUnitEao

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

the class UnitProcessorOperation method optionalUpdateStockUnit.

private StockUnit optionalUpdateStockUnit(UniqueUnit uniqueUnit) {
    StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        return null;
    stockUnit.setRefurbishId(uniqueUnit.getIdentifier(Identifier.REFURBISHED_ID));
    stockUnit.setName(uniqueUnit.getProduct().getName());
    L.debug("updating {}", stockUnit);
    return stockUnit;
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 10 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao 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)

Aggregations

StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)29 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)25 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)19 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)16 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)9 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)6 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)6 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)5 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)5 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)4 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)3 ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)3 FileJacket (eu.ggnet.dwoss.util.FileJacket)3 Test (org.junit.Test)3 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)2 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)2