Search in sources :

Example 46 with SubMonitor

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;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) UserInfoException(eu.ggnet.dwoss.util.UserInfoException)

Example 47 with SubMonitor

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();
    }
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) DesktopBundle(eu.ggnet.dwoss.spec.ee.entity.DesktopBundle) FileJacket(eu.ggnet.dwoss.util.FileJacket) SpecsRoot(eu.ggnet.dwoss.spec.ee.entity.xml.SpecsRoot) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)

Example 48 with SubMonitor

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);
    }
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor)

Example 49 with SubMonitor

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();
}
Also used : RowData(eu.ggnet.dwoss.redtape.ee.sage.xml.RowData) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor)

Example 50 with SubMonitor

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;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) CSheet(eu.ggnet.lucidcalc.CSheet) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) STableColumn(eu.ggnet.lucidcalc.STableColumn) STable(eu.ggnet.lucidcalc.STable) STableModelList(eu.ggnet.lucidcalc.STableModelList) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CFormat(eu.ggnet.lucidcalc.CFormat) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) CBorder(eu.ggnet.lucidcalc.CBorder) File(java.io.File)

Aggregations

SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)63 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)23 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)21 FileJacket (eu.ggnet.dwoss.util.FileJacket)18 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)16 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)14 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)12 File (java.io.File)12 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)11 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)9 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)8 MonitorFactory (eu.ggnet.dwoss.progress.MonitorFactory)7 Inject (javax.inject.Inject)7 Test (org.junit.Test)7 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)6 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)6 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)6 CFormat (eu.ggnet.lucidcalc.CFormat)6 CSheet (eu.ggnet.lucidcalc.CSheet)6 STable (eu.ggnet.lucidcalc.STable)6