mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 21:50:45 +00:00
QQQ-42 adding data-sources to reports, customizer points
This commit is contained in:
@ -50,18 +50,25 @@ public class FormulaInterpreter
|
||||
*******************************************************************************/
|
||||
public static Serializable interpretFormula(QMetaDataVariableInterpreter variableInterpreter, String formula) throws QFormulaException
|
||||
{
|
||||
List<Serializable> results = interpretFormula(variableInterpreter, formula, new AtomicInteger(0));
|
||||
if(results.size() == 1)
|
||||
try
|
||||
{
|
||||
return (results.get(0));
|
||||
List<Serializable> results = interpretFormula(variableInterpreter, formula, new AtomicInteger(0));
|
||||
if(results.size() == 1)
|
||||
{
|
||||
return (results.get(0));
|
||||
}
|
||||
else if(results.isEmpty())
|
||||
{
|
||||
throw (new QFormulaException("No results from formula"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw (new QFormulaException("More than 1 result from formula"));
|
||||
}
|
||||
}
|
||||
else if(results.isEmpty())
|
||||
catch(Exception e)
|
||||
{
|
||||
throw (new QFormulaException("No results from formula"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw (new QFormulaException("More than 1 result from formula"));
|
||||
throw (new QFormulaException("Error interpreting formula [" + formula + "]", e));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,15 +29,19 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import com.kingsrook.qqq.backend.core.actions.async.AsyncRecordPipeLoop;
|
||||
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
||||
import com.kingsrook.qqq.backend.core.actions.reporting.customizers.ReportViewCustomizer;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.values.QValueFormatter;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QFormulaException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QReportingException;
|
||||
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.reporting.ExportInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.reporting.ReportFormat;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.reporting.ReportInput;
|
||||
@ -48,11 +52,13 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportDataSource;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportField;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportView;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.reporting.ReportType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.AbstractTransformStep;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.Pair;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
@ -63,7 +69,16 @@ import com.kingsrook.qqq.backend.core.utils.aggregates.IntegerAggregates;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Action to generate a report!!
|
||||
** Action to generate a report.
|
||||
**
|
||||
** A report can contain 1 or more Data Sources - e.g., tables + filters that define
|
||||
** data that goes into the report.
|
||||
**
|
||||
** A report can also contain 1 or more Views - e.g., sheets in a spreadsheet workbook.
|
||||
** (how do those work in non-XLSX formats??). Views can either be plain tables,
|
||||
** summaries (like pivot tables, but called summary to avoid confusion with "native"
|
||||
** pivot tables), or native pivot tables (not initially supported, due to lack of
|
||||
** support in fastexcel...).
|
||||
*******************************************************************************/
|
||||
public class GenerateReportAction
|
||||
{
|
||||
@ -76,7 +91,6 @@ public class GenerateReportAction
|
||||
Map<String, AggregatesInterface<?>> totalAggregates = new HashMap<>();
|
||||
Map<String, AggregatesInterface<?>> varianceTotalAggregates = new HashMap<>();
|
||||
|
||||
private boolean includeTableView = false;
|
||||
private QReportMetaData report;
|
||||
private ReportFormat reportFormat;
|
||||
private ExportStreamerInterface reportStreamer;
|
||||
@ -89,19 +103,52 @@ public class GenerateReportAction
|
||||
public void execute(ReportInput reportInput) throws QException
|
||||
{
|
||||
report = reportInput.getInstance().getReport(reportInput.getReportName());
|
||||
Optional<QReportView> tableView = report.getViews().stream().filter(v -> v.getType().equals(ReportType.TABLE)).findFirst();
|
||||
|
||||
reportFormat = reportInput.getReportFormat();
|
||||
reportStreamer = reportFormat.newReportStreamer();
|
||||
|
||||
if(tableView.isPresent())
|
||||
for(QReportDataSource dataSource : report.getDataSources())
|
||||
{
|
||||
includeTableView = true;
|
||||
startTableView(reportInput, tableView.get());
|
||||
}
|
||||
List<QReportView> dataSourceTableViews = report.getViews().stream()
|
||||
.filter(v -> v.getType().equals(ReportType.TABLE))
|
||||
.filter(v -> v.getDataSourceName().equals(dataSource.getName()))
|
||||
.toList();
|
||||
|
||||
gatherData(reportInput);
|
||||
gatherVarianceData(reportInput);
|
||||
List<QReportView> dataSourcePivotViews = report.getViews().stream()
|
||||
.filter(v -> v.getType().equals(ReportType.SUMMARY))
|
||||
.filter(v -> v.getDataSourceName().equals(dataSource.getName()))
|
||||
.toList();
|
||||
|
||||
List<QReportView> dataSourceVariantViews = report.getViews().stream()
|
||||
.filter(v -> v.getType().equals(ReportType.SUMMARY))
|
||||
.filter(v -> v.getVarianceDataSourceName() != null && v.getVarianceDataSourceName().equals(dataSource.getName()))
|
||||
.toList();
|
||||
|
||||
if(dataSourceTableViews.isEmpty())
|
||||
{
|
||||
if(!dataSourcePivotViews.isEmpty() || !dataSourceVariantViews.isEmpty())
|
||||
{
|
||||
gatherData(reportInput, dataSource, null, dataSourcePivotViews, dataSourceVariantViews);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(QReportView dataSourceTableView : dataSourceTableViews)
|
||||
{
|
||||
if(dataSourceTableView.getViewCustomizer() != null)
|
||||
{
|
||||
Function<QReportView, QReportView> viewCustomizerFunction = QCodeLoader.getFunction(dataSourceTableView.getViewCustomizer());
|
||||
if(viewCustomizerFunction instanceof ReportViewCustomizer reportViewCustomizer)
|
||||
{
|
||||
reportViewCustomizer.setReportInput(reportInput);
|
||||
}
|
||||
dataSourceTableView = viewCustomizerFunction.apply(dataSourceTableView.clone()); // todo - will this throw concurrent mod exception??
|
||||
}
|
||||
|
||||
startTableView(reportInput, dataSource, dataSourceTableView);
|
||||
gatherData(reportInput, dataSource, dataSourceTableView, dataSourcePivotViews, dataSourceVariantViews);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outputPivots(reportInput);
|
||||
}
|
||||
@ -111,9 +158,9 @@ public class GenerateReportAction
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private void startTableView(ReportInput reportInput, QReportView reportView) throws QReportingException
|
||||
private void startTableView(ReportInput reportInput, QReportDataSource dataSource, QReportView reportView) throws QReportingException
|
||||
{
|
||||
QTableMetaData table = reportInput.getInstance().getTable(report.getSourceTable());
|
||||
QTableMetaData table = reportInput.getInstance().getTable(dataSource.getSourceTable());
|
||||
|
||||
ExportInput exportInput = new ExportInput(reportInput.getInstance());
|
||||
exportInput.setSession(reportInput.getSession());
|
||||
@ -129,7 +176,14 @@ public class GenerateReportAction
|
||||
fields = new ArrayList<>();
|
||||
for(QReportField column : reportView.getColumns())
|
||||
{
|
||||
fields.add(table.getField(column.getName()));
|
||||
if(column.getIsVirtual())
|
||||
{
|
||||
fields.add(column.toField());
|
||||
}
|
||||
else
|
||||
{
|
||||
fields.add(table.getField(column.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -145,50 +199,70 @@ public class GenerateReportAction
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private void gatherData(ReportInput reportInput) throws QException
|
||||
private void gatherData(ReportInput reportInput, QReportDataSource dataSource, QReportView tableView, List<QReportView> pivotViews, List<QReportView> variantViews) throws QException
|
||||
{
|
||||
QQueryFilter queryFilter = report.getQueryFilter();
|
||||
QQueryFilter queryFilter = dataSource.getQueryFilter();
|
||||
setInputValuesInQueryFilter(reportInput, queryFilter);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// check if this view has a transform step - if so, set it up now and run its pre-run //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
AbstractTransformStep transformStep = null;
|
||||
RunBackendStepInput transformStepInput = null;
|
||||
RunBackendStepOutput transformStepOutput = null;
|
||||
if(tableView != null && tableView.getRecordTransformStep() != null)
|
||||
{
|
||||
transformStep = QCodeLoader.getBackendStep(AbstractTransformStep.class, tableView.getRecordTransformStep());
|
||||
|
||||
transformStepInput = new RunBackendStepInput(reportInput.getInstance());
|
||||
transformStepInput.setSession(reportInput.getSession());
|
||||
transformStepInput.setValues(reportInput.getInputValues());
|
||||
|
||||
transformStepOutput = new RunBackendStepOutput();
|
||||
|
||||
transformStep.preRun(transformStepInput, transformStepOutput);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// create effectively-final versions of these vars for the lambda //
|
||||
////////////////////////////////////////////////////////////////////
|
||||
AbstractTransformStep finalTransformStep = transformStep;
|
||||
RunBackendStepInput finalTransformStepInput = transformStepInput;
|
||||
RunBackendStepOutput finalTransformStepOutput = transformStepOutput;
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// run a record pipe loop, over the query for this data source //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
RecordPipe recordPipe = new RecordPipe();
|
||||
new AsyncRecordPipeLoop().run("Report[" + reportInput.getReportName() + "]", null, recordPipe, (callback) ->
|
||||
{
|
||||
QueryInput queryInput = new QueryInput(reportInput.getInstance());
|
||||
queryInput.setSession(reportInput.getSession());
|
||||
queryInput.setRecordPipe(recordPipe);
|
||||
queryInput.setTableName(report.getSourceTable());
|
||||
queryInput.setTableName(dataSource.getSourceTable());
|
||||
queryInput.setFilter(queryFilter);
|
||||
queryInput.setShouldTranslatePossibleValues(true); // todo - any limits or conditions on this?
|
||||
return (new QueryAction().execute(queryInput));
|
||||
}, () -> consumeRecords(reportInput, recordPipe, false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private void gatherVarianceData(ReportInput reportInput) throws QException
|
||||
{
|
||||
QQueryFilter varianceQueryFilter = report.getVarianceQueryFilter();
|
||||
if(varianceQueryFilter == null)
|
||||
}, () ->
|
||||
{
|
||||
return;
|
||||
List<QRecord> records = recordPipe.consumeAvailableRecords();
|
||||
if(finalTransformStep != null)
|
||||
{
|
||||
finalTransformStepInput.setRecords(records);
|
||||
finalTransformStep.run(finalTransformStepInput, finalTransformStepOutput);
|
||||
records = finalTransformStepOutput.getRecords();
|
||||
}
|
||||
|
||||
return (consumeRecords(reportInput, dataSource, records, tableView, pivotViews, variantViews));
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// if there's a transformer, run its post-run //
|
||||
////////////////////////////////////////////////
|
||||
if(transformStep != null)
|
||||
{
|
||||
transformStep.postRun(transformStepInput, transformStepOutput);
|
||||
}
|
||||
|
||||
setInputValuesInQueryFilter(reportInput, varianceQueryFilter);
|
||||
|
||||
RecordPipe recordPipe = new RecordPipe();
|
||||
new AsyncRecordPipeLoop().run("Report[" + reportInput.getReportName() + "]", null, recordPipe, (callback) ->
|
||||
{
|
||||
QueryInput queryInput = new QueryInput(reportInput.getInstance());
|
||||
queryInput.setSession(reportInput.getSession());
|
||||
queryInput.setRecordPipe(recordPipe);
|
||||
queryInput.setTableName(report.getSourceTable());
|
||||
queryInput.setFilter(varianceQueryFilter);
|
||||
queryInput.setShouldTranslatePossibleValues(true); // todo - any limits or conditions on this?
|
||||
return (new QueryAction().execute(queryInput));
|
||||
}, () -> consumeRecords(reportInput, recordPipe, true));
|
||||
}
|
||||
|
||||
|
||||
@ -227,11 +301,14 @@ public class GenerateReportAction
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private Integer consumeRecords(ReportInput reportInput, RecordPipe recordPipe, boolean isForVariance) throws QReportingException
|
||||
private Integer consumeRecords(ReportInput reportInput, QReportDataSource dataSource, List<QRecord> records, QReportView tableView, List<QReportView> pivotViews, List<QReportView> variantViews) throws QException
|
||||
{
|
||||
List<QRecord> records = recordPipe.consumeAvailableRecords();
|
||||
QTableMetaData table = reportInput.getInstance().getTable(dataSource.getSourceTable());
|
||||
|
||||
if(includeTableView && !isForVariance)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// if this record goes on a table view, add it to the report streamer now //
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
if(tableView != null)
|
||||
{
|
||||
reportStreamer.addRecords(records);
|
||||
}
|
||||
@ -239,20 +316,38 @@ public class GenerateReportAction
|
||||
//////////////////////////////
|
||||
// do aggregates for pivots //
|
||||
//////////////////////////////
|
||||
QTableMetaData table = reportInput.getInstance().getTable(report.getSourceTable());
|
||||
report.getViews().stream().filter(v -> v.getType().equals(ReportType.PIVOT)).forEach((view) ->
|
||||
if(pivotViews != null)
|
||||
{
|
||||
addRecordsToPivotAggregates(view, table, records, isForVariance ? variancePivotAggregates : pivotAggregates);
|
||||
});
|
||||
for(QReportView pivotView : pivotViews)
|
||||
{
|
||||
addRecordsToPivotAggregates(pivotView, table, records, pivotAggregates);
|
||||
}
|
||||
}
|
||||
|
||||
if(variantViews != null)
|
||||
{
|
||||
for(QReportView variantView : variantViews)
|
||||
{
|
||||
addRecordsToPivotAggregates(variantView, table, records, variancePivotAggregates);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// do totals too, if any views want them //
|
||||
///////////////////////////////////////////
|
||||
if(report.getViews().stream().filter(v -> v.getType().equals(ReportType.PIVOT)).anyMatch(QReportView::getTotalRow))
|
||||
if(pivotViews != null && pivotViews.stream().anyMatch(QReportView::getTotalRow))
|
||||
{
|
||||
for(QRecord record : records)
|
||||
{
|
||||
addRecordToAggregatesMap(table, record, isForVariance ? varianceTotalAggregates : totalAggregates);
|
||||
addRecordToAggregatesMap(table, record, totalAggregates);
|
||||
}
|
||||
}
|
||||
|
||||
if(variantViews != null && variantViews.stream().anyMatch(QReportView::getTotalRow))
|
||||
{
|
||||
for(QRecord record : records)
|
||||
{
|
||||
addRecordToAggregatesMap(table, record, varianceTotalAggregates);
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,12 +432,12 @@ public class GenerateReportAction
|
||||
*******************************************************************************/
|
||||
private void outputPivots(ReportInput reportInput) throws QReportingException, QFormulaException
|
||||
{
|
||||
QTableMetaData table = reportInput.getInstance().getTable(report.getSourceTable());
|
||||
|
||||
List<QReportView> reportViews = report.getViews().stream().filter(v -> v.getType().equals(ReportType.PIVOT)).toList();
|
||||
List<QReportView> reportViews = report.getViews().stream().filter(v -> v.getType().equals(ReportType.SUMMARY)).toList();
|
||||
for(QReportView view : reportViews)
|
||||
{
|
||||
PivotOutput pivotOutput = computePivotRowsForView(reportInput, view, table);
|
||||
QReportDataSource dataSource = report.getDataSource(view.getDataSourceName());
|
||||
QTableMetaData table = reportInput.getInstance().getTable(dataSource.getSourceTable());
|
||||
PivotOutput pivotOutput = computePivotRowsForView(reportInput, view, table);
|
||||
|
||||
ExportInput exportInput = new ExportInput(reportInput.getInstance());
|
||||
exportInput.setSession(reportInput.getSession());
|
||||
@ -564,11 +659,14 @@ public class GenerateReportAction
|
||||
|
||||
variableInterpreter.addValueMap("pivot", getPivotValuesForInterpreter(totalAggregates));
|
||||
variableInterpreter.addValueMap("variancePivot", getPivotValuesForInterpreter(varianceTotalAggregates));
|
||||
HashMap<String, Serializable> thisRowValues = new HashMap<>();
|
||||
variableInterpreter.addValueMap("thisRow", thisRowValues);
|
||||
|
||||
for(QReportField column : view.getColumns())
|
||||
{
|
||||
Serializable serializable = getValueForColumn(variableInterpreter, column);
|
||||
totalRow.setValue(column.getName(), serializable);
|
||||
thisRowValues.put(column.getName(), serializable);
|
||||
|
||||
String formatted = valueFormatter.formatValue(column.getDisplayFormat(), serializable);
|
||||
System.out.printf("%25s", formatted);
|
||||
|
@ -46,8 +46,9 @@ public class ListOfMapsExportStreamer implements ExportStreamerInterface
|
||||
private ExportInput exportInput;
|
||||
private List<QFieldMetaData> fields;
|
||||
|
||||
private static List<Map<String, String>> list = new ArrayList<>();
|
||||
private static List<String> headers = new ArrayList<>();
|
||||
private static Map<String, List<Map<String, String>>> rows = new LinkedHashMap<>();
|
||||
private static Map<String, List<String>> headers = new LinkedHashMap<>();
|
||||
private static String currentSheetLabel;
|
||||
|
||||
|
||||
|
||||
@ -60,13 +61,25 @@ public class ListOfMapsExportStreamer implements ExportStreamerInterface
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static void reset()
|
||||
{
|
||||
rows.clear();
|
||||
headers.clear();
|
||||
currentSheetLabel = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for list
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static List<Map<String, String>> getList()
|
||||
public static List<Map<String, String>> getList(String name)
|
||||
{
|
||||
return (list);
|
||||
return (rows.get(name));
|
||||
}
|
||||
|
||||
|
||||
@ -80,10 +93,13 @@ public class ListOfMapsExportStreamer implements ExportStreamerInterface
|
||||
this.exportInput = exportInput;
|
||||
this.fields = fields;
|
||||
|
||||
headers = new ArrayList<>();
|
||||
currentSheetLabel = label;
|
||||
|
||||
rows.put(label, new ArrayList<>());
|
||||
headers.put(label, new ArrayList<>());
|
||||
for(QFieldMetaData field : fields)
|
||||
{
|
||||
headers.add(field.getLabel());
|
||||
headers.get(label).add(field.getLabel());
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,10 +128,10 @@ public class ListOfMapsExportStreamer implements ExportStreamerInterface
|
||||
private void addRecord(QRecord qRecord)
|
||||
{
|
||||
Map<String, String> row = new LinkedHashMap<>();
|
||||
list.add(row);
|
||||
rows.get(currentSheetLabel).add(row);
|
||||
for(int i = 0; i < fields.size(); i++)
|
||||
{
|
||||
row.put(headers.get(i), qRecord.getValueString(fields.get(i).getName()));
|
||||
row.put(headers.get(currentSheetLabel).get(i), qRecord.getValueString(fields.get(i).getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +141,7 @@ public class ListOfMapsExportStreamer implements ExportStreamerInterface
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public void addTotalsRow(QRecord record) throws QReportingException
|
||||
public void addTotalsRow(QRecord record)
|
||||
{
|
||||
addRecord(record);
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2022. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.actions.reporting.customizers;
|
||||
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.reporting.ReportInput;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportView;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public interface ReportViewCustomizer extends Function<QReportView, QReportView>
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
void setReportInput(ReportInput reportInput);
|
||||
|
||||
}
|
@ -266,7 +266,7 @@ public class QInstanceEnricher
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
static String nameToLabel(String name)
|
||||
public static String nameToLabel(String name)
|
||||
{
|
||||
if(!StringUtils.hasContent(name))
|
||||
{
|
||||
|
@ -37,7 +37,6 @@ public class QFrontendReportMetaData
|
||||
{
|
||||
private String name;
|
||||
private String label;
|
||||
private String tableName;
|
||||
private String processName;
|
||||
|
||||
private String iconName;
|
||||
@ -55,7 +54,6 @@ public class QFrontendReportMetaData
|
||||
{
|
||||
this.name = reportMetaData.getName();
|
||||
this.label = reportMetaData.getLabel();
|
||||
this.tableName = reportMetaData.getSourceTable();
|
||||
this.processName = reportMetaData.getProcessName();
|
||||
|
||||
if(reportMetaData.getIcon() != null)
|
||||
@ -88,17 +86,6 @@ public class QFrontendReportMetaData
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for primaryKeyField
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getTableName()
|
||||
{
|
||||
return tableName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for processName
|
||||
**
|
||||
|
@ -34,7 +34,8 @@ public enum QComponentType
|
||||
VIEW_FORM,
|
||||
DOWNLOAD_FORM,
|
||||
RECORD_LIST,
|
||||
PROCESS_SUMMARY_RESULTS;
|
||||
PROCESS_SUMMARY_RESULTS,
|
||||
GOOGLE_DRIVE_SELECT_FOLDER;
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// keep these values in sync with QComponentType.ts in qqq-frontend-core //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2022. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.model.metadata.reporting;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class QReportDataSource
|
||||
{
|
||||
private String name;
|
||||
private String sourceTable;
|
||||
private QQueryFilter queryFilter;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for name
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for name
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for name
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportDataSource withName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for sourceTable
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getSourceTable()
|
||||
{
|
||||
return sourceTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for sourceTable
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setSourceTable(String sourceTable)
|
||||
{
|
||||
this.sourceTable = sourceTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for sourceTable
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportDataSource withSourceTable(String sourceTable)
|
||||
{
|
||||
this.sourceTable = sourceTable;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for queryFilter
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QQueryFilter getQueryFilter()
|
||||
{
|
||||
return queryFilter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for queryFilter
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setQueryFilter(QQueryFilter queryFilter)
|
||||
{
|
||||
this.queryFilter = queryFilter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for queryFilter
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportDataSource withQueryFilter(QQueryFilter queryFilter)
|
||||
{
|
||||
this.queryFilter = queryFilter;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
@ -22,16 +22,40 @@
|
||||
package com.kingsrook.qqq.backend.core.model.metadata.reporting;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Field within a report
|
||||
*******************************************************************************/
|
||||
public class QReportField
|
||||
{
|
||||
private String name;
|
||||
private String label;
|
||||
private String formula;
|
||||
private String displayFormat;
|
||||
// todo - type?
|
||||
private String name;
|
||||
private String label;
|
||||
private QFieldType type;
|
||||
private String formula;
|
||||
private String displayFormat;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Noew: new attributes added here probably belong in the toField method //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private boolean isVirtual = false;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QFieldMetaData toField()
|
||||
{
|
||||
return new QFieldMetaData()
|
||||
.withName(name)
|
||||
.withLabel(label)
|
||||
.withType(type)
|
||||
.withDisplayFormat(displayFormat);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -103,6 +127,40 @@ public class QReportField
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for type
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QFieldType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for type
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setType(QFieldType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for type
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportField withType(QFieldType type)
|
||||
{
|
||||
this.type = type;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for formula
|
||||
**
|
||||
@ -169,4 +227,37 @@ public class QReportField
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for isVirtual
|
||||
**
|
||||
*******************************************************************************/
|
||||
public boolean getIsVirtual()
|
||||
{
|
||||
return isVirtual;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for isVirtual
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setIsVirtual(boolean isVirtual)
|
||||
{
|
||||
this.isVirtual = isVirtual;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for isVirtual
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportField withIsVirtual(boolean isVirtual)
|
||||
{
|
||||
this.isVirtual = isVirtual;
|
||||
return (this);
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ package com.kingsrook.qqq.backend.core.model.metadata.reporting;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppChildMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -34,14 +34,14 @@ import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
|
||||
*******************************************************************************/
|
||||
public class QReportMetaData implements QAppChildMetaData
|
||||
{
|
||||
private String name;
|
||||
private String label;
|
||||
private List<QFieldMetaData> inputFields;
|
||||
private String sourceTable;
|
||||
private String name;
|
||||
private String label;
|
||||
|
||||
private String processName;
|
||||
private QQueryFilter queryFilter;
|
||||
private QQueryFilter varianceQueryFilter;
|
||||
private List<QReportView> views;
|
||||
private List<QFieldMetaData> inputFields;
|
||||
|
||||
private List<QReportDataSource> dataSources;
|
||||
private List<QReportView> views;
|
||||
|
||||
private String parentAppName;
|
||||
private QIcon icon;
|
||||
@ -150,40 +150,6 @@ public class QReportMetaData implements QAppChildMetaData
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for sourceTable
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getSourceTable()
|
||||
{
|
||||
return sourceTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for sourceTable
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setSourceTable(String sourceTable)
|
||||
{
|
||||
this.sourceTable = sourceTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for sourceTable
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportMetaData withSourceTable(String sourceTable)
|
||||
{
|
||||
this.sourceTable = sourceTable;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for processName
|
||||
**
|
||||
@ -215,72 +181,38 @@ public class QReportMetaData implements QAppChildMetaData
|
||||
this.processName = processName;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for queryFilter
|
||||
** Getter for dataSources
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QQueryFilter getQueryFilter()
|
||||
public List<QReportDataSource> getDataSources()
|
||||
{
|
||||
return queryFilter;
|
||||
return dataSources;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for queryFilter
|
||||
** Setter for dataSources
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setQueryFilter(QQueryFilter queryFilter)
|
||||
public void setDataSources(List<QReportDataSource> dataSources)
|
||||
{
|
||||
this.queryFilter = queryFilter;
|
||||
this.dataSources = dataSources;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for queryFilter
|
||||
** Fluent setter for dataSources
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportMetaData withQueryFilter(QQueryFilter queryFilter)
|
||||
public QReportMetaData withDataSources(List<QReportDataSource> dataSources)
|
||||
{
|
||||
this.queryFilter = queryFilter;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for varianceQueryFilter
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QQueryFilter getVarianceQueryFilter()
|
||||
{
|
||||
return varianceQueryFilter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for varianceQueryFilter
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setVarianceQueryFilter(QQueryFilter varianceQueryFilter)
|
||||
{
|
||||
this.varianceQueryFilter = varianceQueryFilter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for varianceQueryFilter
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportMetaData withVarianceQueryFilter(QQueryFilter varianceQueryFilter)
|
||||
{
|
||||
this.varianceQueryFilter = varianceQueryFilter;
|
||||
this.dataSources = dataSources;
|
||||
return (this);
|
||||
}
|
||||
|
||||
@ -374,4 +306,22 @@ public class QReportMetaData implements QAppChildMetaData
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportDataSource getDataSource(String dataSourceName)
|
||||
{
|
||||
for(QReportDataSource dataSource : CollectionUtils.nonNullList(dataSources))
|
||||
{
|
||||
if(dataSource.getName().equals(dataSourceName))
|
||||
{
|
||||
return (dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,17 +22,21 @@
|
||||
package com.kingsrook.qqq.backend.core.model.metadata.reporting;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class QReportView
|
||||
public class QReportView implements Cloneable
|
||||
{
|
||||
private String name;
|
||||
private String label;
|
||||
private String dataSourceName;
|
||||
private String varianceDataSourceName;
|
||||
private ReportType type;
|
||||
private String titleFormat;
|
||||
private List<String> titleFields;
|
||||
@ -42,6 +46,13 @@ public class QReportView
|
||||
private List<QReportField> columns;
|
||||
private List<QFilterOrderBy> orderByFields;
|
||||
|
||||
private QCodeReference recordTransformStep;
|
||||
private QCodeReference viewCustomizer;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Note: This class is Cloneable - think about if new fields added here need deep-copied in the clone method! //
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -112,6 +123,74 @@ public class QReportView
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for dataSourceName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getDataSourceName()
|
||||
{
|
||||
return dataSourceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for dataSourceName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setDataSourceName(String dataSourceName)
|
||||
{
|
||||
this.dataSourceName = dataSourceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for dataSourceName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportView withDataSourceName(String dataSourceName)
|
||||
{
|
||||
this.dataSourceName = dataSourceName;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for varianceDataSourceName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getVarianceDataSourceName()
|
||||
{
|
||||
return varianceDataSourceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for varianceDataSourceName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setVarianceDataSourceName(String varianceDataSourceName)
|
||||
{
|
||||
this.varianceDataSourceName = varianceDataSourceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for varianceDataSourceName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportView withVarianceDataSourceName(String varianceDataSourceName)
|
||||
{
|
||||
this.varianceDataSourceName = varianceDataSourceName;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for type
|
||||
**
|
||||
@ -382,4 +461,114 @@ public class QReportView
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for recordTransformerStep
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QCodeReference getRecordTransformStep()
|
||||
{
|
||||
return recordTransformStep;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for recordTransformerStep
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setRecordTransformStep(QCodeReference recordTransformStep)
|
||||
{
|
||||
this.recordTransformStep = recordTransformStep;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for recordTransformerStep
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportView withRecordTransformStep(QCodeReference recordTransformerStep)
|
||||
{
|
||||
this.recordTransformStep = recordTransformerStep;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for viewCustomizer
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QCodeReference getViewCustomizer()
|
||||
{
|
||||
return viewCustomizer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for viewCustomizer
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setViewCustomizer(QCodeReference viewCustomizer)
|
||||
{
|
||||
this.viewCustomizer = viewCustomizer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for viewCustomizer
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QReportView withViewCustomizer(QCodeReference viewCustomizer)
|
||||
{
|
||||
this.viewCustomizer = viewCustomizer;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public QReportView clone()
|
||||
{
|
||||
try
|
||||
{
|
||||
QReportView clone = (QReportView) super.clone();
|
||||
|
||||
/////////////////////////
|
||||
// copy any lists, etc //
|
||||
/////////////////////////
|
||||
if(titleFields != null)
|
||||
{
|
||||
clone.setTitleFields(new ArrayList<>(titleFields));
|
||||
}
|
||||
|
||||
if(pivotFields != null)
|
||||
{
|
||||
clone.setPivotFields(new ArrayList<>(pivotFields));
|
||||
}
|
||||
|
||||
if(columns != null)
|
||||
{
|
||||
clone.setColumns(new ArrayList<>(columns));
|
||||
}
|
||||
|
||||
if(orderByFields != null)
|
||||
{
|
||||
clone.setOrderByFields(new ArrayList<>(orderByFields));
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
catch(CloneNotSupportedException e)
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ package com.kingsrook.qqq.backend.core.model.metadata.reporting;
|
||||
*******************************************************************************/
|
||||
public enum ReportType
|
||||
{
|
||||
PIVOT,
|
||||
TABLE
|
||||
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...
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ public class CollectionUtils
|
||||
else
|
||||
{
|
||||
endAt = startAt + limit;
|
||||
if (endAt > list.size())
|
||||
if(endAt > list.size())
|
||||
{
|
||||
endAt = list.size();
|
||||
}
|
||||
@ -406,4 +406,20 @@ public class CollectionUtils
|
||||
|
||||
return list.subList(startAt, endAt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Returns the input list, unless it was null - in which case a new array list is returned.
|
||||
**
|
||||
** Meant to help avoid null checks on foreach loops.
|
||||
*******************************************************************************/
|
||||
public static <T> List<T> nonNullList(List<T> list)
|
||||
{
|
||||
if(list == null)
|
||||
{
|
||||
return (new ArrayList<>());
|
||||
}
|
||||
return (list);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user