User: kz      
Date: 2008-03-05 17:30:02+0000
Modified:
   dba/reportdesign/java/com/sun/star/report/pentaho/PentahoReportJob.java

Log:
 INTEGRATION: CWS rptchart01_DEV300 (1.2.70); FILE MERGED
 2008/02/21 09:57:23 oj 1.2.70.3: #i85225# fixes found with PMD
 2008/02/19 06:42:48 oj 1.2.70.2: #i85225# ongoing work
 2008/02/13 07:04:22 oj 1.2.70.1: #i85225# impl chart readhandler and 
oleproducer

File Changes:

Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/
==============================================================

File [changed]: PentahoReportJob.java
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/PentahoReportJob.java?r1=1.2&r2=1.3
Delta lines:  +243 -188
-----------------------
--- PentahoReportJob.java       2007-07-09 11:56:04+0000        1.2
+++ PentahoReportJob.java       2008-03-05 17:30:00+0000        1.3
@@ -33,8 +33,6 @@
  *    MA  02111-1307  USA
  *
  ************************************************************************/
-
-
 package com.sun.star.report.pentaho;
 
 import java.io.IOException;
@@ -54,11 +52,18 @@
 import com.sun.star.report.ImageService;
 import com.sun.star.report.pentaho.loader.InputRepositoryLoader;
 import com.sun.star.report.pentaho.model.OfficeDocument;
+import com.sun.star.report.pentaho.model.OfficeGroup;
+import com.sun.star.report.pentaho.model.OfficeReport;
+import com.sun.star.report.pentaho.output.chart.ChartRawReportProcessor;
 import com.sun.star.report.pentaho.output.text.TextRawReportProcessor;
 import 
com.sun.star.report.pentaho.output.spreadsheet.SpreadsheetRawReportProcessor;
+import java.util.Vector;
+import org.jfree.report.expressions.FormulaExpression;
 import org.jfree.report.flow.DefaultReportJob;
 import org.jfree.report.flow.ReportProcessor;
 import org.jfree.report.flow.raw.XmlPrintReportProcessor;
+import org.jfree.report.structure.Node;
+import org.jfree.report.structure.Section;
 import org.jfree.report.util.ReportParameters;
 import org.jfree.resourceloader.Resource;
 import org.jfree.resourceloader.ResourceException;
@@ -70,6 +75,7 @@
  */
 public class PentahoReportJob implements ReportJob
 {
+
   private boolean finished;
   private ArrayList listeners;
   private DataSourceFactory dataSourceFactory;
@@ -80,8 +86,14 @@
   private String outputName;
   private ImageService imageService;
   private InputRepository inputRepository;
+    private ReportJobDefinition definition;
+
+    public ReportJobDefinition getDefinition()
+    {
+        return definition;
+    }
 
-  public PentahoReportJob (final ReportJobDefinition definition)
+    public PentahoReportJob(final ReportJobDefinition definition)
           throws JobDefinitionException
   {
     if (definition == null)
@@ -89,33 +101,30 @@
       throw new NullPointerException();
     }
 
+        this.definition = definition;
     this.listeners = new ArrayList();
     this.jobProperties = definition.getProcessingParameters().copy();
 
-    this.dataSourceFactory = (DataSourceFactory) jobProperties.getProperty
-            (ReportEngineParameterNames.INPUT_DATASOURCE_FACTORY);
+        this.dataSourceFactory = (DataSourceFactory) 
jobProperties.getProperty(ReportEngineParameterNames.INPUT_DATASOURCE_FACTORY);
     if (this.dataSourceFactory == null)
     {
       throw new JobDefinitionException("DataSourceFactory must not be null.");
     }
 
-    this.outputRepository = (OutputRepository) jobProperties.getProperty
-            (ReportEngineParameterNames.OUTPUT_REPOSITORY);
+        this.outputRepository = (OutputRepository) 
jobProperties.getProperty(ReportEngineParameterNames.OUTPUT_REPOSITORY);
     if (this.outputRepository == null)
     {
       throw new JobDefinitionException("OutputRepository must not be null.");
     }
 
     this.inputRepository =
-        (InputRepository) jobProperties.getProperty
-            (ReportEngineParameterNames.INPUT_REPOSITORY);
+                (InputRepository) 
jobProperties.getProperty(ReportEngineParameterNames.INPUT_REPOSITORY);
     if (inputRepository == null)
     {
       throw new JobDefinitionException("InputRepository must not be null.");
     }
 
-    this.outputName = (String) jobProperties
-            .getProperty(ReportEngineParameterNames.OUTPUT_NAME);
+        this.outputName = (String) 
jobProperties.getProperty(ReportEngineParameterNames.OUTPUT_NAME);
     if (outputName == null)
     {
       throw new JobDefinitionException("OutputName must not be null");
@@ -140,21 +149,20 @@
     }
   }
 
-  private OfficeDocument parseReport (final ReportJobDefinition definition)
+    private OfficeDocument parseReport(final ReportJobDefinition definition)
           throws ResourceException, JobDefinitionException
   {
-    final String reportResource = (String) this.jobProperties.getProperty
-            (ReportEngineParameterNames.INPUT_NAME);
+        final String reportResource = (String) 
this.jobProperties.getProperty(ReportEngineParameterNames.INPUT_NAME);
     if (reportResource == null)
     {
       throw new JobDefinitionException("Report definition name must be given");
     }
 
-    final Resource res = resourceManager.createDirectly
-            ("sun:oo://" + reportResource, OfficeDocument.class);
-    final OfficeDocument report = (OfficeDocument) res.getResource();
-    report.setDataFactory(new StarReportDataFactory(dataSourceFactory));
-    final ReportParameters inputParameters = report.getInputParameters();
+        final Resource res = resourceManager.createDirectly("sun:oo://" + 
reportResource, OfficeDocument.class);
+        final OfficeDocument tempReport = (OfficeDocument) res.getResource();
+        tempReport.setDataFactory(new 
StarReportDataFactory(dataSourceFactory));
+        
tempReport.setJobProperties(definition.getProcessingParameters().copy());
+        final ReportParameters inputParameters = 
tempReport.getInputParameters();
 
     final ParameterMap queryParameters = definition.getQueryParameters();
     final String[] paramKeys = queryParameters.keys();
@@ -164,10 +172,10 @@
       inputParameters.put(key, queryParameters.get(key));
     }
 
-    return report;
+        return tempReport;
   }
 
-  public void addProgressIndicator (final JobProgressIndicator indicator)
+    public void addProgressIndicator(final JobProgressIndicator indicator)
   {
     listeners.add(indicator);
   }
@@ -175,7 +183,7 @@
   /**
    * Interrupt the job.
    */
-  public void interrupt ()
+    public void interrupt()
   {
     // hey, not yet ..
   }
@@ -186,12 +194,12 @@
    * @return true, if the job is finished (or has been interrupted), false if 
the job
    *         waits for activation.
    */
-  public boolean isFinished ()
+    public boolean isFinished()
   {
     return finished;
   }
 
-  public void finish ()
+    public void finish()
   {
     finished = true;
   }
@@ -201,38 +209,76 @@
    *
    * @return true, if the job is currently running, false otherwise.
    */
-  public boolean isRunning ()
+    public boolean isRunning()
   {
     return finished == false;
   }
 
-  public void removeProgressIndicator (final JobProgressIndicator indicator)
+    public void removeProgressIndicator(final JobProgressIndicator indicator)
   {
     listeners.remove(indicator);
   }
 
+    private void collectGroupExpressions(Node[] nodes, Vector expressions, 
OfficeReport[] report)
+    {
+        for (int i = 0; i < nodes.length; i++)
+        {
+            Node node = nodes[i];
+            if (node instanceof OfficeGroup)
+            {
+                OfficeGroup group = (OfficeGroup) node;
+                FormulaExpression exp = (FormulaExpression) 
group.getGroupingExpression();
+                Object[] pair = new Object[2];
+                pair[0] = exp.getFormula();
+                pair[1] = group.getAttribute(OfficeNamespaces.OOREPORT_NS, 
"sort-ascending");
+                expressions.add(pair);
+
+            }
+            else if (node instanceof OfficeReport && report[0] == null)
+            {
+                report[0] = (OfficeReport) node;
+            }
+            if (node instanceof Section)
+            {
+                Section section = (Section) node;
+                collectGroupExpressions(section.getNodeArray(), expressions, 
report);
+            }
+
+        }
+    }
+
   /**
    * Although we might want to run the job as soon as it has been created, 
sometimes it is
    * wiser to let the user add some listeners first. If we execute at once, 
the user
    * either has to deal with threading code or wont receive any progress 
information in
    * single threaded environments.
    */
-  public void execute ()
+    public void execute()
           throws ReportExecutionException, IOException
   {
     final DefaultReportJob job = new DefaultReportJob(report);
 
-    final String contentType = (String)
-            jobProperties.getProperty(ReportEngineParameterNames.CONTENT_TYPE);
+        final String contentType = (String) 
jobProperties.getProperty(ReportEngineParameterNames.CONTENT_TYPE);
     //noinspection OverlyBroadCatchBlock
     try
     {
+            ReportParameters parameters = job.getParameters();
+            Node[] nodes = report.getNodeArray();
+            Vector expressions = new Vector();
+            OfficeReport[] officeReport = new OfficeReport[1];
+            collectGroupExpressions(nodes, expressions, officeReport);
+            parameters.put("group-expressions", expressions);
+            String command = (String) 
officeReport[0].getAttribute(OfficeNamespaces.OOREPORT_NS, "command");
+            String commandType = (String) 
officeReport[0].getAttribute(OfficeNamespaces.OOREPORT_NS, "command-type");
+            report.setQuery(command);
+            parameters.put("command-type", commandType);
+
       final long startTime = System.currentTimeMillis();
       final ReportProcessor rp = getProcessorForContentType(contentType);
       rp.processReport(job);
       job.close();
       final long endTime = System.currentTimeMillis();
-      Log.debug ("Report processing time: "  + (endTime - startTime));
+            Log.debug("Report processing time: " + (endTime - startTime));
     }
     catch (final Exception e)
     {
@@ -244,18 +290,27 @@
   protected ReportProcessor getProcessorForContentType(final String mimeType)
       throws ReportExecutionException
   {
+        ReportProcessor ret = null;
     if (PentahoReportEngineMetaData.OPENDOCUMENT_SPREADSHEET.equals(mimeType))
     {
-      return new SpreadsheetRawReportProcessor(inputRepository, 
outputRepository, outputName, imageService);
+            ret = new SpreadsheetRawReportProcessor(inputRepository, 
outputRepository, outputName, imageService, dataSourceFactory);
+        }
+        else if 
(PentahoReportEngineMetaData.OPENDOCUMENT_TEXT.equals(mimeType))
+        {
+            ret = new TextRawReportProcessor(inputRepository, 
outputRepository, outputName, imageService, dataSourceFactory);
     }
-    if (PentahoReportEngineMetaData.OPENDOCUMENT_TEXT.equals(mimeType))
+        else if 
(PentahoReportEngineMetaData.OPENDOCUMENT_CHART.equals(mimeType))
     {
-      return new TextRawReportProcessor(inputRepository, outputRepository, 
outputName, imageService);
+            ret = new ChartRawReportProcessor(inputRepository, 
outputRepository, outputName, imageService, dataSourceFactory);
     }
-    if (PentahoReportEngineMetaData.DEBUG.equals(mimeType))
+        else if (PentahoReportEngineMetaData.DEBUG.equals(mimeType))
     {
-      return new XmlPrintReportProcessor(System.out, "ISO-8859-1");
+            ret = new XmlPrintReportProcessor(System.out, "ISO-8859-1");
     }
+        if (ret == null)
+        {
     throw new ReportExecutionException("Invalid mime-type");
   }
+        return ret;
+    }
 }




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to