CE-881 - Add pivot table details to QReportView, renaming previous "pivot" things to "summary"

This commit is contained in:
2024-03-27 20:04:54 -05:00
parent b802f4a900
commit b1fdd866dd
6 changed files with 170 additions and 38 deletions

View File

@ -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<QFieldMetaData> getFields(QTableMetaData table, QReportView view)
{
List<QFieldMetaData> 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");
}
}

View File

@ -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<PivotTableGroupBy> rows;
private List<PivotTableGroupBy> 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);
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<String> titleFields;
private List<String> pivotFields;
private List<String> 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<QReportField> columns;
private List<QFilterOrderBy> 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<String> getPivotFields()
public List<String> getSummaryFields()
{
return pivotFields;
return summaryFields;
}
/*******************************************************************************
** Setter for pivotFields
** Setter for summaryFields
**
*******************************************************************************/
public void setPivotFields(List<String> pivotFields)
public void setSummaryFields(List<String> summaryFields)
{
this.pivotFields = pivotFields;
this.summaryFields = summaryFields;
}
/*******************************************************************************
** Fluent setter for pivotFields
** Fluent setter for summaryFields
**
*******************************************************************************/
public QReportView withPivotFields(List<String> pivotFields)
public QReportView withSummaryFields(List<String> 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);
}
}

View File

@ -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.
}