Tony CHEMIT pushed to branch feature/issue_2959 at ultreiaio / ird-observe

Commits:

7 changed files:

Changes:

  • core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportReferentialContext.java
    ... ... @@ -69,7 +69,6 @@ import java.util.List;
    69 69
     import java.util.Map;
    
    70 70
     import java.util.Objects;
    
    71 71
     import java.util.TreeMap;
    
    72
    -import java.util.function.Consumer;
    
    73 72
     
    
    74 73
     /**
    
    75 74
      * Contains all referential used in import and all the logic of them.
    
    ... ... @@ -113,8 +112,10 @@ public class ImportReferentialContext {
    113 112
         private SizeMeasureType sizeMeasureTypeDL;
    
    114 113
         private DataQuality dataQualityA;
    
    115 114
         private DataQuality dataQualityE;
    
    116
    -    private Fate fate1;
    
    117
    -    private Fate fate2;
    
    115
    +    private Fate fateProcessed;
    
    116
    +    private Fate fateDiscarded;
    
    117
    +    private Fate fateSoldOnLocalMarket;
    
    118
    +    private Fate fateTransshipment;
    
    118 119
         private AcquisitionStatus acquisitionStatus1;
    
    119 120
         private AcquisitionStatus acquisitionStatus999;
    
    120 121
         private TransmittingBuoyType transmittingBuoyType98;
    
    ... ... @@ -185,8 +186,10 @@ public class ImportReferentialContext {
    185 186
             landingCategories = Maps.uniqueIndex(referential.getWeightCategory(), WeightCategory::getCode);
    
    186 187
     
    
    187 188
             Map<String, Fate> fates = Maps.uniqueIndex(referential.getFate(), Fate::getCode);
    
    188
    -        fate1 = fates.get("1");
    
    189
    -        fate2 = fates.get("2");
    
    189
    +        fateProcessed = fates.get("1");
    
    190
    +        fateDiscarded = fates.get("2");
    
    191
    +        fateSoldOnLocalMarket = fates.get("3");
    
    192
    +        fateTransshipment = fates.get("4");
    
    190 193
     
    
    191 194
             destinations = Maps.uniqueIndex(referential.getDestination(), Destination::getCode);
    
    192 195
     
    
    ... ... @@ -388,8 +391,12 @@ public class ImportReferentialContext {
    388 391
             return schoolType2;
    
    389 392
         }
    
    390 393
     
    
    394
    +    public boolean isSpeciesDiscarded(String speciesCode) {
    
    395
    +        return speciesCode.equals("8") || (speciesCode.startsWith("8") && speciesCode.length() == 3);
    
    396
    +    }
    
    397
    +
    
    391 398
         public SpeciesFate getSpeciesFate(String speciesCode) {
    
    392
    -        if (speciesCode.equals("8") || (speciesCode.startsWith("8") && speciesCode.length() == 3)) {
    
    399
    +        if (isSpeciesDiscarded(speciesCode)) {
    
    393 400
                 // all species in avdth with code 8 or 8xx are discard
    
    394 401
                 return speciesFate11;
    
    395 402
             }
    
    ... ... @@ -453,12 +460,20 @@ public class ImportReferentialContext {
    453 460
             return transmittingBuoyOperation1;
    
    454 461
         }
    
    455 462
     
    
    456
    -    public Fate getFateBySpeciesCode(String originalSpeciesCode) {
    
    457
    -        // fate 1 if not discarded, 2 discarded (only for species 8)
    
    458
    -        if (originalSpeciesCode.equals("8")) {
    
    459
    -            return fate2;
    
    460
    -        }
    
    461
    -        return fate1;
    
    463
    +    public Fate getFateProcessed() {
    
    464
    +        return fateProcessed;
    
    465
    +    }
    
    466
    +
    
    467
    +    public Fate getFateDiscarded() {
    
    468
    +        return fateDiscarded;
    
    469
    +    }
    
    470
    +
    
    471
    +    public Fate getFateSoldOnLocalMarket() {
    
    472
    +        return fateSoldOnLocalMarket;
    
    473
    +    }
    
    474
    +
    
    475
    +    public Fate getFateTransshipment() {
    
    476
    +        return fateTransshipment;
    
    462 477
         }
    
    463 478
     
    
    464 479
         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;
    27 27
     import fr.ird.observe.entities.referential.common.Species;
    
    28 28
     import fr.ird.observe.entities.referential.ps.common.WeightCategory;
    
    29 29
     import fr.ird.observe.entities.referential.ps.landing.Destination;
    
    30
    +import fr.ird.observe.entities.referential.ps.landing.Fate;
    
    30 31
     import fr.ird.observe.persistence.avdth.data.DataQueryDefinition;
    
    31 32
     import fr.ird.observe.persistence.avdth.data.DataReader;
    
    32 33
     import fr.ird.observe.persistence.avdth.data.ImportDataContext;
    
    ... ... @@ -106,8 +107,34 @@ public class LandingReader extends DataReader<Landing> {
    106 107
             String destinationCode = resultSet.getString(7);
    
    107 108
             Destination destination = dataContext.getDestination(destinationCode);
    
    108 109
             entity.setDestination(destination);
    
    109
    -        entity.setFate(dataContext.getFateBySpeciesCode(originalSpeciesCode));
    
    110
    +        Fate fate = getFate(dataContext, originalSpeciesCode, destinationCode);
    
    111
    +        entity.setFate(fate);
    
    110 112
             return entity;
    
    111 113
         }
    
    114
    +
    
    115
    +    private Fate getFate(ImportDataContext dataContext, String originalSpeciesCode, String avdthDestinationCode) {
    
    116
    +        if (avdthDestinationCode != null) {
    
    117
    +            int code = Integer.parseInt(avdthDestinationCode);
    
    118
    +            if (isDestinationCodeToTransshipment(code)) {
    
    119
    +                return dataContext.getFateTransshipment();
    
    120
    +            }
    
    121
    +            if (isDestinationCodeToSoldOnLocalMarket(code)) {
    
    122
    +                return dataContext.getFateSoldOnLocalMarket();
    
    123
    +            }
    
    124
    +        }
    
    125
    +        if (dataContext.isSpeciesDiscarded(originalSpeciesCode)) {
    
    126
    +            return dataContext.getFateDiscarded();
    
    127
    +        }
    
    128
    +        return dataContext.getFateProcessed();
    
    129
    +    }
    
    130
    +
    
    131
    +    private boolean isDestinationCodeToTransshipment(int code) {
    
    132
    +        return code == 3 || code == 4;
    
    133
    +    }
    
    134
    +
    
    135
    +    private boolean isDestinationCodeToSoldOnLocalMarket(int code) {
    
    136
    +        return code == 18 || code == 28 || (code >= 40 && code <= 61) || (code >= 64 && code <= 65);
    
    137
    +    }
    
    138
    +
    
    112 139
     }
    
    113 140
     

  • core/persistence/migration/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_4.java
    ... ... @@ -34,6 +34,9 @@ import java.math.BigDecimal;
    34 34
     import java.math.RoundingMode;
    
    35 35
     import java.sql.ResultSet;
    
    36 36
     import java.sql.SQLException;
    
    37
    +import java.util.LinkedHashSet;
    
    38
    +import java.util.Set;
    
    39
    +import java.util.stream.Stream;
    
    37 40
     
    
    38 41
     /**
    
    39 42
      * Created at 11/09/2024.
    
    ... ... @@ -66,6 +69,8 @@ public class DataSourceMigrationForVersion_9_4 extends ByMajorMigrationVersionRe
    66 69
             issue2669(executor);
    
    67 70
             // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2932
    
    68 71
             issue2932(executor,withIds);
    
    72
    +        // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2959
    
    73
    +        issue2959(executor,withIds);
    
    69 74
         }
    
    70 75
     
    
    71 76
         private void issue2914(MigrationVersionResourceExecutor executor) {
    
    ... ... @@ -104,6 +109,23 @@ public class DataSourceMigrationForVersion_9_4 extends ByMajorMigrationVersionRe
    104 109
             executor.addScript("05_06", "issue-2932_update-table-ll-observation-weight-measure");
    
    105 110
         }
    
    106 111
     
    
    112
    +
    
    113
    +    private void issue2959(MigrationVersionResourceExecutor executor, boolean withIds) {
    
    114
    +        if (withIds) {
    
    115
    +            Set<String> existingCodes = executor.findMultipleResultAstSet(SqlQuery.wrap("SELECT CODE FROM ps_landing.Fate", resultSet -> resultSet.getString(1)));
    
    116
    +            Set<String> newCodes = new LinkedHashSet<>();
    
    117
    +            Stream.of("3", "4").forEach(code -> {
    
    118
    +                if (!existingCodes.contains(code)) {
    
    119
    +                    executor.addScript("06_issue-2959_add_referential_ps_landing_Fate",  code);
    
    120
    +                    newCodes.add(code);
    
    121
    +                }
    
    122
    +            });
    
    123
    +            if (!newCodes.isEmpty()) {
    
    124
    +                executor.addScript("06_issue-2959_add_referential_ps_landing_Fate", "finalize");
    
    125
    +            }
    
    126
    +        }
    
    127
    +    }
    
    128
    +
    
    107 129
         private static class BasketRecord {
    
    108 130
             private final String id;
    
    109 131
             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
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- ObServe Core :: Persistence :: Migration
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2008 - 2024 IRD, Ultreia.io
    
    6
    +-- %%
    
    7
    +-- This program is free software: you can redistribute it and/or modify
    
    8
    +-- it under the terms of the GNU General Public License as
    
    9
    +-- published by the Free Software Foundation, either version 3 of the
    
    10
    +-- License, or (at your option) any later version.
    
    11
    +--
    
    12
    +-- This program is distributed in the hope that it will be useful,
    
    13
    +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    +-- GNU General Public License for more details.
    
    16
    +--
    
    17
    +-- You should have received a copy of the GNU General Public
    
    18
    +-- License along with this program.  If not, see
    
    19
    +-- <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    20
    +-- #L%
    
    21
    +---
    
    22
    +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
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- ObServe Core :: Persistence :: Migration
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2008 - 2024 IRD, Ultreia.io
    
    6
    +-- %%
    
    7
    +-- This program is free software: you can redistribute it and/or modify
    
    8
    +-- it under the terms of the GNU General Public License as
    
    9
    +-- published by the Free Software Foundation, either version 3 of the
    
    10
    +-- License, or (at your option) any later version.
    
    11
    +--
    
    12
    +-- This program is distributed in the hope that it will be useful,
    
    13
    +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    +-- GNU General Public License for more details.
    
    16
    +--
    
    17
    +-- You should have received a copy of the GNU General Public
    
    18
    +-- License along with this program.  If not, see
    
    19
    +-- <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    20
    +-- #L%
    
    21
    +---
    
    22
    +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
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- ObServe Core :: Persistence :: Migration
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2008 - 2024 IRD, Ultreia.io
    
    6
    +-- %%
    
    7
    +-- This program is free software: you can redistribute it and/or modify
    
    8
    +-- it under the terms of the GNU General Public License as
    
    9
    +-- published by the Free Software Foundation, either version 3 of the
    
    10
    +-- License, or (at your option) any later version.
    
    11
    +--
    
    12
    +-- This program is distributed in the hope that it will be useful,
    
    13
    +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    +-- GNU General Public License for more details.
    
    16
    +--
    
    17
    +-- You should have received a copy of the GNU General Public
    
    18
    +-- License along with this program.  If not, see
    
    19
    +-- <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    20
    +-- #L%
    
    21
    +---
    
    22
    +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**.
    14 14
     | LOT_COM_04 | C_ESP      | Landing.species        | [2](#n_0_2), [5](#n_0_5) | 
    
    15 15
     | LOT_COM_05 | C_CAT_C    | Landing.weightCategory | [3](#n_0_3)              | 
    
    16 16
     | LOT_COM_06 | V_POIDS_LC | Landing.weight         |                          |
    
    17
    -| LOT_COM_07 | C_DEST     | Landing.destination    | [4](#n_0_4)              |
    
    17
    +| LOT_COM_07 | C_DEST     | Landing.destination    | [4](#n_0_4), [5](#n_0_5) |
    
    18 18
     
    
    19 19
     * Note 1 <a name="n_0_1"></a>
    
    20 20
     
    
    ... ... @@ -34,8 +34,15 @@ Mapping direct sur le code du référentiel **ps_landing.Destination**.
    34 34
     
    
    35 35
     * Note 5 <a name="n_0_5"></a>
    
    36 36
     
    
    37
    -On positionne **ps_landing.Landing.fate** à partir du code suivant
    
    37
    +On positionne **ps_landing.Landing.fate** en suivant ce code 
    
    38 38
     
    
    39
    -```ps_landing.Fate(LOT_COM.C_ESP == 8 ? 2 : 1)```
    
    39
    +**FIXME Voir https://gitlab.com/ultreiaio/ird-observe/-/issues/2959 **
    
    40
    +
    
    41
    +On distingue quatre cas :
    
    42
    +
    
    43
    +1. Si LOT_COM.C_DEST dans ```4 ou 5``` alors on utilise ps_landing.Fate de code 4 (transbordement)
    
    44
    +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)
    
    45
    +2. Sinon si LOT_COM.C_ESP est dans ```8, 800 à 899``` alors on utilise ps_landing.Fate de code 2 (rejeté)
    
    46
    +3. Sinon on utilise ps_landing.Fate de code 1 (traité)
    
    40 47
     
    
    41 48
     [Retour à l'introduction](./index.html)