Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe Commits: e1803c5e by Tony Chemit at 2022-11-30T18:10:29+01:00 Gestion des assocoations (Observed Systems) par la migration AVDTH - Closes #2548 - - - - - 3 changed files: - core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/ImportDataContext.java - core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/ImportEngineExecution.java - core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/FloatingObjectReader.java Changes: ===================================== core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/ImportDataContext.java ===================================== @@ -26,7 +26,9 @@ import fr.ird.observe.entities.data.ps.common.Trip; import fr.ird.observe.entities.data.ps.logbook.Activity; import fr.ird.observe.entities.data.ps.logbook.Route; import fr.ird.observe.entities.referential.ps.common.ObservedSystem; +import fr.ird.observe.persistence.avdth.data.logbook.FloatingObjectReader; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -106,10 +108,37 @@ public class ImportDataContext extends ImportReferentialContext { this.observedSystemCodes = observedSystemCodes; } - public void addDefaultObservedSystem(Activity entity) { + public void addDefaultObservedSystemOrSanitizeFloatingObjectOnes(Activity entity) { if (entity.isObservedSystemEmpty()) { // add no observed system entity.addObservedSystem(getObservedSystem0()); + } else { + // Remove any observed system from code 21 to 25, and at last if one of them has been found + // add (if not already present the observed system 20, this case should never happen, but just in case...) + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2548 + boolean observedSystemsToRemoveFound = false; + boolean observedSystem20Found = false; + + Set<ObservedSystem> observedSystems = entity.getObservedSystem(); + Iterator<ObservedSystem> iterator = observedSystems.iterator(); + + while (iterator.hasNext()) { + ObservedSystem observedSystem = iterator.next(); + if (FloatingObjectReader.OBSERVED_SYTEM_CODES_TO_REMOVE.contains(observedSystem.getCode())) { + // remove this one + iterator.remove(); + observedSystemsToRemoveFound = true; + continue; + } + if ("20".equals(observedSystem.getCode())) { + observedSystem20Found = true; + } + } + if (observedSystemsToRemoveFound && !observedSystem20Found) { + // add the Observed system 20 (This cas should never happen, but I can not afford to check it now...) + ObservedSystem observedSystem20 = getObservedSystem20(); + observedSystems.add(observedSystem20); + } } } ===================================== core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/ImportEngineExecution.java ===================================== @@ -172,8 +172,8 @@ public class ImportEngineExecution extends ImportEngine { // load activity catches loadCatch(activity, activityId, tables.activityTableReader.lastPrimaryKey()); - // add default observed system (if none found) - context.addDefaultObservedSystem(activity); + // add default observed system (if none found) and sanitize some observed system coming from DCP + context.addDefaultObservedSystemOrSanitizeFloatingObjectOnes(activity); // write activity observed systems activityWriter.writeObservedSystems(activity); ===================================== core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/FloatingObjectReader.java ===================================== @@ -200,6 +200,11 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { .put("13", "20") .build(); public static final Set<String> OBSERVED_SYTEM_CODES_WITH_DCP = Set.of("20", "21", "22", "23", "24", "25"); + /** + * We need to remove thoses observed system at the end when writing them to activity. + * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2548">issue 2548</a> + */ + public static final Set<String> OBSERVED_SYTEM_CODES_TO_REMOVE = Set.of("21", "22", "23", "24", "25"); private final MutableInt floatingObjectPartCount = new MutableInt(); private final MutableInt transmittingBuoyCount = new MutableInt(); View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/e1803c5e34a55f401cfd9b9bae... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/e1803c5e34a55f401cfd9b9bae... You're receiving this email because of your account on gitlab.com.