Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
0029ceac
by Tony Chemit at 2024-12-10T19:27:42+01:00
-
6cf171ff
by Tony Chemit at 2024-12-10T19:27:59+01:00
-
18425465
by Tony Chemit at 2024-12-10T19:27:59+01:00
-
70cf3133
by Tony Chemit at 2024-12-10T19:38:17+01:00
-
2fd99075
by Tony Chemit at 2024-12-10T19:44:09+01:00
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:
| ... | ... | @@ -28,7 +28,6 @@ import fr.ird.observe.entities.data.ps.logbook.Route; |
| 28 | 28 | import fr.ird.observe.entities.referential.ps.common.ObservedSystem;
|
| 29 | 29 | import fr.ird.observe.persistence.avdth.data.logbook.FloatingObjectReader;
|
| 30 | 30 | |
| 31 | -import java.util.Iterator;
|
|
| 32 | 31 | import java.util.LinkedHashSet;
|
| 33 | 32 | import java.util.Map;
|
| 34 | 33 | import java.util.Set;
|
| ... | ... | @@ -50,7 +49,12 @@ public class ImportDataContext extends ImportReferentialContext { |
| 50 | 49 | private Trip trip;
|
| 51 | 50 | private Route route;
|
| 52 | 51 | private Activity activity;
|
| 53 | - private Set<String> observedSystemCodes;
|
|
| 52 | + /**
|
|
| 53 | + * Collected avdth observed system code from the ACT_ASSOC.
|
|
| 54 | + *
|
|
| 55 | + * @see fr.ird.observe.persistence.avdth.data.logbook.ActivityReader.ActivityObservedSystemTableReader
|
|
| 56 | + */
|
|
| 57 | + private Set<String> avdthObservedSystemCodes;
|
|
| 54 | 58 | private boolean canCreateActivity;
|
| 55 | 59 | |
| 56 | 60 | public boolean isCanCreateActivity() {
|
| ... | ... | @@ -96,50 +100,42 @@ public class ImportDataContext extends ImportReferentialContext { |
| 96 | 100 | return activityPkToId;
|
| 97 | 101 | }
|
| 98 | 102 | |
| 99 | - public Set<String> getObservedSystemCodes() {
|
|
| 100 | - return observedSystemCodes;
|
|
| 103 | + public Set<String> getAvdthObservedSystemCodes() {
|
|
| 104 | + return avdthObservedSystemCodes;
|
|
| 101 | 105 | }
|
| 102 | 106 | |
| 103 | 107 | public Set<ObservedSystem> getObservedSystems() {
|
| 104 | 108 | return observedSystems;
|
| 105 | 109 | }
|
| 106 | 110 | |
| 107 | - public void setObservedSystemCodes(Set<String> observedSystemCodes) {
|
|
| 108 | - this.observedSystemCodes = observedSystemCodes;
|
|
| 111 | + public void setAvdthObservedSystemCodes(Set<String> avdthObservedSystemCodes) {
|
|
| 112 | + this.avdthObservedSystemCodes = avdthObservedSystemCodes;
|
|
| 109 | 113 | }
|
| 110 | 114 | |
| 111 | 115 | public void addDefaultObservedSystemOrSanitizeFloatingObjectOnes(Activity entity) {
|
| 112 | - if (entity.isObservedSystemEmpty()) {
|
|
| 113 | - // add no observed system
|
|
| 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();
|
|
| 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 | + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2961
|
|
| 124 | 120 | |
| 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 | - }
|
|
| 121 | + boolean floatingObjectCreatedByObservedSystem = avdthObservedSystemCodes.stream().anyMatch(FloatingObjectReader.OBSERVED_SYTEM_CODES_WITH_DCP::contains);
|
|
| 122 | + if (floatingObjectCreatedByObservedSystem) {
|
|
| 123 | + boolean observedSystem20Found = false;
|
|
| 124 | + for (ObservedSystem observedSystem : entity.getObservedSystem()) {
|
|
| 133 | 125 | if ("20".equals(observedSystem.getCode())) {
|
| 134 | 126 | observedSystem20Found = true;
|
| 135 | 127 | }
|
| 136 | 128 | }
|
| 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);
|
|
| 129 | + if (!observedSystem20Found) {
|
|
| 130 | + // add the Observed system 20
|
|
| 131 | + entity.addObservedSystem(getObservedSystem20());
|
|
| 132 | + return;
|
|
| 141 | 133 | }
|
| 142 | 134 | }
|
| 135 | + if (entity.isObservedSystemEmpty()) {
|
|
| 136 | + // add no observed system
|
|
| 137 | + entity.addObservedSystem(getObservedSystem0());
|
|
| 138 | + }
|
|
| 143 | 139 | }
|
| 144 | 140 | |
| 145 | 141 | public void computeCanCreateActivity() {
|
| ... | ... | @@ -157,7 +157,7 @@ public class ImportEngineExecution extends ImportEngine { |
| 157 | 157 | |
| 158 | 158 | // load observed systems for this activity
|
| 159 | 159 | Set<String> observedSystemCodes = activityReader.readObservedSystem(context, tables.activityObservedSystemTableReader, ActivityReader.getActivityPk(activityRow));
|
| 160 | - context.setObservedSystemCodes(observedSystemCodes);
|
|
| 160 | + context.setAvdthObservedSystemCodes(observedSystemCodes);
|
|
| 161 | 161 | |
| 162 | 162 | // load activity
|
| 163 | 163 | Activity activity = activityWriter.intercept(activityRow, routeId, 0);
|
| ... | ... | @@ -176,6 +176,8 @@ public class ImportEngineExecution extends ImportEngine { |
| 176 | 176 | |
| 177 | 177 | // add default observed system (if none found) and sanitize some observed system coming from DCP
|
| 178 | 178 | context.addDefaultObservedSystemOrSanitizeFloatingObjectOnes(activity);
|
| 179 | + // clean this data context state
|
|
| 180 | + context.setAvdthObservedSystemCodes(null);
|
|
| 179 | 181 | // write activity observed systems
|
| 180 | 182 | activityWriter.writeObservedSystems(activity);
|
| 181 | 183 | // while loading Floating objects, we may have change the vessel activity of the activity
|
| ... | ... | @@ -361,10 +361,10 @@ public class ActivityReader extends DataReader<Activity> { |
| 361 | 361 | ResultSet activityObservedSystemRow = activityObservedSystemTableReader.next();
|
| 362 | 362 | String avdthSystemCode = activityObservedSystemRow.getString(6);
|
| 363 | 363 | observedSystemCodes.add(avdthSystemCode);
|
| 364 | - if (!ObservedSystemInterceptor.CODE_MAPPING.containsKey(avdthSystemCode)) {
|
|
| 364 | + String observeSystemCode = ObservedSystemInterceptor.CODE_MAPPING.get(avdthSystemCode);
|
|
| 365 | + if (observeSystemCode == null) {
|
|
| 365 | 366 | throw new IllegalStateException(String.format("Can't find observedSystem with code: %s from ad-hoc AVDTH to ObServe mapping", avdthSystemCode));
|
| 366 | 367 | }
|
| 367 | - String observeSystemCode = ObservedSystemInterceptor.CODE_MAPPING.get(avdthSystemCode);
|
|
| 368 | 368 | ObservedSystem observedSystem = dataContext.getObservedSystem(observeSystemCode);
|
| 369 | 369 | observedSystems.add(observedSystem);
|
| 370 | 370 | }
|
| ... | ... | @@ -208,11 +208,7 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 208 | 208 | * Observed system from {@code ACT_ASSOC} which can create a Floating object.
|
| 209 | 209 | */
|
| 210 | 210 | public static final Set<String> OBSERVED_SYTEM_CODES_WITH_DCP = Set.of("20", "21", "22", "23", "24", "25", "81");
|
| 211 | - /**
|
|
| 212 | - * We need to remove thoses observed system at the end when writing them to activity.
|
|
| 213 | - * See <a href="https://gitlab.com/ultreiaio/ird-observe/-/issues/2548">issue 2548</a>
|
|
| 214 | - */
|
|
| 215 | - public static final Set<String> OBSERVED_SYTEM_CODES_TO_REMOVE = Set.of("21", "22", "23", "24", "25");
|
|
| 211 | + |
|
| 216 | 212 | private final MutableInt floatingObjectPartCount = new MutableInt();
|
| 217 | 213 | private final MutableInt transmittingBuoyCount = new MutableInt();
|
| 218 | 214 | |
| ... | ... | @@ -232,13 +228,13 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 232 | 228 | VesselActivity vesselActivity = activity.getVesselActivity();
|
| 233 | 229 | |
| 234 | 230 | // Avdth observed system codes associated to the current activity (need them to compute ex nihilo floating object)
|
| 235 | - Set<String> observedSystemCodes = dataContext.getObservedSystemCodes();
|
|
| 231 | + Set<String> avdthObservedSystemCodes = dataContext.getAvdthObservedSystemCodes();
|
|
| 236 | 232 | |
| 237 | 233 | // We need to get the original vessel activity code from AVDTH (to compute some mapping)
|
| 238 | 234 | String vesselActivityCode = resultSet.getString(13);
|
| 239 | 235 | |
| 240 | 236 | // Is the floating object can be created by the observed systems?
|
| 241 | - boolean floatingObjectCreatedByObservedSystem = observedSystemCodes.stream().anyMatch(OBSERVED_SYTEM_CODES_WITH_DCP::contains);
|
|
| 237 | + boolean floatingObjectCreatedByObservedSystem = avdthObservedSystemCodes.stream().anyMatch(OBSERVED_SYTEM_CODES_WITH_DCP::contains);
|
|
| 242 | 238 | |
| 243 | 239 | // Is the current vessel activity accept to create Floating object?
|
| 244 | 240 | boolean vesselActivityAllowFad = vesselActivity.isAllowFad();
|
| ... | ... | @@ -266,7 +262,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 266 | 262 | // neither the buoy exist in avdth,
|
| 267 | 263 | // neither need to be created by observed system,
|
| 268 | 264 | // Do not create the floating object (no log is required here: we are on an activity with no floating object)
|
| 269 | - reset(dataContext);
|
|
| 270 | 265 | return null;
|
| 271 | 266 | }
|
| 272 | 267 | |
| ... | ... | @@ -296,7 +291,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 296 | 291 | }
|
| 297 | 292 | |
| 298 | 293 | // do not create the floating object
|
| 299 | - reset(dataContext);
|
|
| 300 | 294 | return null;
|
| 301 | 295 | }
|
| 302 | 296 | |
| ... | ... | @@ -323,16 +317,11 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 323 | 317 | if (observedSystem != null) {
|
| 324 | 318 | activity.addObservedSystem(observedSystem);
|
| 325 | 319 | }
|
| 326 | - // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2802
|
|
| 327 | - if (observedSystemCodes.contains("81")) {
|
|
| 328 | - activity.addObservedSystem(dataContext.getObservedSystem20());
|
|
| 329 | - }
|
|
| 330 | - |
|
| 331 | 320 | boolean addBuoyFromObservedSystem = addFloatingObjectMaterials(dataContext,
|
| 332 | 321 | resultSet,
|
| 333 | 322 | vesselActivityCode,
|
| 334 | 323 | objectTypeCode,
|
| 335 | - observedSystemCodes,
|
|
| 324 | + avdthObservedSystemCodes,
|
|
| 336 | 325 | objectOperation,
|
| 337 | 326 | entity,
|
| 338 | 327 | floatingObjectExistsInAvdth,
|
| ... | ... | @@ -348,7 +337,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 348 | 337 | // only add buoy if buoy type known
|
| 349 | 338 | entity.addTransmittingBuoy(transmittingBuoy);
|
| 350 | 339 | }
|
| 351 | - reset(dataContext);
|
|
| 352 | 340 | return entity;
|
| 353 | 341 | }
|
| 354 | 342 | |
| ... | ... | @@ -356,7 +344,7 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 356 | 344 | ResultSet resultSet,
|
| 357 | 345 | String vesselActivityCode,
|
| 358 | 346 | String objectTypeCode,
|
| 359 | - Set<String> observedSystemCodes,
|
|
| 347 | + Set<String> avdthObservedSystemCodes,
|
|
| 360 | 348 | ObjectOperation objectOperation,
|
| 361 | 349 | FloatingObject entity,
|
| 362 | 350 | boolean floatingObjectExistsInAvdth,
|
| ... | ... | @@ -379,40 +367,40 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 379 | 367 | }
|
| 380 | 368 | }
|
| 381 | 369 | |
| 382 | - if (observedSystemCodes.contains("20")) {
|
|
| 370 | + if (avdthObservedSystemCodes.contains("20")) {
|
|
| 383 | 371 | // add ObjectMaterial FOB
|
| 384 | 372 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialFOB(), whenArriving, whenLeaving, entity);
|
| 385 | 373 | addDefaultObjectMaterialOnUnknownObjectType = false;
|
| 386 | 374 | }
|
| 387 | - if (observedSystemCodes.contains("21")) {
|
|
| 375 | + if (avdthObservedSystemCodes.contains("21")) {
|
|
| 388 | 376 | // add ObjectMaterial 2-1-1 VNLOG
|
| 389 | 377 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialVNLOG(), whenArriving, whenLeaving, entity);
|
| 390 | 378 | addDefaultObjectMaterialOnUnknownObjectType = false;
|
| 391 | 379 | }
|
| 392 | - if (observedSystemCodes.contains("22")) {
|
|
| 380 | + if (avdthObservedSystemCodes.contains("22")) {
|
|
| 393 | 381 | // add ObjectMaterial 2-1-1 VNLOG + 1-1 DFAD
|
| 394 | 382 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialVNLOG(), whenArriving, whenLeaving, entity);
|
| 395 | 383 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialDFAD(), whenArriving, whenLeaving, entity);
|
| 396 | 384 | addDefaultObjectMaterialOnUnknownObjectType = false;
|
| 397 | 385 | addBuoyFromObservedSystem = true;
|
| 398 | 386 | }
|
| 399 | - if (observedSystemCodes.contains("23")) {
|
|
| 387 | + if (avdthObservedSystemCodes.contains("23")) {
|
|
| 400 | 388 | // add ObjectMaterial 2-2 ALOG
|
| 401 | 389 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialALOG(), whenArriving, whenLeaving, entity);
|
| 402 | 390 | addDefaultObjectMaterialOnUnknownObjectType = false;
|
| 403 | 391 | }
|
| 404 | - if (observedSystemCodes.contains("24")) {
|
|
| 392 | + if (avdthObservedSystemCodes.contains("24")) {
|
|
| 405 | 393 | // add ObjectMaterial 1-1 DFAD
|
| 406 | 394 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialDFAD(), whenArriving, whenLeaving, entity);
|
| 407 | 395 | addDefaultObjectMaterialOnUnknownObjectType = false;
|
| 408 | 396 | addBuoyFromObservedSystem = true;
|
| 409 | 397 | }
|
| 410 | - if (observedSystemCodes.contains("25")) {
|
|
| 398 | + if (avdthObservedSystemCodes.contains("25")) {
|
|
| 411 | 399 | // add ObjectMaterial 1-2 AFAD
|
| 412 | 400 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialAFAD(), whenArriving, whenLeaving, entity);
|
| 413 | 401 | addDefaultObjectMaterialOnUnknownObjectType = false;
|
| 414 | 402 | }
|
| 415 | - if (observedSystemCodes.contains("81")) {
|
|
| 403 | + if (avdthObservedSystemCodes.contains("81")) {
|
|
| 416 | 404 | // add ObjectMaterial 2-1-2-1 Carrion
|
| 417 | 405 | addObjectMaterial(vesselActivityCode, objectMaterialUsed, dataContext.getObjectMaterialCarrion(), whenArriving, whenLeaving, entity);
|
| 418 | 406 | addDefaultObjectMaterialOnUnknownObjectType = false;
|
| ... | ... | @@ -475,11 +463,6 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
| 475 | 463 | return transmittingBuoy;
|
| 476 | 464 | }
|
| 477 | 465 | |
| 478 | - private void reset(ImportDataContext dataContext) {
|
|
| 479 | - // as soon as entity was flush, let's clear internal states
|
|
| 480 | - dataContext.setObservedSystemCodes(null);
|
|
| 481 | - }
|
|
| 482 | - |
|
| 483 | 466 | private void addObjectMaterial(String vesselActivityCode, Set<String> objectMaterialUsed, ObjectMaterial objectMaterial, boolean whenArriving, boolean whenLeaving, FloatingObject floatingObject) {
|
| 484 | 467 | if (!whenArriving && !whenLeaving) {
|
| 485 | 468 | throw new IllegalStateException(String.format("Can't have not whenArriving and not whenLeaving from ACTIVITE.C_OPERA: %s", vesselActivityCode));
|