Package org.efs.openreports.objects

Examples of org.efs.openreports.objects.Report


 
  public JasperPrint fillReport(ReportEngineInput input) throws ProviderException
  {
    Connection conn = null;

    Report report = input.getReport();
    Map<String,Object> parameters = input.getParameters();
   
    ReportDataSource dataSource = report.getDataSource();

    try
    {
      JasperReport jr = null;

      if (report.isQueryReport()) return fillQueryReport(report, parameters, input.getExportType());

      jr = (JasperReport) JRLoader
          .loadObject(directoryProvider.getReportDirectory() + report.getFile());

      List<ReportParameterMap> subReports = report.getSubReportParameters();
      if (subReports != null && subReports.size() > 0)
      {
        Iterator<ReportParameterMap> iterator = report.getSubReportParameters().iterator();
        while (iterator.hasNext())
        {
          ReportParameterMap rpMap = iterator.next();

          JasperReport subReport = (JasperReport) JRLoader.loadObject(directoryProvider
View Full Code Here


            return reportOutput;     
    }   
   
    try
    {
      Report report = reportProvider.getReport(reportInput.getReportName());
      if (report == null)
      {
        reportOutput.setContentMessage("Invalid ReportInput - Report not found: " + reportInput.getReportName());
        log.warn("generateReport: request :  " + reportInput.getRequestId() + " : " + reportOutput.getContentMessage());
       
        return reportOutput;
      }
     
      ReportUser user = userProvider.getUser(reportInput.getUser().getUserName(), reportInput.getUser().getPassword());
      if (user == null)
      {
        reportOutput.setContentMessage("Invalid ReportInput - User not found: " + reportInput.getUser().getUserName());
        log.warn("generateReport: request :  " + reportInput.getRequestId() + " : " + reportOutput.getContentMessage());
       
        return reportOutput;
      }
     
      if (!user.isValidReport(report))
      {
        reportOutput.setContentMessage("Invalid ReportInput - "
            + user.getName() + " not authorized to run: "
            + reportInput.getReportName());
       
        log.warn("generateReport: request :  " + reportInput.getRequestId() + " : " + reportOutput.getContentMessage());
       
        return reportOutput; 
      }   
     
      log.info("generateReport: received request :  " + reportInput.getRequestId() + " : for report : " + report.getName() + " : from : " +  user.getName());
     
            if (reportInput.getDeliveryMethods() == null || reportInput.getDeliveryMethods().length < 1)
            {
                ReportLog reportLog = null;
               
                try
                {
                    reportLog = new ReportLog(user, report, new Date());
                    reportLog.setExportType(reportInput.getExportType().getCode());
                   
                    reportLog = reportLogProvider.insertReportLog(reportLog);              
                                 
                    ReportEngine reportEngine = ReportEngineHelper.getReportEngine(report,
                            dataSourceProvider, directoryProvider, propertiesProvider);
                   
                    ReportEngineInput engineInput = new ReportEngineInput(report, buildParameterMap(reportInput, report));
                    engineInput.setExportType(reportInput.getExportType());
                    engineInput.setXmlInput(reportInput.getXmlInput());
                    engineInput.setLocale(ORUtil.getLocale(reportInput.getLocale()));
                   
                    ReportEngineOutput reportEngineOutput = reportEngine.generateReport(engineInput);
                   
                    reportOutput.setContent(reportEngineOutput.getContent());
                    reportOutput.setContentType(reportEngineOutput.getContentType());
                    reportOutput.setContentExtension(reportEngineOutput.getContentExtension());
                   
                    //convert List of Dynabeans to XML so that it can be serialized
                    if (reportEngineOutput instanceof QueryEngineOutput)
                    {
                        ByteArrayOutputStream out = new ByteArrayOutputStream();          
                                          
                        xStream.toXML(((QueryEngineOutput)reportEngineOutput).getResults(), out);                  
                       
                        reportOutput.setContent(out.toByteArray());
                        reportOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_XML);
                       
                        out.close();                
                    }               
                  
                    reportLog.setStatus(ReportLog.STATUS_SUCCESS);
                    reportLog.setEndTime(new Date());
                   
                    reportLogProvider.updateReportLog(reportLog);
                }
                catch(Exception e)
                {
                    if (reportLog != null && reportLog.getId() != null)
                    {
                        reportLog.setStatus(ReportLog.STATUS_FAILURE);
                        reportLog.setMessage(e.getMessage());
                        reportLog.setEndTime(new Date());
                       
                        try
                        {
                            reportLogProvider.updateReportLog(reportLog);
                        }
                        catch (Exception ex)
                        {
                            log.error("Unable to update ReportLog: " + ex.getMessage());
                        }                      
                    }
                }
            }
            else          
            {          
        ReportSchedule schedule = new ReportSchedule();
        schedule.setReport(report);
        schedule.setUser(user);
        schedule.setReportParameters(buildParameterMap(reportInput, report));
        schedule.setExportType(reportInput.getExportType().getCode());       
        schedule.setScheduleName(report.getId() + "|" + new Date().getTime());
        schedule.setScheduleDescription(reportInput.getScheduleDescription());       
        schedule.setScheduleType(ReportSchedule.ONCE);
        schedule.setXmlInput(reportInput.getXmlInput());               
                schedule.setDeliveryReturnAddress(reportInput.getDeliveryReturnAddress());
                schedule.setRequestId(reportInput.getRequestId());
View Full Code Here

  {
    ReportInfo reportInfo = null;
   
    try
    {
      Report report = reportProvider.getReport(reportName);
      if (report != null)
      {
        reportInfo = Converter.convertToReportInfo(report);
      }
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public ReportEngineOutput generateReport(ReportEngineInput input)
      throws ProviderException
  {
    Report report = input.getReport();
    Map<String,Object> parameters = input.getParameters();
   
    ReportEngineOutput output = new ReportEngineOutput();
    ByteArrayOutputStream out = new ByteArrayOutputStream();     

    IReportEngine engine = BirtProvider
        .getBirtEngine(directoryProvider.getReportDirectory() + "platform");   

    // Set options for task
    HTMLRenderOption renderOption = new HTMLRenderOption();
    renderOption.setOutputStream(out);     
    renderOption.setImageDirectory(directoryProvider.getTempDirectory());
    renderOption.setBaseImageURL("report-images");   
           
    try
    {
      String designFile = directoryProvider.getReportDirectory() + report.getFile();
     
      log.info("Loading BIRT report design: " + report.getFile());
     
      IReportRunnable design = engine.openReportDesign(designFile);     
           
      handleDataSourceOverrides(design);       
     
      if (input.getExportType() == ExportType.PDF)
      {     
        output.setContentType(ReportEngineOutput.CONTENT_TYPE_PDF);
        renderOption.setOutputFormat(IRenderOption.OUTPUT_FORMAT_PDF);       
      }
      else if (input.getExportType() == ExportType.HTML || input.getExportType() == ExportType.HTML_EMBEDDED)
      {     
        output.setContentType(ReportEngineOutput.CONTENT_TYPE_HTML);
        renderOption.setOutputFormat(IRenderOption.OUTPUT_FORMAT_HTML)
       
        if (input.getExportType() == ExportType.HTML_EMBEDDED)
        {
          renderOption.setEmbeddable(true);
        }
      }
      else if (input.getExportType() == ExportType.XLS)
      {     
        output.setContentType(ReportEngineOutput.CONTENT_TYPE_XLS);
        renderOption.setOutputFormat("xls");       
      }
      else
      {
        log.error("Export type not yet implemented: " + input.getExportType());
      }
     
      IRunAndRenderTask task = engine.createRunAndRenderTask(design);         
      task.setRenderOption(renderOption);
      task.setParameterValues(parameters);     
      task.validateParameters();
     
      if (input.getLocale() != null)
      {
        task.setLocale(input.getLocale());
      }
     
      if (input.getXmlInput() != null)
      {
        ByteArrayInputStream stream = new ByteArrayInputStream(input.getXmlInput().getBytes());         
        task.getAppContext().put("org.eclipse.datatools.enablement.oda.xml.inputStream", stream);       
            }
     
      log.info("Generating BIRT report: " + report.getName());
     
      task.run();           
      task.close();
     
      log.info("Finished Generating BIRT report: " + report.getName());
     
      output.setContent(out.toByteArray());
    }
    catch (Throwable e)
    {
View Full Code Here

        super(dataSourceProvider,directoryProvider, propertiesProvider);
    }
   
    public ReportEngineOutput generateReport(ReportEngineInput input) throws ProviderException
    {
        Report report = input.getReport();
        Map parameters = input.getParameters();
       
        try
        {
            Properties properties = new Properties();
            properties.setProperty("file.resource.loader.path", directoryProvider.getReportDirectory());
            properties.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
           
            Velocity.init(properties);
          
            VelocityContext context = new VelocityContext();
            context.put( "parameters", parameters);
            context.put("report", report);           
           
            /*
             * if report has a query, process it like a QueryReport and
             * put the results in the VelocityContext for use in templates
             */
            if (report.getQuery() != null && report.getQuery().trim().length() > 0)
            {
                QueryReportEngine queryReport = new QueryReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);
                QueryEngineOutput queryOutput = (QueryEngineOutput) queryReport.generateReport(input);
               
                context.put("results", queryOutput.getResults());
                context.put("properties", queryOutput.getProperties());
            }
          
            StringWriter writer = new StringWriter();
           
            Template template = Velocity.getTemplate(report.getFile());          
            template.merge(context, writer);         
           
            ReportEngineOutput output = new ReportEngineOutput();
            output.setContent(writer.toString().getBytes());
           
View Full Code Here

  public String execute()
  {
    try
    {
      Report report = reportProvider.getReport(new Integer(id));

      name = report.getName();
      description = report.getDescription();

      if (!submitDelete && !submitCancel)
      {
        return INPUT;
      }
View Full Code Here

  public String execute()
  {   
    ReportUser user =
      (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);

    Report report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);

    int exportTypeCode =
      Integer.parseInt(
        (String) ActionContext.getContext().getSession().get(ORStatics.EXPORT_TYPE));
   
    ExportType exportType = ExportType.findByCode(exportTypeCode);

    Map<String, Object> reportParameters = getReportParameterMap(user, report, exportType);
    Map imagesMap = getImagesMap();

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();

    // set headers to disable caching   
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "max-age=0");

    ReportLog reportLog = new ReportLog(user, report, new Date());
        reportLog.setExportType(exportType.getCode());
   
    JRVirtualizer virtualizer = null;

    try
    {
      if (exportType == ExportType.PDF)       
      {
        // Handle "contype" request from Internet Explorer
        if ("contype".equals(request.getHeader("User-Agent")))
        {         
                  response.setContentType("application/pdf");             
                  response.setContentLength(0);              
                 
                  ServletOutputStream outputStream = response.getOutputStream();
                  outputStream.close();     
                 
                  return NONE;
        }
      }     
             
      log.debug("Filling report: " + report.getName());
     
      reportLogProvider.insertReportLog(reportLog);           

      if (report.isVirtualizationEnabled() && exportType != ExportType.IMAGE)
      {
        log.debug("Virtualization Enabled");
        virtualizer = new JRFileVirtualizer(2, directoryProvider.getTempDirectory());
        reportParameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
      }

      ReportEngineInput reportInput = new ReportEngineInput(report, reportParameters);
      reportInput.setExportType(exportType);
      reportInput.setImagesMap(imagesMap);

      // add any charts
      if (report.getReportChart() != null)
      {
        log.debug("Adding chart: " + report.getReportChart().getName());

        ChartReportEngine chartEngine = new ChartReportEngine(dataSourceProvider,
            directoryProvider, propertiesProvider);
       
        ChartEngineOutput chartOutput = (ChartEngineOutput) chartEngine
            .generateReport(reportInput);

        reportParameters.put("ChartImage", chartOutput.getContent());
      }
     
      ReportEngineOutput reportOutput = null;
      JasperPrint jasperPrint = null;
     
      if (report.isJasperReport())
      {
        JasperReportEngine jasperEngine = new JasperReportEngine(
            dataSourceProvider, directoryProvider, propertiesProvider);
       
        jasperPrint = jasperEngine.fillReport(reportInput);

        log.debug("Report filled - " + report.getName() + " : size = "
            + jasperPrint.getPages().size());

        log.debug("Exporting report: " + report.getName());

        reportOutput = jasperEngine.exportReport(jasperPrint, exportType, report
            .getReportExportOption(), imagesMap, false);
      }
      else
      {
        ReportEngine reportEngine = ReportEngineHelper.getReportEngine(report, dataSourceProvider, directoryProvider, propertiesProvider);
        reportOutput = reportEngine.generateReport(reportInput);
      }
     
      response.setContentType(reportOutput.getContentType());
     
      if (exportType != ExportType.HTML && exportType != ExportType.IMAGE)
      {
        response.setHeader("Content-disposition", "inline; filename="
            + StringUtils.deleteWhitespace(report.getName()) + reportOutput.getContentExtension());
      }     
     
      if (exportType == ExportType.IMAGE)
      {
        if (jasperPrint != null)
        {         
          session.put(ORStatics.JASPERPRINT, jasperPrint);
        }
      }
      else
      {       
        byte[] content = reportOutput.getContent();
       
        response.setContentLength(content.length);
       
        ServletOutputStream out = response.getOutputStream();
        out.write(content, 0, content.length);
        out.flush();
        out.close();       
      }

      reportLog.setEndTime(new Date());
      reportLog.setStatus(ReportLog.STATUS_SUCCESS);
      reportLogProvider.updateReportLog(reportLog);     

      log.debug("Finished report: " + report.getName());
    }
    catch (Exception e)
    {
      if (e.getMessage() != null && e.getMessage().equals(LocalStrings.ERROR_REPORT_EMPTY))
      {       
View Full Code Here

TOP

Related Classes of org.efs.openreports.objects.Report

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.