use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.
the class PersistenceValidatorOperation method validateLogicTransaction.
/**
* This Method Validate all LogicTransaction that will be given.
* First it checks if all UUIds from the Document are in the Logictransaction.
* Then check its in the opposite way.
* <p/>
* @param transactions
* @param dossiers
* @param m
* @return
*/
private void validateLogicTransaction(List<Vm> vms, List<LogicTransaction> transactions, List<Dossier> dossiers, SubMonitor m) {
Map<Long, Dossier> dossierMap = new HashMap<>();
m.setWorkRemaining(transactions.size());
for (Dossier dossier : dossiers) {
dossierMap.put(dossier.getId(), dossier);
}
for (LogicTransaction logicTransaction : transactions) {
m.worked(1, "Validate: LogicTransaction:" + logicTransaction.getId());
Dossier dossier = dossierMap.get(logicTransaction.getDossierId());
DocumentType type = getMostImportandDocument(dossierMap.get(logicTransaction.getDossierId())).getType();
// TODO: Here you discard cases, not good.
if (type != DocumentType.INVOICE && type != DocumentType.ORDER) {
continue;
}
List<Integer> stockUuIds = toUniqueUnitIds(logicTransaction);
if (!stockUuIds.containsAll(dossier.getRelevantUniqueUnitIds())) {
error(vms, "Stock asynchron zu Dossier. LogicTransaction(id=" + logicTransaction.getId() + ", UniqueUnits=" + logicTransaction.getUnits() + ") ->" + "Dossier( id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + ", relevant UniqueUnits=" + dossier.getRelevantUniqueUnitIds() + ")");
}
if (!dossier.getRelevantUniqueUnitIds().containsAll(stockUuIds)) {
error(vms, "Dossier asynchron zu Stock." + "Dossier(id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + ",relevant UniqueUnits=" + dossier.getRelevantUniqueUnitIds() + ") -> LogicTransaction(id=" + logicTransaction.getId() + ", UniqueUnits=" + logicTransaction.getUnits() + ")");
}
for (StockUnit stockUnit : logicTransaction.getUnits()) {
Set<ConstraintViolation<StockUnit>> validateError = validator.validate(stockUnit);
if (!validateError.isEmpty()) {
error(vms, ConstraintViolationFormater.toSingleLine(validateError));
}
}
}
m.finish();
}
use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.
the class LogicTransactionEmo method request.
/**
* Request a LogicTransaction by its DossierId. <br />
* If no LogicTransaction is found, a new is created and the DossierId will be set.
* <p/>
* @param dossierId The Dossier Id
* @return the found or a new LogicTransaction
*/
public LogicTransaction request(long dossierId) {
Query query = em.createNamedQuery("LogicTransaction.findByDossierId");
query.setParameter(1, dossierId);
try {
return (LogicTransaction) query.getSingleResult();
} catch (NoResultException e) {
LogicTransaction lt = new LogicTransaction();
lt.setDossierId(dossierId);
em.persist(lt);
return lt;
}
}
use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction in project dwoss by gg-net.
the class UnitOverseerBean method lockStockUnit.
/**
* Find an available StockUnit and locks it by add to a LogicTransaction via DossierId.
* <p/>
* If no unit is found a LayerEightException is thrown.
* <p/>
* @param dossierId The Dossiers ID
* @param refurbishedId The refurbished id for the Unique Unit search
* @throws IllegalStateException if the refurbishId is not available
*/
@Override
public void lockStockUnit(long dossierId, String refurbishedId) throws IllegalStateException {
if (!internalFind(refurbishedId).isAvailable())
throw new IllegalStateException("Trying to lock refusbishId " + refurbishedId + ", but it is not available!");
UniqueUnit uu = new UniqueUnitEao(uuEm).findByIdentifier(Identifier.REFURBISHED_ID, refurbishedId);
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dossierId);
lt.add(stockUnit);
}
use of eu.ggnet.dwoss.stock.ee.entity.LogicTransaction 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.stock.ee.entity.LogicTransaction in project dwoss by gg-net.
the class RedTapeCloserOperation method closeStock.
/**
* Rolling out the units from the stocks. For this, a {@link StockTransaction} with {@link StockTransactionType#ROLL_OUT} is created,
* all {@link StockUnit}<code>s</code> which are on a {@link LogicTransaction} with matching dossierId are added to this {@link StockTransaction} and
* it gets {@link StockTransactionStatusType#COMPLETED}.
* <p/>
* @param dossierIds the dossierId as reference.
* @param msg a msg for the stocktransaction.
* @param arranger the arranger.
* @param monitor a optional monitor.
* @return the amount of rolled out units.
*/
private int closeStock(Set<Long> dossierIds, String msg, String arranger, IMonitor monitor) {
SubMonitor m = SubMonitor.convert(monitor, 100);
final String h = "Stock:";
m.message(h + "lade logische Transaktionen");
// Rolling out
List<LogicTransaction> lts = ltEao.findByDossierIds(dossierIds);
m.worked(3, h + "sortiere Geräte nach Lager");
stockEao.findAll();
Map<Stock, List<StockUnit>> unitsByStock = lts.stream().flatMap((t) -> t.getUnits().stream()).collect(Collectors.groupingBy(StockUnit::getStock));
validateStockUnits(unitsByStock);
m.setWorkRemaining((int) unitsByStock.values().stream().count());
List<StockTransaction> stockTransactions = new ArrayList<>();
for (Entry<Stock, List<StockUnit>> entry : unitsByStock.entrySet()) {
StockTransaction st = stEmo.requestRollOutPrepared(entry.getKey().getId(), arranger, msg);
for (StockUnit stockUnit : entry.getValue()) {
m.worked(1, h + "verbuche (refurbishId=" + stockUnit.getRefurbishId() + ",uniqueUnitId=" + stockUnit.getUniqueUnitId() + ")");
st.addUnit(stockUnit);
history.fire(new UnitHistory(stockUnit.getUniqueUnitId(), msg, arranger));
}
stockTransactions.add(st);
}
m.message(h + "auslagern");
if (!stockTransactions.isEmpty())
stEmo.completeRollOut(arranger, stockTransactions);
m.finish();
return (int) unitsByStock.values().stream().count();
}
Aggregations