| ... |
... |
@@ -23,6 +23,7 @@ package fr.ird.observe.persistence.avdth.data.logbook; |
|
23
|
23
|
*/
|
|
24
|
24
|
|
|
25
|
25
|
import com.google.common.collect.ImmutableMap;
|
|
|
26
|
+import fr.ird.observe.entities.data.ps.logbook.Activity;
|
|
26
|
27
|
import fr.ird.observe.entities.data.ps.logbook.FloatingObject;
|
|
27
|
28
|
import fr.ird.observe.entities.data.ps.logbook.FloatingObjectPart;
|
|
28
|
29
|
import fr.ird.observe.entities.data.ps.logbook.TransmittingBuoy;
|
| ... |
... |
@@ -232,54 +233,113 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
|
232
|
233
|
@Override
|
|
233
|
234
|
public FloatingObject read(ImportDataContext dataContext, ResultSet resultSet) throws SQLException {
|
|
234
|
235
|
|
|
235
|
|
- String vesselActivityCode = resultSet.getString(13);
|
|
236
|
|
- VesselActivity vesselActivity = dataContext.getVesselActivity(vesselActivityCode);
|
|
|
236
|
+ // Get the current activity where to add the optional floating object
|
|
|
237
|
+ Activity activity = dataContext.getActivity();
|
|
|
238
|
+
|
|
|
239
|
+ // Get his vessel activity
|
|
|
240
|
+ VesselActivity vesselActivity = activity.getVesselActivity();
|
|
|
241
|
+
|
|
|
242
|
+ // Avdth observed system codes associated to the current activity (need them to compute ex nihilo floating object)
|
|
237
|
243
|
Set<String> observedSystemCodes = dataContext.getObservedSystemCodes();
|
|
238
|
|
- if (!Objects.equals(vesselActivity.getCode(), "13")) {
|
|
239
|
|
- boolean noDcpInObservedSystems = observedSystemCodes.stream().noneMatch(OBSERVED_SYTEM_CODES_WITH_DCP::contains);
|
|
240
|
|
- if (noDcpInObservedSystems) {
|
|
241
|
|
- reset(dataContext);
|
|
242
|
|
- return null;
|
|
243
|
|
- }
|
|
244
|
|
- }
|
|
245
|
244
|
|
|
246
|
|
- FloatingObject entity = newEntity(FloatingObject.SPI);
|
|
|
245
|
+ // We need to get the original vessel activity code from AVDTH (to compute some mapping)
|
|
|
246
|
+ String vesselActivityCode = resultSet.getString(13);
|
|
247
|
247
|
|
|
248
|
|
- ObjectOperation objectOperation = dataContext.getObjectOperationByVesselActivityCode(vesselActivityCode);
|
|
249
|
|
- entity.setObjectOperation(Objects.requireNonNull(objectOperation, String.format("Can't find objectOperation with code: %s", vesselActivityCode)));
|
|
250
|
|
- boolean addCoordinate = "11".equals(objectOperation.getCode());
|
|
251
|
|
- boolean whenArriving = WHEN_ARRIVING_CODE.contains(vesselActivityCode);
|
|
252
|
|
- boolean whenLeaving = WHEN_LEAVING_CODE.contains(vesselActivityCode);
|
|
|
248
|
+ // Is the floating object can be created by the observed systems?
|
|
|
249
|
+ boolean floatingObjectCreatedByObservedSystem = observedSystemCodes.stream().anyMatch(OBSERVED_SYTEM_CODES_WITH_DCP::contains);
|
|
|
250
|
+
|
|
|
251
|
+ // Is the current vessel activity accept to create Floating object?
|
|
|
252
|
+ boolean vesselActivityAllowFad = vesselActivity.isAllowFad();
|
|
|
253
|
+
|
|
|
254
|
+ // Get object type code
|
|
253
|
255
|
String objectTypeCode = resultSet.getString(28);
|
|
254
|
256
|
if (objectTypeCode == null) {
|
|
255
|
|
- //FIXME should fail ?
|
|
|
257
|
+ // If null, then consider it as not found in avdth
|
|
256
|
258
|
objectTypeCode = "999";
|
|
257
|
259
|
}
|
|
258
|
|
- //FIXME 29 - F_DCP_ECO
|
|
259
|
|
-// int dcpEcoCode = resultSet.getInt(29);
|
|
260
|
|
- String buoyOwnershipCode = resultSet.getString(30);
|
|
|
260
|
+
|
|
|
261
|
+ // Is floating object exists in avdth?
|
|
|
262
|
+ boolean floatingObjectExistsInAvdth = !objectTypeCode.equals("999");
|
|
|
263
|
+
|
|
|
264
|
+ //FIXME Improve this condition
|
|
|
265
|
+ if (!vesselActivityAllowFad && !floatingObjectCreatedByObservedSystem) {
|
|
|
266
|
+ // do not create the floating object
|
|
|
267
|
+ reset(dataContext);
|
|
|
268
|
+ return null;
|
|
|
269
|
+ }
|
|
|
270
|
+
|
|
|
271
|
+ FloatingObject entity = newEntity(FloatingObject.SPI);
|
|
|
272
|
+
|
|
|
273
|
+ // Get floating object operation
|
|
|
274
|
+ ObjectOperation objectOperation = getObjectOperationByVesselActivityCode(dataContext, vesselActivityCode);
|
|
|
275
|
+ entity.setObjectOperation(Objects.requireNonNull(objectOperation, String.format("Can't find objectOperation with ACTIVITE.C_OPERA: %s", vesselActivityCode)));
|
|
|
276
|
+
|
|
261
|
277
|
String buoyTypeCode = resultSet.getString(31);
|
|
262
|
278
|
if (buoyTypeCode == null) {
|
|
263
|
|
- //FIXME should fail?
|
|
|
279
|
+ // If null, then consider it as not found in avdth
|
|
264
|
280
|
buoyTypeCode = "999";
|
|
265
|
281
|
}
|
|
266
|
|
- String buoyId = resultSet.getString(32);
|
|
267
|
|
- String dcpWeight = resultSet.getString(33);
|
|
268
|
|
- if (dcpWeight != null) {
|
|
269
|
|
- //FIXME Check if ok
|
|
270
|
|
- entity.setComment(String.format("ACTIVITE.POIDS_ESTIM_DCP value from avdth: %s", dcpWeight));
|
|
271
|
|
- }
|
|
272
|
|
- ObservedSystem observedSystem = dataContext.getObservedSystem(objectTypeCode, buoyTypeCode);
|
|
|
282
|
+ // IS buoy exists in avdth?
|
|
|
283
|
+ boolean buoyExistsInAvdth = !"999".equals(buoyTypeCode);
|
|
|
284
|
+
|
|
|
285
|
+ ObservedSystem observedSystem = getObservedSystem(dataContext, objectTypeCode, floatingObjectExistsInAvdth, buoyExistsInAvdth);
|
|
273
|
286
|
if (observedSystem != null) {
|
|
274
|
|
- dataContext.getActivity().addObservedSystem(observedSystem);
|
|
|
287
|
+ activity.addObservedSystem(observedSystem);
|
|
|
288
|
+ }
|
|
|
289
|
+
|
|
|
290
|
+ boolean addBuoyFromObservedSystem = addFloatingObjectMaterials(dataContext,
|
|
|
291
|
+ resultSet,
|
|
|
292
|
+ vesselActivityCode,
|
|
|
293
|
+ objectTypeCode,
|
|
|
294
|
+ observedSystemCodes,
|
|
|
295
|
+ entity,
|
|
|
296
|
+ floatingObjectExistsInAvdth,
|
|
|
297
|
+ buoyExistsInAvdth);
|
|
|
298
|
+
|
|
|
299
|
+ TransmittingBuoy transmittingBuoy = null;
|
|
|
300
|
+ if (buoyExistsInAvdth) {
|
|
|
301
|
+ transmittingBuoy = getBuoyFromAvdthActivity(dataContext, resultSet, buoyTypeCode, vesselActivityCode, objectOperation, activity);
|
|
|
302
|
+ } else if (addBuoyFromObservedSystem) {
|
|
|
303
|
+ transmittingBuoy = getBuoyFromObservedSystem(dataContext);
|
|
275
|
304
|
}
|
|
276
|
|
- // avdth data has a buoy
|
|
277
|
|
- boolean willCreateBuoy = !"999".equals(buoyTypeCode);
|
|
|
305
|
+ if (transmittingBuoy != null) {
|
|
|
306
|
+ // only add buoy if buoy type known
|
|
|
307
|
+ entity.addTransmittingBuoy(transmittingBuoy);
|
|
|
308
|
+ }
|
|
|
309
|
+ reset(dataContext);
|
|
|
310
|
+ return entity;
|
|
|
311
|
+ }
|
|
|
312
|
+
|
|
|
313
|
+ private boolean addFloatingObjectMaterials(ImportDataContext dataContext,
|
|
|
314
|
+ ResultSet resultSet,
|
|
|
315
|
+ String vesselActivityCode,
|
|
|
316
|
+ String objectTypeCode,
|
|
|
317
|
+ Set<String> observedSystemCodes,
|
|
|
318
|
+ FloatingObject entity,
|
|
|
319
|
+ boolean floatingObjectExistsInAvdth,
|
|
|
320
|
+ boolean buoyExistsInAvdth) throws SQLException {
|
|
|
321
|
+ boolean whenArriving = WHEN_ARRIVING_CODE.contains(vesselActivityCode);
|
|
|
322
|
+ boolean whenLeaving = WHEN_LEAVING_CODE.contains(vesselActivityCode);
|
|
|
323
|
+
|
|
278
|
324
|
// to add default material if there is a declared buoy and no object material created by ObservedSystem
|
|
279
|
325
|
boolean addDefaultObjectMaterialOnUnknownObjectType = true;
|
|
280
|
326
|
// should create a buoy from ObservedSystem
|
|
281
|
327
|
boolean addBuoyFromObservedSystem = false;
|
|
282
|
328
|
Set<String> objectMaterialUsed = new TreeSet<>();
|
|
|
329
|
+
|
|
|
330
|
+ if (floatingObjectExistsInAvdth) {
|
|
|
331
|
+ String dcpWeight = resultSet.getString(33);
|
|
|
332
|
+ if (dcpWeight != null) {
|
|
|
333
|
+ //FIXME Check if ok
|
|
|
334
|
+ entity.setComment(String.format("ACTIVITE.POIDS_ESTIM_DCP value from avdth: %s", dcpWeight));
|
|
|
335
|
+ }
|
|
|
336
|
+ Object dcpEcoCode = resultSet.getObject(29);
|
|
|
337
|
+ if (dcpEcoCode != null && Objects.equals(2, dcpEcoCode)) {
|
|
|
338
|
+ // add material 4-1 (Biodegradable materials)
|
|
|
339
|
+ addObjectMaterial(objectMaterialUsed, dataContext.getObjectMaterialBiodegradable(), whenArriving, whenLeaving, entity);
|
|
|
340
|
+ }
|
|
|
341
|
+ }
|
|
|
342
|
+
|
|
283
|
343
|
if (observedSystemCodes.contains("20")) {
|
|
284
|
344
|
// add ObjectMaterial FOB
|
|
285
|
345
|
addObjectMaterial(objectMaterialUsed, dataContext.getObjectMaterialFOB(), whenArriving, whenLeaving, entity);
|
| ... |
... |
@@ -309,47 +369,52 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
|
309
|
369
|
addObjectMaterial(objectMaterialUsed, dataContext.getObjectMaterialAFAD(), whenArriving, whenLeaving, entity);
|
|
310
|
370
|
addDefaultObjectMaterialOnUnknownObjectType = false;
|
|
311
|
371
|
}
|
|
312
|
|
- if ("999".equals(objectTypeCode)) {
|
|
313
|
|
- if (willCreateBuoy && addDefaultObjectMaterialOnUnknownObjectType) {
|
|
314
|
|
- // add ObjectMaterial 2-2-4-4
|
|
315
|
|
- addObjectMaterial(objectMaterialUsed, dataContext.getObjectMaterialAlone(), whenArriving, whenLeaving, entity);
|
|
|
372
|
+ if (floatingObjectExistsInAvdth) {
|
|
|
373
|
+ // simple mapping
|
|
|
374
|
+ ObjectMaterial objectMaterial = getObjectMaterialByObjectTypeCode(dataContext, objectTypeCode);
|
|
|
375
|
+ if (objectMaterial != null) {
|
|
|
376
|
+ addObjectMaterial(objectMaterialUsed, objectMaterial, whenArriving, whenLeaving, entity);
|
|
316
|
377
|
}
|
|
317
|
378
|
} else {
|
|
318
|
|
- // simple mapping
|
|
319
|
|
- ObjectMaterial objectMaterial1 = dataContext.getObjectMaterialByObjectTypeCode(objectTypeCode);
|
|
320
|
|
- if (objectMaterial1 != null) {
|
|
321
|
|
- addObjectMaterial(objectMaterialUsed, objectMaterial1, whenArriving, whenLeaving, entity);
|
|
|
379
|
+ if (buoyExistsInAvdth && addDefaultObjectMaterialOnUnknownObjectType) {
|
|
|
380
|
+ // add ObjectMaterial 2-2-4-4
|
|
|
381
|
+ addObjectMaterial(objectMaterialUsed, dataContext.getObjectMaterialAlone(), whenArriving, whenLeaving, entity);
|
|
322
|
382
|
}
|
|
323
|
383
|
}
|
|
324
|
|
- if (willCreateBuoy) {
|
|
325
|
|
- // only add buoy if buoy type known
|
|
326
|
|
- TransmittingBuoyType transmittingBuoyType = dataContext.getTransmittingBuoyTypeByBuoyTypeCode(buoyTypeCode);
|
|
327
|
|
- TransmittingBuoyOperation transmittingBuoyOperation = dataContext.getTransmittingBuoyOperationByVesselActivityCode(vesselActivityCode);
|
|
328
|
|
- if (transmittingBuoyOperation != null) {
|
|
329
|
|
- TransmittingBuoy transmittingBuoy = newEntity(TransmittingBuoy.SPI, transmittingBuoyCount);
|
|
330
|
|
- transmittingBuoy.setTransmittingBuoyOperation(transmittingBuoyOperation);
|
|
331
|
|
- transmittingBuoy.setTransmittingBuoyType(transmittingBuoyType);
|
|
332
|
|
- transmittingBuoy.setCode(buoyId);
|
|
333
|
|
- if (addCoordinate) {
|
|
334
|
|
- transmittingBuoy.setLatitude(dataContext.getActivity().getLatitude());
|
|
335
|
|
- transmittingBuoy.setLongitude(dataContext.getActivity().getLongitude());
|
|
336
|
|
- }
|
|
337
|
|
- TransmittingBuoyOwnership transmittingBuoyOwnership = dataContext.getTransmittingBuoyOwnership(buoyOwnershipCode);
|
|
338
|
|
- transmittingBuoy.setTransmittingBuoyOwnership(transmittingBuoyOwnership);
|
|
339
|
|
- entity.addTransmittingBuoy(transmittingBuoy);
|
|
340
|
|
- }
|
|
341
|
|
- } else if (addBuoyFromObservedSystem) {
|
|
342
|
|
- // only add buoy if observed system ask for it (22 and 24)
|
|
343
|
|
- TransmittingBuoyType transmittingBuoyType = dataContext.getTransmittingBuoyType98();
|
|
344
|
|
- TransmittingBuoyOperation transmittingBuoyOperation = dataContext.getTransmittingBuoyOperation1();
|
|
|
384
|
+ return addBuoyFromObservedSystem;
|
|
|
385
|
+ }
|
|
|
386
|
+
|
|
|
387
|
+ private TransmittingBuoy getBuoyFromAvdthActivity(ImportDataContext dataContext, ResultSet resultSet, String buoyTypeCode, String vesselActivityCode, ObjectOperation objectOperation, Activity activity) throws SQLException {
|
|
|
388
|
+ boolean addCoordinate = "11".equals(objectOperation.getCode());
|
|
|
389
|
+ TransmittingBuoyType transmittingBuoyType = getTransmittingBuoyTypeByBuoyTypeCode(dataContext, buoyTypeCode);
|
|
|
390
|
+ TransmittingBuoyOperation transmittingBuoyOperation = getTransmittingBuoyOperationByVesselActivityCode(dataContext, vesselActivityCode);
|
|
|
391
|
+ if (transmittingBuoyOperation != null) {
|
|
|
392
|
+ String buoyOwnershipCode = resultSet.getString(30);
|
|
|
393
|
+ String buoyId = resultSet.getString(32);
|
|
345
|
394
|
TransmittingBuoy transmittingBuoy = newEntity(TransmittingBuoy.SPI, transmittingBuoyCount);
|
|
346
|
395
|
transmittingBuoy.setTransmittingBuoyOperation(transmittingBuoyOperation);
|
|
347
|
396
|
transmittingBuoy.setTransmittingBuoyType(transmittingBuoyType);
|
|
348
|
|
- transmittingBuoy.setCode(null);
|
|
349
|
|
- entity.addTransmittingBuoy(transmittingBuoy);
|
|
|
397
|
+ transmittingBuoy.setCode(buoyId);
|
|
|
398
|
+ if (addCoordinate) {
|
|
|
399
|
+ transmittingBuoy.setLatitude(activity.getLatitude());
|
|
|
400
|
+ transmittingBuoy.setLongitude(activity.getLongitude());
|
|
|
401
|
+ }
|
|
|
402
|
+ TransmittingBuoyOwnership transmittingBuoyOwnership = getTransmittingBuoyOwnership(dataContext, buoyOwnershipCode);
|
|
|
403
|
+ transmittingBuoy.setTransmittingBuoyOwnership(transmittingBuoyOwnership);
|
|
|
404
|
+ return transmittingBuoy;
|
|
350
|
405
|
}
|
|
351
|
|
- reset(dataContext);
|
|
352
|
|
- return entity;
|
|
|
406
|
+ return null;
|
|
|
407
|
+ }
|
|
|
408
|
+
|
|
|
409
|
+ private TransmittingBuoy getBuoyFromObservedSystem(ImportDataContext dataContext) {
|
|
|
410
|
+ // only add buoy if observed system ask for it (22 and 24)
|
|
|
411
|
+ TransmittingBuoyType transmittingBuoyType = dataContext.getTransmittingBuoyType98();
|
|
|
412
|
+ TransmittingBuoyOperation transmittingBuoyOperation = dataContext.getTransmittingBuoyOperation1();
|
|
|
413
|
+ TransmittingBuoy transmittingBuoy = newEntity(TransmittingBuoy.SPI, transmittingBuoyCount);
|
|
|
414
|
+ transmittingBuoy.setTransmittingBuoyOperation(transmittingBuoyOperation);
|
|
|
415
|
+ transmittingBuoy.setTransmittingBuoyType(transmittingBuoyType);
|
|
|
416
|
+ transmittingBuoy.setCode(null);
|
|
|
417
|
+ return transmittingBuoy;
|
|
353
|
418
|
}
|
|
354
|
419
|
|
|
355
|
420
|
private void reset(ImportDataContext dataContext) {
|
| ... |
... |
@@ -380,4 +445,74 @@ public class FloatingObjectReader extends DataReader<FloatingObject> { |
|
380
|
445
|
return floatingObjectPartCount.intValue();
|
|
381
|
446
|
}
|
|
382
|
447
|
|
|
|
448
|
+ private ObjectOperation getObjectOperationByVesselActivityCode(ImportDataContext dataContext, String vesselActivityCode) {
|
|
|
449
|
+ String objectOperationCode = DCP_OBJECT_OPERATION_CODE_MAPPING.get(vesselActivityCode);
|
|
|
450
|
+ return dataContext.getObjectOperation(Objects.requireNonNull(objectOperationCode, String.format("Can't find objectOperation with ACTIVITE.C_OPERA: %s", vesselActivityCode)));
|
|
|
451
|
+ }
|
|
|
452
|
+
|
|
|
453
|
+ private ObservedSystem getObservedSystem(ImportDataContext dataContext, String objectTypeCode, boolean floatingObjectExistsInAvdth,boolean buoyExistsInAvdth) {
|
|
|
454
|
+ if (!floatingObjectExistsInAvdth) {
|
|
|
455
|
+ if (!buoyExistsInAvdth) {
|
|
|
456
|
+ return dataContext.getObservedSystem0();
|
|
|
457
|
+ }
|
|
|
458
|
+ return dataContext.getObservedSystem20();
|
|
|
459
|
+ }
|
|
|
460
|
+ String observedSystemCode = OBSERVED_SYSTEM_CODE_MAPPING.get(objectTypeCode);
|
|
|
461
|
+ return dataContext.getObservedSystem(observedSystemCode, false);
|
|
|
462
|
+ }
|
|
|
463
|
+
|
|
|
464
|
+ private TransmittingBuoyOwnership getTransmittingBuoyOwnership(ImportDataContext dataContext, String buoyOwnershipCode) {
|
|
|
465
|
+ if (buoyOwnershipCode == null) {
|
|
|
466
|
+ return null;
|
|
|
467
|
+ }
|
|
|
468
|
+ String transmittingBuoyOwnershipCode = TRANSMITTING_BUOY_OWNERSHIP_CODE_MAPPING.get(buoyOwnershipCode);
|
|
|
469
|
+ if (transmittingBuoyOwnershipCode == null) {
|
|
|
470
|
+ return null;
|
|
|
471
|
+ }
|
|
|
472
|
+ return dataContext.getTransmittingBuoyOwnership(transmittingBuoyOwnershipCode);
|
|
|
473
|
+ }
|
|
|
474
|
+
|
|
|
475
|
+ private TransmittingBuoyOperation getTransmittingBuoyOperationByVesselActivityCode(ImportDataContext dataContext, String vesselActivityCode) {
|
|
|
476
|
+ String transmittingBuoyTypeCode = TRANSMITTING_BUOY_OPERATION_CODE_MAPPING.get(vesselActivityCode);
|
|
|
477
|
+ if (transmittingBuoyTypeCode == null) {
|
|
|
478
|
+ return null;
|
|
|
479
|
+ }
|
|
|
480
|
+ return dataContext.getTransmittingBuoyOperation(transmittingBuoyTypeCode);
|
|
|
481
|
+ }
|
|
|
482
|
+
|
|
|
483
|
+
|
|
|
484
|
+ private TransmittingBuoyType getTransmittingBuoyTypeByBuoyTypeCode(ImportDataContext dataContext, String buoyTypeCode) {
|
|
|
485
|
+ String transmittingBuoyTypeCode = TRANSMITTING_BUOY_TYPE_CODE_MAPPING.get(buoyTypeCode);
|
|
|
486
|
+ if (transmittingBuoyTypeCode == null) {
|
|
|
487
|
+ transmittingBuoyTypeCode = "999";
|
|
|
488
|
+ }
|
|
|
489
|
+ TransmittingBuoyType transmittingBuoyType = dataContext.getTransmittingBuoyType(transmittingBuoyTypeCode);
|
|
|
490
|
+ return Objects.requireNonNull(transmittingBuoyType, String.format("Can't find transmittingBuoyType with code: %s", buoyTypeCode));
|
|
|
491
|
+ }
|
|
|
492
|
+
|
|
|
493
|
+ /**
|
|
|
494
|
+ * To get objectMaterial id associated by a DCP from avdth ACTIVITE.C_TYP_OBJET code.
|
|
|
495
|
+ *
|
|
|
496
|
+ * @param objectTypeCode ACTIVITE.C_TYP_OBJET
|
|
|
497
|
+ * @return material or null
|
|
|
498
|
+ */
|
|
|
499
|
+ private ObjectMaterial getObjectMaterialByObjectTypeCode(ImportDataContext dataContext, String objectTypeCode) {
|
|
|
500
|
+ switch (objectTypeCode) {
|
|
|
501
|
+ case "1":
|
|
|
502
|
+ return dataContext.getObjectMaterialAFAD();
|
|
|
503
|
+ case "2":
|
|
|
504
|
+ return dataContext.getObjectMaterialDFAD();
|
|
|
505
|
+ case "3":
|
|
|
506
|
+ return dataContext.getObjectMaterialLOG();
|
|
|
507
|
+ case "9":
|
|
|
508
|
+ return dataContext.getObjectMaterialFOB();
|
|
|
509
|
+ case "10":
|
|
|
510
|
+ return dataContext.getObjectMaterialFALOG();
|
|
|
511
|
+ case "11":
|
|
|
512
|
+ return dataContext.getObjectMaterialHALOG();
|
|
|
513
|
+ case "13":
|
|
|
514
|
+ return dataContext.getObjectMaterialVNLOG();
|
|
|
515
|
+ }
|
|
|
516
|
+ return null;
|
|
|
517
|
+ }
|
|
383
|
518
|
} |