Search in sources :

Example 21 with JasperPrint

use of net.sf.jasperreports.engine.JasperPrint in project VaadinUtils by rlsutton1.

the class JasperManager method fillReport.

// /**
// * Binds a value to a report parameter.
// *
// * Essentially a report can have a no. of named parameters which are used
// to
// * filter the report or display on the report. This method allows you to
// * pass in a map (name, value) of parameter value at runtime.
// *
// * @param parameters
// * a map of name/value pairs to bind to report parameters of the
// * given names.
// */
// 
// private void bindParameters(Map<String, Object> parameters)
// {
// for (String parameterName : parameters.keySet())
// {
// Preconditions.checkArgument(paramExists(parameterName),
// "The passed Jasper Report parameter: "
// + parameterName + " does not existing on the Report");
// 
// boundParams.put(parameterName, parameters.get(parameterName));
// }
// }
private JasperPrint fillReport(OutputFormat outputFormat) throws JRException, InterruptedException {
    Connection connection = reportProperties.getConnection();
    fillHandle = CustomAsynchronousFillHandle.createCustomHandle(jasperReport, boundParams, connection);
    fillHandle.setDataProvider(reportProperties, outputFormat);
    fillHandle.addFillListener(new FillListener() {

        @Override
        public void pageUpdated(JasperPrint jasperPrint, int pageIndex) {
            queueEntry.setStatus("Filling page " + pageIndex);
        }

        @Override
        public void pageGenerated(JasperPrint jasperPrint, int pageIndex) {
            queueEntry.setStatus("Generating page " + pageIndex);
        }
    });
    AsyncJasperPrintAccessor asyncAccessor = new AsyncJasperPrintAccessor(fillHandle);
    if (!stop) {
        fillHandle.startFill();
    }
    // boundParams, connection);
    while (asyncAccessor.getReportStatus().getStatus() == ReportExecutionStatus.Status.RUNNING) {
        Thread.sleep(100);
    }
    return asyncAccessor.getFinalJasperPrint();
}
Also used : AsyncJasperPrintAccessor(net.sf.jasperreports.web.servlets.AsyncJasperPrintAccessor) FillListener(net.sf.jasperreports.engine.fill.FillListener) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Connection(java.sql.Connection) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 22 with JasperPrint

use of net.sf.jasperreports.engine.JasperPrint in project archi by archimatetool.

the class JasperReportsExporter method export.

/**
 * Export the model to Jasper Reports
 * @param monitor       Progress Monitor. Can be null
 * @throws IOException
 * @throws JRException
 */
public void export(IProgressMonitor monitor) throws IOException, JRException {
    progressMonitor = monitor;
    if (progressMonitor != null) {
        progressMonitor.beginTask(Messages.JasperReportsExporter_0, -1);
    }
    // Temp Folder to store assets
    // $NON-NLS-1$
    File tmpFolder = new File(fExportFolder, "tmp");
    tmpFolder.mkdirs();
    try {
        writeDiagrams(tmpFolder);
        JasperPrint jasperPrint = createJasperPrint(tmpFolder);
        if ((fExportOptions & EXPORT_HTML) != 0) {
            setProgressSubTask(Messages.JasperReportsExporter_3);
            // $NON-NLS-1$
            exportHTML(jasperPrint, new File(fExportFolder, fExportFileName + ".html"));
        }
        if ((fExportOptions & EXPORT_PDF) != 0) {
            setProgressSubTask(Messages.JasperReportsExporter_4);
            // $NON-NLS-1$
            exportPDF(jasperPrint, new File(fExportFolder, fExportFileName + ".pdf"));
        }
        if ((fExportOptions & EXPORT_DOCX) != 0) {
            setProgressSubTask(Messages.JasperReportsExporter_5);
            // $NON-NLS-1$
            exportDOCX(jasperPrint, new File(fExportFolder, fExportFileName + ".docx"));
        }
        if ((fExportOptions & EXPORT_PPT) != 0) {
            setProgressSubTask(Messages.JasperReportsExporter_6);
            // $NON-NLS-1$
            exportPPT(jasperPrint, new File(fExportFolder, fExportFileName + ".pptx"));
        }
        if ((fExportOptions & EXPORT_RTF) != 0) {
            setProgressSubTask(Messages.JasperReportsExporter_7);
            // $NON-NLS-1$
            exportRTF(jasperPrint, new File(fExportFolder, fExportFileName + ".rtf"));
        }
        if ((fExportOptions & EXPORT_ODT) != 0) {
            setProgressSubTask(Messages.JasperReportsExporter_8);
            // $NON-NLS-1$
            exportODT(jasperPrint, new File(fExportFolder, fExportFileName + ".odt"));
        }
    } finally {
        if (DELETE_TEMP_FILES) {
            setProgressSubTask(Messages.JasperReportsExporter_9);
            FileUtils.deleteFolder(tmpFolder);
        }
    }
}
Also used : JasperPrint(net.sf.jasperreports.engine.JasperPrint) File(java.io.File)

Example 23 with JasperPrint

use of net.sf.jasperreports.engine.JasperPrint in project dwoss by gg-net.

the class DocumentPrintAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Ui.exec(() -> {
        // TODO: This is a very special case, there the Ui needs the result on construction. So the consumer pattern cannot be used.
        // This meeans, for now no progress display.
        JasperPrint print = Dl.remote().lookup(DocumentSupporter.class).render(document, type);
        CustomerMetaData customer = Dl.remote().lookup(CustomerService.class).asCustomerMetaData(customerId);
        boolean mailAvailable = customer.getEmail() != null && !customer.getEmail().trim().isEmpty();
        Ui.exec(() -> {
            Ui.build().parent(controller.getView()).swing().eval(() -> new JRViewerCask(print, document, type, mailAvailable)).opt().filter(c -> c.isCorrectlyBriefed()).ifPresent(c -> Ui.progress().call(() -> {
                CustomerDocument customerDocument = new CustomerDocument(customer.getFlags(), document, customer.getShippingCondition(), customer.getPaymentMethod());
                for (StateTransition<CustomerDocument> stateTransition : Dl.remote().lookup(RedTapeWorker.class).getPossibleTransitions(customerDocument)) {
                    RedTapeStateTransition redTapeStateTransition = (RedTapeStateTransition) stateTransition;
                    for (RedTapeStateTransition.Hint hint : redTapeStateTransition.getHints()) {
                        if (hint == RedTapeStateTransition.Hint.SENDED_INFORMATION) {
                            this.document = Optional.of(Dl.remote().lookup(RedTapeWorker.class).stateChange(customerDocument, redTapeStateTransition, Lookup.getDefault().lookup(Guardian.class).getUsername())).filter(Ui.failure()::handle).map(Reply::getPayload).orElse(document);
                        }
                    }
                }
                controller.reloadSelectionOnStateChange(Dl.remote().lookup(DocumentSupporter.class).briefed(document, Dl.local().lookup(Guardian.class).getUsername()));
                return null;
            }));
        });
    });
}
Also used : Lookup(org.openide.util.Lookup) JasperPrint(net.sf.jasperreports.engine.JasperPrint) CustomerService(eu.ggnet.dwoss.customer.opi.CustomerService) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) DocumentViewType(eu.ggnet.dwoss.mandator.api.DocumentViewType) RedTapeWorker(eu.ggnet.dwoss.redtapext.ee.RedTapeWorker) RedTapeController(eu.ggnet.dwoss.redtapext.ui.cao.RedTapeController) Ui(eu.ggnet.saft.Ui) ActionEvent(java.awt.event.ActionEvent) StateTransition(eu.ggnet.statemachine.StateTransition) Dl(eu.ggnet.saft.Dl) Guardian(eu.ggnet.saft.core.auth.Guardian) AbstractAction(javax.swing.AbstractAction) RedTapeStateTransition(eu.ggnet.dwoss.redtapext.ee.state.RedTapeStateTransition) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) DocumentSupporter(eu.ggnet.dwoss.redtapext.ee.DocumentSupporter) Reply(eu.ggnet.saft.api.Reply) Optional(java.util.Optional) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument) CustomerService(eu.ggnet.dwoss.customer.opi.CustomerService) RedTapeStateTransition(eu.ggnet.dwoss.redtapext.ee.state.RedTapeStateTransition) DocumentSupporter(eu.ggnet.dwoss.redtapext.ee.DocumentSupporter) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) JasperPrint(net.sf.jasperreports.engine.JasperPrint) StateTransition(eu.ggnet.statemachine.StateTransition) RedTapeStateTransition(eu.ggnet.dwoss.redtapext.ee.state.RedTapeStateTransition) RedTapeWorker(eu.ggnet.dwoss.redtapext.ee.RedTapeWorker) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)

Example 24 with JasperPrint

use of net.sf.jasperreports.engine.JasperPrint in project dwoss by gg-net.

the class RedTapeController method openDocument.

/**
 * This method is called if a chosen Document will be printed and/or sent per E-Mail.
 * This Method become a Document and will open a JasperViewer that contains also a Send Button for sending E-Mail
 * <p/>
 * @param document
 */
public void openDocument(Document document, boolean printAsReservation) {
    JasperPrint print = Dl.remote().lookup(DocumentSupporter.class).render(document, (printAsReservation ? DocumentViewType.RESERVATION : DocumentViewType.DEFAULT));
    JDialog d = new JDialog(parent(), "Dokument drucken/versenden");
    d.setSize(800, 1000);
    d.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
    d.setLocationRelativeTo(view);
    d.getContentPane().setLayout(new BorderLayout());
    boolean canEmaild = model.getPurchaseCustomer().getEmail() != null && model.getPurchaseCustomer().getEmail().trim().isEmpty();
    JRViewerCask jrViewerCask = new JRViewerCask(print, document, (printAsReservation ? DocumentViewType.RESERVATION : DocumentViewType.DEFAULT), canEmaild);
    d.getContentPane().add(jrViewerCask, BorderLayout.CENTER);
    d.setVisible(true);
    if (jrViewerCask.isCorrectlyBriefed()) {
        reloadSelectionOnStateChange(Dl.remote().lookup(DocumentSupporter.class).briefed(document, Dl.local().lookup(Guardian.class).getUsername()));
    }
}
Also used : JRViewerCask(eu.ggnet.dwoss.redtapext.ui.cao.jasper.JRViewerCask) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Guardian(eu.ggnet.saft.core.auth.Guardian)

Example 25 with JasperPrint

use of net.sf.jasperreports.engine.JasperPrint in project dwoss by gg-net.

the class DocumentSupporterIT method testCreate.

/**
 * Test of create method, of class RedTapeOperation.
 */
@Test
public void testCreate() {
    Dossier dos = new Dossier();
    dos.setPaymentMethod(PaymentMethod.ADVANCE_PAYMENT);
    dos.setDispatch(true);
    dos.setCustomerId(1);
    Document doc = new Document();
    doc.setType(DocumentType.ORDER);
    doc.setActive(true);
    doc.setDirective(Document.Directive.WAIT_FOR_MONEY);
    doc.setHistory(new DocumentHistory("JUnit", "Automatische Erstellung eines leeren Dokuments"));
    Address a = new Address("Herr Muh\nMuhstrasse 7\n12345 Muhstadt");
    doc.setInvoiceAddress(a);
    doc.setShippingAddress(a);
    dos.add(doc);
    doc.append(NaivBuilderUtil.comment());
    doc.append(NaivBuilderUtil.service());
    doc.append(NaivBuilderUtil.shippingcost());
    JasperPrint print = documentSupporter.render(doc, DocumentViewType.DEFAULT);
    assertNotNull("A JasperPrint should not be null", print);
}
Also used : Address(eu.ggnet.dwoss.redtape.ee.entity.Address) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) JasperPrint(net.sf.jasperreports.engine.JasperPrint) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Test(org.junit.Test)

Aggregations

JasperPrint (net.sf.jasperreports.engine.JasperPrint)30 JasperReport (net.sf.jasperreports.engine.JasperReport)13 JRException (net.sf.jasperreports.engine.JRException)11 HashMap (java.util.HashMap)10 Connection (java.sql.Connection)8 File (java.io.File)7 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)5 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)4 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)3 Map (java.util.Map)3 SimpleExporterInput (net.sf.jasperreports.export.SimpleExporterInput)3 SimpleOutputStreamExporterOutput (net.sf.jasperreports.export.SimpleOutputStreamExporterOutput)3 Address (eu.ggnet.dwoss.redtape.ee.entity.Address)2 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)2 Guardian (eu.ggnet.saft.core.auth.Guardian)2 PrinterJob (java.awt.print.PrinterJob)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 MalformedURLException (java.net.MalformedURLException)2