Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
6684283f
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
18379b3e
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
12dfe7b6
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
46e605b6
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
34b3dec6
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
0ac163ca
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
5694c752
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
357f447c
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
6295fc29
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
bacdc4d1
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
be74c546
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
81146b7a
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
c0fab2d0
by Tony Chemit at 2022-11-16T02:11:22+01:00
-
f0e84c38
by Tony Chemit at 2022-11-16T02:11:22+01:00
24 changed files:
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportModel.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ResultTableModel.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/table/actions/entry/ResetEntry.java
- client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/SampleUIHandler.java
- core/api/dto/src/main/resources/observe-reports.properties
- − core/services/local/src/test/java/fr/ird/observe/services/local/service/ReportServiceLocalReadTest.java
- core/services/test/src/main/java/fr/ird/observe/services/service/ReportFixture.java
- core/services/test/src/main/java/fr/ird/observe/services/service/report/ps/PsObservationAccessoryCatchReportFixture.java → core/services/test/src/main/java/fr/ird/observe/services/service/report/ps/PsObservationCatchReportFixture.java
- core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ReportService-psObservationAccessoryCatch.properties → core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ReportService-psObservationCatch.properties
- toolkit/api/src/main/java/fr/ird/observe/dto/report/DataMatrix.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/ReportBuilder.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/ReportRequest.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/ReportRequestExecutor.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/ReportVariable.java
- + toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/ComputeDynamicHeader.java
- + toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/CopyRepeatVariableToFirstColumn.java
- + toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/ExecuteRequestAndReorganizeCountByRepeatVariable.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/ExecuteRequests.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/SumColumn.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/SumFloatColumn.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/SumIntColumn.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/SumIntRow.java
- toolkit/api/src/main/java/fr/ird/observe/dto/report/operations/SumRow.java
- toolkit/persistence/src/main/java/fr/ird/observe/spi/report/DefaultReportRequestExecutor.java
Changes:
| ... | ... | @@ -43,10 +43,10 @@ import java.net.URL; |
| 43 | 43 | import java.nio.file.Files;
|
| 44 | 44 | import java.util.Collections;
|
| 45 | 45 | import java.util.Date;
|
| 46 | +import java.util.LinkedHashMap;
|
|
| 46 | 47 | import java.util.List;
|
| 47 | 48 | import java.util.Map;
|
| 48 | 49 | import java.util.Objects;
|
| 49 | -import java.util.TreeMap;
|
|
| 50 | 50 | import java.util.stream.Collectors;
|
| 51 | 51 | |
| 52 | 52 | /**
|
| ... | ... | @@ -81,7 +81,7 @@ public class ReportModel extends AdminActionModel { |
| 81 | 81 | /**
|
| 82 | 82 | * les variables utilisées pour le report.
|
| 83 | 83 | */
|
| 84 | - protected final Map<String, Object> variables;
|
|
| 84 | + protected final Map<String, Object> variables = new LinkedHashMap<>();
|
|
| 85 | 85 | /**
|
| 86 | 86 | * la fichier contenant la définition des reports.
|
| 87 | 87 | */
|
| ... | ... | @@ -128,7 +128,6 @@ public class ReportModel extends AdminActionModel { |
| 128 | 128 | |
| 129 | 129 | public ReportModel() {
|
| 130 | 130 | super(AdminStep.REPORT);
|
| 131 | - variables = new TreeMap<>();
|
|
| 132 | 131 | // quand le type de modèle change, on mets à jour les rapports disponibles
|
| 133 | 132 | addPropertyChangeListener(REPORT_FILE_PROPERTY_NAME, evt -> updateReports());
|
| 134 | 133 | }
|
| ... | ... | @@ -149,12 +149,11 @@ public class ResultTableModel extends AbstractTableModel { |
| 149 | 149 | rowNames.addAll(Arrays.asList(report.getRowHeaders()));
|
| 150 | 150 | }
|
| 151 | 151 | |
| 152 | - withColumnHeader = !columnNames.isEmpty();
|
|
| 153 | - withRowHeader = !rowNames.isEmpty();
|
|
| 154 | - table.setTableHeader(!withColumnHeader ? null : tableHeader);
|
|
| 155 | - table.createDefaultColumnsFromModel();
|
|
| 156 | 152 | int nbRows = incomingData.getHeight();
|
| 157 | 153 | int nbCols = incomingData.getWidth();
|
| 154 | + |
|
| 155 | + withColumnHeader = !columnNames.isEmpty();
|
|
| 156 | + withRowHeader = !rowNames.isEmpty();
|
|
| 158 | 157 | if (withRowHeader) {
|
| 159 | 158 | // on ajoute une première colonne aux données
|
| 160 | 159 | nbCols += 1;
|
| ... | ... | @@ -162,6 +161,22 @@ public class ResultTableModel extends AbstractTableModel { |
| 162 | 161 | incomingData.setX(1);
|
| 163 | 162 | }
|
| 164 | 163 | |
| 164 | + if (!withColumnHeader && !withRowHeader) {
|
|
| 165 | + // let's say we always use columns from incomingData
|
|
| 166 | + table.setTableHeader(tableHeader);
|
|
| 167 | + for (int i = 0; i < nbCols; i++) {
|
|
| 168 | + columnNames.add((String) incomingData.getValue(i, 0));
|
|
| 169 | + }
|
|
| 170 | + incomingData.setY(-1);
|
|
| 171 | + withColumnHeader = true;
|
|
| 172 | + nbRows--;
|
|
| 173 | + |
|
| 174 | + } else {
|
|
| 175 | + table.setTableHeader(!withColumnHeader ? null : tableHeader);
|
|
| 176 | + }
|
|
| 177 | + table.createDefaultColumnsFromModel();
|
|
| 178 | + |
|
| 179 | + |
|
| 165 | 180 | data.setHeight(nbRows);
|
| 166 | 181 | data.setWidth(nbCols);
|
| 167 | 182 | |
| ... | ... | @@ -185,7 +200,9 @@ public class ResultTableModel extends AbstractTableModel { |
| 185 | 200 | } else if (withColumnHeader) {
|
| 186 | 201 | |
| 187 | 202 | }
|
| 188 | - data.copyData(incomingData);
|
|
| 203 | + if (nbCols > 0) {
|
|
| 204 | + data.copyData(incomingData);
|
|
| 205 | + }
|
|
| 189 | 206 | fireTableStructureChanged();
|
| 190 | 207 | table.revalidate();
|
| 191 | 208 | table.repaint();
|
| ... | ... | @@ -220,7 +237,7 @@ public class ResultTableModel extends AbstractTableModel { |
| 220 | 237 | }
|
| 221 | 238 | |
| 222 | 239 | public String getClipboardContent(boolean copyRowHeaders, boolean copyColumnHeaders) {
|
| 223 | - return getDataContent(copyRowHeaders, copyColumnHeaders, true,'\t');
|
|
| 240 | + return getDataContent(copyRowHeaders, copyColumnHeaders, true, '\t');
|
|
| 224 | 241 | }
|
| 225 | 242 | |
| 226 | 243 | public String getCsvContent() {
|
| ... | ... | @@ -59,7 +59,12 @@ public final class ResetEntry extends ContentTableUIActionSupport<ContentTableUI |
| 59 | 59 | }
|
| 60 | 60 | } else {
|
| 61 | 61 | // reset existing entry
|
| 62 | - tableModel.resetEditBean();
|
|
| 62 | + ui.getStates().setResetEdit(true);
|
|
| 63 | + try {
|
|
| 64 | + tableModel.resetEditBean();
|
|
| 65 | + } finally {
|
|
| 66 | + ui.getStates().setResetEdit(false);
|
|
| 67 | + }
|
|
| 63 | 68 | }
|
| 64 | 69 | }
|
| 65 | 70 |
| ... | ... | @@ -72,12 +72,11 @@ public class SampleUIHandler extends GeneratedSampleUIHandler { |
| 72 | 72 | private final PropertyChangeListener speciesChanged;
|
| 73 | 73 | |
| 74 | 74 | public SampleUIHandler() {
|
| 75 | - weightChanged = evt -> onWeightChanged((Float) evt.getNewValue());
|
|
| 76 | - lengthChanged = evt -> onLengthChanged((Float) evt.getNewValue());
|
|
| 75 | + weightChanged = evt -> onWeightChanged((Float) evt.getNewValue(), !ui.getStates().isResetEdit());
|
|
| 76 | + lengthChanged = evt -> onLengthChanged((Float) evt.getNewValue(), !ui.getStates().isResetEdit());
|
|
| 77 | 77 | speciesChanged = evt -> onSpeciesChanged((SpeciesReference) evt.getNewValue());
|
| 78 | 78 | }
|
| 79 | 79 | |
| 80 | - |
|
| 81 | 80 | @Override
|
| 82 | 81 | public void onInit(SampleUI ui) {
|
| 83 | 82 | super.onInit(ui);
|
| ... | ... | @@ -97,8 +96,8 @@ public class SampleUIHandler extends GeneratedSampleUIHandler { |
| 97 | 96 | |
| 98 | 97 | public void onSelectedRowChanged(SampleMeasureDto tableEditBean, SampleMeasureDto previousRowBean, boolean notPersisted, boolean newRow) {
|
| 99 | 98 | |
| 100 | - onLengthChanged(tableEditBean.getLength());
|
|
| 101 | - onWeightChanged(tableEditBean.getWeight());
|
|
| 99 | + onLengthChanged(tableEditBean.getLength(), false);
|
|
| 100 | + onWeightChanged(tableEditBean.getWeight(), false);
|
|
| 102 | 101 | |
| 103 | 102 | SampleUIModel sampleModel = getModel();
|
| 104 | 103 | |
| ... | ... | @@ -209,6 +208,9 @@ public class SampleUIHandler extends GeneratedSampleUIHandler { |
| 209 | 208 | }
|
| 210 | 209 | |
| 211 | 210 | public void startEditTableEditBean(SampleMeasureDto tableEditBean) {
|
| 211 | + tableEditBean.removePropertyChangeListener(SampleMeasureDto.PROPERTY_WEIGHT, weightChanged);
|
|
| 212 | + tableEditBean.removePropertyChangeListener(SampleMeasureDto.PROPERTY_LENGTH, lengthChanged);
|
|
| 213 | + tableEditBean.removePropertyChangeListener(SampleMeasureDto.PROPERTY_SPECIES, speciesChanged);
|
|
| 212 | 214 | tableEditBean.addPropertyChangeListener(SampleMeasureDto.PROPERTY_WEIGHT, weightChanged);
|
| 213 | 215 | tableEditBean.addPropertyChangeListener(SampleMeasureDto.PROPERTY_LENGTH, lengthChanged);
|
| 214 | 216 | tableEditBean.addPropertyChangeListener(SampleMeasureDto.PROPERTY_SPECIES, speciesChanged);
|
| ... | ... | @@ -249,9 +251,9 @@ public class SampleUIHandler extends GeneratedSampleUIHandler { |
| 249 | 251 | acquisitionModeGroup.setSelectedValue(acquisitionMode);
|
| 250 | 252 | }
|
| 251 | 253 | |
| 252 | - protected void onWeightChanged(Float newValue) {
|
|
| 254 | + protected void onWeightChanged(Float newValue, boolean realChange) {
|
|
| 253 | 255 | SampleMeasureDto tableEditBean = ui.getModel().getStates().getTableEditBean();
|
| 254 | - if (tableEditBean.getAcquisitionMode() == 1) {
|
|
| 256 | + if (realChange && tableEditBean.getAcquisitionMode() == 1) {
|
|
| 255 | 257 | tableEditBean.setIsWeightComputed(false);
|
| 256 | 258 | }
|
| 257 | 259 | if (newValue == null) {
|
| ... | ... | @@ -259,9 +261,11 @@ public class SampleUIHandler extends GeneratedSampleUIHandler { |
| 259 | 261 | }
|
| 260 | 262 | }
|
| 261 | 263 | |
| 262 | - protected void onLengthChanged(Float newValue) {
|
|
| 264 | + protected void onLengthChanged(Float newValue, boolean realChange) {
|
|
| 263 | 265 | SampleMeasureDto tableEditBean = ui.getModel().getStates().getTableEditBean();
|
| 264 | - tableEditBean.setIsLengthComputed(false);
|
|
| 266 | + if (realChange) {
|
|
| 267 | + tableEditBean.setIsLengthComputed(false);
|
|
| 268 | + }
|
|
| 265 | 269 | if (newValue == null) {
|
| 266 | 270 | tableEditBean.setLengthMeasureMethod(null);
|
| 267 | 271 | }
|
| ... | ... | @@ -697,26 +697,26 @@ report.psObservationTargetDiscardedByAssociation.request.19=0,3|row|\ |
| 697 | 697 | and os.topiaId = 'fr.ird.referential.ps.common.ObservedSystem#1239832686428#0.9217864901728908' \
|
| 698 | 698 | and os not in elements(a.observedSystem)
|
| 699 | 699 | ################################################################################
|
| 700 | -## Captures accessoires observées
|
|
| 700 | +## Captures observées
|
|
| 701 | 701 | ################################################################################
|
| 702 | -report.psObservationAccessoryCatch.modelType=PS
|
|
| 703 | -report.psObservationAccessoryCatch.name=Observations - Liste des captures accessoires selon le type de banc, filtrées par groupe
|
|
| 704 | -report.psObservationAccessoryCatch.description=Afficher les captures accessoires par groupe d'espèce\nLes poids sont exprimés en tonnes.
|
|
| 705 | -report.psObservationAccessoryCatch.columns=Espèce, Banc libre, Banc objet
|
|
| 706 | -report.psObservationAccessoryCatch.variable.speciesGroup=fr.ird.observe.dto.referential.common.SpeciesGroupDto|From SpeciesGroupImpl ge Order By ge.code
|
|
| 707 | -report.psObservationAccessoryCatch.repeatVariable.speciesId=java.lang.String|\
|
|
| 702 | +report.psObservationCatch.modelType=PS
|
|
| 703 | +report.psObservationCatch.name=Observations - Liste des captures selon le type de banc, filtrées par groupe
|
|
| 704 | +report.psObservationCatch.description=Afficher les captures par groupe d'espèce\nLes poids sont exprimés en tonnes.
|
|
| 705 | +report.psObservationCatch.columns=Espèce, Banc libre, Banc objet
|
|
| 706 | +report.psObservationCatch.variable.speciesGroup=fr.ird.observe.dto.referential.common.SpeciesGroupDto|From SpeciesGroupImpl ge Order By ge.code
|
|
| 707 | +report.psObservationCatch.repeatVariable.speciesId=java.lang.String|\
|
|
| 708 | 708 | Select e.id From SpeciesImpl e \
|
| 709 | 709 | Where e.speciesGroup.id = :speciesGroup \
|
| 710 | 710 | Order By e.homeId
|
| 711 | -report.psObservationAccessoryCatch.request.1=0,0|row|\
|
|
| 711 | +report.psObservationCatch.request.1=0,0|row|\
|
|
| 712 | 712 | Select \
|
| 713 | 713 | concat('[FAO]', (case when e.faoCode is not null then e.faoCode else '-' end), \
|
| 714 | 714 | ' [sc]', (case when e.scientificLabel is not null then e.scientificLabel else '-' end), \
|
| 715 | 715 | ' [fr]', (case when e.label2 is not null then e.label2 else '-' end)) \
|
| 716 | 716 | From SpeciesImpl e \
|
| 717 | 717 | Where e.id = :speciesId
|
| 718 | -report.psObservationAccessoryCatch.request.1.repeat=speciesId|column
|
|
| 719 | -report.psObservationAccessoryCatch.request.2=1,0|row|\
|
|
| 718 | +report.psObservationCatch.request.1.repeat=speciesId|column
|
|
| 719 | +report.psObservationCatch.request.2=1,0|row|\
|
|
| 720 | 720 | Select \
|
| 721 | 721 | case when Count(ca) > 0 then \
|
| 722 | 722 | concat('+', \
|
| ... | ... | @@ -731,8 +731,8 @@ report.psObservationAccessoryCatch.request.2=1,0|row|\ |
| 731 | 731 | Join c.catches ca \
|
| 732 | 732 | with ca.species.id = :speciesId \
|
| 733 | 733 | Where m.id In :tripId
|
| 734 | -report.psObservationAccessoryCatch.request.2.repeat=speciesId|column
|
|
| 735 | -report.psObservationAccessoryCatch.request.3=2,0|row|\
|
|
| 734 | +report.psObservationCatch.request.2.repeat=speciesId|column
|
|
| 735 | +report.psObservationCatch.request.3=2,0|row|\
|
|
| 736 | 736 | Select \
|
| 737 | 737 | case when Count(ca) > 0 then \
|
| 738 | 738 | concat('+', \
|
| ... | ... | @@ -747,7 +747,7 @@ report.psObservationAccessoryCatch.request.3=2,0|row|\ |
| 747 | 747 | Join c.catches ca \
|
| 748 | 748 | with ca.species.id = :speciesId \
|
| 749 | 749 | Where m.id In :tripId
|
| 750 | -report.psObservationAccessoryCatch.request.3.repeat=speciesId|column
|
|
| 750 | +report.psObservationCatch.request.3.repeat=speciesId|column
|
|
| 751 | 751 | ################################################################################
|
| 752 | 752 | ## Captures accessoires par speciesGroup d'espèces
|
| 753 | 753 | ################################################################################
|
| 1 | -package fr.ird.observe.services.local.service;
|
|
| 2 | - |
|
| 3 | -/*-
|
|
| 4 | - * #%L
|
|
| 5 | - * ObServe Core :: Services :: Local
|
|
| 6 | - * %%
|
|
| 7 | - * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | - * %%
|
|
| 9 | - * This program is free software: you can redistribute it and/or modify
|
|
| 10 | - * it under the terms of the GNU General Public License as
|
|
| 11 | - * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | - * License, or (at your option) any later version.
|
|
| 13 | - *
|
|
| 14 | - * This program is distributed in the hope that it will be useful,
|
|
| 15 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | - * GNU General Public License for more details.
|
|
| 18 | - *
|
|
| 19 | - * You should have received a copy of the GNU General Public
|
|
| 20 | - * License along with this program. If not, see
|
|
| 21 | - * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | - * #L%
|
|
| 23 | - */
|
|
| 24 | - |
|
| 25 | -import fr.ird.observe.services.service.ReportServiceFixtures;
|
|
| 26 | -import org.junit.AfterClass;
|
|
| 27 | - |
|
| 28 | -public class ReportServiceLocalReadTest extends GeneratedReportServiceLocalReadTest {
|
|
| 29 | - |
|
| 30 | - @AfterClass
|
|
| 31 | - public static void afterClass() {
|
|
| 32 | - if (!ReportServiceFixtures.WITH_ASSERT) {
|
|
| 33 | - System.out.println("New asserts:\n" + String.join("\n", ReportServiceFixtures.getAsserts()));
|
|
| 34 | - ReportServiceFixtures.getAsserts().clear();
|
|
| 35 | - }
|
|
| 36 | - }
|
|
| 37 | - |
|
| 38 | -} |
| ... | ... | @@ -76,6 +76,7 @@ public abstract class ReportFixture { |
| 76 | 76 | }
|
| 77 | 77 | |
| 78 | 78 | public final DataMatrix execute(ReportService service, Report report) {
|
| 79 | + log.warn("Starting report {}", report.getName());
|
|
| 79 | 80 | return service.executeReport(report, getTripIds());
|
| 80 | 81 | }
|
| 81 | 82 | |
| ... | ... | @@ -127,6 +128,8 @@ public abstract class ReportFixture { |
| 127 | 128 | for (int i = 0; i < rows; i++) {
|
| 128 | 129 | ReportServiceFixtures.writeArrayAssert(String.format("result.%d", i), actual.getData()[i]);
|
| 129 | 130 | }
|
| 131 | + System.out.println("New asserts:\n" + String.join("\n", ReportServiceFixtures.getAsserts()));
|
|
| 132 | + ReportServiceFixtures.getAsserts().clear();
|
|
| 130 | 133 | }
|
| 131 | 134 | }
|
| 132 | 135 | |
| ... | ... | @@ -159,7 +162,11 @@ public abstract class ReportFixture { |
| 159 | 162 | |
| 160 | 163 | Assert.assertEquals(rows, report.getRows());
|
| 161 | 164 | Assert.assertEquals(columns, report.getColumns());
|
| 162 | - Assert.assertArrayEquals(columnsHeader, report.getColumnHeaders());
|
|
| 165 | + if (report.getColumnHeaders() == null) {
|
|
| 166 | + Assert.assertEquals(0, columnsHeader.length);
|
|
| 167 | + } else {
|
|
| 168 | + Assert.assertArrayEquals(columnsHeader, report.getColumnHeaders());
|
|
| 169 | + }
|
|
| 163 | 170 | if (report.getRowHeaders() == null) {
|
| 164 | 171 | Assert.assertEquals(0, rowsHeader.length);
|
| 165 | 172 | } else {
|
| ... | ... | @@ -168,7 +175,11 @@ public abstract class ReportFixture { |
| 168 | 175 | } else {
|
| 169 | 176 | ReportServiceFixtures.addAssert("syntax.rows", report.getRows());
|
| 170 | 177 | ReportServiceFixtures.addAssert("syntax.columns", report.getColumns());
|
| 171 | - ReportServiceFixtures.writeArrayAssert("syntax.columnsHeader", (Object[]) report.getColumnHeaders());
|
|
| 178 | + if (report.getRowHeaders() == null) {
|
|
| 179 | + ReportServiceFixtures.writeArrayAssert("syntax.columnsHeader");
|
|
| 180 | + } else {
|
|
| 181 | + ReportServiceFixtures.writeArrayAssert("syntax.columnsHeader", (Object[]) report.getColumnHeaders());
|
|
| 182 | + }
|
|
| 172 | 183 | if (report.getRowHeaders() == null) {
|
| 173 | 184 | ReportServiceFixtures.writeArrayAssert("syntax.rowsHeader");
|
| 174 | 185 | } else {
|
| ... | ... | @@ -36,7 +36,7 @@ import java.util.Iterator; |
| 36 | 36 | * @since 1.9
|
| 37 | 37 | */
|
| 38 | 38 | @AutoService(ReportFixture.class)
|
| 39 | -public class PsObservationAccessoryCatchReportFixture extends ReportFixture {
|
|
| 39 | +public class PsObservationCatchReportFixture extends ReportFixture {
|
|
| 40 | 40 | |
| 41 | 41 | @Override
|
| 42 | 42 | public void assertSyntax(Report report) {
|
| ... | ... | @@ -19,8 +19,24 @@ |
| 19 | 19 | # <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| 20 | 20 | # #L%
|
| 21 | 21 | ###
|
| 22 | +syntax.name=Observations - Liste des captures selon le type de banc, filtrées par groupe
|
|
| 23 | +syntax.description=Afficher les captures par groupe d'espèce-Les poids sont exprimés en tonnes.
|
|
| 24 | +syntax.columns=3
|
|
| 25 | +syntax.rows=-1
|
|
| 26 | +syntax.columnsHeader=Espèce^Banc libre^Banc objet
|
|
| 27 | +syntax.nbRequests=3
|
|
| 28 | +result.columns=3
|
|
| 29 | +result.rows=49
|
|
| 22 | 30 | result.0=[FAO]CCB [sc]Carcharhinus brevipinna [fr]Requin tisserand^-^-
|
| 23 | 31 | result.1=[FAO]ALS [sc]Carcharhinus albimarginatus [fr]Requin pointe blanche^-^-
|
| 32 | +result.2=[FAO]AML [sc]Carcharhinus amblyrhynchos [fr]Grey reef shark^-^-
|
|
| 33 | +result.3=[FAO]PTH [sc]Alopias pelagicus [fr]Renard pélagique^-^-
|
|
| 34 | +result.4=[FAO]BTH [sc]Alopias superciliosus [fr]Renard à gros yeux^-^-
|
|
| 35 | +result.5=[FAO]ALV [sc]Alopias vulpinus [fr]Renard^-^+ Effectif : 3 Poids total (t) : 12.0
|
|
| 36 | +result.6=[FAO]BLR [sc]Carcharhinus melanopterus [fr]Requin pointes noires^-^-
|
|
| 37 | +result.7=[FAO]BRO [sc]Carcharhinus brachyurus [fr]Requin cuivre^-^-
|
|
| 38 | +result.8=[FAO]WSH [sc]Carcharodon carcharias [fr]Grand requin blanc^-^-
|
|
| 39 | +result.9=[FAO]CCE [sc]Carcharhinus leucas [fr]Requin bouledogue^-^-
|
|
| 24 | 40 | result.10=[FAO]CCL [sc]Carcharhinus limbatus [fr]Requin bordé^-^-
|
| 25 | 41 | result.11=[FAO]CCP [sc]Carcharhinus plumbeus [fr]Requin gris^-^-
|
| 26 | 42 | result.12=[FAO]FAL [sc]Carcharhinus falciformis [fr]Requin soyeux^-^-
|
| ... | ... | @@ -28,10 +44,9 @@ result.13=[FAO]OCS [sc]Carcharhinus longimanus [fr]Requin océanique^-^- |
| 28 | 44 | result.14=[FAO]CWZ [sc]Carcharhinus spp [fr]Requins Carcharhinus nca^-^-
|
| 29 | 45 | result.15=[FAO]DUS [sc]Carcharhinus obscurus [fr]Requin sombre^-^-
|
| 30 | 46 | result.16=[FAO]SHL [sc]Etmopterus spp [fr]Genre Etmopterus^-^-
|
| 31 | -result.17=[FAO]THR [sc]Alopias spp [fr]Renards de mer nca ^-^-
|
|
| 47 | +result.17=[FAO]THR [sc]Alopias spp [fr]Renards de mer nca^-^-
|
|
| 32 | 48 | result.18=[FAO]RSK [sc]Carcharhinidae spp [fr]Famille Carcharhinidae^-^-
|
| 33 | 49 | result.19=[FAO]MSK [sc]Lamnidae [fr]Famille Lamnidae^-^-
|
| 34 | -result.2=[FAO]AML [sc]Carcharhinus amblyrhynchos [fr]Grey reef shark^-^-
|
|
| 35 | 50 | result.20=[FAO]2FOD [sc]Odontaspididae [fr]Odontaspididae^-^-
|
| 36 | 51 | result.21=[FAO]2FRH [sc]Rhincodontidae [fr]Famille Rhincodontidae^-^-
|
| 37 | 52 | result.22=[FAO]SPY [sc]Sphyrnidae [fr]Famille Sphyrnidae^-^-
|
| ... | ... | @@ -42,18 +57,16 @@ result.26=[FAO]LMA [sc]Isurus paucus [fr]Petite taupe, Mako^-^- |
| 42 | 57 | result.27=[FAO]MAK [sc]Isurus spp [fr]Taupes^-^-
|
| 43 | 58 | result.28=[FAO]LMP [sc]Megachasma pelagios [fr]Requin grande gueule^-^-
|
| 44 | 59 | result.29=[FAO]CVX [sc]Carcharhiniformes [fr]Ordre Carcharhiniformes^-^-
|
| 45 | -result.3=[FAO]PTH [sc]Alopias pelagicus [fr]Renard pélagique^-^-
|
|
| 46 | 60 | result.30=[FAO]HDQ [sc]Heterodontiformes [fr]Ordre Heterodontiformes^-^-
|
| 47 | 61 | result.31=[FAO]HXW [sc]Hexanchiformes [fr]Ordre Hexanchiformes^-^-
|
| 48 | 62 | result.32=[FAO]LMZ [sc]Lamniformes [fr]Ordre Lamniformes^-^-
|
| 49 | 63 | result.33=[FAO]OCX [sc]Orectolobiformes [fr]Ordre Orectolobiformes^-^-
|
| 50 | -result.34=[FAO]PWS [sc]Pristiophorus spp [fr]Requins-scies nca ^-^-
|
|
| 64 | +result.34=[FAO]PWS [sc]Pristiophorus spp [fr]Requins-scies nca^-^-
|
|
| 51 | 65 | result.35=[FAO]OSF [sc]Stegostoma fasciatum [fr]Requin zèbre^-^-
|
| 52 | 66 | result.36=[FAO]SHX [sc]Squaliformes [fr]Ordre Squaliformes^-^-
|
| 53 | -result.37=[FAO]ASK [sc]Squatinidae [fr]Anges de mer nca ^-^-
|
|
| 67 | +result.37=[FAO]ASK [sc]Squatinidae [fr]Anges de mer nca^-^-
|
|
| 54 | 68 | result.38=[FAO]BSH [sc]Prionace glauca [fr]Peau bleue^-^-
|
| 55 | 69 | result.39=[FAO]POR [sc]Lamna nasus [fr]Requin taupe commun^-^-
|
| 56 | -result.4=[FAO]BTH [sc]Alopias superciliosus [fr]Renard à gros yeux^-^-
|
|
| 57 | 70 | result.40=[FAO]PSK [sc]Pseudocarcharias kamoharai [fr]Requin crocodile^-^-
|
| 58 | 71 | result.41=[FAO]2REX [sc]Requin non identifié [fr]Requin non identifié^-^-
|
| 59 | 72 | result.42=[FAO]BSK [sc]Cetorhinus maximus [fr]Requin pèlerin^-^-
|
| ... | ... | @@ -63,17 +76,3 @@ result.45=[FAO]SPL [sc]Sphyrna lewini [fr]Requin marteau halicorne^-^- |
| 63 | 76 | result.46=[FAO]SPK [sc]Sphyrna mokarran [fr]Grand requin marteau^-^-
|
| 64 | 77 | result.47=[FAO]SPN [sc]Sphyrna spp [fr]Requins marteau nca^-^-
|
| 65 | 78 | result.48=[FAO]SPZ [sc]Sphyrna zygaena [fr]Requin marteau commun^-^- |
| 66 | -result.5=[FAO]ALV [sc]Alopias vulpinus [fr]Renard^-^+ Effectif : 3 Poids total (t) : 12.0
|
|
| 67 | -result.6=[FAO]BLR [sc]Carcharhinus melanopterus [fr]Requin pointes noires^-^-
|
|
| 68 | -result.7=[FAO]BRO [sc]Carcharhinus brachyurus [fr]Requin cuivre^-^-
|
|
| 69 | -result.8=[FAO]WSH [sc]Carcharodon carcharias [fr]Grand requin blanc^-^-
|
|
| 70 | -result.9=[FAO]CCE [sc]Carcharhinus leucas [fr]Requin bouledogue^-^-
|
|
| 71 | -result.columns=3
|
|
| 72 | -result.rows=49
|
|
| 73 | -syntax.columns=3
|
|
| 74 | -syntax.columnsHeader=Espèce^Banc libre^Banc objet
|
|
| 75 | -syntax.description=Afficher les captures accessoires par groupe d'espèce-Les poids sont exprimés en tonnes.
|
|
| 76 | -syntax.name=Observations - Liste des captures accessoires selon le type de banc, filtrées par groupe
|
|
| 77 | -syntax.nbRequests=3
|
|
| 78 | -syntax.rows=-1
|
|
| 79 | -syntax.rowsHeader= |
| ... | ... | @@ -159,7 +159,13 @@ public class DataMatrix implements JsonAware { |
| 159 | 159 | log.debug(String.format("copying incoming matrix (dim: %s, location: %s)", incoming.getDimension(), incoming.getLocation()));
|
| 160 | 160 | |
| 161 | 161 | for (int i = 0; i < width; i++) {
|
| 162 | + if (x + i < 0) {
|
|
| 163 | + continue;
|
|
| 164 | + }
|
|
| 162 | 165 | for (int j = 0; j < height; j++) {
|
| 166 | + if (y + j < 0) {
|
|
| 167 | + continue;
|
|
| 168 | + }
|
|
| 163 | 169 | Serializable value = incoming.getValue(i, j);
|
| 164 | 170 | setValue(x + i, y + j, value);
|
| 165 | 171 | }
|
| ... | ... | @@ -319,12 +319,14 @@ public class ReportBuilder { |
| 319 | 319 | Map.Entry<String, String> entry = itr.next();
|
| 320 | 320 | String key = entry.getKey();
|
| 321 | 321 | if (!key.startsWith(VARIABLE_PREFIX)) {
|
| 322 | - |
|
| 323 | 322 | continue;
|
| 324 | 323 | }
|
| 325 | 324 | String operations = entry.getValue();
|
| 326 | 325 | String id = key.substring(VARIABLE_PREFIX.length());
|
| 327 | - |
|
| 326 | + int indexOf = id.indexOf(".");
|
|
| 327 | + if (indexOf > -1) {
|
|
| 328 | + id = id.substring(indexOf + 1);
|
|
| 329 | + }
|
|
| 328 | 330 | // on interdit la surcharge d'une variable déjà trouvée pour le report
|
| 329 | 331 | if (ids.contains(id)) {
|
| 330 | 332 | throw new IllegalArgumentException("La variable " + id + " est déjà définie pour le report " + reportName);
|
| ... | ... | @@ -359,12 +361,14 @@ public class ReportBuilder { |
| 359 | 361 | Map.Entry<String, String> entry = itr.next();
|
| 360 | 362 | String key = entry.getKey();
|
| 361 | 363 | if (!key.startsWith(REPEAT_VARIABLE_PREFIX)) {
|
| 362 | - |
|
| 363 | 364 | continue;
|
| 364 | 365 | }
|
| 365 | 366 | String operations = entry.getValue();
|
| 366 | 367 | String id = key.substring(REPEAT_VARIABLE_PREFIX.length());
|
| 367 | - |
|
| 368 | + int indexOf = id.indexOf(".");
|
|
| 369 | + if (indexOf > -1) {
|
|
| 370 | + id = id.substring(indexOf + 1);
|
|
| 371 | + }
|
|
| 368 | 372 | // on interdit la surcharge d'une variable déjà trouvée pour le report
|
| 369 | 373 | if (ids.contains(id)) {
|
| 370 | 374 | throw new IllegalArgumentException("La variable de répétition " + id + " est déjà définie pour le report " + reportName);
|
| ... | ... | @@ -27,9 +27,9 @@ import org.apache.commons.lang3.builder.ToStringBuilder; |
| 27 | 27 | |
| 28 | 28 | import java.awt.Point;
|
| 29 | 29 | import java.io.Serializable;
|
| 30 | -import java.util.HashMap;
|
|
| 31 | 30 | import java.util.Map;
|
| 32 | 31 | import java.util.Set;
|
| 32 | +import java.util.TreeMap;
|
|
| 33 | 33 | |
| 34 | 34 | /**
|
| 35 | 35 | * Pour caractériser une requète à lancer dans un report.
|
| ... | ... | @@ -90,46 +90,17 @@ public class ReportRequest implements Serializable, JsonAware { |
| 90 | 90 | }
|
| 91 | 91 | |
| 92 | 92 | public static Map<String, Object> extractParams(Report report, Set<String> tripId) {
|
| 93 | - |
|
| 94 | - Map<String, Object> params = new HashMap<>();
|
|
| 95 | - |
|
| 93 | + Map<String, Object> params = new TreeMap<>();
|
|
| 96 | 94 | params.put(TRIP_ID_VARIABLE, tripId);
|
| 97 | - |
|
| 98 | 95 | for (ReportVariable<?> variable : report.getVariables()) {
|
| 99 | - |
|
| 100 | 96 | String name = variable.getName();
|
| 101 | - |
|
| 102 | 97 | Object value = variable.getSelectedValue();
|
| 103 | - |
|
| 104 | 98 | params.put(name, value);
|
| 105 | - |
|
| 106 | 99 | }
|
| 107 | 100 | return params;
|
| 108 | 101 | |
| 109 | 102 | }
|
| 110 | 103 | |
| 111 | -// public static Object[] getParams(String request, Map<String, Object> params) {
|
|
| 112 | -//
|
|
| 113 | -// // on parcourt la liste de tous les paramètres pour savoir si on doit
|
|
| 114 | -// // les inclure pour la requête donnée :
|
|
| 115 | -// List<String> namesToUsed = new ArrayList<>();
|
|
| 116 | -// for (String paramName : params.keySet()) {
|
|
| 117 | -// if (request.contains(":" + paramName)) {
|
|
| 118 | -// namesToUsed.add(paramName);
|
|
| 119 | -// }
|
|
| 120 | -// }
|
|
| 121 | -// Object[] datas = new Object[namesToUsed.size() * 2];
|
|
| 122 | -// int index = 0;
|
|
| 123 | -// for (String name : namesToUsed) {
|
|
| 124 | -// Object value = params.get(name);
|
|
| 125 | -// datas[index * 2] = name;
|
|
| 126 | -// datas[index * 2 + 1] = value;
|
|
| 127 | -// index++;
|
|
| 128 | -// }
|
|
| 129 | -// namesToUsed.clear();
|
|
| 130 | -// return datas;
|
|
| 131 | -// }
|
|
| 132 | - |
|
| 133 | 104 | public ReportRequest(RequestLayout layout,
|
| 134 | 105 | int x,
|
| 135 | 106 | int y,
|
| ... | ... | @@ -29,6 +29,7 @@ import java.util.LinkedHashSet; |
| 29 | 29 | import java.util.List;
|
| 30 | 30 | import java.util.Map;
|
| 31 | 31 | import java.util.Set;
|
| 32 | +import java.util.TreeMap;
|
|
| 32 | 33 | |
| 33 | 34 | /**
|
| 34 | 35 | * To execute a request.
|
| ... | ... | @@ -49,11 +50,20 @@ public interface ReportRequestExecutor { |
| 49 | 50 | |
| 50 | 51 | <V> void populateVariable(ReportVariable<V> variable, Map<String, Object> vars);
|
| 51 | 52 | |
| 52 | - default DataMatrix executeReportRequest(ReportRequest request, Report report, Set<String> dataId, ReportVariable<?> repeatValues) {
|
|
| 53 | + default DataMatrix executeReportRequest(ReportRequest request, Report report, Set<String> dataId) {
|
|
| 53 | 54 | Map<String, Object> params = ReportRequest.extractParams(report, dataId);
|
| 54 | - if (repeatValues == null) {
|
|
| 55 | - return executeReportRequest(request, params);
|
|
| 55 | + String hql = request.getRequest();
|
|
| 56 | + for (ReportVariable<?> repeatVariable : report.getRepeatVariables()) {
|
|
| 57 | + if (hql.contains(":" + repeatVariable.getName() + " ")) {
|
|
| 58 | + // add this repeat variable values to parameters
|
|
| 59 | + params.put(repeatVariable.getName(), repeatVariable.computeIndexList());
|
|
| 60 | + }
|
|
| 56 | 61 | }
|
| 62 | + return executeReportRequest(request, params);
|
|
| 63 | + }
|
|
| 64 | + |
|
| 65 | + default DataMatrix executeReportRequest(ReportRequest request, Report report, Set<String> dataId, ReportVariable<?> repeatValues) {
|
|
| 66 | + Map<String, Object> params = ReportRequest.extractParams(report, dataId);
|
|
| 57 | 67 | DataMatrix result = new DataMatrix();
|
| 58 | 68 | for (Object repeatValue : repeatValues.getValues()) {
|
| 59 | 69 | params.put(request.getRepeat().getVariableName(), repeatValue);
|
| ... | ... | @@ -97,15 +107,27 @@ public interface ReportRequestExecutor { |
| 97 | 107 | return result;
|
| 98 | 108 | }
|
| 99 | 109 | |
| 100 | - @SuppressWarnings("unchecked")
|
|
| 101 | 110 | default void doPopulateRepeatVariables(Report report, Set<String> tripId) {
|
| 102 | 111 | Map<String, Object> vars = ReportRequest.extractParams(report, tripId);
|
| 103 | - for (@SuppressWarnings("rawtypes") ReportVariable variable : report.getRepeatVariables()) {
|
|
| 104 | - String hql = variable.getRequest();
|
|
| 105 | - List<Object> universe = executeRequest(hql, vars);
|
|
| 106 | - LinkedHashSet<Object> values = new LinkedHashSet<>(universe);
|
|
| 107 | - variable.setValues(values);
|
|
| 112 | + for (ReportVariable<?> variable : report.getRepeatVariables()) {
|
|
| 113 | + doPopulateRepeatVariable(report, tripId, new TreeMap<>(vars), variable);
|
|
| 114 | + }
|
|
| 115 | + }
|
|
| 116 | + |
|
| 117 | + default <R> void doPopulateRepeatVariable(Report report, Set<String> tripId, Map<String, Object> vars, ReportVariable<R> variable) {
|
|
| 118 | + String hql = variable.getRequest();
|
|
| 119 | + for (ReportVariable<?> repeatVariable : report.getRepeatVariables()) {
|
|
| 120 | + if (variable.equals(repeatVariable)) {
|
|
| 121 | + continue;
|
|
| 122 | + }
|
|
| 123 | + if (hql.contains(":" + repeatVariable.getName() + " ")) {
|
|
| 124 | + // add this repeat variable values to parameters
|
|
| 125 | + vars.put(repeatVariable.getName(), repeatVariable.computeIndexList());
|
|
| 126 | + }
|
|
| 108 | 127 | }
|
| 128 | + List<R> universe = executeRequest(hql, vars);
|
|
| 129 | + LinkedHashSet<R> values = new LinkedHashSet<>(universe);
|
|
| 130 | + variable.setValues(values);
|
|
| 109 | 131 | }
|
| 110 | 132 | |
| 111 | 133 | private DataMatrixDimension computeDimension(ReportRequest request, List<?> list) {
|
| ... | ... | @@ -22,10 +22,15 @@ package fr.ird.observe.dto.report; |
| 22 | 22 | * #L%
|
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | +import fr.ird.observe.dto.ToolkitId;
|
|
| 25 | 26 | import io.ultreia.java4all.util.json.JsonAware;
|
| 26 | 27 | |
| 27 | 28 | import java.io.Serializable;
|
| 29 | +import java.util.LinkedHashSet;
|
|
| 30 | +import java.util.List;
|
|
| 31 | +import java.util.Objects;
|
|
| 28 | 32 | import java.util.Set;
|
| 33 | +import java.util.stream.Collectors;
|
|
| 29 | 34 | |
| 30 | 35 | /**
|
| 31 | 36 | * La définition d'une variable utilisable dans un report.
|
| ... | ... | @@ -90,4 +95,31 @@ public class ReportVariable<V> implements Serializable, JsonAware { |
| 90 | 95 | public void setSelectedValue(V selectedValue) {
|
| 91 | 96 | this.selectedValue = selectedValue;
|
| 92 | 97 | }
|
| 98 | + |
|
| 99 | + public List<String> computeIndexList() {
|
|
| 100 | + Set<V> tmp = new LinkedHashSet<>(values);
|
|
| 101 | + boolean useNullValue = tmp.remove(null);
|
|
| 102 | + List<String> result = tmp.stream().map(s -> s instanceof ToolkitId ? ((ToolkitId) s).getId() : String.valueOf(s)).collect(Collectors.toList());
|
|
| 103 | + if (useNullValue) {
|
|
| 104 | + result.add("null");
|
|
| 105 | + }
|
|
| 106 | + return result;
|
|
| 107 | + }
|
|
| 108 | + |
|
| 109 | + public boolean isEmpty() {
|
|
| 110 | + return values == null || values.isEmpty();
|
|
| 111 | + }
|
|
| 112 | + |
|
| 113 | + @Override
|
|
| 114 | + public boolean equals(Object o) {
|
|
| 115 | + if (this == o) return true;
|
|
| 116 | + if (!(o instanceof ReportVariable)) return false;
|
|
| 117 | + ReportVariable<?> that = (ReportVariable<?>) o;
|
|
| 118 | + return Objects.equals(name, that.name);
|
|
| 119 | + }
|
|
| 120 | + |
|
| 121 | + @Override
|
|
| 122 | + public int hashCode() {
|
|
| 123 | + return Objects.hash(name);
|
|
| 124 | + }
|
|
| 93 | 125 | } |
| 1 | +package fr.ird.observe.dto.report.operations;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Toolkit :: API
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import com.google.auto.service.AutoService;
|
|
| 26 | +import fr.ird.observe.dto.referential.WithI18n;
|
|
| 27 | +import fr.ird.observe.dto.report.DataMatrix;
|
|
| 28 | +import fr.ird.observe.dto.report.Report;
|
|
| 29 | +import fr.ird.observe.dto.report.ReportOperationConsumer;
|
|
| 30 | +import fr.ird.observe.dto.report.ReportRequestExecutor;
|
|
| 31 | + |
|
| 32 | +import java.util.Set;
|
|
| 33 | + |
|
| 34 | +/**
|
|
| 35 | + * To compute dynamic headers (for report with no column headers defined).
|
|
| 36 | + * <p>
|
|
| 37 | + * You can set as parameters an array of fixed column names + a repeat variable to complete the header.
|
|
| 38 | + * <p>
|
|
| 39 | + * Example:
|
|
| 40 | + * <code>Col1,Col2,Col3|repeatVariableName</code>
|
|
| 41 | + * <p>
|
|
| 42 | + * Created on 15/11/2022.
|
|
| 43 | + *
|
|
| 44 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 45 | + * @since 9.0.17
|
|
| 46 | + */
|
|
| 47 | +@AutoService(ReportOperationConsumer.class)
|
|
| 48 | +public class ComputeDynamicHeader implements ReportOperationConsumer {
|
|
| 49 | + @Override
|
|
| 50 | + public DataMatrix consume(String parameters, ReportRequestExecutor requestExecutor, Report report, Set<String> tripId, DataMatrix incoming) {
|
|
| 51 | + if (parameters.isEmpty()) {
|
|
| 52 | + throw new IllegalStateException(String.format("parameters of operation %s can't not be null (format: col1,col2,...|repeatVariableName)", getClass().getName()));
|
|
| 53 | + }
|
|
| 54 | + String[] split = parameters.split("\\|");
|
|
| 55 | + if (split.length != 2) {
|
|
| 56 | + throw new IllegalStateException(String.format("parameters of operation %s (value %s) has bad format (format: col1,col2,...|repeatVariableName)", getClass().getName(), parameters));
|
|
| 57 | + }
|
|
| 58 | + String[] fixedColumnNames = split[0].split("\\s*,\\s*");
|
|
| 59 | + String repeatVariableName = split[1].trim();
|
|
| 60 | + Set<?> repeatVariableValues = report.getRepeatVariable(repeatVariableName).getValues();
|
|
| 61 | + int columnIndex = 0;
|
|
| 62 | + DataMatrix tmpMatrix = createTmpMatrix(0, 0, incoming.getWidth(), 1);
|
|
| 63 | + boolean useNullRepeatVariableValue = false;
|
|
| 64 | + for (String beginHeader : fixedColumnNames) {
|
|
| 65 | + tmpMatrix.setValue(columnIndex++, 0, beginHeader);
|
|
| 66 | + }
|
|
| 67 | + for (Object repeatVariable : repeatVariableValues) {
|
|
| 68 | + if (repeatVariable == null) {
|
|
| 69 | + useNullRepeatVariableValue = true;
|
|
| 70 | + } else {
|
|
| 71 | + if (repeatVariable instanceof WithI18n) {
|
|
| 72 | + tmpMatrix.setValue(columnIndex++, 0, ((WithI18n) repeatVariable).getLabel2());
|
|
| 73 | + } else {
|
|
| 74 | + tmpMatrix.setValue(columnIndex++, 0, repeatVariable.toString());
|
|
| 75 | + }
|
|
| 76 | + }
|
|
| 77 | + }
|
|
| 78 | + if (useNullRepeatVariableValue) {
|
|
| 79 | + tmpMatrix.setValue(columnIndex, 0, "Aucun");
|
|
| 80 | + }
|
|
| 81 | + incoming.setY(1);
|
|
| 82 | + return DataMatrix.merge(incoming, tmpMatrix);
|
|
| 83 | + }
|
|
| 84 | +} |
| 1 | +package fr.ird.observe.dto.report.operations;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Toolkit :: API
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import com.google.auto.service.AutoService;
|
|
| 26 | +import fr.ird.observe.dto.referential.WithI18n;
|
|
| 27 | +import fr.ird.observe.dto.report.DataMatrix;
|
|
| 28 | +import fr.ird.observe.dto.report.Report;
|
|
| 29 | +import fr.ird.observe.dto.report.ReportOperationConsumer;
|
|
| 30 | +import fr.ird.observe.dto.report.ReportRequestExecutor;
|
|
| 31 | + |
|
| 32 | +import java.util.Set;
|
|
| 33 | + |
|
| 34 | +/**
|
|
| 35 | + * To copy all values of a repeat variable to the first column.
|
|
| 36 | + * <p>
|
|
| 37 | + * If repeat variables values are {@link WithI18n}, then will use the {@link WithI18n#getLabel2()}.
|
|
| 38 | + * <p>
|
|
| 39 | + * TODO: Be able to use the correct locale to translate with correct label.
|
|
| 40 | + * <p>
|
|
| 41 | + * Created on 15/11/2022.
|
|
| 42 | + *
|
|
| 43 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 44 | + * @since 9.0.17
|
|
| 45 | + */
|
|
| 46 | +@AutoService(ReportOperationConsumer.class)
|
|
| 47 | +public class CopyRepeatVariableToFirstColumn implements ReportOperationConsumer {
|
|
| 48 | + @Override
|
|
| 49 | + public DataMatrix consume(String parameters, ReportRequestExecutor requestExecutor, Report report, Set<String> tripId, DataMatrix incoming) {
|
|
| 50 | + if (parameters.isEmpty()) {
|
|
| 51 | + throw new IllegalStateException(String.format("parameters of operation %s can't not be null (format: repeatVariableName)", getClass().getName()));
|
|
| 52 | + }
|
|
| 53 | + String repeatVariableName = parameters.trim();
|
|
| 54 | + Set<?> repeatVariableValues = report.getRepeatVariable(repeatVariableName).getValues();
|
|
| 55 | + DataMatrix tmpMatrix = createTmpMatrix(0, 0, 1 + incoming.getWidth(), repeatVariableValues.size());
|
|
| 56 | + int index = 0;
|
|
| 57 | + for (Object value : repeatVariableValues) {
|
|
| 58 | + if (value instanceof WithI18n) {
|
|
| 59 | + value = ((WithI18n) value).getLabel2();
|
|
| 60 | + }
|
|
| 61 | + tmpMatrix.setValue(0, index++, value);
|
|
| 62 | + }
|
|
| 63 | + incoming.setX(1);
|
|
| 64 | + return DataMatrix.merge(incoming, tmpMatrix);
|
|
| 65 | + }
|
|
| 66 | +} |
| 1 | +package fr.ird.observe.dto.report.operations;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Toolkit :: API
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import com.google.auto.service.AutoService;
|
|
| 26 | +import fr.ird.observe.dto.report.DataMatrix;
|
|
| 27 | +import fr.ird.observe.dto.report.Report;
|
|
| 28 | +import fr.ird.observe.dto.report.ReportOperationConsumer;
|
|
| 29 | +import fr.ird.observe.dto.report.ReportRequest;
|
|
| 30 | +import fr.ird.observe.dto.report.ReportRequestExecutor;
|
|
| 31 | +import fr.ird.observe.dto.report.ReportVariable;
|
|
| 32 | + |
|
| 33 | +import java.util.List;
|
|
| 34 | +import java.util.Map;
|
|
| 35 | +import java.util.Set;
|
|
| 36 | + |
|
| 37 | +/**
|
|
| 38 | + * To execute a query and then reorganize it using repeat variables position (on x axis and y axis).
|
|
| 39 | + * <p>
|
|
| 40 | + * Created on 15/11/2022.
|
|
| 41 | + * <p>
|
|
| 42 | + * Parameters format is
|
|
| 43 | + * <code>repeatVariableForRow|repeatVariableFormColum|request</code>
|
|
| 44 | + *
|
|
| 45 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 46 | + * @since 9.0.17
|
|
| 47 | + */
|
|
| 48 | +@AutoService(ReportOperationConsumer.class)
|
|
| 49 | +public class ExecuteRequestAndReorganizeCountByRepeatVariable implements ReportOperationConsumer {
|
|
| 50 | + |
|
| 51 | + @Override
|
|
| 52 | + public DataMatrix consume(String parameters, ReportRequestExecutor requestExecutor, Report report, Set<String> tripId, DataMatrix incoming) {
|
|
| 53 | + if (parameters.isEmpty()) {
|
|
| 54 | + throw new IllegalStateException(String.format("parameters of operation %s can't not be null (format: repeatVariableForRow|repeatVariableFormColum|request)", getClass().getName()));
|
|
| 55 | + }
|
|
| 56 | + String[] split = parameters.split("\\|");
|
|
| 57 | + if (split.length != 3) {
|
|
| 58 | + throw new IllegalStateException(String.format("parameters of operation %s (value %s) has bad format (format: repeatVariableForRow|repeatVariableFormColum|request)", getClass().getName(), parameters));
|
|
| 59 | + }
|
|
| 60 | + String repeatVariableForColumName = split[1].trim();
|
|
| 61 | + ReportVariable<?> repeatVariableForColumn = report.getRepeatVariable(repeatVariableForColumName);
|
|
| 62 | + if (repeatVariableForColumn.isEmpty()) {
|
|
| 63 | + return incoming;
|
|
| 64 | + }
|
|
| 65 | + String repeatVariableForRowName = split[0].trim();
|
|
| 66 | + ReportVariable<?> repeatVariableForRow = report.getRepeatVariable(repeatVariableForRowName);
|
|
| 67 | + if (repeatVariableForRow.isEmpty()) {
|
|
| 68 | + return incoming;
|
|
| 69 | + }
|
|
| 70 | + String request = split[2].trim();
|
|
| 71 | + |
|
| 72 | + List<String> columnIdList = repeatVariableForColumn.computeIndexList();
|
|
| 73 | + List<String> rowIdList = repeatVariableForRow.computeIndexList();
|
|
| 74 | + |
|
| 75 | + Map<String, Object> queryParameters = computeQueryParameters(report,
|
|
| 76 | + tripId,
|
|
| 77 | + request,
|
|
| 78 | + repeatVariableForRowName,
|
|
| 79 | + rowIdList,
|
|
| 80 | + repeatVariableForColumName,
|
|
| 81 | + columnIdList);
|
|
| 82 | + |
|
| 83 | + DataMatrix result = createTmpMatrix(incoming.getWidth(), 0, columnIdList.size(), rowIdList.size());
|
|
| 84 | + |
|
| 85 | + List<Object[]> rows = requestExecutor.executeRequest(request, queryParameters);
|
|
| 86 | + reorganize(result, rows, rowIdList, columnIdList);
|
|
| 87 | + return DataMatrix.merge(incoming, result);
|
|
| 88 | + }
|
|
| 89 | + |
|
| 90 | + private Map<String, Object> computeQueryParameters(Report report,
|
|
| 91 | + Set<String> tripId,
|
|
| 92 | + String request,
|
|
| 93 | + String repeatVariableForRow,
|
|
| 94 | + List<String> rowIdList,
|
|
| 95 | + String repeatVariableFormColum,
|
|
| 96 | + List<String> columnIdList) {
|
|
| 97 | + Map<String, Object> queryParameters = ReportRequest.extractParams(report, tripId);
|
|
| 98 | + |
|
| 99 | + if (request.contains(":" + repeatVariableForRow + " ")) {
|
|
| 100 | + // add this variable to queryParameters
|
|
| 101 | + queryParameters.put(repeatVariableForRow, rowIdList);
|
|
| 102 | + }
|
|
| 103 | + if (request.contains(":" + repeatVariableFormColum + " ")) {
|
|
| 104 | + // add this variable to queryParameters
|
|
| 105 | + queryParameters.put(repeatVariableFormColum, columnIdList);
|
|
| 106 | + }
|
|
| 107 | + return queryParameters;
|
|
| 108 | + }
|
|
| 109 | + |
|
| 110 | + private void reorganize(DataMatrix result, List<Object[]> rows, List<String> rowIdList, List<String> columnIdList) {
|
|
| 111 | + for (Object[] row : rows) {
|
|
| 112 | + String rowId = String.valueOf(row[0]);
|
|
| 113 | + int rowIndex = rowIdList.indexOf(rowId);
|
|
| 114 | + String columnId = String.valueOf(row[1]);
|
|
| 115 | + int columnIndex = columnIdList.indexOf(columnId);
|
|
| 116 | + Number count = (Number) row[2];
|
|
| 117 | + result.setValue(columnIndex, rowIndex, count);
|
|
| 118 | + }
|
|
| 119 | + }
|
|
| 120 | +} |
| ... | ... | @@ -53,7 +53,7 @@ public class ExecuteRequests implements ReportOperationConsumer { |
| 53 | 53 | DataMatrix result;
|
| 54 | 54 | if (repeatVariable == null) {
|
| 55 | 55 | // requête simple sans repetition
|
| 56 | - result = requestExecutor.executeReportRequest(request, report, tripId, null);
|
|
| 56 | + result = requestExecutor.executeReportRequest(request, report, tripId);
|
|
| 57 | 57 | } else {
|
| 58 | 58 | // on a une requête avec repetition
|
| 59 | 59 | String repeatVariableName = repeatVariable.getVariableName();
|
| ... | ... | @@ -27,6 +27,7 @@ import fr.ird.observe.dto.report.DataMatrix; |
| 27 | 27 | import fr.ird.observe.dto.report.Report;
|
| 28 | 28 | import fr.ird.observe.dto.report.ReportOperationConsumer;
|
| 29 | 29 | import fr.ird.observe.dto.report.ReportRequestExecutor;
|
| 30 | +import io.ultreia.java4all.lang.Numbers;
|
|
| 30 | 31 | import org.apache.logging.log4j.LogManager;
|
| 31 | 32 | import org.apache.logging.log4j.Logger;
|
| 32 | 33 | |
| ... | ... | @@ -45,19 +46,37 @@ public class SumColumn implements ReportOperationConsumer { |
| 45 | 46 | |
| 46 | 47 | @Override
|
| 47 | 48 | public DataMatrix consume(String parameters, ReportRequestExecutor requestExecutor, Report report, Set<String> tripId, DataMatrix incoming) {
|
| 48 | - DataMatrix tmpMatrix = createTmpMatrix(0, incoming.getHeight(), incoming.getWidth(), 1);
|
|
| 49 | - for (int column = 0, nbColumns = incoming.getWidth(); column < nbColumns; column++) {
|
|
| 50 | - Object sumColumn = getSumColumn(column, incoming);
|
|
| 49 | + int x = 0;
|
|
| 50 | + int y = 0;
|
|
| 51 | + int height = incoming.getHeight();
|
|
| 52 | + int width = incoming.getWidth();
|
|
| 53 | + if (!parameters.isEmpty()) {
|
|
| 54 | + String[] split = parameters.split("\\|");
|
|
| 55 | + x = Integer.parseInt(split[0]);
|
|
| 56 | + y = Integer.parseInt(split[1]);
|
|
| 57 | + if (x + 1 >= height) {
|
|
| 58 | + // only one row in column to sum, so skip operation
|
|
| 59 | + return incoming;
|
|
| 60 | + }
|
|
| 61 | + }
|
|
| 62 | + |
|
| 63 | + DataMatrix tmpMatrix = createTmpMatrix(0, height, width, 1);
|
|
| 64 | + for (int column = y; column < width; column++) {
|
|
| 65 | + Object sumColumn = getSumColumn(column, x, incoming);
|
|
| 51 | 66 | tmpMatrix.setValue(column, 0, sumColumn);
|
| 52 | 67 | }
|
| 53 | - return DataMatrix.merge(incoming, tmpMatrix);
|
|
| 68 | + DataMatrix merge = DataMatrix.merge(incoming, tmpMatrix);
|
|
| 69 | + if (report.getColumnHeaders() == null) {
|
|
| 70 | + merge.setValue(0, height, "Total");
|
|
| 71 | + }
|
|
| 72 | + return merge;
|
|
| 54 | 73 | |
| 55 | 74 | }
|
| 56 | 75 | |
| 57 | - protected Object getSumColumn(int column, DataMatrix incoming) {
|
|
| 58 | - double result = 0d;
|
|
| 76 | + protected Object getSumColumn(int column, int x, DataMatrix incoming) {
|
|
| 77 | + float result = 0f;
|
|
| 59 | 78 | int nbRows = incoming.getHeight();
|
| 60 | - for (int row = 0; row < nbRows; row++) {
|
|
| 79 | + for (int row = x; row < nbRows; row++) {
|
|
| 61 | 80 | Serializable o = incoming.getValue(column, row);
|
| 62 | 81 | if (o == null || "null".equals(o)) {
|
| 63 | 82 | o = 0;
|
| ... | ... | @@ -71,6 +90,6 @@ public class SumColumn implements ReportOperationConsumer { |
| 71 | 90 | }
|
| 72 | 91 | result += d;
|
| 73 | 92 | }
|
| 74 | - return result;
|
|
| 93 | + return Numbers.roundFourDigits(result);
|
|
| 75 | 94 | }
|
| 76 | 95 | } |
| ... | ... | @@ -41,7 +41,7 @@ public class SumFloatColumn extends SumColumn implements ReportOperationConsumer |
| 41 | 41 | private static final Logger log = LogManager.getLogger(SumFloatColumn.class);
|
| 42 | 42 | |
| 43 | 43 | @Override
|
| 44 | - protected Object getSumColumn(int column, DataMatrix incoming) {
|
|
| 44 | + protected Object getSumColumn(int column, int x, DataMatrix incoming) {
|
|
| 45 | 45 | double result = 0d;
|
| 46 | 46 | int nbRows = incoming.getHeight();
|
| 47 | 47 | for (int row = 0; row < nbRows; row++) {
|
| ... | ... | @@ -36,8 +36,8 @@ import fr.ird.observe.dto.report.ReportOperationConsumer; |
| 36 | 36 | public class SumIntColumn extends SumColumn implements ReportOperationConsumer {
|
| 37 | 37 | |
| 38 | 38 | @Override
|
| 39 | - protected Object getSumColumn(int column, DataMatrix incoming) {
|
|
| 40 | - Object sumColumn = super.getSumColumn(column, incoming);
|
|
| 39 | + protected Object getSumColumn(int column, int x, DataMatrix incoming) {
|
|
| 40 | + Object sumColumn = super.getSumColumn(column, x, incoming);
|
|
| 41 | 41 | return sumColumn instanceof Number ? ((Number) sumColumn).intValue() : sumColumn;
|
| 42 | 42 | }
|
| 43 | 43 | } |
| ... | ... | @@ -35,8 +35,8 @@ import fr.ird.observe.dto.report.ReportOperationConsumer; |
| 35 | 35 | @AutoService(ReportOperationConsumer.class)
|
| 36 | 36 | public class SumIntRow extends SumRow implements ReportOperationConsumer {
|
| 37 | 37 | @Override
|
| 38 | - protected Object getSumRow(int row, DataMatrix incoming) {
|
|
| 39 | - Object sumColumn = super.getSumRow(row, incoming);
|
|
| 38 | + protected Object getSumRow(int row, int y, DataMatrix incoming) {
|
|
| 39 | + Object sumColumn = super.getSumRow(row, y, incoming);
|
|
| 40 | 40 | return sumColumn instanceof Number ? ((Number) sumColumn).intValue() : sumColumn;
|
| 41 | 41 | }
|
| 42 | 42 | } |
| ... | ... | @@ -27,6 +27,7 @@ import fr.ird.observe.dto.report.DataMatrix; |
| 27 | 27 | import fr.ird.observe.dto.report.Report;
|
| 28 | 28 | import fr.ird.observe.dto.report.ReportOperationConsumer;
|
| 29 | 29 | import fr.ird.observe.dto.report.ReportRequestExecutor;
|
| 30 | +import io.ultreia.java4all.lang.Numbers;
|
|
| 30 | 31 | import org.apache.logging.log4j.LogManager;
|
| 31 | 32 | import org.apache.logging.log4j.Logger;
|
| 32 | 33 | |
| ... | ... | @@ -45,18 +46,37 @@ public class SumRow implements ReportOperationConsumer { |
| 45 | 46 | |
| 46 | 47 | @Override
|
| 47 | 48 | public DataMatrix consume(String parameters, ReportRequestExecutor requestExecutor, Report report, Set<String> tripId, DataMatrix incoming) {
|
| 48 | - DataMatrix tmpMatrix = createTmpMatrix(incoming.getWidth(), 0, 1, incoming.getHeight());
|
|
| 49 | - for (int row = 0, nbRows = incoming.getHeight(); row < nbRows; row++) {
|
|
| 50 | - Object sumRow = getSumRow(row, incoming);
|
|
| 49 | + int x = 0;
|
|
| 50 | + int y = 0;
|
|
| 51 | + int width = incoming.getWidth();
|
|
| 52 | + int height = incoming.getHeight();
|
|
| 53 | + |
|
| 54 | + |
|
| 55 | + if (!parameters.isEmpty()) {
|
|
| 56 | + String[] split = parameters.split("\\|");
|
|
| 57 | + x = Integer.parseInt(split[0]);
|
|
| 58 | + y = Integer.parseInt(split[1]);
|
|
| 59 | + if (y + 1 >= width) {
|
|
| 60 | + // only one column in row to sum, so skip operation
|
|
| 61 | + return incoming;
|
|
| 62 | + }
|
|
| 63 | + }
|
|
| 64 | + DataMatrix tmpMatrix = createTmpMatrix(width, 0, 1, height);
|
|
| 65 | + for (int row = x; row < height; row++) {
|
|
| 66 | + Object sumRow = getSumRow(row, y, incoming);
|
|
| 51 | 67 | tmpMatrix.setValue(0, row, sumRow);
|
| 52 | 68 | }
|
| 53 | - return DataMatrix.merge(incoming, tmpMatrix);
|
|
| 69 | + DataMatrix merge = DataMatrix.merge(incoming, tmpMatrix);
|
|
| 70 | + if (report.getRowHeaders() == null) {
|
|
| 71 | + merge.setValue(width, 0, "Total");
|
|
| 72 | + }
|
|
| 73 | + return merge;
|
|
| 54 | 74 | }
|
| 55 | 75 | |
| 56 | - protected Object getSumRow(int row, DataMatrix incoming) {
|
|
| 57 | - double result = 0d;
|
|
| 76 | + protected Object getSumRow(int row, int y, DataMatrix incoming) {
|
|
| 77 | + float result = 0f;
|
|
| 58 | 78 | int nbColumns = incoming.getWidth();
|
| 59 | - for (int col = 0; col < nbColumns; col++) {
|
|
| 79 | + for (int col = y; col < nbColumns; col++) {
|
|
| 60 | 80 | Serializable o = incoming.getValue(col, row);
|
| 61 | 81 | if (o == null || "null".equals(o)) {
|
| 62 | 82 | o = 0;
|
| ... | ... | @@ -71,6 +91,6 @@ public class SumRow implements ReportOperationConsumer { |
| 71 | 91 | }
|
| 72 | 92 | result += d;
|
| 73 | 93 | }
|
| 74 | - return result;
|
|
| 94 | + return Numbers.roundFourDigits(result);
|
|
| 75 | 95 | }
|
| 76 | 96 | } |
| ... | ... | @@ -36,6 +36,7 @@ import fr.ird.observe.dto.report.ReportRequestExecutor; |
| 36 | 36 | import fr.ird.observe.dto.report.ReportVariable;
|
| 37 | 37 | import fr.ird.observe.dto.report.operations.ExecuteRequests;
|
| 38 | 38 | import fr.ird.observe.spi.PersistenceBusinessProject;
|
| 39 | +import io.ultreia.java4all.util.TimeLog;
|
|
| 39 | 40 | import org.nuiton.topia.persistence.TopiaDao;
|
| 40 | 41 | |
| 41 | 42 | import java.util.Collection;
|
| ... | ... | @@ -57,6 +58,7 @@ import java.util.function.Supplier; |
| 57 | 58 | @SuppressWarnings("SpellCheckingInspection")
|
| 58 | 59 | public abstract class DefaultReportRequestExecutor implements ReportRequestExecutor {
|
| 59 | 60 | |
| 61 | + public static final TimeLog TIME_LOG = new TimeLog(DefaultReportRequestExecutor.class, 500, 1000);
|
|
| 60 | 62 | private final Supplier<? extends TopiaDao<?>> daoSupplier;
|
| 61 | 63 | private final ReferentialLocale referentialLocale;
|
| 62 | 64 | |
| ... | ... | @@ -67,11 +69,15 @@ public abstract class DefaultReportRequestExecutor implements ReportRequestExecu |
| 67 | 69 | |
| 68 | 70 | @Override
|
| 69 | 71 | public Report populateVariables(Report report, Set<String> tripIds) {
|
| 72 | + long t00 = TimeLog.getTime();
|
|
| 70 | 73 | Map<String, Object> vars = new TreeMap<>();
|
| 71 | 74 | vars.put(ReportRequest.TRIP_ID_VARIABLE, tripIds);
|
| 72 | 75 | for (ReportVariable<?> variable : report.getVariables()) {
|
| 76 | + long t0 = TimeLog.getTime();
|
|
| 73 | 77 | populateVariable(variable, vars);
|
| 78 | + TIME_LOG.log(t0, "populate variable", variable.getName());
|
|
| 74 | 79 | }
|
| 80 | + TIME_LOG.log(t00, "populate variables");
|
|
| 75 | 81 | return report;
|
| 76 | 82 | }
|
| 77 | 83 | |
| ... | ... | @@ -103,14 +109,29 @@ public abstract class DefaultReportRequestExecutor implements ReportRequestExecu |
| 103 | 109 | return result;
|
| 104 | 110 | }
|
| 105 | 111 | |
| 112 | + @Override
|
|
| 113 | + public void doPopulateRepeatVariables(Report report, Set<String> tripId) {
|
|
| 114 | + long t0 = TimeLog.getTime();
|
|
| 115 | + ReportRequestExecutor.super.doPopulateRepeatVariables(report, tripId);
|
|
| 116 | + TIME_LOG.log(t0, "populate repeat variables");
|
|
| 117 | + }
|
|
| 118 | + |
|
| 119 | + @Override
|
|
| 120 | + public <R> void doPopulateRepeatVariable(Report report, Set<String> tripId, Map<String, Object> vars, ReportVariable<R> variable) {
|
|
| 121 | + long t0 = TimeLog.getTime();
|
|
| 122 | + ReportRequestExecutor.super.doPopulateRepeatVariable(report, tripId, vars, variable);
|
|
| 123 | + TIME_LOG.log(t0, "populate repeat variable", variable.getName());
|
|
| 124 | + }
|
|
| 125 | + |
|
| 106 | 126 | @Override
|
| 107 | 127 | public <R> List<R> executeRequest(String request, Map<String, Object> params) {
|
| 128 | + long t0 = TimeLog.getTime();
|
|
| 108 | 129 | // si il y a des references de DTO dans les valeurs des paramètres on les remplace par leur id
|
| 109 | 130 | // on copie pour ne pas modifier le paramètre de la méthode
|
| 110 | 131 | Map<String, Object> paramsFixes = new HashMap<>();
|
| 111 | 132 | for (Map.Entry<String, Object> entry : params.entrySet()) {
|
| 112 | 133 | String name = entry.getKey();
|
| 113 | - if (request.contains(":" + name)) {
|
|
| 134 | + if (request.contains(":" + name + " ") || request.endsWith(":" + name)) {
|
|
| 114 | 135 | Object value = entry.getValue();
|
| 115 | 136 | if (value instanceof DtoReference) {
|
| 116 | 137 | DtoReference referenceDto = (DtoReference) value;
|
| ... | ... | @@ -120,7 +141,11 @@ public abstract class DefaultReportRequestExecutor implements ReportRequestExecu |
| 120 | 141 | }
|
| 121 | 142 | }
|
| 122 | 143 | log.debug(String.format("Request: %s, params: %s", request, paramsFixes));
|
| 123 | - return daoSupplier.get().findAll(request, paramsFixes);
|
|
| 144 | + try {
|
|
| 145 | + return daoSupplier.get().findAll(request, paramsFixes);
|
|
| 146 | + } finally {
|
|
| 147 | + TIME_LOG.log(t0, "execute request", request);
|
|
| 148 | + }
|
|
| 124 | 149 | }
|
| 125 | 150 | |
| 126 | 151 | @SuppressWarnings("unchecked")
|