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

Commits:

3 changed files:

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;
    26 26
     import fr.ird.observe.entities.data.ps.logbook.Activity;
    
    27 27
     import fr.ird.observe.entities.data.ps.logbook.Route;
    
    28 28
     import fr.ird.observe.entities.referential.ps.common.ObservedSystem;
    
    29
    +import fr.ird.observe.persistence.avdth.data.logbook.FloatingObjectReader;
    
    29 30
     
    
    31
    +import java.util.Iterator;
    
    30 32
     import java.util.LinkedHashSet;
    
    31 33
     import java.util.Map;
    
    32 34
     import java.util.Set;
    
    ... ... @@ -106,10 +108,37 @@ public class ImportDataContext extends ImportReferentialContext {
    106 108
             this.observedSystemCodes = observedSystemCodes;
    
    107 109
         }
    
    108 110
     
    
    109
    -    public void addDefaultObservedSystem(Activity entity) {
    
    111
    +    public void addDefaultObservedSystemOrSanitizeFloatingObjectOnes(Activity entity) {
    
    110 112
             if (entity.isObservedSystemEmpty()) {
    
    111 113
                 // add no observed system
    
    112 114
                 entity.addObservedSystem(getObservedSystem0());
    
    115
    +        }  else {
    
    116
    +            // Remove any observed system from code 21 to 25, and at last if one of them has been found
    
    117
    +            // add (if not already present the observed system 20, this case should never happen, but just in case...)
    
    118
    +            // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2548
    
    119
    +            boolean observedSystemsToRemoveFound = false;
    
    120
    +            boolean observedSystem20Found = false;
    
    121
    +
    
    122
    +            Set<ObservedSystem> observedSystems = entity.getObservedSystem();
    
    123
    +            Iterator<ObservedSystem> iterator = observedSystems.iterator();
    
    124
    +
    
    125
    +            while (iterator.hasNext()) {
    
    126
    +                ObservedSystem observedSystem = iterator.next();
    
    127
    +                if (FloatingObjectReader.OBSERVED_SYTEM_CODES_TO_REMOVE.contains(observedSystem.getCode())) {
    
    128
    +                    // remove this one
    
    129
    +                    iterator.remove();
    
    130
    +                    observedSystemsToRemoveFound = true;
    
    131
    +                    continue;
    
    132
    +                }
    
    133
    +                if ("20".equals(observedSystem.getCode())) {
    
    134
    +                    observedSystem20Found = true;
    
    135
    +                }
    
    136
    +            }
    
    137
    +            if (observedSystemsToRemoveFound && !observedSystem20Found) {
    
    138
    +                // add the Observed system 20 (This cas should never happen, but I can not afford to check it now...)
    
    139
    +                ObservedSystem observedSystem20 = getObservedSystem20();
    
    140
    +                observedSystems.add(observedSystem20);
    
    141
    +            }
    
    113 142
             }
    
    114 143
         }
    
    115 144
     
    

  • core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/ImportEngineExecution.java
    ... ... @@ -172,8 +172,8 @@ public class ImportEngineExecution extends ImportEngine {
    172 172
                 // load activity catches
    
    173 173
                 loadCatch(activity, activityId, tables.activityTableReader.lastPrimaryKey());
    
    174 174
     
    
    175
    -            // add default observed system (if none found)
    
    176
    -            context.addDefaultObservedSystem(activity);
    
    175
    +            // add default observed system (if none found) and sanitize some observed system coming from DCP
    
    176
    +            context.addDefaultObservedSystemOrSanitizeFloatingObjectOnes(activity);
    
    177 177
                 // write activity observed systems
    
    178 178
                 activityWriter.writeObservedSystems(activity);
    
    179 179
     
    

  • 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> {
    200 200
                 .put("13", "20")
    
    201 201
                 .build();
    
    202 202
         public static final Set<String> OBSERVED_SYTEM_CODES_WITH_DCP = Set.of("20", "21", "22", "23", "24", "25");
    
    203
    +    /**
    
    204
    +     * We need to remove thoses observed system at the end when writing them to activity.
    
    205
    +     * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2548">issue 2548</a>
    
    206
    +     */
    
    207
    +    public static final Set<String> OBSERVED_SYTEM_CODES_TO_REMOVE = Set.of("21", "22", "23", "24", "25");
    
    203 208
         private final MutableInt floatingObjectPartCount = new MutableInt();
    
    204 209
         private final MutableInt transmittingBuoyCount = new MutableInt();
    
    205 210