Search in sources :

Example 16 with JRException

use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.

the class MeasurementQueryExecutorRemoteIT method testReportHwForecast.

@Test
public void testReportHwForecast() throws IOException, JRException {
    createReport("Forecast", new ReportFiller() {

        @Override
        public void fill(Map<String, Object> params) throws Exception {
            params.put(JRParameter.IS_IGNORE_PAGINATION, true);
            params.put("MEASUREMENT_URL", "http://localhost:9999/opennms/rest/measurements");
            params.put("dsName", "ifInOctets");
            params.put("startDate", "1414602000000");
            params.put("endDate", "1417046400000");
        }
    });
    // Verify the results of the generated report
    Table<Integer, String, Double> forecasts = TreeBasedTable.create();
    FileReader reader = new FileReader(createFileName("Forecast", "csv"));
    CSVParser parser = new CSVParser(reader, CSVFormat.RFC4180.withHeader());
    int k = 0;
    for (CSVRecord record : parser) {
        try {
            Double fit = Double.parseDouble(record.get("HWFit"));
            Double lwr = Double.parseDouble(record.get("HWLwr"));
            Double upr = Double.parseDouble(record.get("HWUpr"));
            if (Double.isNaN(fit)) {
                continue;
            }
            forecasts.put(k, "fit", fit);
            forecasts.put(k, "lwr", lwr);
            forecasts.put(k, "upr", upr);
            k++;
        } catch (NumberFormatException e) {
        // pass
        }
    }
    Assert.assertEquals(340, forecasts.rowKeySet().size());
    // First fitted value
    Assert.assertEquals(432.526086422424, forecasts.get(0, "fit"), 0.00001);
    // Last fitted value for which there is a known data point
    Assert.assertEquals(24079.4692522087, forecasts.get(327, "fit"), 0.00001);
    // First forecasted value
    Assert.assertEquals(22245.5417010936, forecasts.get(328, "fit"), 0.00001);
}
Also used : JRException(net.sf.jasperreports.engine.JRException) IOException(java.io.IOException) CSVParser(org.apache.commons.csv.CSVParser) FileReader(java.io.FileReader) CSVRecord(org.apache.commons.csv.CSVRecord) Test(org.junit.Test)

Example 17 with JRException

use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.

the class DefaultReportService method runReport.

/** {@inheritDoc} 
     * @throws ReportRunException */
@Override
public synchronized String runReport(Report report, String reportDirectory) throws ReportRunException {
    String outputFile = null;
    try {
        outputFile = generateReportName(reportDirectory, report.getReportName(), report.getReportFormat());
        JasperPrint print = runAndRender(report);
        outputFile = saveReport(print, report, outputFile);
    } catch (JRException e) {
        LOG.error("Error running report: {}", e.getMessage(), e);
        throw new ReportRunException("Caught JRException: " + e.getMessage());
    } catch (Throwable e) {
        LOG.error("Unexpected exception: {}", e.getMessage(), e);
        throw new ReportRunException("Caught unexpected " + e.getClass().getName() + ": " + e.getMessage());
    }
    return outputFile;
}
Also used : JRException(net.sf.jasperreports.engine.JRException) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 18 with JRException

use of net.sf.jasperreports.engine.JRException in project Asqatasun by Asqatasun.

the class AuditExportResultController method prepareSuccessfullAuditDataToExport.

/**
     * 
     * @param page
     * @param model
     * @param locale
     * @param exportFormat
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
private void prepareSuccessfullAuditDataToExport(WebResource webResource, Model model, Locale locale, String exportFormat, HttpServletRequest request, HttpServletResponse response) throws NotSupportedExportFormatException {
    model.addAttribute(TgolKeyStore.LOCALE_KEY, locale);
    Scope scope = getSiteScope();
    if (webResource instanceof Page) {
        scope = getPageScope();
    }
    List<TestResult> testResultList = TestResultFactory.getInstance().getTestResultList(webResource, scope, getLocaleResolver().resolveLocale(request));
    AuditStatistics auditStatistics = getAuditStatistics(webResource, model, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE, //TODO a revoir dans le cas manuel 
    false);
    model.addAttribute(TgolKeyStore.STATISTICS_KEY, auditStatistics);
    try {
        exportService.export(response, webResource.getId(), auditStatistics, testResultList, locale, exportFormat);
    } catch (ColumnBuilderException | ClassNotFoundException | JRException ex) {
        LOGGER.error(ex);
    }
}
Also used : AuditStatistics(org.asqatasun.webapp.presentation.data.AuditStatistics) ColumnBuilderException(ar.com.fdvs.dj.domain.builders.ColumnBuilderException) Scope(org.asqatasun.entity.reference.Scope) JRException(net.sf.jasperreports.engine.JRException) Page(org.asqatasun.entity.subject.Page) TestResult(org.asqatasun.webapp.presentation.data.TestResult)

Example 19 with JRException

use of net.sf.jasperreports.engine.JRException in project midpoint by Evolveum.

the class JasperReports method getData.

public static byte[] getData(JasperPrint print) {
    JRPdfExporter exporter = new JRPdfExporter();
    exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
    try {
        exporter.exportReport();
    } catch (JRException e) {
        e.printStackTrace();
    }
    return os.toByteArray();
}
Also used : JRException(net.sf.jasperreports.engine.JRException) JRPdfExporter(net.sf.jasperreports.engine.export.JRPdfExporter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 20 with JRException

use of net.sf.jasperreports.engine.JRException in project midpoint by Evolveum.

the class JasperReportDto method getTemplate.

public byte[] getTemplate() {
    try {
        //			design.remadgetFields().
        design.getFieldsList().clear();
        design.getParametersList().clear();
        design.getFieldsMap().clear();
        design.getParametersMap().clear();
        for (JasperReportFieldDto field : fields) {
            if (field.isEmpty()) {
                continue;
            }
            JRDesignField f = new JRDesignField();
            f.setValueClassName(field.getTypeAsString());
            f.setValueClass(Class.forName(field.getTypeAsString()));
            f.setName(field.getName());
            design.addField(f);
        }
        for (JasperReportParameterDto param : parameters) {
            if (param.isEmpty()) {
                continue;
            }
            JRDesignParameter p = new JRDesignParameter();
            p.setValueClassName(param.getTypeAsString());
            p.setValueClass(Class.forName(param.getTypeAsString()));
            p.setName(param.getName());
            p.setForPrompting(param.isForPrompting());
            p.setDescription(param.getDescription());
            p.setNestedTypeName(param.getNestedTypeAsString());
            p.setNestedType(param.getNestedType());
            p.getPropertiesMap().setBaseProperties(param.getJRProperties());
            //			p.getPropertiesMap().setProperty(propName, value);
            design.addParameter(p);
        }
        JasperDesign oldDesign = ReportTypeUtil.loadJasperDesign(jasperReportXml);
        oldDesign.getParametersList().clear();
        oldDesign.getParametersList().addAll(design.getParametersList());
        oldDesign.getFieldsList().clear();
        oldDesign.getFieldsList().addAll(design.getFieldsList());
        JRDesignQuery q = new JRDesignQuery();
        q.setLanguage("mql");
        q.setText(query);
        oldDesign.setQuery(q);
        String reportAsString = JRXmlWriter.writeReport(oldDesign, "UTF-8");
        return Base64.encodeBase64(reportAsString.getBytes("UTF-8"));
    } catch (JRException | ClassNotFoundException | SchemaException | UnsupportedEncodingException ex) {
        throw new IllegalStateException(ex.getMessage(), ex.getCause());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) JasperDesign(net.sf.jasperreports.engine.design.JasperDesign) JRException(net.sf.jasperreports.engine.JRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JRDesignField(net.sf.jasperreports.engine.design.JRDesignField) JRDesignParameter(net.sf.jasperreports.engine.design.JRDesignParameter) JRDesignQuery(net.sf.jasperreports.engine.design.JRDesignQuery)

Aggregations

JRException (net.sf.jasperreports.engine.JRException)33 JasperReport (net.sf.jasperreports.engine.JasperReport)8 File (java.io.File)7 InputStream (java.io.InputStream)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 JasperPrint (net.sf.jasperreports.engine.JasperPrint)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ArrayList (java.util.ArrayList)4 JRBeanCollectionDataSource (net.sf.jasperreports.engine.data.JRBeanCollectionDataSource)4 Containerable (com.evolveum.midpoint.prism.Containerable)3 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Map (java.util.Map)3 JasperDesign (net.sf.jasperreports.engine.design.JasperDesign)3 BusinessServiceException (sic.service.BusinessServiceException)3 ServiceException (sic.service.ServiceException)3 Item (com.evolveum.midpoint.prism.Item)2 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)2