From b1fdd866ddd8a7b35cf3cd53f13e31c0f4c5f68c Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Wed, 27 Mar 2024 20:04:54 -0500 Subject: [PATCH] CE-881 - Add pivot table details to QReportView, renaming previous "pivot" things to "summary" --- .../reporting/GenerateReportAction.java | 18 +-- .../pivottable/PivotTableDefinition.java | 42 ++++++- .../pivottable/PivotTableGroupBy.java | 14 ++- .../reporting/pivottable/PivotTableValue.java | 15 ++- .../model/metadata/reporting/QReportView.java | 115 ++++++++++++++---- .../model/metadata/reporting/ReportType.java | 4 +- 6 files changed, 170 insertions(+), 38 deletions(-) diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/GenerateReportAction.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/GenerateReportAction.java index 91f07d98..4d220a59 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/GenerateReportAction.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/GenerateReportAction.java @@ -428,7 +428,7 @@ public class GenerateReportAction } } - for(String summaryField : CollectionUtils.nonNullList(view.getPivotFields())) + for(String summaryField : CollectionUtils.nonNullList(view.getSummaryFields())) { /////////////////////////////////////////////////////////////////////////////// // all pivotFields that are possible value sources are implicitly translated // @@ -545,7 +545,7 @@ public class GenerateReportAction for(QRecord record : records) { SummaryKey key = new SummaryKey(); - for(String summaryField : view.getPivotFields()) + for(String summaryField : view.getSummaryFields()) { Serializable summaryValue = record.getValue(summaryField); if(table.getField(summaryField).getPossibleValueSourceName() != null) @@ -557,7 +557,7 @@ public class GenerateReportAction } key.add(summaryField, summaryValue); - if(view.getIncludePivotSubTotals() && key.getKeys().size() < view.getPivotFields().size()) + if(view.getIncludeSummarySubTotals() && key.getKeys().size() < view.getSummaryFields().size()) { ///////////////////////////////////////////////////////////////////////////////////////// // be careful here, with these key objects, and their identity, being used as map keys // @@ -694,10 +694,10 @@ public class GenerateReportAction private List getFields(QTableMetaData table, QReportView view) { List fields = new ArrayList<>(); - for(String pivotField : view.getPivotFields()) + for(String summaryField : view.getSummaryFields()) { - QFieldMetaData field = table.getField(pivotField); - fields.add(new QFieldMetaData(pivotField, field.getType()).withLabel(field.getLabel())); // todo do we need the type? if so need table as input here + QFieldMetaData field = table.getField(summaryField); + fields.add(new QFieldMetaData(summaryField, field.getType()).withLabel(field.getLabel())); // todo do we need the type? if so need table as input here } for(QReportField column : view.getColumns()) { @@ -761,7 +761,7 @@ public class GenerateReportAction /////////////////////////////////////////////////////////////////////////////// // for summary subtotals, add the text "Total" to the last field in this key // /////////////////////////////////////////////////////////////////////////////// - if(summaryKey.getKeys().size() < view.getPivotFields().size()) + if(summaryKey.getKeys().size() < view.getSummaryFields().size()) { String fieldName = summaryKey.getKeys().get(summaryKey.getKeys().size() - 1).getA(); summaryRow.setValue(fieldName, summaryRow.getValueString(fieldName) + " Total"); @@ -799,11 +799,11 @@ public class GenerateReportAction { totalRow = new QRecord(); - for(String pivotField : view.getPivotFields()) + for(String summaryField : view.getSummaryFields()) { if(totalRow.getValues().isEmpty()) { - totalRow.setValue(pivotField, "Totals"); + totalRow.setValue(summaryField, "Totals"); } } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableDefinition.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableDefinition.java index 541b537b..cbc688aa 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableDefinition.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableDefinition.java @@ -29,7 +29,7 @@ import java.util.List; /******************************************************************************* ** Full definition of a pivot table - its rows, columns, and values. *******************************************************************************/ -public class PivotTableDefinition +public class PivotTableDefinition implements Cloneable { private List rows; private List columns; @@ -37,6 +37,46 @@ public class PivotTableDefinition + /******************************************************************************* + ** + *******************************************************************************/ + @Override + protected PivotTableDefinition clone() throws CloneNotSupportedException + { + PivotTableDefinition clone = (PivotTableDefinition) super.clone(); + + if(rows != null) + { + clone.rows = new ArrayList<>(); + for(PivotTableGroupBy row : rows) + { + clone.rows.add(row.clone()); + } + } + + if(columns != null) + { + clone.columns = new ArrayList<>(); + for(PivotTableGroupBy column : columns) + { + clone.columns.add(column.clone()); + } + } + + if(values != null) + { + clone.values = new ArrayList<>(); + for(PivotTableValue value : values) + { + clone.values.add(value.clone()); + } + } + + return (clone); + } + + + /******************************************************************************* ** *******************************************************************************/ diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableGroupBy.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableGroupBy.java index f3224a6d..c4503969 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableGroupBy.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableGroupBy.java @@ -26,7 +26,7 @@ package com.kingsrook.qqq.backend.core.actions.reporting.pivottable; ** Either a row or column grouping in a pivot table. e.g., a field plus ** sorting details, plus showTotals boolean. *******************************************************************************/ -public class PivotTableGroupBy +public class PivotTableGroupBy implements Cloneable { private String fieldName; private PivotTableOrderBy orderBy; @@ -125,4 +125,16 @@ public class PivotTableGroupBy return (this); } + + + /******************************************************************************* + ** + *******************************************************************************/ + @Override + public PivotTableGroupBy clone() throws CloneNotSupportedException + { + PivotTableGroupBy clone = (PivotTableGroupBy) super.clone(); + return clone; + } + } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableValue.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableValue.java index 3982fcf2..27350021 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableValue.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/pivottable/PivotTableValue.java @@ -25,12 +25,13 @@ package com.kingsrook.qqq.backend.core.actions.reporting.pivottable; /******************************************************************************* ** a value (e.g., field name + function) used in a pivot table *******************************************************************************/ -public class PivotTableValue +public class PivotTableValue implements Cloneable { private String fieldName; private PivotTableFunction function; + /******************************************************************************* ** Getter for fieldName *******************************************************************************/ @@ -91,4 +92,16 @@ public class PivotTableValue return (this); } + + + /******************************************************************************* + ** + *******************************************************************************/ + @Override + public PivotTableValue clone() throws CloneNotSupportedException + { + PivotTableValue clone = (PivotTableValue) super.clone(); + return clone; + } + } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/QReportView.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/QReportView.java index 1247ddfe..e2aba8b3 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/QReportView.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/QReportView.java @@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.model.metadata.reporting; import java.util.ArrayList; import java.util.List; +import com.kingsrook.qqq.backend.core.actions.reporting.pivottable.PivotTableDefinition; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy; import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference; @@ -40,11 +41,11 @@ public class QReportView implements Cloneable private ReportType type; private String titleFormat; private List titleFields; - private List pivotFields; + private List summaryFields; - private boolean includeHeaderRow = true; - private boolean includeTotalRow = false; - private boolean includePivotSubTotals = false; + private boolean includeHeaderRow = true; + private boolean includeTotalRow = false; + private boolean includeSummarySubTotals = false; private List columns; private List orderByFields; @@ -52,6 +53,9 @@ public class QReportView implements Cloneable private QCodeReference recordTransformStep; private QCodeReference viewCustomizer; + private String pivotTableSourceViewName; + private PivotTableDefinition pivotTableDefinition; + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Note: This class is Cloneable - think about if new fields added here need deep-copied in the clone method! // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -297,34 +301,34 @@ public class QReportView implements Cloneable /******************************************************************************* - ** Getter for pivotFields + ** Getter for summaryFields ** *******************************************************************************/ - public List getPivotFields() + public List getSummaryFields() { - return pivotFields; + return summaryFields; } /******************************************************************************* - ** Setter for pivotFields + ** Setter for summaryFields ** *******************************************************************************/ - public void setPivotFields(List pivotFields) + public void setSummaryFields(List summaryFields) { - this.pivotFields = pivotFields; + this.summaryFields = summaryFields; } /******************************************************************************* - ** Fluent setter for pivotFields + ** Fluent setter for summaryFields ** *******************************************************************************/ - public QReportView withPivotFields(List pivotFields) + public QReportView withSummaryFields(List summaryFields) { - this.pivotFields = pivotFields; + this.summaryFields = summaryFields; return (this); } @@ -399,34 +403,34 @@ public class QReportView implements Cloneable /******************************************************************************* - ** Getter for pivotSubTotals + ** Getter for summarySubTotals ** *******************************************************************************/ - public boolean getIncludePivotSubTotals() + public boolean getIncludeSummarySubTotals() { - return includePivotSubTotals; + return includeSummarySubTotals; } /******************************************************************************* - ** Setter for pivotSubTotals + ** Setter for summarySubTotals ** *******************************************************************************/ - public void setIncludePivotSubTotals(boolean includePivotSubTotals) + public void setIncludeSummarySubTotals(boolean includeSummarySubTotals) { - this.includePivotSubTotals = includePivotSubTotals; + this.includeSummarySubTotals = includeSummarySubTotals; } /******************************************************************************* - ** Fluent setter for pivotSubTotals + ** Fluent setter for summarySubTotals ** *******************************************************************************/ - public QReportView withIncludePivotSubTotals(boolean pivotSubTotals) + public QReportView withIncludeSummarySubTotals(boolean summarySubTotals) { - this.includePivotSubTotals = pivotSubTotals; + this.includeSummarySubTotals = summarySubTotals; return (this); } @@ -602,9 +606,9 @@ public class QReportView implements Cloneable clone.setTitleFields(new ArrayList<>(titleFields)); } - if(pivotFields != null) + if(summaryFields != null) { - clone.setPivotFields(new ArrayList<>(pivotFields)); + clone.setSummaryFields(new ArrayList<>(summaryFields)); } if(columns != null) @@ -624,4 +628,67 @@ public class QReportView implements Cloneable throw new AssertionError(); } } + + + + /******************************************************************************* + ** Getter for pivotTableSourceViewName + *******************************************************************************/ + public String getPivotTableSourceViewName() + { + return (this.pivotTableSourceViewName); + } + + + + /******************************************************************************* + ** Setter for pivotTableSourceViewName + *******************************************************************************/ + public void setPivotTableSourceViewName(String pivotTableSourceViewName) + { + this.pivotTableSourceViewName = pivotTableSourceViewName; + } + + + + /******************************************************************************* + ** Fluent setter for pivotTableSourceViewName + *******************************************************************************/ + public QReportView withPivotTableSourceViewName(String pivotTableSourceViewName) + { + this.pivotTableSourceViewName = pivotTableSourceViewName; + return (this); + } + + + + /******************************************************************************* + ** Getter for pivotTableDefinition + *******************************************************************************/ + public PivotTableDefinition getPivotTableDefinition() + { + return (this.pivotTableDefinition); + } + + + + /******************************************************************************* + ** Setter for pivotTableDefinition + *******************************************************************************/ + public void setPivotTableDefinition(PivotTableDefinition pivotTableDefinition) + { + this.pivotTableDefinition = pivotTableDefinition; + } + + + + /******************************************************************************* + ** Fluent setter for pivotTableDefinition + *******************************************************************************/ + public QReportView withPivotTableDefinition(PivotTableDefinition pivotTableDefinition) + { + this.pivotTableDefinition = pivotTableDefinition; + return (this); + } + } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/ReportType.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/ReportType.java index 8492537a..22b5cb67 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/ReportType.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/reporting/ReportType.java @@ -28,6 +28,6 @@ package com.kingsrook.qqq.backend.core.model.metadata.reporting; public enum ReportType { TABLE, // e.g., raw data in tabular form. - SUMMARY, // e.g., summaries computed within QQQ - PIVOT // e.g., a true spreadsheet pivot. Not initially supported... + SUMMARY, // e.g., summaries computed within QQQ. + PIVOT // e.g., a true spreadsheet pivot. }