[Git][ultreiaio/ird-observe][develop] 5 commits: Rename ImportDataContext.observedSystemCodes to ImportDataContext.avdthObservedSystemCodes
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 0029ceac by Tony Chemit at 2024-12-10T19:27:42+01:00 Rename ImportDataContext.observedSystemCodes to ImportDataContext.avdthObservedSystemCodes - - - - - 6cf171ff by Tony Chemit at 2024-12-10T19:27:59+01:00 Clean ImportDataContext.avdthObservedSystemCodes at a better place and no more in FloatingObjectReader.resetContext method (which is removed) - - - - - 18425465 by Tony Chemit at 2024-12-10T19:27:59+01:00 Clean code - - - - - 70cf3133 by Tony Chemit at 2024-12-10T19:38:17+01:00 Now just clean the method to add observed system 20 if required from avdth observed system code found - - - - - 2fd99075 by Tony Chemit at 2024-12-10T19:44:09+01:00 Merge branch 'feature/issue_2961' into develop 2 mappings AVDTH ASSOC non fonctionnels - Closes #2961 - - - - - 4 changed files: - core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportDataContext.java - 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/logbook/ActivityReader.java - core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/FloatingObjectReader.java Changes: ===================================== core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportDataContext.java ===================================== @@ -28,7 +28,6 @@ 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; @@ -50,7 +49,12 @@ public class ImportDataContext extends ImportReferentialContext { private Trip trip; private Route route; private Activity activity; - private Set<String> observedSystemCodes; + /** + * Collected avdth observed system code from the ACT_ASSOC. + * + * @see fr.ird.observe.persistence.avdth.data.logbook.ActivityReader.ActivityObservedSystemTableReader + */ + private Set<String> avdthObservedSystemCodes; private boolean canCreateActivity; public boolean isCanCreateActivity() { @@ -96,50 +100,42 @@ public class ImportDataContext extends ImportReferentialContext { return activityPkToId; } - public Set<String> getObservedSystemCodes() { - return observedSystemCodes; + public Set<String> getAvdthObservedSystemCodes() { + return avdthObservedSystemCodes; } public Set<ObservedSystem> getObservedSystems() { return observedSystems; } - public void setObservedSystemCodes(Set<String> observedSystemCodes) { - this.observedSystemCodes = observedSystemCodes; + public void setAvdthObservedSystemCodes(Set<String> avdthObservedSystemCodes) { + this.avdthObservedSystemCodes = avdthObservedSystemCodes; } 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(); + // 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 + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2961 - 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; - } + boolean floatingObjectCreatedByObservedSystem = avdthObservedSystemCodes.stream().anyMatch(FloatingObjectReader.OBSERVED_SYTEM_CODES_WITH_DCP::contains); + if (floatingObjectCreatedByObservedSystem) { + boolean observedSystem20Found = false; + for (ObservedSystem observedSystem : entity.getObservedSystem()) { 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); + if (!observedSystem20Found) { + // add the Observed system 20 + entity.addObservedSystem(getObservedSystem20()); + return; } } + if (entity.isObservedSystemEmpty()) { + // add no observed system + entity.addObservedSystem(getObservedSystem0()); + } } public void computeCanCreateActivity() { ===================================== core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/ImportEngineExecution.java ===================================== @@ -157,7 +157,7 @@ public class ImportEngineExecution extends ImportEngine { // load observed systems for this activity Set<String> observedSystemCodes = activityReader.readObservedSystem(context, tables.activityObservedSystemTableReader, ActivityReader.getActivityPk(activityRow)); - context.setObservedSystemCodes(observedSystemCodes); + context.setAvdthObservedSystemCodes(observedSystemCodes); // load activity Activity activity = activityWriter.intercept(activityRow, routeId, 0); @@ -176,6 +176,8 @@ public class ImportEngineExecution extends ImportEngine { // add default observed system (if none found) and sanitize some observed system coming from DCP context.addDefaultObservedSystemOrSanitizeFloatingObjectOnes(activity); + // clean this data context state + context.setAvdthObservedSystemCodes(null); // write activity observed systems activityWriter.writeObservedSystems(activity); // while loading Floating objects, we may have change the vessel activity of the activity ===================================== core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/ActivityReader.java ===================================== @@ -361,10 +361,10 @@ public class ActivityReader extends DataReader<Activity> { ResultSet activityObservedSystemRow = activityObservedSystemTableReader.next(); String avdthSystemCode = activityObservedSystemRow.getString(6); observedSystemCodes.add(avdthSystemCode); - if (!ObservedSystemInterceptor.CODE_MAPPING.containsKey(avdthSystemCode)) { + String observeSystemCode = ObservedSystemInterceptor.CODE_MAPPING.get(avdthSystemCode); + if (observeSystemCode == null) { throw new IllegalStateException(String.format("Can't find observedSystem with code: %s from ad-hoc AVDTH to ObServe mapping", avdthSystemCode)); } - String observeSystemCode = ObservedSystemInterceptor.CODE_MAPPING.get(avdthSystemCode); ObservedSystem observedSystem = dataContext.getObservedSystem(observeSystemCode); observedSystems.add(observedSystem); } ===================================== core/persistence/avdth/src/main/java/fr/ird/observe/persistence/avdth/data/logbook/FloatingObjectReader.java ===================================== @@ -208,11 +208,7 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { * Observed system from {@code ACT_ASSOC} which can create a Floating object. */ public static final Set<String> OBSERVED_SYTEM_CODES_WITH_DCP = Set.of("20", "21", "22", "23", "24", "25", "81"); - /** - * 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(); @@ -232,13 +228,13 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { VesselActivity vesselActivity = activity.getVesselActivity(); // Avdth observed system codes associated to the current activity (need them to compute ex nihilo floating object) - Set<String> observedSystemCodes = dataContext.getObservedSystemCodes(); + Set<String> avdthObservedSystemCodes = dataContext.getAvdthObservedSystemCodes(); // We need to get the original vessel activity code from AVDTH (to compute some mapping) String vesselActivityCode = resultSet.getString(13); // Is the floating object can be created by the observed systems? - boolean floatingObjectCreatedByObservedSystem = observedSystemCodes.stream().anyMatch(OBSERVED_SYTEM_CODES_WITH_DCP::contains); + boolean floatingObjectCreatedByObservedSystem = avdthObservedSystemCodes.stream().anyMatch(OBSERVED_SYTEM_CODES_WITH_DCP::contains); // Is the current vessel activity accept to create Floating object? boolean vesselActivityAllowFad = vesselActivity.isAllowFad(); @@ -266,7 +262,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { // neither the buoy exist in avdth, // neither need to be created by observed system, // Do not create the floating object (no log is required here: we are on an activity with no floating object) - reset(dataContext); return null; } @@ -296,7 +291,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { } // do not create the floating object - reset(dataContext); return null; } @@ -323,16 +317,11 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { if (observedSystem != null) { activity.addObservedSystem(observedSystem); } - // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2802 - if (observedSystemCodes.contains("81")) { - activity.addObservedSystem(dataContext.getObservedSystem20()); - } - boolean addBuoyFromObservedSystem = addFloatingObjectMaterials(dataContext, resultSet, vesselActivityCode, objectTypeCode, - observedSystemCodes, + avdthObservedSystemCodes, objectOperation, entity, floatingObjectExistsInAvdth, @@ -348,7 +337,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { // only add buoy if buoy type known entity.addTransmittingBuoy(transmittingBuoy); } - reset(dataContext); return entity; } @@ -356,7 +344,7 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { ResultSet resultSet, String vesselActivityCode, String objectTypeCode, - Set<String> observedSystemCodes, + Set<String> avdthObservedSystemCodes, ObjectOperation objectOperation, FloatingObject entity, boolean floatingObjectExistsInAvdth, @@ -379,40 +367,40 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { } } - if (observedSystemCodes.contains("20")) { + if (avdthObservedSystemCodes.contains("20")) { // add ObjectMaterial FOB addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialFOB(), whenArriving, whenLeaving, entity); addDefaultObjectMaterialOnUnknownObjectType = false; } - if (observedSystemCodes.contains("21")) { + if (avdthObservedSystemCodes.contains("21")) { // add ObjectMaterial 2-1-1 VNLOG addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialVNLOG(), whenArriving, whenLeaving, entity); addDefaultObjectMaterialOnUnknownObjectType = false; } - if (observedSystemCodes.contains("22")) { + if (avdthObservedSystemCodes.contains("22")) { // add ObjectMaterial 2-1-1 VNLOG + 1-1 DFAD addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialVNLOG(), whenArriving, whenLeaving, entity); addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialDFAD(), whenArriving, whenLeaving, entity); addDefaultObjectMaterialOnUnknownObjectType = false; addBuoyFromObservedSystem = true; } - if (observedSystemCodes.contains("23")) { + if (avdthObservedSystemCodes.contains("23")) { // add ObjectMaterial 2-2 ALOG addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialALOG(), whenArriving, whenLeaving, entity); addDefaultObjectMaterialOnUnknownObjectType = false; } - if (observedSystemCodes.contains("24")) { + if (avdthObservedSystemCodes.contains("24")) { // add ObjectMaterial 1-1 DFAD addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialDFAD(), whenArriving, whenLeaving, entity); addDefaultObjectMaterialOnUnknownObjectType = false; addBuoyFromObservedSystem = true; } - if (observedSystemCodes.contains("25")) { + if (avdthObservedSystemCodes.contains("25")) { // add ObjectMaterial 1-2 AFAD addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialAFAD(), whenArriving, whenLeaving, entity); addDefaultObjectMaterialOnUnknownObjectType = false; } - if (observedSystemCodes.contains("81")) { + if (avdthObservedSystemCodes.contains("81")) { // add ObjectMaterial 2-1-2-1 Carrion addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialCarrion(), whenArriving, whenLeaving, entity); addDefaultObjectMaterialOnUnknownObjectType = false; @@ -475,11 +463,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { return transmittingBuoy; } - private void reset(ImportDataContext dataContext) { - // as soon as entity was flush, let's clear internal states - dataContext.setObservedSystemCodes(null); - } - private void addObjectMaterial(String vesselActivityCode, Set<String> objectMaterialUsed, ObjectMaterial objectMaterial, boolean whenArriving, boolean whenLeaving, FloatingObject floatingObject) { if (!whenArriving && !whenLeaving) { throw new IllegalStateException(String.format("Can't have not whenArriving and not whenLeaving from ACTIVITE.C_OPERA: %s", vesselActivityCode)); View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/3774d8273efe98d3f0094a482... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/3774d8273efe98d3f0094a482... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT (@tchemit)