use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class StockTransactionEmo method prepare.
/**
* Prepares the transfer of multiple units.
* Creates an amount of needed transactions in the form,
* - that the transactions are correct (all units of a transaction have the same source as the transaciton)
* - that no transaction has more units than maxUnitSize.
* <p/>
* @param t a merged parameter view.
* @param partialMonitor an optional monitor
* @return a map containing uniqueUnitIds and comments for their history.
* @throws UserInfoException
*/
public SortedMap<Integer, String> prepare(Transfer t, IMonitor partialMonitor) throws UserInfoException {
SubMonitor m = SubMonitor.convert(partialMonitor, "Preparing Transfer Transaciton", (t.getStockUnitIds().size() * 2) + 15);
m.start();
ValidationUtil.validate(t);
Stock destination = em.find(Stock.class, t.getDestinationStockId());
Stock source = null;
List<StockUnit> unhandledUnits = new ArrayList<>();
for (int unitId : t.getStockUnitIds()) {
m.worked(1, "Loading StockUnit(" + unitId + ")");
StockUnit stockUnit = em.find(StockUnit.class, unitId);
if (stockUnit == null)
throw new UserInfoException("StockUnit " + unitId + " nicht vorhanden.");
if (stockUnit.getStock() == null)
throw new UserInfoException(stockUnit + " nicht auf einem Lagerplatz.");
if (source == null)
source = stockUnit.getStock();
if (!source.equals(stockUnit.getStock()))
throw new UserInfoException(stockUnit + " nicht auf Quelle " + source.getName() + ", wie alle anderen");
unhandledUnits.add(stockUnit);
}
L.debug("Unhandeled units {}", unhandledUnits.stream().map(StockUnit::toSimple).collect(Collectors.joining(",")));
SortedMap<Integer, String> result = new TreeMap<>();
for (int i = 0; i < unhandledUnits.size(); i += t.getMaxTransactionSize()) {
List<StockUnit> subList = unhandledUnits.subList(i, Math.min(unhandledUnits.size(), i + t.getMaxTransactionSize()));
L.debug("Eplizit Transfer {}", subList.stream().map(StockUnit::toSimple).collect(Collectors.joining(",")));
result.putAll(prepareExplicitTransfer(subList, destination, t.getArranger(), t.getComment()));
m.worked(t.getMaxTransactionSize());
}
m.message("committing");
m.finish();
return result;
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class SpecExporterOperation method toXml.
/**
* Exports specs to an XML till the supplied amount.
* <p>
* @param amount the amount to export
* @return a FileJacket containing all the found specs.
*/
@Override
public FileJacket toXml(int amount) {
SubMonitor m = monitorFactory.newSubMonitor("Export ProductSpecs", amount + 10);
m.start();
m.message("init");
ProductSpecEao specEao = new ProductSpecEao(em);
int count = specEao.count();
m.worked(2);
if (count < amount) {
m.setWorkRemaining(count + 8);
amount = count;
}
// load in the batches of 10
int step = 10;
List<ProductSpec> exportSpecs = new ArrayList<>();
for (int i = 0; i <= amount; i = i + step) {
m.worked(step, "loading " + step + " Spec beginning by " + i);
for (ProductSpec spec : specEao.findAll(i, step)) {
if (spec instanceof DesktopBundle)
continue;
exportSpecs.add(spec);
}
}
try {
File f = File.createTempFile("specs", ".xml");
try (OutputStream fw = new BufferedOutputStream(new FileOutputStream(f))) {
m.message("marschaling");
JAXB.marshal(new SpecsRoot(exportSpecs), fw);
}
return new FileJacket("specs", ".xml", f);
} catch (IOException ex) {
throw new RuntimeException("", ex);
} finally {
m.finish();
}
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class ReportLineGeneratorOperation method makeReportLines.
public void makeReportLines(int amount) {
SubMonitor m = monitorFactory.newSubMonitor("Erzeuge " + amount + " ReportLines", amount);
m.start();
for (int i = 0; i < amount; i++) {
reportEm.persist(generator.makeReportLine());
m.worked(1);
}
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class SageExporterEngine method execute.
public void execute(IMonitor monitor) {
SubMonitor m = SubMonitor.convert(monitor, "Create GS-Office XML Data", customerInvoices.size() + 10);
RowData rowData = generateGSRowData(monitor);
m.message("writting Output");
try {
JAXBContext context = JAXBContext.newInstance(RowData.class);
Marshaller ms = context.createMarshaller();
ms.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
ms.setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1");
ms.marshal(rowData, output);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
m.finish();
}
use of eu.ggnet.dwoss.progress.SubMonitor in project dwoss by gg-net.
the class DebitorsReporterOperation method toXls.
/**
* Creates the Report
*
* @param monitor
* @return a ByteArray represeting the content of an xls file.
*/
@Override
public FileJacket toXls(Date start, Date end) {
SubMonitor m = monitorFactory.newSubMonitor("DebitorenReport", 25);
m.message("loading Dossiers");
DocumentEao documentEao = new DocumentEao(redTapeEm);
List<Document> documents = new ArrayList<>();
documents.addAll(documentEao.findDocumentsBetweenDates(start, end, DocumentType.INVOICE));
m.worked(10, "preparing Data");
List<Object[]> rows = new ArrayList<>();
for (Document document : documents) {
UiCustomer c = customerService.asUiCustomer(document.getDossier().getCustomerId());
rows.add(new Object[] { c.getId(), document.getDossier().getIdentifier(), c.getCompany(), c.toNameLine(), document.getDossier().getCrucialDirective().getName(), document.getDossier().getComment(), document.getActual(), document.getIdentifier(), document.getPrice(), document.toAfterTaxPrice(), document.getDossier().getPaymentMethod().getNote() });
}
m.worked(10, "building Report");
STable table = new STable();
table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
table.setHeadlineFormat(new CFormat(BOLD_ITALIC, WHITE, BLUE, CENTER, new CBorder(BLACK)));
table.add(new STableColumn("Kid", 8, new CFormat(RIGHT))).add(new STableColumn("AiD", 10, new CFormat(RIGHT))).add(new STableColumn("Firma", 20));
table.add(new STableColumn("Nachname", 20)).add(new STableColumn("Letzer Status", 20));
table.add(new STableColumn("Bemerkung", 10)).add(new STableColumn("Datum", 10, new CFormat(RIGHT, SHORT_DATE)));
table.add(new STableColumn("RE_Nr", 10, new CFormat(RIGHT))).add(new STableColumn("Netto", 15, new CFormat(RIGHT, CURRENCY_EURO))).add(new STableColumn("Brutto", 10, new CFormat(RIGHT, CURRENCY_EURO)));
table.add(new STableColumn("ZahlungsModalität", 10, new CFormat(RIGHT)));
table.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument("Debitoren_");
cdoc.add(new CSheet("DebitorenReport", table));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
FileJacket result = new FileJacket("Debitoren", ".xls", file);
m.finish();
return result;
}
Aggregations