Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe

Commits:

9 changed files:

Changes:

  • core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportEngineExecution.java
    ... ... @@ -178,6 +178,9 @@ public class ImportEngineExecution extends ImportEngine {
    178 178
                 context.addDefaultObservedSystemOrSanitizeFloatingObjectOnes(activity);
    
    179 179
                 // write activity observed systems
    
    180 180
                 activityWriter.writeObservedSystems(activity);
    
    181
    +            // while loading Floating objects, we may have change the vessel activity of the activity
    
    182
    +            // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2612
    
    183
    +            activityWriter.updateVesselActivity(activity);
    
    181 184
     
    
    182 185
                 // get another activity ?
    
    183 186
                 if (tables.activityTableReader.hasNext()) {
    

  • core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportReferentialContext.java
    ... ... @@ -137,6 +137,8 @@ public class ImportReferentialContext {
    137 137
         private ObservedSystem observedSystem103;
    
    138 138
         private ObservedSystem observedSystem110;
    
    139 139
         private VesselActivity vesselActivity6;
    
    140
    +    private VesselActivity vesselActivity101;
    
    141
    +    private VesselActivity vesselActivity102;
    
    140 142
         private SchoolType schoolType0;
    
    141 143
         private SchoolType schoolType1;
    
    142 144
         private SchoolType schoolType2;
    
    ... ... @@ -189,6 +191,8 @@ public class ImportReferentialContext {
    189 191
             // activity
    
    190 192
             vesselActivity = Maps.uniqueIndex(referential.getVesselActivity(), VesselActivity::getCode);
    
    191 193
             vesselActivity6 = vesselActivity.get("6");
    
    194
    +        vesselActivity101 = vesselActivity.get("101");
    
    195
    +        vesselActivity102 = vesselActivity.get("102");
    
    192 196
             schoolType = Maps.uniqueIndex(referential.getSchoolType(), SchoolType::getCode);
    
    193 197
             schoolType0 = schoolType.get("0");
    
    194 198
             schoolType1 = schoolType.get("1");
    
    ... ... @@ -587,4 +591,11 @@ public class ImportReferentialContext {
    587 591
             return vesselActivity6;
    
    588 592
         }
    
    589 593
     
    
    594
    +    public VesselActivity getVesselActivity101() {
    
    595
    +        return vesselActivity101;
    
    596
    +    }
    
    597
    +
    
    598
    +    public VesselActivity getVesselActivity102() {
    
    599
    +        return vesselActivity102;
    
    600
    +    }
    
    590 601
     }

  • core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/ActivityWriter.java
    ... ... @@ -156,6 +156,24 @@ public class ActivityWriter extends DataWriter<Activity, ActivityReader> {
    156 156
             }
    
    157 157
         }
    
    158 158
     
    
    159
    +    /**
    
    160
    +     * To update the activity sql code if vessel activity was changed while floating object import.
    
    161
    +     * <p>
    
    162
    +     * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2612">Issue 2612</a>
    
    163
    +     *
    
    164
    +     * @param entity activity to process
    
    165
    +     */
    
    166
    +    public void updateVesselActivity(Activity entity) {
    
    167
    +        if (FloatingObjectReader.CHANGED_VESSEL_ACTIVITY_CODE_BY_FLOATING_OBJECT.containsValue(entity.getVesselActivity().getCode())) {
    
    168
    +            String id = entity.getId();
    
    169
    +            String vesselActivityId = entity.getVesselActivity().getId();
    
    170
    +            String sql = String.format("UPDATE ps_logbook.activity SET vesselActivity = %1$s WHERE topiaId = %2$s;",
    
    171
    +                                       escapeString(vesselActivityId),
    
    172
    +                                       escapeString(id));
    
    173
    +            writer().writeSql(sql);
    
    174
    +        }
    
    175
    +    }
    
    176
    +
    
    159 177
         @Override
    
    160 178
         public void toResult(Map<String, Integer> resultBuilder) {
    
    161 179
             super.toResult(resultBuilder);
    

  • core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/FloatingObjectReader.java
    ... ... @@ -59,6 +59,15 @@ import java.util.TreeSet;
    59 59
      */
    
    60 60
     @SuppressWarnings("SpellCheckingInspection")
    
    61 61
     public class FloatingObjectReader extends DataReader<FloatingObject> {
    
    62
    +    /**
    
    63
    +     * To map ObServe vessel activity when in Avdth we found a Floating object to persist.
    
    64
    +     * <p>
    
    65
    +     * Keys are current ObServe vessel activity code used, values are the real vessel activity code to use (which allow fad)
    
    66
    +     * <p>
    
    67
    +     * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2612">Issue 2612</a>
    
    68
    +     */
    
    69
    +    public static final Map<String, String> CHANGED_VESSEL_ACTIVITY_CODE_BY_FLOATING_OBJECT = Map.of("1", "101",
    
    70
    +                                                                                                     "2", "102");
    
    62 71
         private static final Logger log = LogManager.getLogger(FloatingObjectReader.class);
    
    63 72
         /**
    
    64 73
          * To get FloatingObject.objectOperation code from avdth ACTIVITE.C_OPERA.
    
    ... ... @@ -275,21 +284,42 @@ public class FloatingObjectReader extends DataReader<FloatingObject> {
    275 284
             }
    
    276 285
     
    
    277 286
             if (!vesselActivityAllowFad) {
    
    278
    -            // If ObServe veseel activity does not support Floating object, reject import
    
    279
    -            List<Object> activityPrimaryKey = ActivityReader.getActivityPk(resultSet);
    
    280
    -            String activityPk = Query.primaryKeyString(activityPrimaryKey);
    
    281
    -            String message = String.format("On activity %s (ACTIVITE.C_OPERA %s), can not add Floating object since ObServe Vessel activity with code : %s does not allow FAD (floatingObjectExistsInAvdth? %b, floatingObjectCreatedByObservedSystem? %b).",
    
    282
    -                                           activityPk,
    
    283
    -                                           vesselActivityCode,
    
    284
    -                                           vesselActivity.getCode(),
    
    285
    -                                           floatingObjectExistsInAvdth,
    
    286
    -                                           floatingObjectCreatedByObservedSystem);
    
    287
    -            log.warn(message);
    
    288
    -            badVesselActivityCodes.computeIfAbsent(vesselActivityCode, MutableInt::new).increment();
    
    287
    +
    
    288
    +            String observeVesselActivityCode = activity.getVesselActivity().getCode();
    
    289
    +            String realObserveVesselActivityCode = CHANGED_VESSEL_ACTIVITY_CODE_BY_FLOATING_OBJECT.get(observeVesselActivityCode);
    
    290
    +            if (realObserveVesselActivityCode == null) {
    
    291
    +
    
    292
    +                // If ObServe veseel activity does not support Floating object, reject import
    
    293
    +                List<Object> activityPrimaryKey = ActivityReader.getActivityPk(resultSet);
    
    294
    +                String activityPk = Query.primaryKeyString(activityPrimaryKey);
    
    295
    +                String message = String.format("For AVDTH activity %s (ACTIVITE.C_OPERA %s), the ObServe vessel activity (code: %s, label: %s) does not allow FAD, we still import it... (floatingObjectExistsInAvdth? %b, floatingObjectCreatedByObservedSystem? %b).",
    
    296
    +                                               activityPk,
    
    297
    +                                               vesselActivityCode,
    
    298
    +                                               vesselActivity.getCode(),
    
    299
    +                                               vesselActivity.getLabel1(),
    
    300
    +                                               floatingObjectExistsInAvdth,
    
    301
    +                                               floatingObjectCreatedByObservedSystem);
    
    302
    +                log.warn(message);
    
    303
    +                badVesselActivityCodes.computeIfAbsent(vesselActivityCode, MutableInt::new).increment();
    
    289 304
     
    
    290 305
     //            // do not create the floating object
    
    291 306
     //            reset(dataContext);
    
    292 307
     //            return null;
    
    308
    +
    
    309
    +            } else {
    
    310
    +                // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2612
    
    311
    +                switch (realObserveVesselActivityCode) {
    
    312
    +                    case "101":
    
    313
    +                        // Use vessel activity 101
    
    314
    +                        activity.setVesselActivity(dataContext.getVesselActivity101());
    
    315
    +                        break;
    
    316
    +                    case "102":
    
    317
    +                        // Use vessel activity 102
    
    318
    +                        activity.setVesselActivity(dataContext.getVesselActivity102());
    
    319
    +                        break;
    
    320
    +                }
    
    321
    +            }
    
    322
    +
    
    293 323
             }
    
    294 324
     
    
    295 325
             FloatingObject entity = newEntity(FloatingObject.SPI);
    
    ... ... @@ -474,7 +504,7 @@ public class FloatingObjectReader extends DataReader<FloatingObject> {
    474 504
             return dataContext.getObjectOperation(Objects.requireNonNull(objectOperationCode, String.format("Can't find objectOperation with ACTIVITE.C_OPERA: %s", vesselActivityCode)));
    
    475 505
         }
    
    476 506
     
    
    477
    -    private ObservedSystem getObservedSystem(ImportDataContext dataContext, String objectTypeCode, boolean floatingObjectExistsInAvdth,boolean buoyExistsInAvdth) {
    
    507
    +    private ObservedSystem getObservedSystem(ImportDataContext dataContext, String objectTypeCode, boolean floatingObjectExistsInAvdth, boolean buoyExistsInAvdth) {
    
    478 508
             if (!floatingObjectExistsInAvdth) {
    
    479 509
                 if (!buoyExistsInAvdth) {
    
    480 510
                     return dataContext.getObservedSystem0();
    

  • core/persistence/migration/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_1.java
    ... ... @@ -275,16 +275,16 @@ public class DataSourceMigrationForVersion_9_1 extends ByMajorMigrationVersionRe
    275 275
             executor.addScript("04", "drop_ll_common_weightDeterminationMethod");
    
    276 276
     
    
    277 277
             if (withIds) {
    
    278
    -            addVesselActivity36(executor);
    
    278
    +            addVesselActivities(executor);
    
    279 279
             }
    
    280 280
             // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2435
    
    281 281
             addNewTable(executor, withIds, "06", "table-common_sizemeasuremethod");
    
    282 282
         }
    
    283 283
     
    
    284
    -    private void addVesselActivity36(MigrationVersionResourceExecutor executor) {
    
    284
    +    private void addVesselActivities(MigrationVersionResourceExecutor executor) {
    
    285 285
             Set<String> existingCodes = executor.findMultipleResultAstSet(SqlQuery.wrap("SELECT CODE FROM ps_common.VesselActivity", resultSet -> resultSet.getString(1)));
    
    286 286
             Set<String> newCodes = new LinkedHashSet<>();
    
    287
    -        Stream.of("36").forEach(code -> {
    
    287
    +        Stream.of("36", "101", "102").forEach(code -> {
    
    288 288
                 if (!existingCodes.contains(code)) {
    
    289 289
                     executor.addScript("05", "add_referential_ps_common_VesselActivity_" + code);
    
    290 290
                     newCodes.add(code);
    

  • core/persistence/migration/src/main/resources/db/migration/v9/9.1/05_add_referential_ps_common_VesselActivity_101-common.sql
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- ObServe Core :: Persistence :: Migration
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2008 - 2023 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_common.vesselActivity(topiaid, topiaversion, topiacreatedate, lastupdatedate, code, uri, homeid, needcomment, status, label1, label2, label3, label4, label5, label6, label7, label8, allowFad) VALUES ('fr.ird.referential.ps.common.VesselActivity#${REFERENTIAL_PREFIX}101', 0, ${CURRENT_DATE}, ${CURRENT_TIMESTAMP}, '101', null, null, FALSE, 0, '[déprécié] Transit (route sans recherche)', '[deprecated] Transit (steaming without searching)', '[deprecated] Transit (steaming without searching) TODO', null, null, null, null, null, TRUE);

  • core/persistence/migration/src/main/resources/db/migration/v9/9.1/05_add_referential_ps_common_VesselActivity_102-common.sql
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- ObServe Core :: Persistence :: Migration
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2008 - 2023 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_common.vesselActivity(topiaid, topiaversion, topiacreatedate, lastupdatedate, code, uri, homeid, needcomment, status, label1, label2, label3, label4, label5, label6, label7, label8, allowFad) VALUES ('fr.ird.referential.ps.common.VesselActivity#${REFERENTIAL_PREFIX}102', 0, ${CURRENT_DATE}, ${CURRENT_TIMESTAMP}, '102', null, null, FALSE, 0, '[deprecated] Searching (in general)', '[déprécié] Recherche (général)', '[deprecated] Searching (in general) TODO', null, null, null, null, null, TRUE);

  • core/persistence/test/src/test/resources/fixtures/persistence/table_count/referential.properties
    ... ... @@ -89,7 +89,7 @@ ps_common.speciesFate=15
    89 89
     ps_common.transmittingBuoyOperation=5
    
    90 90
     ps_common.transmittingBuoyOwnership=5
    
    91 91
     ps_common.transmittingBuoyType=62
    
    92
    -ps_common.vesselActivity=37
    
    92
    +ps_common.vesselActivity=39
    
    93 93
     ps_common.weightCategory=137
    
    94 94
     ps_landing.destination=28
    
    95 95
     ps_landing.fate=2
    

  • model/src/main/resources/fixtures/global.properties
    ... ... @@ -25,4 +25,4 @@ REFERENCE_DATA_COUNT=68
    25 25
     ENTITIES_LIMIT_SIZE=100
    
    26 26
     # fr.ird.observe.services.service.referential.ReferentialService
    
    27 27
     # fr.ird.observe.services.local.service.referential.DifferentialModelTest
    
    28
    -REFERENTIAL_COUNT=4094
    28
    +REFERENTIAL_COUNT=4096