Search in sources :

Example 11 with JasperReport

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

the class JasperReportServiceTest method testEvaluateToString.

@Test
public void testEvaluateToString() throws JRException {
    final JasperReport report = JasperCompileManager.compileReport(getClass().getResourceAsStream("/etc/report-templates/subreport-expression-visitor-test.jrxml"));
    Assert.assertEquals("/home/ulf/opennms-reports", JasperReportService.evaluateToString(report, new JRDesignExpression("$P{ONMS_REPORT_DIR}")));
    Assert.assertEquals("/home/ulf/opennms-reports/subreports/", JasperReportService.evaluateToString(report, new JRDesignExpression("$P{SUBREPORT_DIR}")));
    Assert.assertEquals("This is a test with number 10", JasperReportService.evaluateToString(report, new JRDesignExpression("$P{COMPLEX}")));
}
Also used : JRDesignExpression(net.sf.jasperreports.engine.design.JRDesignExpression) JasperReport(net.sf.jasperreports.engine.JasperReport) Test(org.junit.Test)

Example 12 with JasperReport

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

the class AbstractMeasurementQueryExecutorTest method createReport.

protected void createReport(String reportName, ReportFiller filler) throws JRException, IOException {
    JasperReport jasperReport = JasperCompileManager.compileReport(getClass().getResourceAsStream("/reports/" + reportName + ".jrxml"));
    JasperPrint jasperPrint = fill(jasperReport, filler);
    createPdf(jasperPrint, reportName);
    createXhtml(jasperPrint, reportName);
    createCsv(jasperPrint, reportName);
    // this is ugly, but we verify that the reports exists and have a file size > 0
    verifyReport(reportName, "pdf");
    verifyReport(reportName, "html");
    verifyReport(reportName, "csv");
}
Also used : JasperPrint(net.sf.jasperreports.engine.JasperPrint) JasperReport(net.sf.jasperreports.engine.JasperReport)

Example 13 with JasperReport

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

the class TestReport method f.

@Test
public void f() throws Exception {
    OperationResult initResult = new OperationResult("generate report");
    JasperDesign jd = JRXmlLoader.load(new File("src/test/resources/reports/report-users-ds.jrxml"));
    JasperReport jr = JasperCompileManager.compileReport(jd);
    Task task = taskManager.createTaskInstance();
    Map<String, Object> params = new HashMap<String, Object>();
    //	  params.put(MidPointQueryExecutorFactory.PARAMETER_MIDPOINT_CONNECTION, modelService);
    //	  params.put(MidPointQueryExecutorFactory.PARAMETER_PRISM_CONTEXT, prismContext);
    //	  params.put(MidPointQueryExecutorFactory.PARAMETER_TASK_MANAGER, taskManager);
    //	  params.put(MidPointQueryExecutorFactory.PARAMETER_EXPRESSION_FACTORY, expressionFactory);
    params.put("userName", new PolyString("administrator"));
    reportTaskHandler.run(task);
    //	  byte[] reportTemplatebase64 = "".getBytes();
    //	 	byte[] reportTemplate = Base64.decodeBase64("UEdwaGMzQmxjbEpsY0c5eWRDQU5DaUFnSUNBSkNYaHRiRzV6UFNKb2RIUndPaTh2YW1GemNHVnljbVZ3YjNKMGN5NXpiM1Z5WTJWbWIzSm5aUzV1WlhRdmFtRnpjR1Z5Y21Wd2IzSjBjeUlnRFFvSkNRbDRiV3h1Y3pwNGMyazlJbWgwZEhBNkx5OTNkM2N1ZHpNdWIzSm5Mekl3TURFdldFMU1VMk5vWlcxaExXbHVjM1JoYm1ObElpQU5DZ2tKQ1hoemFUcHpZMmhsYldGTWIyTmhkR2x2YmowaWFIUjBjRG92TDJwaGMzQmxjbkpsY0c5eWRITXVjMjkxY21ObFptOXlaMlV1Ym1WMEwycGhjM0JsY25KbGNHOXlkSE1nYUhSMGNEb3ZMMnBoYzNCbGNuSmxjRzl5ZEhNdWMyOTFjbU5sWm05eVoyVXVibVYwTDNoelpDOXFZWE53WlhKeVpYQnZjblF1ZUhOa0lpQU5DZ2tKQ1c1aGJXVTlJbkpsY0c5eWRGVnpaWEpCWTJOdmRXNTBjeUlnRFFvSkNRbGpiMngxYlc1RGIzVnVkRDBpTWlJZ0RRb0pDUWx3WVdkbFYybGtkR2c5SWpFNE1DSWdEUW9KQ1Fsd1lXZGxTR1ZwWjJoMFBTSXhPQ0lnRFFvSkNRbDNhR1Z1VG05RVlYUmhWSGx3WlQwaVFXeHNVMlZqZEdsdmJuTk9iMFJsZEdGcGJDS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ZMmhVZVhCbFBTSlNaV3hoZEdsMlpWUnZWR0ZzYkdWemRFOWlhbVZqZENJZ2MzUjViR1U5SWtSbGRHRnBiQ0lnZUQwaU1DSWdlVDBpTWlJZ2QybGtkR2c5SWpFNE1DSWdhR1ZwWjJoMFBTSXhNeUl2UGcwS0NRa0pDUWtKQ1R4MFpYaDBSV3hsYldWdWRDQjJaWEowYVdOaGJFRnNhV2R1YldWdWREMGlUV2xrWkd4bElpOCtJQTBLQ1FrSkNRa0pDVHgwWlhoMFJtbGxiR1JGZUhCeVpYTnphVzl1UGp3aFcwTkVRVlJCV3lSR2UzSmxjMjkxY21ObFRtRnRaWDBySUNJNklDSWdLeUFrUm50aFkyTnZkVzUwVG1GdFpYMWRYVDQ4TDNSbGVIUkdhV1ZzWkVWNGNISmxjM05wYjI0K0RRb0pDUWtKQ1FrOEwzUmxlSFJHYVdWc1pENE5DZ2tKQ1FrSlBDOW1jbUZ0WlQ0TkNna0pDUWs4TDJKaGJtUStEUW9KQ1FrOEwyUmxkR0ZwYkQ0TkNna0pQQzlxWVhOd1pYSlNaWEJ2Y25RKw==".getBytes());
    //	  
    //	 	byte[] decoded = Base64.decodeBase64(reportTemplate);
    //	 	String s = new String(decoded);
    //	 	System.out.println(s);
    File f = new File("src/test/resources/reports/reportAccounts.txt");
    //	 	DataOutputStream fos = new DataOutputStream(new FileOutputStream(f));
    //	 	fos.writeUTF(s);
    //	 	fos.close();
    JasperPrint jasperPrint = JasperFillManager.fillReport(jr, params);
    f = new File("src/test/resources/reports/report5.pdf");
    JasperExportManager.exportReportToPdfFile(jasperPrint, f.getAbsolutePath());
//	  System.out.println("output: " + output);
//	  jr.
//	  jr.getQuery().getLanguage();
//	  jr.getQuery().getText();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) JasperDesign(net.sf.jasperreports.engine.design.JasperDesign) HashMap(java.util.HashMap) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) JasperPrint(net.sf.jasperreports.engine.JasperPrint) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) JasperReport(net.sf.jasperreports.engine.JasperReport) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 14 with JasperReport

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

the class ReportManagerImpl method invoke.

/**
     * Transforms change:
     * 1/ ReportOutputType DELETE to MODIFY some attribute to mark it for deletion.
     * 2/ ReportType ADD and MODIFY should compute jasper design and styles if necessary
     *
     * @param context
     * @param task
     * @param result
     * @return
     * @throws UnsupportedEncodingException 
     */
@Override
public HookOperationMode invoke(@NotNull ModelContext context, @NotNull Task task, @NotNull OperationResult parentResult) {
    ModelState state = context.getState();
    if (state != ModelState.FINAL) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("report manager called in state = " + state + ", exiting.");
        }
        return HookOperationMode.FOREGROUND;
    } else {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("report manager called in state = " + state + ", proceeding.");
        }
    }
    boolean relatesToReport = false;
    boolean isDeletion = false;
    PrismObject<?> object = null;
    for (Object o : context.getProjectionContexts()) {
        boolean deletion = false;
        object = ((ModelElementContext<?>) o).getObjectNew();
        if (object == null) {
            deletion = true;
            object = ((ModelElementContext<?>) o).getObjectOld();
        }
        if (object == null) {
            LOGGER.warn("Probably invalid projection context: both old and new objects are null");
        } else if (object.getCompileTimeClass().isAssignableFrom(ReportType.class)) {
            relatesToReport = true;
            isDeletion = deletion;
        }
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("change relates to report: " + relatesToReport + ", is deletion: " + isDeletion);
    }
    if (!relatesToReport) {
        LOGGER.trace("invoke() EXITING: Changes not related to report");
        return HookOperationMode.FOREGROUND;
    }
    if (isDeletion) {
        LOGGER.trace("invoke() EXITING because operation is DELETION");
        return HookOperationMode.FOREGROUND;
    }
    OperationResult result = parentResult.createSubresult(CLASS_NAME_WITH_DOT + "invoke");
    try {
        ReportType reportType = (ReportType) object.asObjectable();
        JasperDesign jasperDesign = null;
        if (reportType.getTemplate() == null) {
            String message = "Report template must not be null";
            LOGGER.error(message);
            result.recordFatalError(message, new SystemException());
        } else //             {
        //            	 PrismSchema reportSchema = null;
        //            	 PrismContainer<ReportConfigurationType> parameterConfiguration = null;  
        //            	 try
        //            	 {
        //            		reportSchema = ReportUtils.getParametersSchema(reportType, prismContext);
        //            		parameterConfiguration = ReportUtils.getParametersContainer(reportType, reportSchema);
        //             		
        //            	 } catch (Exception ex){
        //            		 String message = "Cannot create parameter configuration: " + ex.getMessage();
        //            		 LOGGER.error(message);
        //            		 result.recordFatalError(message, ex);
        //            	 }
        //            	 
        //            	 jasperDesign = ReportUtils.createJasperDesign(reportType, parameterConfiguration, reportSchema) ;
        //            	 LOGGER.trace("create jasper design : {}", jasperDesign);
        //             }
        {
            byte[] reportTemplateBase64 = reportType.getTemplate();
            byte[] reportTemplate = Base64.decodeBase64(reportTemplateBase64);
            InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate);
            jasperDesign = JRXmlLoader.load(inputStreamJRXML);
            LOGGER.trace("load jasper design : {}", jasperDesign);
        }
        // Compile template
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport);
        //result.computeStatus();
        result.recordSuccessIfUnknown();
    } catch (JRException ex) {
        String message = "Cannot load or compile jasper report: " + ex.getMessage();
        LOGGER.error(message);
        result.recordFatalError(message, ex);
    }
    return HookOperationMode.FOREGROUND;
}
Also used : JasperDesign(net.sf.jasperreports.engine.design.JasperDesign) JRException(net.sf.jasperreports.engine.JRException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ModelState(com.evolveum.midpoint.model.api.context.ModelState) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) JasperReport(net.sf.jasperreports.engine.JasperReport) ByteArrayInputStream(java.io.ByteArrayInputStream) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 15 with JasperReport

use of net.sf.jasperreports.engine.JasperReport in project adempiere by adempiere.

the class ReportStarter method compileReport.

/**
     * @author rlemeill
     * @param reportFile
     * @param jasperFile
     * @return compiled JasperReport
     */
private JasperReport compileReport(File reportFile, File jasperFile) {
    JWScorrectClassPath();
    JasperReport compiledJasperReport = null;
    try {
        JasperCompileManager.compileReportToFile(reportFile.getAbsolutePath(), jasperFile.getAbsolutePath());
        //Synchronize Dates
        jasperFile.setLastModified(reportFile.lastModified());
        compiledJasperReport = (JasperReport) JRLoader.loadObject(jasperFile);
    } catch (JRException e) {
        log.log(Level.SEVERE, "Error", e);
    }
    return compiledJasperReport;
}
Also used : JRException(net.sf.jasperreports.engine.JRException) JasperReport(net.sf.jasperreports.engine.JasperReport)

Aggregations

JasperReport (net.sf.jasperreports.engine.JasperReport)18 JRException (net.sf.jasperreports.engine.JRException)11 JasperPrint (net.sf.jasperreports.engine.JasperPrint)10 HashMap (java.util.HashMap)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 File (java.io.File)4 Connection (java.sql.Connection)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 JasperDesign (net.sf.jasperreports.engine.design.JasperDesign)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ReportType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)2 SQLException (java.sql.SQLException)2 JRDesignExpression (net.sf.jasperreports.engine.design.JRDesignExpression)2 DigestOfFile (org.compiere.util.DigestOfFile)2 ReportException (org.opennms.api.reporting.ReportException)2 ModelState (com.evolveum.midpoint.model.api.context.ModelState)1 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)1 Item (com.evolveum.midpoint.prism.Item)1 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1