use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class ImageIdHandlerOperation method exportMissing.
/**
* Returns a FileJacket of XLS, which contains all Products with missing ImageIds.
* <p/>
* Acitve Filters are:
* <ul>
* <li>If SalesChannel is supplied, only Products, which have units in the SalesChannel.</li>
* <li>Only Products, which don't have an image id.</li>
* <li>Only Products, which have Unit in stock.</li>
* </ul>
* <p/>
* @param salesChannel
* @return
*/
@Override
public FileJacket exportMissing(SalesChannel salesChannel) {
SubMonitor m = monitorFactory.newSubMonitor("Fehlende Image Ids exportieren", 100);
m.message("Loading Missing IDs");
m.start();
List<Integer> uniqueUnitIds = new StockUnitEao(stockEm).findByNoLogicTransactionAsUniqueUnitId();
List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(uniqueUnitIds);
SortedSet<Product> products = new TreeSet<>();
for (UniqueUnit uniqueUnit : uniqueUnits) {
if (uniqueUnit.getProduct() == null)
continue;
if (salesChannel != null && uniqueUnit.getSalesChannel() != salesChannel)
continue;
if (uniqueUnit.getProduct().getImageId() > 0)
continue;
products.add(uniqueUnit.getProduct());
}
STable table = new STable();
table.setHeadlineFormat(new CFormat(BOLD, BLACK, LIGHT_GRAY, CENTER, MIDDLE));
table.add(new STableColumn("ArtikelNr", 15).setAction(SUtil.getBeanProperty("partNo")));
table.add(new STableColumn("Warengruppe", 22).setAction(SUtil.getBeanProperty("group.name")));
table.add(new STableColumn("Hersteller", 16).setAction(SUtil.getBeanProperty("tradeName.name")));
table.add(new STableColumn("Bezeichnung", 45).setAction(SUtil.getBeanProperty("name")));
table.add(new STableColumn("Image Id", 10).setAction(SUtil.getNull()));
table.setModel(new STableModelList(products));
CCalcDocument doc = new TempCalcDocument("ImageIds");
doc.add(new CSheet("ImageIds", table));
FileJacket fj = new FileJacket("MissingImageIds", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(doc));
m.finish();
return fj;
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class ImageIdHandlerOperation method importMissing.
@Override
public Reply<Void> importMissing(FileJacket inFile) {
final SubMonitor m = monitorFactory.newSubMonitor("Image Ids importieren", 100);
m.message("Reading File");
m.start();
LucidCalcReader reader = new JExcelLucidCalcReader();
reader.addColumn(0, String.class);
reader.addColumn(1, String.class);
reader.addColumn(2, String.class);
reader.addColumn(3, String.class);
reader.addColumn(4, Integer.class);
reader.setHeadline(true);
reader.setTrim(true);
File f = inFile.toTemporaryFile();
List<ImageIdLine> lines = reader.read(f, ImageIdLine.class);
List<String> errors = reader.getErrors();
ProductEao productEao = new ProductEao(uuEm);
m.message("Importing Data");
m.setWorkRemaining(lines.size());
for (ImageIdLine line : lines) {
m.worked(1, "importing " + line.getPartNo());
if (line.getImageId() == null) {
errors.add("No ImageId for " + line.getPartNo());
continue;
}
Product p = productEao.findByPartNo(line.getPartNo());
if (p != null) {
p.setImageId(line.getImageId());
} else {
errors.add("No Product for '" + line.getPartNo() + "'");
}
}
m.finish();
if (!errors.isEmpty())
return Reply.failure(errors.toString());
return Reply.success(null);
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class PersistenceValidatorOperation method validateDatabase.
/**
* This Method Validate all Databases.
* It's validate:
* - RedTape
* - UniqueUnit
* - Sopo
* - Stock
* <p/>
* @return a Filejacket where a xls from the JExcel api is, that contains all Errors.
*/
@Override
public Optional<FileJacket> validateDatabase() {
List<Vm> vms = new ArrayList<>();
UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
DossierEao dossierEao = new DossierEao(redTapeEm);
LogicTransactionEao logicEao = new LogicTransactionEao(stockEm);
StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
int uuMax = uuEao.count();
int dossierMax = dossierEao.count();
int logicMax = logicEao.count();
int stockUnitMax = stockUnitEao.count();
SubMonitor m = monitorFactory.newSubMonitor("DatenbankValidation", 100);
// All Listen
List<Dossier> dossiers;
List<UniqueUnit> uniqueUnits;
List<LogicTransaction> logicTransactions;
List<StockUnit> stockUnits;
m.message("Hole alle Unique Units. " + uuMax);
uniqueUnits = uuEao.findAll();
m.worked(10, "Hole Alle Dossiers. " + dossierMax);
dossiers = dossierEao.findAll();
m.worked(10, "Hole Alle LogicTransaction. " + logicMax);
logicTransactions = logicEao.findAll();
m.worked(10, "Hole Alle StockUnit. " + stockUnitMax);
stockUnits = stockUnitEao.findAll();
m.worked(10, "Validieren.");
validateRedTape(vms, dossiers, convertUnitListToMap(uniqueUnits), m.newChild(10));
validateUniqueUnit(vms, uniqueUnits, m.newChild(10));
validateLogicTransaction(vms, logicTransactions, dossiers, m.newChild(10));
// TODO: split:
// 1. Sopo Validation <-> RedTape
// 2. Sopo Only.
m.finish();
return createFileJacket(vms);
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class MovementListingProducerOperation method generateList.
@Override
public JasperPrint generateList(ListType listType, Stock stock) {
SubMonitor m = monitorFactory.newSubMonitor("Versand und Abholung", 100);
m.message("lade Vorgänge");
m.start();
LogicTransactionEao ltEao = new LogicTransactionEao(stockEm);
UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
List<Document> documents = new DocumentEao(redTapeEm).findActiveByDirective(listType.getDirective());
m.worked(5);
m.setWorkRemaining(documents.size() + 2);
List<MovementLine> lines = new ArrayList<>();
List<String> dossierids = new ArrayList<>();
List<Long> systemCustomers = customerService.allSystemCustomerIds();
for (Document document : documents) {
if (systemCustomers.contains(document.getDossier().getCustomerId()))
continue;
m.worked(1, "verarbeite " + document.getDossier().getIdentifier());
LogicTransaction lt = ltEao.findByDossierId(document.getDossier().getId());
// Filter by stock
if (!hasUnitOnStock(lt, stock))
continue;
MovementLine line = new MovementLine();
line.setCustomerId(document.getDossier().getCustomerId());
line.setCustomerComment(customerService.findComment(document.getDossier().getCustomerId()));
line.setComment(document.getDossier().getComment());
line.setInvoiceAddress(document.getInvoiceAddress().getDescription());
line.setDeliveryAddress(document.getShippingAddress().getDescription());
line.setDossierIdentifier(document.getDossier().getIdentifier());
dossierids.add(document.getDossier().getIdentifier());
line.setPaymentMethod(document.getDossier().getPaymentMethod().getNote());
for (StockUnit stockUnit : lt.getUnits()) {
UniqueUnit uniqueUnit = uniqueUnitEao.findById(stockUnit.getUniqueUnitId());
Product p = uniqueUnit.getProduct();
MovementSubline elem = new MovementSubline(1, (p == null ? "Kein Produkt" : ProductFormater.toName(p) + " (" + p.getGroup().getNote() + ")"), uniqueUnit.getRefurbishId(), (stockUnit.getStock() == null ? stockUnit.getTransaction().toString() : stockUnit.getStock().getName()), uniqueUnit.getInternalComments().contains(UniqueUnit.StaticInternalComment.PREPARED_SHIPMENT));
line.addMovementSubline(elem);
}
lines.add(line);
}
String title = listType.getName() + " - " + stock.getName();
L.info("generateList {} containing {}", title, dossierids);
m.message("erzeuge Report");
Map<String, Object> reportParameter = new HashMap<>();
reportParameter.put("TITLE", title);
JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(lines);
String name = "MovementList.jrxml";
URL url = Objects.requireNonNull(getClass().getResource(name), "The Resource " + getClass().getPackage() + "/" + name + " not found.");
try (InputStream is = url.openStream()) {
JasperReport jasperReport = JasperCompileManager.compileReport(is);
JasperPrint result = JasperFillManager.fillReport(jasperReport, reportParameter, datasource);
return result;
} catch (IOException | JRException e) {
L.error("Exception during movementList", e);
throw new RuntimeException(e);
} finally {
m.finish();
}
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class SubMonitorUnitTest method testNewChild.
@Test
public void testNewChild() {
JUnitMonitor m = new JUnitMonitor(1000);
SubMonitor sm = SubMonitor.convert(m);
m.testRemaining(1000, 1);
sm.setWorkRemaining(100);
sm.start();
m.testRemaining(1000, 2);
sm.worked(20);
m.testRemaining(800, 2);
SubMonitor child1 = SubMonitor.convert(sm.newChild(50));
child1.setWorkRemaining(100);
child1.worked(10);
m.testRemaining(750, 2);
child1.worked(40);
m.testRemaining(550, 2);
// child1.message(50); // idealfall
// m.testRemaining(300, 2); //idealfall
child1.finish();
m.testRemaining(300, 2);
sm.worked(20);
m.testRemaining(100, 2);
SubMonitor child2 = SubMonitor.convert(sm.newChild(10));
child2.setWorkRemaining(500);
child2.worked(50);
m.testRemaining(90, 2);
child2.finish();
m.testRemaining(0, 2);
}
Aggregations