Tony CHEMIT pushed to branch feature/issue_2959 at ultreiaio / ird-observe Commits: daaf003d by Tony Chemit at 2024-12-11T11:23:11+01:00 Review import code for Landing.fate field - - - - - 0c74c297 by Tony Chemit at 2024-12-11T11:23:11+01:00 Update AVDTH documentation - - - - - 0c44ebc6 by Tony Chemit at 2024-12-11T11:23:11+01:00 Add by migration ps_landing.Fate 3 and 4 if necessary - - - - - 7 changed files: - core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportReferentialContext.java - core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/common/LandingReader.java - core/persistence/migration/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_4.java - + core/persistence/migration/src/main/resources/db/migration/v9/9.4/06_issue-2959_add_referential_ps_landing_Fate_3-common.sql - + core/persistence/migration/src/main/resources/db/migration/v9/9.4/06_issue-2959_add_referential_ps_landing_Fate_4-common.sql - + core/persistence/migration/src/main/resources/db/migration/v9/9.4/06_issue-2959_add_referential_ps_landing_Fate_finalize-common.sql - src/site/markdown/avdth/landing.md Changes: ===================================== core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportReferentialContext.java ===================================== @@ -69,7 +69,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.function.Consumer; /** * Contains all referential used in import and all the logic of them. @@ -113,8 +112,10 @@ public class ImportReferentialContext { private SizeMeasureType sizeMeasureTypeDL; private DataQuality dataQualityA; private DataQuality dataQualityE; - private Fate fate1; - private Fate fate2; + private Fate fateProcessed; + private Fate fateDiscarded; + private Fate fateSoldOnLocalMarket; + private Fate fateTransshipment; private AcquisitionStatus acquisitionStatus1; private AcquisitionStatus acquisitionStatus999; private TransmittingBuoyType transmittingBuoyType98; @@ -185,8 +186,10 @@ public class ImportReferentialContext { landingCategories = Maps.uniqueIndex(referential.getWeightCategory(), WeightCategory::getCode); Map<String, Fate> fates = Maps.uniqueIndex(referential.getFate(), Fate::getCode); - fate1 = fates.get("1"); - fate2 = fates.get("2"); + fateProcessed = fates.get("1"); + fateDiscarded = fates.get("2"); + fateSoldOnLocalMarket = fates.get("3"); + fateTransshipment = fates.get("4"); destinations = Maps.uniqueIndex(referential.getDestination(), Destination::getCode); @@ -388,8 +391,12 @@ public class ImportReferentialContext { return schoolType2; } + public boolean isSpeciesDiscarded(String speciesCode) { + return speciesCode.equals("8") || (speciesCode.startsWith("8") && speciesCode.length() == 3); + } + public SpeciesFate getSpeciesFate(String speciesCode) { - if (speciesCode.equals("8") || (speciesCode.startsWith("8") && speciesCode.length() == 3)) { + if (isSpeciesDiscarded(speciesCode)) { // all species in avdth with code 8 or 8xx are discard return speciesFate11; } @@ -453,12 +460,20 @@ public class ImportReferentialContext { return transmittingBuoyOperation1; } - public Fate getFateBySpeciesCode(String originalSpeciesCode) { - // fate 1 if not discarded, 2 discarded (only for species 8) - if (originalSpeciesCode.equals("8")) { - return fate2; - } - return fate1; + public Fate getFateProcessed() { + return fateProcessed; + } + + public Fate getFateDiscarded() { + return fateDiscarded; + } + + public Fate getFateSoldOnLocalMarket() { + return fateSoldOnLocalMarket; + } + + public Fate getFateTransshipment() { + return fateTransshipment; } public Harbour getHarbour(String code) { ===================================== core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/common/LandingReader.java ===================================== @@ -27,6 +27,7 @@ import fr.ird.observe.entities.data.ps.landing.Landing; import fr.ird.observe.entities.referential.common.Species; import fr.ird.observe.entities.referential.ps.common.WeightCategory; import fr.ird.observe.entities.referential.ps.landing.Destination; +import fr.ird.observe.entities.referential.ps.landing.Fate; import fr.ird.observe.persistence.avdth.data.DataQueryDefinition; import fr.ird.observe.persistence.avdth.data.DataReader; import fr.ird.observe.persistence.avdth.data.ImportDataContext; @@ -106,8 +107,34 @@ public class LandingReader extends DataReader<Landing> { String destinationCode = resultSet.getString(7); Destination destination = dataContext.getDestination(destinationCode); entity.setDestination(destination); - entity.setFate(dataContext.getFateBySpeciesCode(originalSpeciesCode)); + Fate fate = getFate(dataContext, originalSpeciesCode, destinationCode); + entity.setFate(fate); return entity; } + + private Fate getFate(ImportDataContext dataContext, String originalSpeciesCode, String avdthDestinationCode) { + if (avdthDestinationCode != null) { + int code = Integer.parseInt(avdthDestinationCode); + if (isDestinationCodeToTransshipment(code)) { + return dataContext.getFateTransshipment(); + } + if (isDestinationCodeToSoldOnLocalMarket(code)) { + return dataContext.getFateSoldOnLocalMarket(); + } + } + if (dataContext.isSpeciesDiscarded(originalSpeciesCode)) { + return dataContext.getFateDiscarded(); + } + return dataContext.getFateProcessed(); + } + + private boolean isDestinationCodeToTransshipment(int code) { + return code == 3 || code == 4; + } + + private boolean isDestinationCodeToSoldOnLocalMarket(int code) { + return code == 18 || code == 28 || (code >= 40 && code <= 61) || (code >= 64 && code <= 65); + } + } ===================================== core/persistence/migration/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_4.java ===================================== @@ -34,6 +34,9 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.stream.Stream; /** * Created at 11/09/2024. @@ -66,6 +69,8 @@ public class DataSourceMigrationForVersion_9_4 extends ByMajorMigrationVersionRe issue2669(executor); // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2932 issue2932(executor,withIds); + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2959 + issue2959(executor,withIds); } private void issue2914(MigrationVersionResourceExecutor executor) { @@ -104,6 +109,23 @@ public class DataSourceMigrationForVersion_9_4 extends ByMajorMigrationVersionRe executor.addScript("05_06", "issue-2932_update-table-ll-observation-weight-measure"); } + + private void issue2959(MigrationVersionResourceExecutor executor, boolean withIds) { + if (withIds) { + Set<String> existingCodes = executor.findMultipleResultAstSet(SqlQuery.wrap("SELECT CODE FROM ps_landing.Fate", resultSet -> resultSet.getString(1))); + Set<String> newCodes = new LinkedHashSet<>(); + Stream.of("3", "4").forEach(code -> { + if (!existingCodes.contains(code)) { + executor.addScript("06_issue-2959_add_referential_ps_landing_Fate", code); + newCodes.add(code); + } + }); + if (!newCodes.isEmpty()) { + executor.addScript("06_issue-2959_add_referential_ps_landing_Fate", "finalize"); + } + } + } + private static class BasketRecord { private final String id; private final Float floatline1Length; ===================================== core/persistence/migration/src/main/resources/db/migration/v9/9.4/06_issue-2959_add_referential_ps_landing_Fate_3-common.sql ===================================== @@ -0,0 +1,22 @@ +--- +-- #%L +-- ObServe Core :: Persistence :: Migration +-- %% +-- Copyright (C) 2008 - 2024 IRD, Ultreia.io +-- %% +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public +-- License along with this program. If not, see +-- <http://www.gnu.org/licenses/gpl-3.0.html>. +-- #L% +--- +INSERT INTO ps_landing.Fate(topiaid, topiaversion, topiacreatedate, lastUpdateDate, needComment, status, code, label1, label2, label3, discard) VALUES ('fr.ird.referential.ps.landing.Fate#1714114980513#0.3095970028802679', 0, '2024-04-26T09:00:41.215Z'::timestamp, '2024-04-26T09:03:00.513Z'::timestamp, FALSE, 1, '3' , 'Sold for local market', 'Vendu sur le marché local', 'Vendido en el mercado local', false); ===================================== core/persistence/migration/src/main/resources/db/migration/v9/9.4/06_issue-2959_add_referential_ps_landing_Fate_4-common.sql ===================================== @@ -0,0 +1,22 @@ +--- +-- #%L +-- ObServe Core :: Persistence :: Migration +-- %% +-- Copyright (C) 2008 - 2024 IRD, Ultreia.io +-- %% +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public +-- License along with this program. If not, see +-- <http://www.gnu.org/licenses/gpl-3.0.html>. +-- #L% +--- +INSERT INTO ps_landing.Fate(topiaid, topiaversion, topiacreatedate, lastUpdateDate, needComment, status, code, label1, label2, label3, discard) VALUES ('fr.ird.referential.ps.landing.Fate#1714115075625#0.4347800278392995', 0, '2024-04-26T09:03:12.339Z'::timestamp, '2024-04-26T09:04:35.625Z'::timestamp, FALSE, 1, '4' , 'Transshipment (container or cargo)', 'Transbordé (conteneur ou cargo)', 'Transbordo (contenedor o carga)', false); ===================================== core/persistence/migration/src/main/resources/db/migration/v9/9.4/06_issue-2959_add_referential_ps_landing_Fate_finalize-common.sql ===================================== @@ -0,0 +1,22 @@ +--- +-- #%L +-- ObServe Core :: Persistence :: Migration +-- %% +-- Copyright (C) 2008 - 2024 IRD, Ultreia.io +-- %% +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public +-- License along with this program. If not, see +-- <http://www.gnu.org/licenses/gpl-3.0.html>. +-- #L% +--- +UPDATE common.LastUpdateDate SET lastUpdateDate = ${CURRENT_TIMESTAMP} WHERE type ='fr.ird.observe.entities.referential.ps.landing.Fate'; ===================================== src/site/markdown/avdth/landing.md ===================================== @@ -14,7 +14,7 @@ Table déversée dans la table d'ObServe **Landing**. | LOT_COM_04 | C_ESP | Landing.species | [2](#n_0_2), [5](#n_0_5) | | LOT_COM_05 | C_CAT_C | Landing.weightCategory | [3](#n_0_3) | | LOT_COM_06 | V_POIDS_LC | Landing.weight | | -| LOT_COM_07 | C_DEST | Landing.destination | [4](#n_0_4) | +| LOT_COM_07 | C_DEST | Landing.destination | [4](#n_0_4), [5](#n_0_5) | * Note 1 <a name="n_0_1"></a> @@ -34,8 +34,15 @@ Mapping direct sur le code du référentiel **ps_landing.Destination**. * Note 5 <a name="n_0_5"></a> -On positionne **ps_landing.Landing.fate** à partir du code suivant +On positionne **ps_landing.Landing.fate** en suivant ce code -```ps_landing.Fate(LOT_COM.C_ESP == 8 ? 2 : 1)``` +**FIXME Voir https://gitlab.com/ultreiaio/ird-observe/-/issues/2959 ** + +On distingue quatre cas : + +1. Si LOT_COM.C_DEST dans ```4 ou 5``` alors on utilise ps_landing.Fate de code 4 (transbordement) +2. Si LOT_COM.C_DEST dans ```18, 28, 40 à 61, 64 à 65)``` alors on utilise ps_landing.Fate de code 3 (vendu au marché local) +2. Sinon si LOT_COM.C_ESP est dans ```8, 800 à 899``` alors on utilise ps_landing.Fate de code 2 (rejeté) +3. Sinon on utilise ps_landing.Fate de code 1 (traité) [Retour à l'introduction](./index.html) View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/9bc1160aed3074cbdf48383c0... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/9bc1160aed3074cbdf48383c0... You're receiving this email because of your account on gitlab.com.