Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 05efd969 by Tony Chemit at 2023-01-24T13:14:47+01:00 Migration - Add VesselActivity 101 and 102 - - - - - 6b441c82 by Tony Chemit at 2023-01-24T13:14:47+01:00 Avdth - use new vessel activity for activity that does not allow fad - - - - - fe1373e0 by Tony Chemit at 2023-01-24T14:02:59+01:00 Merge branch 'feature/issue_2612' into develop Gestion des FAD sur OPERA AVDTH non mappées vers VesselActivity avec allowFad=TRUE - Closes #2612 - - - - - 9 changed files: - core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportEngineExecution.java - 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/logbook/ActivityWriter.java - core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/FloatingObjectReader.java - core/persistence/migration/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_1.java - + core/persistence/migration/src/main/resources/db/migration/v9/9.1/05_add_referential_ps_common_VesselActivity_101-common.sql - + core/persistence/migration/src/main/resources/db/migration/v9/9.1/05_add_referential_ps_common_VesselActivity_102-common.sql - core/persistence/test/src/test/resources/fixtures/persistence/table_count/referential.properties - model/src/main/resources/fixtures/global.properties Changes: ===================================== core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportEngineExecution.java ===================================== @@ -178,6 +178,9 @@ public class ImportEngineExecution extends ImportEngine { context.addDefaultObservedSystemOrSanitizeFloatingObjectOnes(activity); // write activity observed systems activityWriter.writeObservedSystems(activity); + // while loading Floating objects, we may have change the vessel activity of the activity + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2612 + activityWriter.updateVesselActivity(activity); // get another activity ? 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 { private ObservedSystem observedSystem103; private ObservedSystem observedSystem110; private VesselActivity vesselActivity6; + private VesselActivity vesselActivity101; + private VesselActivity vesselActivity102; private SchoolType schoolType0; private SchoolType schoolType1; private SchoolType schoolType2; @@ -189,6 +191,8 @@ public class ImportReferentialContext { // activity vesselActivity = Maps.uniqueIndex(referential.getVesselActivity(), VesselActivity::getCode); vesselActivity6 = vesselActivity.get("6"); + vesselActivity101 = vesselActivity.get("101"); + vesselActivity102 = vesselActivity.get("102"); schoolType = Maps.uniqueIndex(referential.getSchoolType(), SchoolType::getCode); schoolType0 = schoolType.get("0"); schoolType1 = schoolType.get("1"); @@ -587,4 +591,11 @@ public class ImportReferentialContext { return vesselActivity6; } + public VesselActivity getVesselActivity101() { + return vesselActivity101; + } + + public VesselActivity getVesselActivity102() { + return vesselActivity102; + } } ===================================== 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> { } } + /** + * To update the activity sql code if vessel activity was changed while floating object import. + * <p> + * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2612">Issue 2612</a> + * + * @param entity activity to process + */ + public void updateVesselActivity(Activity entity) { + if (FloatingObjectReader.CHANGED_VESSEL_ACTIVITY_CODE_BY_FLOATING_OBJECT.containsValue(entity.getVesselActivity().getCode())) { + String id = entity.getId(); + String vesselActivityId = entity.getVesselActivity().getId(); + String sql = String.format("UPDATE ps_logbook.activity SET vesselActivity = %1$s WHERE topiaId = %2$s;", + escapeString(vesselActivityId), + escapeString(id)); + writer().writeSql(sql); + } + } + @Override public void toResult(Map<String, Integer> resultBuilder) { 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; */ @SuppressWarnings("SpellCheckingInspection") public class FloatingObjectReader extends DataReader<FloatingObject> { + /** + * To map ObServe vessel activity when in Avdth we found a Floating object to persist. + * <p> + * Keys are current ObServe vessel activity code used, values are the real vessel activity code to use (which allow fad) + * <p> + * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2612">Issue 2612</a> + */ + public static final Map<String, String> CHANGED_VESSEL_ACTIVITY_CODE_BY_FLOATING_OBJECT = Map.of("1", "101", + "2", "102"); private static final Logger log = LogManager.getLogger(FloatingObjectReader.class); /** * To get FloatingObject.objectOperation code from avdth ACTIVITE.C_OPERA. @@ -275,21 +284,42 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { } if (!vesselActivityAllowFad) { - // If ObServe veseel activity does not support Floating object, reject import - List<Object> activityPrimaryKey = ActivityReader.getActivityPk(resultSet); - String activityPk = Query.primaryKeyString(activityPrimaryKey); - 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).", - activityPk, - vesselActivityCode, - vesselActivity.getCode(), - floatingObjectExistsInAvdth, - floatingObjectCreatedByObservedSystem); - log.warn(message); - badVesselActivityCodes.computeIfAbsent(vesselActivityCode, MutableInt::new).increment(); + + String observeVesselActivityCode = activity.getVesselActivity().getCode(); + String realObserveVesselActivityCode = CHANGED_VESSEL_ACTIVITY_CODE_BY_FLOATING_OBJECT.get(observeVesselActivityCode); + if (realObserveVesselActivityCode == null) { + + // If ObServe veseel activity does not support Floating object, reject import + List<Object> activityPrimaryKey = ActivityReader.getActivityPk(resultSet); + String activityPk = Query.primaryKeyString(activityPrimaryKey); + 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).", + activityPk, + vesselActivityCode, + vesselActivity.getCode(), + vesselActivity.getLabel1(), + floatingObjectExistsInAvdth, + floatingObjectCreatedByObservedSystem); + log.warn(message); + badVesselActivityCodes.computeIfAbsent(vesselActivityCode, MutableInt::new).increment(); // // do not create the floating object // reset(dataContext); // return null; + + } else { + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2612 + switch (realObserveVesselActivityCode) { + case "101": + // Use vessel activity 101 + activity.setVesselActivity(dataContext.getVesselActivity101()); + break; + case "102": + // Use vessel activity 102 + activity.setVesselActivity(dataContext.getVesselActivity102()); + break; + } + } + } FloatingObject entity = newEntity(FloatingObject.SPI); @@ -474,7 +504,7 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { return dataContext.getObjectOperation(Objects.requireNonNull(objectOperationCode, String.format("Can't find objectOperation with ACTIVITE.C_OPERA: %s", vesselActivityCode))); } - private ObservedSystem getObservedSystem(ImportDataContext dataContext, String objectTypeCode, boolean floatingObjectExistsInAvdth,boolean buoyExistsInAvdth) { + private ObservedSystem getObservedSystem(ImportDataContext dataContext, String objectTypeCode, boolean floatingObjectExistsInAvdth, boolean buoyExistsInAvdth) { if (!floatingObjectExistsInAvdth) { if (!buoyExistsInAvdth) { 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 executor.addScript("04", "drop_ll_common_weightDeterminationMethod"); if (withIds) { - addVesselActivity36(executor); + addVesselActivities(executor); } // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2435 addNewTable(executor, withIds, "06", "table-common_sizemeasuremethod"); } - private void addVesselActivity36(MigrationVersionResourceExecutor executor) { + private void addVesselActivities(MigrationVersionResourceExecutor executor) { Set<String> existingCodes = executor.findMultipleResultAstSet(SqlQuery.wrap("SELECT CODE FROM ps_common.VesselActivity", resultSet -> resultSet.getString(1))); Set<String> newCodes = new LinkedHashSet<>(); - Stream.of("36").forEach(code -> { + Stream.of("36", "101", "102").forEach(code -> { if (!existingCodes.contains(code)) { executor.addScript("05", "add_referential_ps_common_VesselActivity_" + code); newCodes.add(code); ===================================== core/persistence/migration/src/main/resources/db/migration/v9/9.1/05_add_referential_ps_common_VesselActivity_101-common.sql ===================================== @@ -0,0 +1,22 @@ +--- +-- #%L +-- ObServe Core :: Persistence :: Migration +-- %% +-- Copyright (C) 2008 - 2023 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_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 ===================================== @@ -0,0 +1,22 @@ +--- +-- #%L +-- ObServe Core :: Persistence :: Migration +-- %% +-- Copyright (C) 2008 - 2023 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_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 ps_common.transmittingBuoyOperation=5 ps_common.transmittingBuoyOwnership=5 ps_common.transmittingBuoyType=62 -ps_common.vesselActivity=37 +ps_common.vesselActivity=39 ps_common.weightCategory=137 ps_landing.destination=28 ps_landing.fate=2 ===================================== model/src/main/resources/fixtures/global.properties ===================================== @@ -25,4 +25,4 @@ REFERENCE_DATA_COUNT=68 ENTITIES_LIMIT_SIZE=100 # fr.ird.observe.services.service.referential.ReferentialService # fr.ird.observe.services.local.service.referential.DifferentialModelTest -REFERENTIAL_COUNT=4094 +REFERENTIAL_COUNT=4096 View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/ac810ae19e72c394093bd8b78... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/ac810ae19e72c394093bd8b78... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT (@tchemit)