summaryrefslogtreecommitdiff
path: root/reportbuilder
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2013-03-12 17:57:57 +0100
committerLionel Elie Mamane <lionel@mamane.lu>2013-03-12 18:16:45 +0100
commit4178806bb010129f3b13b62825476666fe48ddcd (patch)
tree26f68a3eb4891945ee06f3630dcf93960de7b3ac /reportbuilder
parent36caac0e029a3caf50cb27af339efd69008d414e (diff)
reportbuilder: make "Group on" not-"Each Value" actually work
Change-Id: Id5d73f9aac48ebfb6987e5bf0df37e62f1817bdc
Diffstat (limited to 'reportbuilder')
-rw-r--r--reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java9
-rw-r--r--reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java40
-rw-r--r--reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java11
-rw-r--r--reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java13
-rw-r--r--reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java5
5 files changed, 71 insertions, 7 deletions
diff --git a/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java b/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java
index a22be04503cc..24e1fe10ba52 100644
--- a/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java
+++ b/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java
@@ -139,6 +139,7 @@ public class SDBCReportDataFactory implements DataSourceFactory
private static final Log LOGGER = LogFactory.getLog(SDBCReportDataFactory.class);
public static final String COMMAND_TYPE = "command-type";
public static final String ESCAPE_PROCESSING = "escape-processing";
+ public static final String SORT_EXPRESSIONS = "sort-expressions";
public static final String GROUP_EXPRESSIONS = "group-expressions";
public static final String MASTER_VALUES = "master-values";
public static final String MASTER_COLUMNS = "master-columns";
@@ -229,10 +230,10 @@ public class SDBCReportDataFactory implements DataSourceFactory
}
}
- private String getOrderStatement(final int commandType, final String command, final List groupExpressions)
+ private String getOrderStatement(final int commandType, final String command, final List sortExpressions)
{
final StringBuffer order = new StringBuffer();
- final int count = groupExpressions.size();
+ final int count = sortExpressions.size();
if (count != 0)
{
try
@@ -244,7 +245,7 @@ public class SDBCReportDataFactory implements DataSourceFactory
{
for (int i = 0; i < count; i++)
{
- final Object[] pair = (Object[]) groupExpressions.get(i);
+ final Object[] pair = (Object[]) sortExpressions.get(i);
String expression = (String) pair[0];
if (!expression.startsWith(quote) && columns.hasByName(expression))
@@ -533,7 +534,7 @@ public class SDBCReportDataFactory implements DataSourceFactory
WrappedTargetException,
NoSuchElementException
{
- final StringBuffer order = new StringBuffer(getOrderStatement(commandType, command, (ArrayList<?>) parameters.get(GROUP_EXPRESSIONS)));
+ final StringBuffer order = new StringBuffer(getOrderStatement(commandType, command, (ArrayList<?>) parameters.get(SORT_EXPRESSIONS)));
if (order.length() > 0 && commandType != CommandType.TABLE)
{
String statement = command;
diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java b/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java
index e1cf4f3900e9..fc8b4ff4b2d1 100644
--- a/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java
+++ b/reportbuilder/java/org/libreoffice/report/pentaho/PentahoReportJob.java
@@ -311,6 +311,37 @@ public class PentahoReportJob implements ReportJob
}
}
+ private void collectSortExpressions(final Node[] nodes, final List<Object[]> expressions, final FormulaParser parser, final Expression reportFunctions[])
+ {
+ for (int i = 0; i < nodes.length; i++)
+ {
+ final Node node = nodes[i];
+ if (node instanceof OfficeGroup)
+ {
+ final OfficeGroup group = (OfficeGroup) node;
+ final String exp = group.getSortingExpression();
+ if (exp == null)
+ {
+ continue;
+ }
+
+ final Object[] pair = new Object[2];
+ pair[0] = exp;
+ pair[1] = group.getAttribute(OfficeNamespaces.OOREPORT_NS, "sort-ascending");
+ expressions.add(pair);
+ }
+ else if (node instanceof OfficeDetailSection)
+ {
+ return;
+ }
+ if (node instanceof Section)
+ {
+ final Section section = (Section) node;
+ collectSortExpressions(section.getNodeArray(), expressions, parser, reportFunctions);
+ }
+ }
+ }
+
private void setMetaDataProperties(DefaultReportJob job)
{
job.getConfiguration().setConfigProperty(ReportEngineParameterNames.AUTHOR, (String) jobProperties.getProperty(ReportEngineParameterNames.AUTHOR));
@@ -343,11 +374,14 @@ public class PentahoReportJob implements ReportJob
final Node[] nodes = report.getNodeArray();
final FormulaParser parser = new FormulaParser();
- final ArrayList<Object[]> expressions = new ArrayList<Object[]>();
final OfficeReport officeReport = (OfficeReport) ((Section) nodes[0]).getNode(0);
final Section reportBody = (Section) officeReport.getBodySection();
- collectGroupExpressions(reportBody.getNodeArray(), expressions, parser, officeReport.getExpressions());
- parameters.put(SDBCReportDataFactory.GROUP_EXPRESSIONS, expressions);
+ final ArrayList<Object[]> sortExpressions = new ArrayList<Object[]>();
+ collectSortExpressions(reportBody.getNodeArray(), sortExpressions, parser, officeReport.getExpressions());
+ parameters.put(SDBCReportDataFactory.SORT_EXPRESSIONS, sortExpressions);
+ final ArrayList<Object[]> groupExpressions = new ArrayList<Object[]>();
+ collectGroupExpressions(reportBody.getNodeArray(), groupExpressions, parser, officeReport.getExpressions());
+ parameters.put(SDBCReportDataFactory.GROUP_EXPRESSIONS, groupExpressions);
final String command = (String) officeReport.getAttribute(OfficeNamespaces.OOREPORT_NS, "command");
final String commandType = (String) officeReport.getAttribute(OfficeNamespaces.OOREPORT_NS, SDBCReportDataFactory.COMMAND_TYPE);
final String escapeProcessing = (String) officeReport.getAttribute(OfficeNamespaces.OOREPORT_NS, SDBCReportDataFactory.ESCAPE_PROCESSING);
diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java
index b10aab188d0c..79ea585ebf3a 100644
--- a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java
+++ b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroup.java
@@ -81,4 +81,15 @@ public class OfficeGroup extends Section
}
return instanceSection.getGroupingExpression();
}
+
+ public String getSortingExpression()
+ {
+ final OfficeGroupInstanceSection instanceSection =
+ (OfficeGroupInstanceSection) findFirstChild(JFreeReportInfo.REPORT_NAMESPACE, "group-instance");
+ if (instanceSection == null)
+ {
+ return null;
+ }
+ return instanceSection.getSortingExpression();
+ }
}
diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java
index a9adad301c41..cd7ed7b694c1 100644
--- a/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java
+++ b/reportbuilder/java/org/libreoffice/report/pentaho/model/OfficeGroupInstanceSection.java
@@ -27,7 +27,20 @@ import org.jfree.report.structure.Group;
public class OfficeGroupInstanceSection extends Group
{
+ String sortingExpression;
+
public OfficeGroupInstanceSection()
{
}
+
+ public void setSortingExpression(String s)
+ {
+ sortingExpression=s;
+ }
+
+ public String getSortingExpression()
+ {
+ return sortingExpression;
+ }
+
}
diff --git a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java
index 22def36e179b..7843d8afd160 100644
--- a/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java
+++ b/reportbuilder/java/org/libreoffice/report/pentaho/parser/rpt/GroupReadHandler.java
@@ -77,6 +77,11 @@ public class GroupReadHandler extends ElementReadHandler
function.setFormula(groupExpr);
groupInstanceSection.setGroupingExpression(function);
}
+ final String sortExpr = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "sort-expression");
+ if (sortExpr != null && !"".equals(sortExpr))
+ {
+ groupInstanceSection.setSortingExpression(sortExpr);
+ }
}
/**