use of eu.ggnet.saft.api.progress.IMonitor 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