Package org.efs.openreports.objects

Examples of org.efs.openreports.objects.ReportSchedule


        {
        String group = reportUser.getId().toString();
   
        JobDetail jobDetail = scheduler.getJobDetail(name,  group);
   
        ReportSchedule reportSchedule = (ReportSchedule) jobDetail.getJobDataMap().get(ORStatics.REPORT_SCHEDULE);
        reportSchedule.setScheduleDescription(jobDetail.getDescription());
        reportSchedule.setScheduleState(getTriggerStateName(name, group));
           
        return reportSchedule;
        }
        catch(SchedulerException e)
        {
View Full Code Here


       
        ApplicationContext appContext = init(context);
           
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();

    ReportSchedule reportSchedule =
      (ReportSchedule) jobDataMap.get(ORStatics.REPORT_SCHEDULE);
    reportSchedule.setScheduleDescription(context.getJobDetail().getDescription());

    Report report = reportSchedule.getReport();
    ReportUser user = reportSchedule.getUser();
    Map<String,Object> reportParameters = reportSchedule.getReportParameters();

    log.debug("Report: " + report.getName());
    log.debug("User: " + user.getName());   

    JRVirtualizer virtualizer = null;
          
    ReportLog reportLog = new ReportLog(user, report, new Date());
        reportLog.setExportType(reportSchedule.getExportType());
        reportLog.setRequestId(reportSchedule.getRequestId());
       
    try
    {
      //
      ReportUserAlert alert = reportSchedule.getAlert();     
     
      if (alert != null)
      {
        log.debug("Executing Alert Condition");
       
        alert.setReport(report);
        alert = alertProvider.executeAlert(alert, true);
       
        if (!alert.isTriggered())
        {
          log.debug("Alert Not Triggered. Report not run.");
          return;
        }
       
        log.debug("Alert Triggered. Running report.");
      }
      //     

      // add standard report parameters
      reportParameters.put(ORStatics.USER_ID, user.getId());
      reportParameters.put(ORStatics.EXTERNAL_ID, user.getExternalId());
      reportParameters.put(ORStatics.USER_NAME, user.getName());
      reportParameters.put(ORStatics.IMAGE_DIR, new File(directoryProvider.getReportImageDirectory()));
      reportParameters.put(ORStatics.REPORT_DIR, new File(directoryProvider.getReportDirectory()));
      //
     
      reportLogProvider.insertReportLog(reportLog);     
     
      ReportEngineInput reportInput = new ReportEngineInput(report, reportParameters);
      reportInput.setExportType(ExportType.findByCode(reportSchedule.getExportType()));
            reportInput.setXmlInput(reportSchedule.getXmlInput());
            reportInput.setLocale(reportSchedule.getLocale());
     
      if (report.isJasperReport())
      {
        // 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());       
        }

        if (report.isVirtualizationEnabled())
        {
          log.debug("Virtualization Enabled");
          virtualizer = new JRFileVirtualizer(2, directoryProvider.getTempDirectory());
          reportParameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
        }
       
        reportInput.setParameters(reportParameters);
        reportInput.setInlineImages(true);       
      }
     
      ReportEngine reportEngine = ReportEngineHelper.getReportEngine(report,
          dataSourceProvider, directoryProvider, propertiesProvider)
      reportEngine.setApplicationContext(appContext);
     
      ReportEngineOutput reportOutput = reportEngine.generateReport(reportInput);           
          
            String[] deliveryMethods = reportSchedule.getDeliveryMethods();     
           
            if (deliveryMethods == null || deliveryMethods.length == 0)
            {
                deliveryMethods = new String[]{org.efs.openreports.ReportConstants.DeliveryMethod.EMAIL.getName()};
                log.warn("DeliveryMethod not set, defaulting to email delivery");
            }
           
            // set status to success. if a delivery method fails, this is updated to delivery failure
            reportLog.setStatus(ReportLog.STATUS_SUCCESS);
           
            ArrayList<ReportDeliveryLog> deliveryLogs = new ArrayList<ReportDeliveryLog>();
           
            for (int i=0; i < deliveryMethods.length; i++)
            {                                 
                ReportDeliveryLog deliveryLog = new ReportDeliveryLog(deliveryMethods[i], new Date());
           
                try
                {     
                  String deliveryMethodBeanId = deliveryMethods[i] + "DeliveryMethod";
                 
                    DeliveryMethod deliveryMethod = (DeliveryMethod) appContext.getBean(deliveryMethodBeanId, DeliveryMethod.class);           
                    deliveryMethod.deliverReport(reportSchedule, reportOutput);
                   
                    deliveryLog.setEndTime(new Date());
                    deliveryLog.setStatus(ReportLog.STATUS_SUCCESS);
                }               
                catch(DeliveryException de)
                {
                  log.error("Delivery Error: " + reportSchedule.getRequestId(), de);
                 
                    deliveryLog.setMessage(de.toString());
                    deliveryLog.setStatus(ReportLog.STATUS_DELIVERY_FAILURE);
                   
                    reportLog.setMessage(de.toString());
                    reportLog.setStatus(ReportLog.STATUS_DELIVERY_FAILURE);                   
                }
               
                deliveryLogs.add(deliveryLog);               
            }   

            reportLog.setDeliveryLogs(deliveryLogs);
      reportLog.setEndTime(new Date());     
           
      reportLogProvider.updateReportLog(reportLog);

      log.debug("Scheduled Report Finished...");
    }
    catch (Exception e)
    {
      if (e.getMessage() != null && e.getMessage().indexOf("Empty") > 0)
      {
        reportLog.setStatus(ReportLog.STATUS_EMPTY);
      }
      else
      {       
        log.error("ScheduledReport Error: " + reportSchedule.getRequestId(), e);

        reportLog.setMessage(e.toString());
        reportLog.setStatus(ReportLog.STATUS_FAILURE);
      }
View Full Code Here

TOP

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

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.