From 31fa3c3921dc0f697a476633f4802ebdc7815696 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Mon, 8 Jul 2024 15:19:33 -0500 Subject: [PATCH] CE-1406 Update to clone queryJoins... since our friend the JoinContext likes to mutate them, and break things! also cleaned up all warnings. --- .../reporting/GenerateReportAction.java | 66 ++++++++++++------- 1 file changed, 43 insertions(+), 23 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 a984bed3..a216e9e5 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 @@ -66,6 +66,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.JoinsContext; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput; +import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin; 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; @@ -303,7 +304,7 @@ public class GenerateReportAction extends AbstractQActionFunction cloneDataSourceQueryJoins(QReportDataSource dataSource) + { + if(dataSource == null || dataSource.getQueryJoins() == null) + { + return (null); + } + + List rs = new ArrayList<>(); + for(QueryJoin queryJoin : dataSource.getQueryJoins()) + { + rs.add(queryJoin.clone()); + } + return (rs); + } + + + /******************************************************************************* ** *******************************************************************************/ @@ -417,12 +438,12 @@ public class GenerateReportAction extends AbstractQActionFunction setupFieldsToTranslatePossibleValues(ReportInput reportInput, QReportDataSource dataSource, JoinsContext joinsContext) throws QException + private Set setupFieldsToTranslatePossibleValues(ReportInput reportInput, QReportDataSource dataSource) throws QException { Set fieldsToTranslatePossibleValues = new HashSet<>(); @@ -574,9 +595,9 @@ public class GenerateReportAction extends AbstractQActionFunction records, QReportView tableView, List summaryViews, List variantViews) throws QException + private Integer consumeRecords(QReportDataSource dataSource, List records, QReportView tableView, List summaryViews, List variantViews) throws QException { - QTableMetaData table = reportInput.getInstance().getTable(dataSource.getSourceTable()); + QTableMetaData table = QContext.getQInstance().getTable(dataSource.getSourceTable()); //////////////////////////////////////////////////////////////////////////// // if this record goes on a table view, add it to the report streamer now // @@ -687,7 +708,7 @@ public class GenerateReportAction extends AbstractQActionFunction>> viewAggregates, SummaryKey key) throws QException + private void addRecordToSummaryKeyAggregates(QTableMetaData table, QRecord record, Map>> viewAggregates, SummaryKey key) { Map> keyAggregates = viewAggregates.computeIfAbsent(key, (name) -> new HashMap<>()); addRecordToAggregatesMap(table, record, keyAggregates); @@ -698,7 +719,7 @@ public class GenerateReportAction extends AbstractQActionFunction> aggregatesMap) throws QException + private void addRecordToAggregatesMap(QTableMetaData table, QRecord record, Map> aggregatesMap) { ////////////////////////////////////////////////////////////////////////////////////// // todo - an optimization could be, to only compute aggregates that we'll need... // @@ -706,7 +727,7 @@ public class GenerateReportAction extends AbstractQActionFunction reportViews = views.stream().filter(v -> v.getType().equals(ReportType.SUMMARY)).toList(); for(QReportView view : reportViews) { - QReportDataSource dataSource = getDataSource(view.getDataSourceName()); - QTableMetaData table = reportInput.getInstance().getTable(dataSource.getSourceTable()); - SummaryOutput summaryOutput = computeSummaryRowsForView(reportInput, view, table); + QReportDataSource dataSource = getDataSource(view.getDataSourceName()); + if(dataSource == null) + { + throw new QReportingException("Data source for summary view was not found (viewName=" + view.getName() + ", dataSourceName=" + view.getDataSourceName() + ")."); + } + + QTableMetaData table = QContext.getQInstance().getTable(dataSource.getSourceTable()); + SummaryOutput summaryOutput = computeSummaryRowsForView(reportInput, view, table); ExportInput exportInput = new ExportInput(); exportInput.setReportDestination(reportInput.getReportDestination()); @@ -867,9 +893,8 @@ public class GenerateReportAction extends AbstractQActionFunction - { - return summaryRowComparator(view, o1, o2); - }); + summaryRows.sort((o1, o2) -> summaryRowComparator(view, o1, o2)); } //////////////// @@ -979,8 +1001,6 @@ public class GenerateReportAction extends AbstractQActionFunction