diff --git a/LIQUIBASE/changelog/db-changelog-master.xml b/LIQUIBASE/changelog/db-changelog-master.xml
index 027eed847..35897bb8f 100644
--- a/LIQUIBASE/changelog/db-changelog-master.xml
+++ b/LIQUIBASE/changelog/db-changelog-master.xml
@@ -58,4 +58,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml
index 6512be3e8..a6347d8e8 100644
--- a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4313.xml
@@ -23,4 +23,26 @@
-
\ No newline at end of file
+
+
+
+
+ rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0601')
+
+
+
+ rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0600')
+
+
+
+
+
+ rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0601')
+
+
+
+ rule_id=(select rule_id from rules."rule" where br_id='FA-L02-00-0600')
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4477.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4477.xml
new file mode 100644
index 000000000..cae3338c1
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4477.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ rule_id = '395'
+
+
+
+
+
+
+ rule_id = '395'
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4636.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4636.xml
new file mode 100644
index 000000000..487847185
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4636.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+ id = '171'
+
+
+
+
+ id = '219'
+
+
+
+
+
+
+
+ id = '171'
+
+
+
+
+ id = '219'
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml
new file mode 100644
index 000000000..7a8724037
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4660.xml
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+ template_id = 2000
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20001
+
+
+ br_id = 'MO-R01-00-0001'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20002
+
+
+ br_id = 'MO-R01-00-0002'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id = 20003
+
+
+ br_id = 'MO-R01-00-0003'
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4685.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4685.xml
new file mode 100644
index 000000000..e020a6c1d
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4685.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ id = '146'
+
+
+
+
+
+ id = '146'
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-correction.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-correction.xml
new file mode 100644
index 000000000..30b9b928b
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-correction.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+ rule_id=61
+
+
+
+
+ rule_id=66
+
+
+
+
+ rule_id=339
+
+
+
+ rule_id=339
+
+
+
+
+ rule_id=340
+
+
+
+ rule_id=340
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-revert.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-revert.xml
new file mode 100644
index 000000000..678559725
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792-revert.xml
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792.xml
new file mode 100644
index 000000000..5e289db56
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4792.xml
@@ -0,0 +1,157 @@
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793-patch_V1.0.xml
new file mode 100644
index 000000000..ecd1556b0
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793-patch_V1.0.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+ id = '632'
+
+
+
+
+ id = '634'
+
+
+
+
+ id = '635'
+
+
+
+
+ id = '637'
+
+
+
+
+
+
+ id = '632'
+
+
+
+
+ id = '634'
+
+
+
+
+ id = '635'
+
+
+
+
+ id = '637'
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml
new file mode 100644
index 000000000..3f2dfb21a
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4793.xml
@@ -0,0 +1,288 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4794.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4794.xml
new file mode 100644
index 000000000..3e0f7dbc6
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4794.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+ br_id = 'FA-L03-00-0038'
+
+
+
+
+
+ br_id = 'FA-L03-00-0038'
+
+
+
+
+
+
+
+ br_id = 'FA-L02-00-0366'
+
+
+
+
+
+ br_id = 'FA-L02-00-0366'
+
+
+
+
+
+
+
+ br_id = 'FA-L02-00-0374'
+
+
+
+
+
+ br_id = 'FA-L02-00-0374'
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.0.xml
new file mode 100644
index 000000000..634e78c26
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.0.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+ br_id = 'FA-L00-00-0621'
+
+
+
+
+ id = '620'
+
+
+
+
+ id = '621'
+
+
+
+
+
+ br_id = 'FA-L00-00-0621'
+
+
+
+
+ id = '620'
+
+
+
+
+ id = '621'
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.1.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.1.xml
new file mode 100644
index 000000000..4c761b48b
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795-patch_V1.1.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ id = '620'
+
+
+
+
+
+ id = '620'
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795.xml
new file mode 100644
index 000000000..62179bed4
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4795.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4796.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4796.xml
new file mode 100644
index 000000000..eb618d9e3
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4796.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4797.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4797.xml
new file mode 100644
index 000000000..6ad31c7c2
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4797.xml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.0.xml
new file mode 100644
index 000000000..20fe20da6
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.0.xml
@@ -0,0 +1,89 @@
+
+
+
+
+
+
+
+ br_id = 'FA-L02-00-0656'
+
+
+
+
+ br_id = 'FA-L02-00-0657'
+
+
+
+
+
+ br_id = 'FA-L02-00-0658'
+
+
+
+
+
+ br_id = 'FA-L02-00-0659'
+
+
+
+
+ br_id = 'FA-L02-00-0660'
+
+
+
+
+
+ id = '660'
+
+
+
+
+ id = '666'
+
+
+
+
+
+
+
+
+ br_id = 'FA-L02-00-0656'
+
+
+
+
+ br_id = 'FA-L02-00-0657'
+
+
+
+
+
+ br_id = 'FA-L02-00-0658'
+
+
+
+
+
+ br_id = 'FA-L02-00-0659'
+
+
+
+
+ br_id = 'FA-L02-00-0660'
+
+
+
+
+
+ id = '660'
+
+
+
+
+ id = '666'
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.1.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.1.xml
new file mode 100644
index 000000000..fb02d68fd
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.1.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+ br_id = 'FA-L02-00-0659'
+
+
+
+
+ id = '659'
+
+
+
+
+
+ br_id = 'FA-L02-00-0659'
+
+
+
+
+ id = '659'
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.2.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.2.xml
new file mode 100644
index 000000000..13d40a2f1
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.2.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+ br_id = 'FA-L02-00-0660'
+
+
+
+
+ id = '660'
+
+
+
+
+
+ br_id = 'FA-L02-00-0660'
+
+
+
+
+ id = '660'
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.3.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.3.xml
new file mode 100644
index 000000000..b2fd3b55d
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798-patch_V1.3.xml
@@ -0,0 +1,141 @@
+
+
+
+
+
+
+
+
+ br_id = 'FA-L02-00-0656'
+
+
+
+
+ br_id = 'FA-L02-00-0657'
+
+
+
+
+ br_id = 'FA-L02-00-0658'
+
+
+
+
+ br_id = 'FA-L02-00-0662'
+
+
+
+
+ br_id = 'FA-L02-00-0663'
+
+
+
+
+ br_id = 'FA-L02-00-0664'
+
+
+
+
+
+
+
+
+ id = '656'
+
+
+
+
+ id = '657'
+
+
+
+
+ id = '658'
+
+
+
+
+ id = '662'
+
+
+
+
+ id = '663'
+
+
+
+
+ id = '664'
+
+
+
+
+
+
+
+
+
+
+ br_id = 'FA-L02-00-0656'
+
+
+
+
+ br_id = 'FA-L02-00-0657'
+
+
+
+
+ br_id = 'FA-L02-00-0658'
+
+
+
+
+ br_id = 'FA-L02-00-0662'
+
+
+
+
+ br_id = 'FA-L02-00-0663'
+
+
+
+
+ br_id = 'FA-L02-00-0664'
+
+
+
+
+
+
+
+ id = '656'
+
+
+
+
+ id = '657'
+
+
+
+
+ id = '658'
+
+
+
+
+ id = '662'
+
+
+
+
+ id = '663'
+
+
+
+
+ id = '664'
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml
new file mode 100644
index 000000000..3a4644845
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4798.xml
@@ -0,0 +1,376 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799-patch_V1.0.xml
new file mode 100644
index 000000000..1b3d475d7
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799-patch_V1.0.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+ id = '642'
+
+
+
+
+ id = '642'
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799.xml
new file mode 100644
index 000000000..28a49749f
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4799.xml
@@ -0,0 +1,146 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4800.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4800.xml
new file mode 100644
index 000000000..2128b8851
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4800.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4801.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4801.xml
new file mode 100644
index 000000000..2ef695fdb
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4801.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.0.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.0.xml
new file mode 100644
index 000000000..61aa1726d
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.0.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.1.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.1.xml
new file mode 100644
index 000000000..13d10da2b
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802-patch_V1.1.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802.xml
new file mode 100644
index 000000000..287c92fa7
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4802.xml
@@ -0,0 +1,135 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+ id=:value
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4803.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4803.xml
new file mode 100644
index 000000000..b3d5ea903
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4803.xml
@@ -0,0 +1,119 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+ template_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4804.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4804.xml
new file mode 100644
index 000000000..e63189407
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4804.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4806.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4806.xml
new file mode 100644
index 000000000..7bc6bdf0a
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4806.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4807.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4807.xml
new file mode 100644
index 000000000..d971ff137
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-4807.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+ rule_id=:value
+
+
+
+
+
+ br_id=:value
+
+
+
+
+
+
+
diff --git a/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-incorrect-triggered-rules.xml b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-incorrect-triggered-rules.xml
new file mode 100644
index 000000000..9dd2e8ca0
--- /dev/null
+++ b/LIQUIBASE/changelog/v3.4/db-changelog-UNIONVMS-incorrect-triggered-rules.xml
@@ -0,0 +1,111 @@
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
+
+ id=:value
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java
index f11c900f5..b32970cf0 100644
--- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/bean/RulesDomainModelBean.java
@@ -31,6 +31,8 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.uvms.rules.entity.*;
import eu.europa.ec.fisheries.uvms.rules.exception.DaoException;
import eu.europa.ec.fisheries.uvms.rules.exception.DaoMappingException;
+import eu.europa.ec.fisheries.uvms.rules.exception.DaoMappingRuntimeException;
+import eu.europa.ec.fisheries.uvms.rules.exception.DaoRuntimeException;
import eu.europa.ec.fisheries.uvms.rules.exception.InputArgumentException;
import eu.europa.ec.fisheries.uvms.rules.mapper.*;
import eu.europa.ec.fisheries.uvms.rules.mapper.search.*;
@@ -47,6 +49,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
@Stateless
public class RulesDomainModelBean implements RulesDomainModel {
@@ -782,10 +785,7 @@ public long getNumberOfOpenTickets(String userName) throws RulesModelException {
LOG.info("[INFO] Counting open tickets");
try {
List validRuleGuids = rulesDao.getCustomRulesForTicketsByUser(userName);
- if (!validRuleGuids.isEmpty()) {
- return rulesDao.getNumberOfOpenTickets(validRuleGuids);
- }
- return 0;
+ return rulesDao.getNumberOfOpenTickets(validRuleGuids);
} catch (DaoException e) {
LOG.error("[ERROR] Error when counting open tickets {}", e.getMessage());
throw new RulesModelException(e.getMessage(), e);
@@ -811,18 +811,38 @@ public List getTicketsAndRulesByMovements(List moveme
// TODO: This can be done more efficiently with some join stuff
List tickets = rulesDao.getTicketsByMovements(movementGuids);
for (Ticket ticket : tickets) {
- CustomRule rule = rulesDao.getCustomRuleByGuid(ticket.getRuleGuid());
TicketType ticketType = TicketMapper.toTicketType(ticket);
- CustomRuleType ruleType = CustomRuleMapper.toCustomRuleType(rule);
TicketAndRuleType ticketsAndRule = new TicketAndRuleType();
ticketsAndRule.setTicket(ticketType);
- ticketsAndRule.setRule(ruleType);
+ Optional.ofNullable(ticket.getRuleGuid())
+ .map(this::getCustomRuleByGuid)
+ .map(this::toCustomRuleType)
+ .ifPresent(ticketsAndRule::setRule);
ticketsAndRules.add(ticketsAndRule);
}
return ticketsAndRules;
} catch (DaoException | DaoMappingException e) {
- LOG.error("[ERROR] Error when getting list {}", e.getMessage());
throw new RulesModelException("[ERROR] Error when getting list.", e);
+ } catch (DaoRuntimeException dre) {
+ throw new RulesModelException("[ERROR] Error when getting list.", dre.unwrap());
+ } catch (DaoMappingRuntimeException dmre) {
+ throw new RulesModelException("[ERROR] Error when getting list.", dmre.unwrap());
+ }
+ }
+
+ private CustomRule getCustomRuleByGuid(String id) {
+ try {
+ return rulesDao.getCustomRuleByGuid(id);
+ } catch (DaoException e) {
+ throw new DaoRuntimeException("", e);
+ }
+ }
+
+ private CustomRuleType toCustomRuleType(CustomRule customRuleEntity) {
+ try {
+ return CustomRuleMapper.toCustomRuleType(customRuleEntity);
+ } catch (DaoMappingException e) {
+ throw new DaoMappingRuntimeException("", e);
}
}
-}
\ No newline at end of file
+}
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java
index a372419a0..ec6ddd2e2 100644
--- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/constant/UvmsConstants.java
@@ -18,6 +18,7 @@ public final class UvmsConstants {
public static final String FIND_ALARM_BY_GUID = "AlarmReport.findByGuid";
public static final String COUNT_OPEN_ALARMS = "AlarmReport.countOpenAlarms";
public static final String COUNT_OPEN_TICKETS = "AlarmReport.countOpenTickets";
+ public static final String COUNT_OPEN_TICKETS_NO_RULES = "AlarmReport.countOpenTicketsNoRules";
public static final String FIND_ALARM_REPORT_BY_ASSET_GUID_AND_RULE_GUID = "AlarmReport.findByAssetGuidRuleGuid";
public static final String GET_RUNNABLE_CUSTOM_RULES = "CustomRule.getValidCustomRule";
public static final String LIST_CUSTOM_RULES_BY_USER = "CustomRule.listCustomRules"; // rule engine
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java
index 104a59e3a..4480afe2d 100644
--- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dao/bean/RulesDaoBean.java
@@ -19,7 +19,6 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceException;
import javax.persistence.TransactionRequiredException;
import javax.persistence.TypedQuery;
import java.util.ArrayList;
@@ -131,10 +130,6 @@ public List getTicketsByMovements(List movements) throws DaoExce
TypedQuery query = em.createNamedQuery(UvmsConstants.FIND_TICKETS_BY_MOVEMENTS, Ticket.class);
query.setParameter("movements", movements);
return query.getResultList();
- } catch (NoResultException e) {
- // TODO: Return empty list???
- log.error("[ No tickets found for movements ]");
- throw new NoEntityFoundException("[ No tickets found for movements ]", e);
} catch (Exception e) {
log.error("[ERROR] when getting Ticket by movements. {}", e.getMessage());
throw new DaoException("[ERROR] when getting Ticket by movements. ", e);
@@ -160,8 +155,6 @@ public List getCustomRulesForTicketsByUser(String owner) throws DaoExcep
TypedQuery query = em.createNamedQuery(UvmsConstants.FIND_CUSTOM_RULE_GUID_FOR_TICKETS, String.class);
query.setParameter("owner", owner);
return query.getResultList();
- } catch (NoResultException e) {
- return new ArrayList<>();
} catch (Exception e) {
log.error("[ERROR] when getting Tickets by userName. {}", e.getMessage());
throw new DaoException("[ERROR] when getting Tickets by userName. ", e);
@@ -182,8 +175,13 @@ public long getNumberOfOpenAlarms() throws DaoException {
@Override
public long getNumberOfOpenTickets(List validRuleGuids) throws DaoException {
try {
- TypedQuery query = em.createNamedQuery(UvmsConstants.COUNT_OPEN_TICKETS, Long.class);
- query.setParameter("validRuleGuids", validRuleGuids);
+ TypedQuery query;
+ if (validRuleGuids.isEmpty()) {
+ query = em.createNamedQuery(UvmsConstants.COUNT_OPEN_TICKETS_NO_RULES, Long.class);
+ } else {
+ query = em.createNamedQuery(UvmsConstants.COUNT_OPEN_TICKETS, Long.class);
+ query.setParameter("validRuleGuids", validRuleGuids);
+ }
return query.getSingleResult();
} catch (NoResultException e) {
return 0;
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java
index 1de4ba834..f4fea5823 100644
--- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/dto/GearMatrix.java
@@ -225,17 +225,38 @@ private void fillNEAFCGearMetrix() {
private void fillGearMetrix() {
// Trawl nets
+ matrix.put("TBB", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", false),
+ new Condition("GN", false))
+ );
matrix.put("OTB", Arrays.asList(
new Condition("ME", false),
new Condition("GM", true),
new Condition("MT", true))
);
- matrix.put("TBN", Arrays.asList(
+ matrix.put("OT", Arrays.asList(
new Condition("ME", false),
new Condition("GM", true),
new Condition("MT", true))
);
- matrix.put("TBS", Arrays.asList(
+ matrix.put("OTT", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", true),
+ new Condition("GN", false),
+ new Condition("MT", true))
+ );
+ matrix.put("OTP", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", true),
+ new Condition("MT", true))
+ );
+ matrix.put("PTB", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", true),
+ new Condition("MT", true))
+ );
+ matrix.put("PT", Arrays.asList(
new Condition("ME", false),
new Condition("GM", true),
new Condition("MT", true))
@@ -245,18 +266,22 @@ private void fillGearMetrix() {
new Condition("GM", true),
new Condition("MT", true))
);
- matrix.put("TBB", Arrays.asList(
+ matrix.put("TBN", Arrays.asList(
new Condition("ME", false),
- new Condition("GM", false),
- new Condition("GN", false))
+ new Condition("GM", true),
+ new Condition("MT", true))
);
- matrix.put("OTT", Arrays.asList(
+ matrix.put("TBS", Arrays.asList(
new Condition("ME", false),
new Condition("GM", true),
- new Condition("GN", false),
new Condition("MT", true))
);
- matrix.put("PTB", Arrays.asList(
+ matrix.put("PUK", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", false),
+ new Condition("GN", false))
+ );
+ matrix.put("PUL", Arrays.asList(
new Condition("ME", false),
new Condition("GM", true),
new Condition("MT", true))
@@ -269,6 +294,21 @@ private void fillGearMetrix() {
new Condition("ME", false),
new Condition("MT", false))
);
+ matrix.put("TM", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("MT", false))
+ );
+ matrix.put("TMS", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("MT", false))
+ );
+ matrix.put("TSP", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("MT", false))
+ );
+ matrix.put("TX", Arrays.asList(
+ new Condition("ME", false))
+ );
// Seine nets
matrix.put("SDN", Arrays.asList(
@@ -291,6 +331,10 @@ private void fillGearMetrix() {
new Condition("ME", false),
new Condition("GM", false))
);
+ matrix.put("SB", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", false))
+ );
// Surrounding nets
matrix.put("PS", Arrays.asList(
@@ -313,6 +357,11 @@ private void fillGearMetrix() {
new Condition("GM", false),
new Condition("HE", false))
);
+ matrix.put("SUX", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", false),
+ new Condition("HE", false))
+ );
// Dredges
matrix.put("DRB", Arrays.asList(
@@ -369,12 +418,27 @@ private void fillGearMetrix() {
new Condition("NN", false),
new Condition("QG", true))
);
+ matrix.put("GNF", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", false),
+ new Condition("HE", false),
+ new Condition("NL", false),
+ new Condition("NN", false),
+ new Condition("QG", true))
+ );
+ matrix.put("GEN", Arrays.asList(
+ new Condition("ME", false),
+ new Condition("GM", false),
+ new Condition("HE", false),
+ new Condition("NL", false),
+ new Condition("NN", false),
+ new Condition("QG", true))
+ );
// Traps
matrix.put("FPO",
Collections.singletonList(new Condition("GN", false))
);
- matrix.put("FIX", Collections.emptyList());
// Hooks & Lines
matrix.put("LHP", Arrays.asList(
@@ -397,20 +461,6 @@ private void fillGearMetrix() {
new Condition("GN", false),
new Condition("NI", false))
);
- matrix.put("LTL", Collections.emptyList());
- matrix.put("LX", Collections.emptyList());
-
- // Harvesting machines
- matrix.put("HMD", Collections.emptyList());
-
- // Miscellaneous gear
- matrix.put("MIS", Collections.emptyList());
-
- // Recreational gear
- matrix.put("RG", Collections.emptyList());
-
- // Gear not known or not specified
- matrix.put("NK", Collections.emptyList());
}
@Data
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java
index 613001b11..a280e2d0b 100644
--- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/entity/Ticket.java
@@ -27,7 +27,8 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
@NamedQueries({
@NamedQuery(name = UvmsConstants.FIND_TICKET_BY_GUID, query = "SELECT t FROM Ticket t WHERE t.guid = :guid"),
@NamedQuery(name = UvmsConstants.FIND_TICKET_BY_ASSET_AND_RULE, query = "SELECT t FROM Ticket t WHERE t.assetGuid = :assetGuid and status <> 'CLOSED' and ruleGuid = :ruleGuid"),
- @NamedQuery(name = UvmsConstants.COUNT_OPEN_TICKETS, query = "SELECT count(t) FROM Ticket t where t.status = 'OPEN' AND t.ruleGuid IN :validRuleGuids"),
+ @NamedQuery(name = UvmsConstants.COUNT_OPEN_TICKETS, query = "SELECT count(t) FROM Ticket t where t.status = 'OPEN' AND (t.ruleGuid IN :validRuleGuids OR t.ruleGuid IS NULL)"),
+ @NamedQuery(name = UvmsConstants.COUNT_OPEN_TICKETS_NO_RULES, query = "SELECT count(t) FROM Ticket t where t.status = 'OPEN' AND t.ruleGuid IS NULL"),
@NamedQuery(name = UvmsConstants.FIND_TICKETS_BY_MOVEMENTS, query = "SELECT t FROM Ticket t where t.movementGuid IN :movements"),
@NamedQuery(name = UvmsConstants.COUNT_TICKETS_BY_MOVEMENTS, query = "SELECT count(t) FROM Ticket t where t.movementGuid IN :movements"),
@NamedQuery(name = UvmsConstants.COUNT_ASSETS_NOT_SENDING, query = "SELECT count(t) FROM Ticket t where t.ruleGuid = :ruleGuid")
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoMappingRuntimeException.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoMappingRuntimeException.java
new file mode 100644
index 000000000..fe74bf9f3
--- /dev/null
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoMappingRuntimeException.java
@@ -0,0 +1,14 @@
+package eu.europa.ec.fisheries.uvms.rules.exception;
+
+/**
+ * RuntimeException wrapper for the {@link DaoMappingException}
+ */
+public class DaoMappingRuntimeException extends RuntimeException {
+ public DaoMappingRuntimeException(String s, DaoMappingException throwable) {
+ super(s, throwable);
+ }
+
+ public DaoMappingException unwrap() {
+ return (DaoMappingException) getCause();
+ }
+}
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoRuntimeException.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoRuntimeException.java
new file mode 100644
index 000000000..c99051da0
--- /dev/null
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/exception/DaoRuntimeException.java
@@ -0,0 +1,14 @@
+package eu.europa.ec.fisheries.uvms.rules.exception;
+
+/**
+ * RuntimeException wrapper for a {@link DaoException}.
+ */
+public class DaoRuntimeException extends RuntimeException {
+ public DaoRuntimeException(String s, DaoException throwable) {
+ super(s, throwable);
+ }
+
+ public DaoException unwrap() {
+ return (DaoException) getCause();
+ }
+}
diff --git a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java
index f1ddd382d..1d4b53d83 100644
--- a/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java
+++ b/domain/src/main/java/eu/europa/ec/fisheries/uvms/rules/mapper/search/TicketSearchFieldMapper.java
@@ -21,7 +21,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
@@ -40,42 +40,13 @@ public class TicketSearchFieldMapper {
*/
public static String createSelectSearchSql(List searchFields, List validRuleGuids, boolean isDynamic) throws SearchMapperException {
StringBuilder selectBuffer = new StringBuilder();
- selectBuffer.append("SELECT ")
- .append(TicketSearchTables.TICKET.getTableAlias())
- .append(" FROM ")
- .append(TicketSearchTables.TICKET.getTableName())
- .append(" ")
- .append(TicketSearchTables.TICKET.getTableAlias())
- .append(" ");
- if (searchFields != null && !searchFields.isEmpty()) {
- selectBuffer.append(createSearchSql(searchFields, isDynamic));
-
- selectBuffer.append(" AND ");
- } else {
- selectBuffer.append(" WHERE ");
- }
- selectBuffer.append(TicketSearchTables.TICKET.getTableAlias())
- .append(".")
- .append(TicketSearchField.RULE_GUID.getFieldName());
-
- selectBuffer.append(" IN ( ");
- selectBuffer.append("'").append(UvmsConstants.ASSET_NOT_SENDING_RULE).append("'");
- for (String validRuleGuid : validRuleGuids) {
- selectBuffer.append(", ");
- selectBuffer.append("'").append(validRuleGuid).append("'");
- }
- selectBuffer.append(" )");
-
- selectBuffer
- .append(" ORDER BY ")
- .append(TicketSearchTables.TICKET.getTableAlias())
- .append(".")
- .append(TicketSearchField.FROM_DATE.getFieldName())
- .append(" DESC");
- LOG.info("[ SQL: ] {}", selectBuffer.toString());
- return selectBuffer.toString();
+ selectBuffer.append("SELECT {ticket_alias} ");
+ queryBody(selectBuffer,searchFields,validRuleGuids,isDynamic);
+ selectBuffer.append("ORDER BY {ticket_alias}.{from_date} DESC");
+ String query = replaceTemplates(selectBuffer);
+ LOG.info("[ SQL: ] {}", query);
+ return query;
}
-
/**
*
* Creates a JPQL count query based on the search fields. This is used for
@@ -88,33 +59,34 @@ public static String createSelectSearchSql(List searchFields,
*/
public static String createCountSearchSql(List searchFields, List validRuleGuids, boolean isDynamic) throws SearchMapperException {
StringBuilder countBuffer = new StringBuilder();
- countBuffer.append("SELECT COUNT(")
- .append(TicketSearchTables.TICKET.getTableAlias())
- .append(") FROM ")
- .append(TicketSearchTables.TICKET.getTableName())
- .append(" ")
- .append(TicketSearchTables.TICKET.getTableAlias())
- .append(" ");
+ countBuffer.append("SELECT COUNT({ticket_alias}) ");
+ queryBody(countBuffer,searchFields,validRuleGuids,isDynamic);
+ String query = replaceTemplates(countBuffer);
+ LOG.debug("[ COUNT SQL: ]{}", query);
+ return query;
+ }
+
+ private static void queryBody(StringBuilder buffer,List searchFields, List validRuleGuids, boolean isDynamic) throws SearchMapperException {
+ buffer.append("FROM {ticket_table} {ticket_alias} ");
if (searchFields != null && !searchFields.isEmpty()) {
- countBuffer.append(createSearchSql(searchFields, isDynamic));
- countBuffer.append(" AND ");
+ buffer.append(createSearchSql(searchFields, isDynamic));
+ buffer.append(" AND ");
} else {
- countBuffer.append(" WHERE ");
+ buffer.append(" WHERE ");
}
- countBuffer.append(TicketSearchTables.TICKET.getTableAlias())
- .append(".")
- .append(TicketSearchField.RULE_GUID.getFieldName());
-
- countBuffer.append(" IN ( ");
- countBuffer.append("'").append(UvmsConstants.ASSET_NOT_SENDING_RULE).append("'");
+ buffer.append("({ticket_alias}.{rule_guid} IN ('").append(UvmsConstants.ASSET_NOT_SENDING_RULE).append("'");
for (String validRuleGuid : validRuleGuids) {
- countBuffer.append(", ");
- countBuffer.append("'").append(validRuleGuid).append("'");
+ buffer.append(",'").append(validRuleGuid).append("'");
}
- countBuffer.append(" )");
+ buffer.append(" ) OR {ticket_alias}.{rule_guid} IS NULL) ");
+ }
- LOG.debug("[ COUNT SQL: ]{}", countBuffer.toString());
- return countBuffer.toString();
+ private static String replaceTemplates(StringBuilder buffer) {
+ return buffer.toString()
+ .replace("{ticket_table}",TicketSearchTables.TICKET.getTableName())
+ .replace("{ticket_alias}",TicketSearchTables.TICKET.getTableAlias())
+ .replace("{rule_guid}",TicketSearchField.RULE_GUID.getFieldName())
+ .replace("{from_date}",TicketSearchField.FROM_DATE.getFieldName());
}
/**
@@ -291,7 +263,7 @@ private static HashMap> combineSearch
if (values.containsKey(search.getField())) {
values.get(search.getField()).add(search);
} else {
- values.put(search.getField(), new ArrayList(Arrays.asList(search)));
+ values.put(search.getField(), new ArrayList<>(Collections.singletonList(search)));
}
}
return values;
diff --git a/message/pom.xml b/message/pom.xml
index 315b3b849..6c745c5d1 100755
--- a/message/pom.xml
+++ b/message/pom.xml
@@ -13,11 +13,6 @@
-
- fish.focus.uvms.maven
- uvms-pom-monitoring-deps
- pom
-
eu.europa.ec.fisheries.uvms.rules
rules-model
diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java
index 166b87b6d..f591b909a 100644
--- a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java
+++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/consumer/bean/RulesEventMessageConsumerBean.java
@@ -109,6 +109,18 @@ public class RulesEventMessageConsumerBean implements MessageListener {
@GetFLUXMDRSyncMessageResponseEvent
private Event getFluxMdrSynchMessageResponse;
+ @Inject
+ @SendFluxMovementReportEvent
+ private Event sendFluxMovementReportEvent;
+
+ @Inject
+ @CreateAlarmReceivedEvent
+ private Event createAlarmReceivedEvent;
+
+ @Inject
+ @CreateTicketsReceivedEvent
+ private Event createTicketsReceivedEvent;
+
@Inject
@ErrorEvent
private Event errorEvent;
@@ -167,6 +179,15 @@ public void onMessage(Message message) {
case GET_FLUX_MDR_SYNC_RESPONSE :
getFluxMdrSynchMessageResponse.fire(eventMessage);
break;
+ case SEND_FLUX_MOVEMENT_REPORT:
+ sendFluxMovementReportEvent.fire(eventMessage);
+ break;
+ case CREATE_ALARMS_REPORT_REQUEST :
+ createAlarmReceivedEvent.fire(eventMessage);
+ break;
+ case CREATE_TICKETS_REQUEST:
+ createTicketsReceivedEvent.fire(eventMessage);
+ break;
default:
LOG.error("[ Request method '{}' is not implemented ]", method.name());
errorEvent.fire(new EventMessage(textMessage, ModuleResponseMapper.createFaultMessage(FaultCode.RULES_MESSAGE, "Method not implemented:" + method.name())));
diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateAlarmReceivedEvent.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateAlarmReceivedEvent.java
new file mode 100644
index 000000000..4d8b03ab2
--- /dev/null
+++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateAlarmReceivedEvent.java
@@ -0,0 +1,25 @@
+/*
+Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries
+© European Union, 2015-2016.
+
+This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can
+redistribute it and/or modify it under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite is distributed in
+the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a
+copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.message.event;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
+public @interface CreateAlarmReceivedEvent {
+
+}
\ No newline at end of file
diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateTicketsReceivedEvent.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateTicketsReceivedEvent.java
new file mode 100644
index 000000000..6e532a037
--- /dev/null
+++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/CreateTicketsReceivedEvent.java
@@ -0,0 +1,25 @@
+/*
+Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries
+© European Union, 2015-2016.
+
+This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can
+redistribute it and/or modify it under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite is distributed in
+the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a
+copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.message.event;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
+public @interface CreateTicketsReceivedEvent {
+
+}
\ No newline at end of file
diff --git a/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/SendFluxMovementReportEvent.java b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/SendFluxMovementReportEvent.java
new file mode 100644
index 000000000..0755a6be9
--- /dev/null
+++ b/message/src/main/java/eu/europa/ec/fisheries/uvms/rules/message/event/SendFluxMovementReportEvent.java
@@ -0,0 +1,25 @@
+/*
+Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries
+© European Union, 2015-2016.
+
+This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can
+redistribute it and/or modify it under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite is distributed in
+the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a
+copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.message.event;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
+public @interface SendFluxMovementReportEvent {
+
+}
\ No newline at end of file
diff --git a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java
index a9e115296..9b3290612 100755
--- a/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java
+++ b/model/src/main/java/eu/europa/ec/fisheries/uvms/rules/model/mapper/RulesModuleRequestMapper.java
@@ -54,17 +54,17 @@ public static String createSetFLUXFAReportMessageRequest(PluginType type, String
SetFLUXFAReportMessageRequest request = new SetFLUXFAReportMessageRequest();
request.setMethod(RulesModuleMethod.SET_FLUX_FA_REPORT);
request.setRequest(fluxFAReportMessage);
- request.setType(type);
+ request.setPluginType(type);
populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, onValue);
return JAXBMarshaller.marshallJaxBObjectToString(request);
}
- public static String createSendFLUXFAReportMessageRequest(String fluxFAReportMessage, String username, String logId, String fluxDataFlow,
- String senderOrReceiver, String onValue, boolean isEmpty) throws RulesModelMapperException {
+ public static String createSendFLUXFAReportMessageRequest(String fluxFAReportMessage, String username, String logId, String fluxDataFlow, String senderOrReceiver, String onValue, boolean isEmpty) throws RulesModelMapperException {
SetFLUXFAReportMessageRequest request = new SetFLUXFAReportMessageRequest();
request.setMethod(RulesModuleMethod.SEND_FLUX_FA_REPORT);
request.setRequest(fluxFAReportMessage);
request.setIsEmptyReport(isEmpty);
+ request.setAd(senderOrReceiver);
populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, onValue);
return JAXBMarshaller.marshallJaxBObjectToString(request);
}
@@ -90,10 +90,22 @@ public static String createRcvFluxFaResponseMessageRequest(PluginType type, Stri
}
public static String createSendFaQueryMessageRequest(String faQueryMessageStr, String username, String logId, String fluxDataFlow,
- String senderOrReceiver) throws RulesModelMapperException {
+ String senderOrReceiver, String ad) throws RulesModelMapperException {
SetFaQueryMessageRequest request = new SetFaQueryMessageRequest();
request.setMethod(RulesModuleMethod.SEND_FLUX_FA_QUERY);
request.setRequest(faQueryMessageStr);
+ request.setAd(ad);
+ populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, null);
+ return JAXBMarshaller.marshallJaxBObjectToString(request);
+ }
+
+ public static String createSendFluxMovementReportMessageRequest(PluginType type, String forwardPositionMessageStr, String username, String logId, String fluxDataFlow,
+ String senderOrReceiver,String ad) throws RulesModelMapperException {
+ SendFLUXMovementReportRequest request = new SendFLUXMovementReportRequest();
+ request.setMethod(RulesModuleMethod.SEND_FLUX_MOVEMENT_REPORT);
+ request.setRequest(forwardPositionMessageStr);
+ request.setType(type);
+ request.setAd(ad);
populateCommonProperties(request, username, logId, fluxDataFlow, senderOrReceiver, null);
return JAXBMarshaller.marshallJaxBObjectToString(request);
}
diff --git a/model/src/main/resources/contract/Movement.xsd b/model/src/main/resources/contract/Movement.xsd
index 7a8b9feb0..45e3866a0 100755
--- a/model/src/main/resources/contract/Movement.xsd
+++ b/model/src/main/resources/contract/Movement.xsd
@@ -18,6 +18,7 @@
+
diff --git a/model/src/main/resources/contract/RulesModuleService.wsdl b/model/src/main/resources/contract/RulesModuleService.wsdl
index 8a1c52190..fcb9cd058 100755
--- a/model/src/main/resources/contract/RulesModuleService.wsdl
+++ b/model/src/main/resources/contract/RulesModuleService.wsdl
@@ -50,6 +50,8 @@
+
+
@@ -62,6 +64,8 @@
+
+
@@ -83,7 +87,7 @@
-
+
@@ -276,6 +280,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -365,13 +382,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/model/src/main/resources/contract/Template.xsd b/model/src/main/resources/contract/Template.xsd
index cfbb359f5..e99548f72 100755
--- a/model/src/main/resources/contract/Template.xsd
+++ b/model/src/main/resources/contract/Template.xsd
@@ -47,6 +47,7 @@
+
@@ -85,6 +86,8 @@
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 927bf9955..a0f6e7f26 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,12 +110,6 @@
hibernate-entitymanager
${hibernate.version}
-
- fish.focus.uvms.maven
- uvms-pom-monitoring-deps
- 1.21
- pom
-
fish.focus.uvms.maven
uvms-pom-test-deps
diff --git a/rest/pom.xml b/rest/pom.xml
index 9df014394..edd039a8d 100755
--- a/rest/pom.xml
+++ b/rest/pom.xml
@@ -55,11 +55,6 @@
-
- fish.focus.uvms.maven
- uvms-pom-monitoring-deps
- pom
-
eu.europa.ec.fisheries.uvms.commons
uvms-commons-notification
diff --git a/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java b/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java
index 607fa4237..79c57189c 100644
--- a/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java
+++ b/rest/src/main/java/eu/europa/ec/fisheries/uvms/rules/rest/service/AlarmRestResource.java
@@ -12,6 +12,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
package eu.europa.ec.fisheries.uvms.rules.rest.service;
import javax.ejb.EJB;
+import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
@@ -135,6 +136,11 @@ public ResponseDto reprocessAlarm(final List alarmGuidList) {
LOG.error("[ Error when reprocessing. ] {} ", e.getMessage());
return ErrorHandler.getFault(e);
}
+ catch (EJBException e) {
+ LOG.error("[ Error when reprocessing. ] {} ", e.getMessage());
+ Exception cause = e.getCausedByException();
+ return ErrorHandler.getFault(cause instanceof EJBException ? ((EJBException)cause).getCausedByException() : cause);
+ }
}
/**
diff --git a/rest/src/main/webapp/WEB-INF/web.xml b/rest/src/main/webapp/WEB-INF/web.xml
index 0c4f76442..581122cb5 100755
--- a/rest/src/main/webapp/WEB-INF/web.xml
+++ b/rest/src/main/webapp/WEB-INF/web.xml
@@ -7,41 +7,6 @@
Rules
-
- javamelody.datasources
- java:/jdbc/uvms_rules
-
-
- net.bull.javamelody.SessionListener
-
-
- javamelody
- net.bull.javamelody.MonitoringFilter
- true
-
- displayed-counters
- http,sql,ejb,error,log
-
-
- system-actions-enabled
- true
-
-
- storage-directory
- javamelody-rules
-
-
- datasources
- java:/jdbc/uvms_rules
-
-
-
- javamelody
- /*
- REQUEST
- ASYNC
-
-
AuthenticationFilter
eu.europa.ec.fisheries.uvms.rest.security.AuthenticationFilter
diff --git a/service/pom.xml b/service/pom.xml
index 9fa94f728..aedf78de6 100755
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -40,11 +40,6 @@
-
- fish.focus.uvms.maven
- uvms-pom-monitoring-deps
- pom
-
eu.europa.ec.fisheries.uvms.rules
rules-model
@@ -270,6 +265,12 @@
+
+
+ true
+ src/main/resources
+
+
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/JmsMovementClient.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/JmsMovementClient.java
new file mode 100644
index 000000000..01ab501bc
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/JmsMovementClient.java
@@ -0,0 +1,72 @@
+/*
+ Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020.
+
+ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.movement.communication;
+
+import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsRequest;
+import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsResponse;
+import eu.europa.ec.fisheries.uvms.commons.message.api.MessageException;
+import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException;
+import eu.europa.ec.fisheries.uvms.movement.model.mapper.JAXBMarshaller;
+import eu.europa.ec.fisheries.uvms.rules.message.consumer.bean.RulesResponseConsumerBean;
+import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesProducerBean;
+import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceTechnicalException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.jms.Queue;
+import javax.jms.TextMessage;
+
+/**
+ * JMS implementation of the {@link MovementClient}.
+ */
+@ApplicationScoped
+public class JmsMovementClient implements MovementClient {
+
+ private RulesProducerBean rulesProducerBean;
+ private RulesResponseConsumerBean rulesResponseConsumerBean;
+ private Queue movementQueue;
+
+ /**
+ * Injection constructor.
+ *
+ * @param rulesProducerBean The rules module producer bean
+ * @param rulesResponseConsumerBean The rules module consumer bean
+ * @param movementQueue The movement specific queue created by ManagedObjectsProducer
+ */
+ @Inject
+ public JmsMovementClient(RulesProducerBean rulesProducerBean, RulesResponseConsumerBean rulesResponseConsumerBean, @MovementQueue Queue movementQueue) {
+ this.rulesProducerBean = rulesProducerBean;
+ this.rulesResponseConsumerBean = rulesResponseConsumerBean;
+ this.movementQueue = movementQueue;
+ }
+
+ /**
+ * Constructor for frameworks.
+ */
+ @SuppressWarnings("unused")
+ JmsMovementClient() {
+ // NOOP
+ }
+
+ @Override
+ public FindRawMovementsResponse findRawMovements(FindRawMovementsRequest request) throws MovementModelException {
+ try {
+ String correlationId = rulesProducerBean.sendMessageToSpecificQueue(JAXBMarshaller.marshallJaxBObjectToString(request), movementQueue, rulesResponseConsumerBean.getDestination());
+ FindRawMovementsResponse response = null;
+ if (correlationId != null) {
+ TextMessage textMessage = rulesResponseConsumerBean.getMessage(correlationId, TextMessage.class);
+ response = JAXBMarshaller.unmarshallTextMessage(textMessage, FindRawMovementsResponse.class);
+ }
+ return response;
+ } catch (MessageException e) {
+ throw new RulesServiceTechnicalException("error while calling findRawMovements", e);
+ }
+ }
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/ManagedObjectsProducer.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/ManagedObjectsProducer.java
new file mode 100644
index 000000000..bd1e5ad8d
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/ManagedObjectsProducer.java
@@ -0,0 +1,33 @@
+/*
+ Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016.
+
+ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.movement.communication;
+
+import eu.europa.ec.fisheries.uvms.commons.message.api.MessageConstants;
+
+import javax.annotation.Resource;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.jms.Queue;
+
+/**
+ * Introduces various Movement-related application server objects into CDI.
+ */
+@Dependent
+class ManagedObjectsProducer {
+
+ @Resource(mappedName = "java:/" + MessageConstants.QUEUE_MODULE_MOVEMENT)
+ private Queue movementQueue;
+
+ @Produces @ApplicationScoped @MovementQueue
+ public Queue getMovementQueue() {
+ return movementQueue;
+ }
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementClient.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementClient.java
new file mode 100644
index 000000000..159a1e08d
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementClient.java
@@ -0,0 +1,28 @@
+/*
+ Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020.
+
+ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.movement.communication;
+
+import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsRequest;
+import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsResponse;
+import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException;
+
+/**
+ * Low-level client to interesting Movement module services.
+ */
+public interface MovementClient {
+
+ /**
+ * Call @{@code FIND_RAW_MOVEMENTS}
+ *
+ * @param request the movement module request
+ * @return The movement module response
+ */
+ FindRawMovementsResponse findRawMovements(FindRawMovementsRequest request) throws MovementModelException;
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementQueue.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementQueue.java
new file mode 100644
index 000000000..ad763f289
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementQueue.java
@@ -0,0 +1,25 @@
+/*
+ Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016.
+
+ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.movement.communication;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Qualifier for injecting the Movement queue.
+ */
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
+public @interface MovementQueue {
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSender.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSender.java
new file mode 100644
index 000000000..0aeb94868
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSender.java
@@ -0,0 +1,28 @@
+/*
+ Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016.
+
+ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.movement.communication;
+
+import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType;
+import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException;
+
+import java.util.List;
+
+/**
+ * Service for sending messages to Movement.
+ */
+public interface MovementSender {
+
+
+ /**
+ * @param guildList the guid list used to filter and fetch movements
+ * @return a list of {@code MovementBaseType}
+ */
+ List findRawMovements(List guildList) throws RulesServiceException;
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSenderImpl.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSenderImpl.java
new file mode 100644
index 000000000..d667c91f5
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/movement/communication/MovementSenderImpl.java
@@ -0,0 +1,62 @@
+/*
+ Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016.
+
+ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ */
+package eu.europa.ec.fisheries.uvms.rules.movement.communication;
+
+import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsRequest;
+import eu.europa.ec.fisheries.schema.movement.module.v1.FindRawMovementsResponse;
+import eu.europa.ec.fisheries.schema.movement.module.v1.MovementModuleMethod;
+import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType;
+import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException;
+import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import java.util.List;
+
+/**
+ * Implementation of {@link MovementSender}.
+ */
+@ApplicationScoped
+class MovementSenderImpl implements MovementSender {
+
+ private MovementClient movementClient;
+
+ /**
+ * Injection constructor
+ *
+ * @param movementClient The low-level client to the services of the activity module
+ */
+ @Inject
+ public MovementSenderImpl(MovementClient movementClient) {
+ this.movementClient = movementClient;
+ }
+
+ /**
+ * Constructor for frameworks.
+ */
+ @SuppressWarnings("unused")
+ MovementSenderImpl() {
+ // NOOP
+ }
+
+ @Override
+ public List findRawMovements(List guildList) throws RulesServiceException {
+ try {
+ FindRawMovementsRequest request = new FindRawMovementsRequest();
+ request.setMethod(MovementModuleMethod.FIND_RAW_MOVEMENTS);
+ request.getMovementGuids().addAll(guildList);
+ FindRawMovementsResponse response = null;
+ response = movementClient.findRawMovements(request);
+ return response != null ? response.getResponse() : null;
+ } catch (MovementModelException e) {
+ throw new RulesServiceException("error converting to movement model", e);
+ }
+ }
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java
index 11380db10..8f2424292 100755
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/EventService.java
@@ -66,4 +66,10 @@ public interface EventService {
void sendSalesResponseEvent(@Observes @SendSalesResponseEvent EventMessage message);
void getValidationResultsByRawGuid(@Observes @GetValidationResultsByRawGuid EventMessage message);
+
+ void sendFluxMovementReportEvent(@Observes @SendFluxMovementReportEvent EventMessage message);
+
+ void createAlarmReceivedEvent(@Observes @CreateAlarmReceivedEvent EventMessage message);
+
+ void createTicketsReceivedEvent(@Observes @CreateTicketsReceivedEvent EventMessage message);
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java
index bf9a17de0..84fa3c640 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/ContainerType.java
@@ -26,7 +26,7 @@ public enum ContainerType {
FactType.FA_RELOCATION, FactType.FA_DISCARD, FactType.FA_EXIT_FROM_SEA,
FactType.FA_NOTIFICATION_OF_ARRIVAL, FactType.FA_ARRIVAL, FactType.FA_LANDING,
FactType.FA_TRANSHIPMENT, FactType.FA_APPLIED_AAP_PROCESS, FactType.FA_NOTIFICATION_OF_TRANSHIPMENT_OR_RELOCATION,
- FactType.FA_DECLARATION_OF_TRANSHIPMENT_OR_RELOCATION, FactType.SIMPLE_ID_TYPE_FACT,
+ FactType.FA_DECLARATION_OF_TRANSHIPMENT_OR_RELOCATION,FactType.FA_FLAP_DOCUMENT, FactType.SIMPLE_ID_TYPE_FACT,
FactType.FA_VESSEL_POSITION_EVENT, FactType.FA_AAP_STOCK),
FA_QUERY("faQuery", "ec.europa.eu.faQuery", FactType.FA_QUERY,
@@ -45,7 +45,10 @@ public enum ContainerType {
FactType.SALES_FISHING_TRIP, FactType.SALES_FLUX_LOCATION, FactType.SALES_FLUX_GEOGRAPHICAL_COORDINATE,
FactType.SALES_STRUCTURED_ADDRESS, FactType.SALES_QUERY, FactType.SALES_FLUX_RESPONSE_DOCUMENT,
FactType.SALES_VALIDATION_RESULT_DOCUMENT, FactType.SALES_VALIDATION_QUALITY_ANALYSIS,FactType.SALES_REPORT_WRAPPER,
- FactType.SALES_AUCTION_SALE, FactType.SALES_FLUX_SALES_QUERY_MESSAGE, FactType.SALES_QUERY_PARAMETER, FactType.SALES_FLUX_SALES_RESPONSE_MESSAGE);
+ FactType.SALES_AUCTION_SALE, FactType.SALES_FLUX_SALES_QUERY_MESSAGE, FactType.SALES_QUERY_PARAMETER, FactType.SALES_FLUX_SALES_RESPONSE_MESSAGE),
+
+ MOVEMENTS("movement","ec.europa.eu.movement", FactType.MOVEMENT_REPORT_DOCUMENT
+ );
private final String packageName;
private final String containerName;
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java
index 925af43b4..5f9781245 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/PropertiesBean.java
@@ -34,6 +34,11 @@ public void startup() {
InputStream propsStream = PropertiesBean.class.getResourceAsStream("/logging.properties");
props = new Properties();
props.load(propsStream);
+ propsStream.close();
+
+ InputStream propsStream2 = PropertiesBean.class.getResourceAsStream("/app-version.properties");
+ props.load(propsStream2);
+ propsStream2.close();
} catch (IOException e) {
throw new EJBException("PropertiesBean initialization error", e);
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java
index 1e633180f..2d78f14e8 100755
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesConfigHelper.java
@@ -15,6 +15,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.uvms.rules.service.config.ParameterKey;
import javax.ejb.Stateless;
+import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
@@ -23,6 +24,11 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
@Stateless
public class RulesConfigHelper implements ConfigHelper {
+ public static final String MODULE_VERSION_PROPERTIES_KEY = "uvms.module.version";
+
+ @Inject
+ private PropertiesBean propertiesBean;
+
@PersistenceContext(unitName = "rules")
protected EntityManager em;
@@ -39,8 +45,13 @@ public List getAllParameterKeys() {
public String getModuleName() {
return "rules";
}
-
- @Override
+
+ @Override
+ public String getModuleVersion() {
+ return propertiesBean.getProperty(MODULE_VERSION_PROPERTIES_KEY);
+ }
+
+ @Override
public EntityManager getEntityManager() {
return em;
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java
index ea9d3ba8a..1470c24e4 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEngineBean.java
@@ -17,7 +17,14 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType;
import eu.europa.ec.fisheries.uvms.rules.service.business.fact.IdType;
-import eu.europa.ec.fisheries.uvms.rules.service.business.generator.*;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.AbstractGenerator;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.ActivityFaReportFactGenerator;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.ActivityQueryFactGenerator;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.ActivityResponseFactGenerator;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.MovementFactGenerator;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.SalesQueryFactGenerator;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.SalesReportFactGenerator;
+import eu.europa.ec.fisheries.uvms.rules.service.business.generator.SalesResponseFactGenerator;
import eu.europa.ec.fisheries.uvms.rules.service.business.helper.RuleApplicabilityChecker;
import eu.europa.ec.fisheries.uvms.rules.service.config.BusinessObjectType;
import eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType;
@@ -36,12 +43,19 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import static eu.europa.ec.fisheries.uvms.rules.service.business.MessageType.PULL;
import static eu.europa.ec.fisheries.uvms.rules.service.business.MessageType.PUSH;
-import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.*;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.RESPONSE_IDS;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.SENDER_RECEIVER;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.XML;
@Stateless
@Slf4j
@@ -67,6 +81,7 @@ public class RulesEngineBean {
private SalesResponseFactGenerator salesResponseFactGenerator;
+
private FaResponseFactMapper faResponseFactMapper;
@EJB
@@ -181,6 +196,22 @@ public Collection evaluate(BusinessObjectType businessObjectType,
return validateFacts(facts, initializer.getContainerByType(ContainerType.SALES), globals, extraValues);
}
+ else if (businessObjectType == BusinessObjectType.RECEIVING_MOVEMENT_MSG){
+ StopWatch stopWatch = StopWatch.createStarted();
+ AbstractGenerator generator = new MovementFactGenerator(PUSH);
+ generator.setBusinessObjectMessage(businessObject);
+ generator.setExtraValueMap(extraValues);
+
+ List facts = generator.generateAllFacts();
+ log.info("Flow Report, Generating the facts took: {} ms", stopWatch.getTime());
+ stopWatch.reset();
+ stopWatch.start();
+
+ Map globals = new HashMap<>();
+ globals.put("mdrService", mdrCacheRuleService);
+ globals.put("appliChecker", appliChecker);
+ return validateFacts(facts, initializer.getContainerByType(ContainerType.MOVEMENTS), globals, extraValues);
+ }
log.info(String.format("It took %s to evaluate the message.", stopwatch));
log.debug(String.format("%s fact instances holding in memory.", AbstractFact.getNumOfInstances()));
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java
index ae5a2afcc..006dc783c 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesEventServiceBean.java
@@ -35,6 +35,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFAResponseServiceBean;
import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFaQueryServiceBean;
import eu.europa.ec.fisheries.uvms.rules.service.bean.activity.RulesFaReportServiceBean;
+import eu.europa.ec.fisheries.uvms.rules.service.bean.alarms.AlarmsServiceBean;
import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MdrRulesMessageServiceBean;
import eu.europa.ec.fisheries.uvms.rules.service.bean.movement.RulesMovementProcessorBean;
import eu.europa.ec.fisheries.uvms.rules.service.bean.sales.SalesRulesMessageServiceBean;
@@ -86,6 +87,9 @@ public class RulesEventServiceBean implements EventService {
@EJB
private SalesRulesMessageServiceBean salesRulesMessageServiceBean;
+ @EJB
+ private AlarmsServiceBean alarmsServiceBean;
+
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void pingReceived(@Observes @PingReceivedEvent EventMessage eventMessage) {
@@ -312,6 +316,41 @@ public void getValidationResultsByRawGuid(@Observes @GetValidationResultsByRawGu
}
}
+ @Override
+ public void sendFluxMovementReportEvent(@Observes @SendFluxMovementReportEvent EventMessage message) {
+ log.info(" Received SendFluxMovementReportEvent..");
+ TextMessage jmsRequestMessage = message.getJmsMessage();
+ SendFLUXMovementReportRequest request = (SendFLUXMovementReportRequest) message.getRulesBaseRequest();
+ try {
+ rulesService.sendMovementReport(request, jmsRequestMessage.getJMSMessageID());
+ } catch (RulesServiceException | JMSException e) {
+ log.error(" Error when forwarding movement report {}", e.getMessage());
+ }
+ }
+
+ @Override
+ public void createAlarmReceivedEvent(@Observes @CreateAlarmReceivedEvent EventMessage message) {
+ log.info("Received event to create alarm..");
+ try {
+ CreateAlarmsReportRequest request = (CreateAlarmsReportRequest) message.getRulesBaseRequest();
+ alarmsServiceBean.createAlarmReport(request);
+ } catch (RulesServiceException e) {
+ log.error(" Error when creating creating alarm {}", e.getMessage());
+ }
+ }
+
+ @Override
+ public void createTicketsReceivedEvent(@Observes @CreateTicketsReceivedEvent EventMessage message) {
+ log.info("Received event to create tickets..");
+ try {
+ CreateTicketRequest request = (CreateTicketRequest) message.getRulesBaseRequest();
+ alarmsServiceBean.createTickets(request);
+ } catch (RulesServiceException e) {
+ log.error(" Error when creating creating alarm {}", e.getMessage());
+ }
+ }
+
+
@SuppressWarnings("unused")
private void sendAuditMessage(AuditObjectTypeEnum type, AuditOperationEnum operation, String affectedObject, String comment, String username) {
try {
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java
index 5dae11646..eef73df83 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/RulesKieContainerInitializer.java
@@ -60,6 +60,7 @@ public void init() {
List faTemplatesAndRules = getFaMessageRules(allTemplates);
List salesTemplatesAndRules = getSalesRules(allTemplates);
List faQueryTemplatesAndRules = getFaQueryRules(allTemplates);
+ List movementTemplatesAndRules = getMovementRules(allTemplates);
log.info("Initializing templates and rules for FA-Report facts. Nr. of Rules : {}", countRuleExpressions(faTemplatesAndRules));
KieContainer faReportContainer = createContainer(faTemplatesAndRules);
@@ -73,11 +74,16 @@ public void init() {
log.info("Initializing templates and rules for Sales facts. Nr. of Rules : {}", countRuleExpressions(salesTemplatesAndRules));
KieContainer salesContainer = createContainer(salesTemplatesAndRules);
+ log.info("Initializing templates and rules for Movement facts. Nr. of Rules : {}", countRuleExpressions(movementTemplatesAndRules));
+ KieContainer movementContainer = createContainer(movementTemplatesAndRules);
+
+
containers = new EnumMap<>(ContainerType.class);
containers.put(ContainerType.FA_REPORT, faReportContainer);
containers.put(ContainerType.FA_RESPONSE, faRespContainer);
containers.put(ContainerType.FA_QUERY, faQueryContainer);
containers.put(ContainerType.SALES, salesContainer);
+ containers.put(ContainerType.MOVEMENTS, movementContainer);
// To make sure that we have deployed all the templates!
if (!allTemplates.isEmpty()) {
@@ -214,6 +220,18 @@ private List getFaQueryRules(List allTem
return faQueryTemplates;
}
+ private List getMovementRules(List allTemplates) {
+ List movementTemplates = new ArrayList<>();
+ List factTypesList = ContainerType.MOVEMENTS.getFactTypesList();
+ for (TemplateRuleMapDto actualTemplate : allTemplates) {
+ if (factTypesList.contains(actualTemplate.getTemplateType().getType())) {
+ movementTemplates.add(actualTemplate);
+ }
+ }
+ allTemplates.removeAll(movementTemplates);
+ return movementTemplates;
+ }
+
public KieContainer getContainerByType(ContainerType containerType) {
return containers.get(containerType);
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java
index bf2097ae0..88ebc84f6 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaQueryServiceBean.java
@@ -116,12 +116,15 @@ public void evaluateIncomingFAQuery(SetFaQueryMessageRequest request) {
log.info("Evaluate FAQuery with ID {}", faQueryGUID);
boolean needToSendToExchange = true;
Set idsFromIncomingMessage = fluxMessageHelper.mapQueryToFADocumentID(faQueryMessage);
+ rulesDaoBean.takeNoteOfDocumentIds(idsFromIncomingMessage);
+ rulesDaoBean.lockDocumentIds(idsFromIncomingMessage);
List faQueryIdsFromDb = rulesDaoBean.loadFADocumentIDByIdsByIds(idsFromIncomingMessage);
Map extraValues = new EnumMap<>(ExtraValueType.class);
extraValues.put(SENDER_RECEIVER, request.getSenderOrReceiver());
extraValues.put(XML, requestStr);
extraValues.put(DATA_FLOW, dataFlow);
+ extraValues.put(FA_QUERY_AND_REPORT_IDS, faQueryIdsFromDb);
Collection faQueryFacts = rulesEngine.evaluate(RECEIVING_FA_QUERY_MSG, faQueryMessage, extraValues, String.valueOf(faQueryMessage.getFAQuery().getID()));
@@ -208,7 +211,7 @@ public void evaluateOutgoingFAQuery(SetFaQueryMessageRequest request) {
if (faQueryValidationReport != null && !faQueryValidationReport.isError()) {
log.debug("The Validation of FaQueryMessage is successful, forwarding message to Exchange");
String exchangeReq = ExchangeModuleRequestMapper.createSendFaQueryMessageRequest(request.getRequest(),
- "movement", logGuid, request.getFluxDataFlow(), request.getSenderOrReceiver(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST");
+ "movement", logGuid, request.getFluxDataFlow(), request.getSenderOrReceiver(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", request.getAd() == null ? "IMPLEMENTTO_FROM_REQUEST" : request.getAd());
sendToExchange(exchangeReq);
} else {
log.debug("Validation resulted in errors. Not going to send msg to Exchange module..");
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java
index 3f090b701..f6841ca04 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/activity/RulesFaReportServiceBean.java
@@ -142,7 +142,7 @@ public void evaluateIncomingFLUXFAReport(SetFLUXFAReportMessageRequest request)
if (hasPermissions) {
rulesDaoBean.saveFaIdsPerTripList(faIdsPerTripsFromMessage);
log.debug(" Request has permissions. Going to send FaReportMessage to Activity Module...");
- sendRequestToActivity(requestStr, request.getType(), MessageType.FLUX_FA_REPORT_MESSAGE, exchangeLogGuid);
+ sendRequestToActivity(requestStr, request.getPluginType(), MessageType.FLUX_FA_REPORT_MESSAGE, exchangeLogGuid);
Set result = idsFromIncomingMessage.stream().filter(faDocumentID -> !FAUUIDType.FA_REPORT_REF_ID.equals(faDocumentID.getType()))
.collect(Collectors.toSet());
@@ -158,7 +158,7 @@ public void evaluateIncomingFLUXFAReport(SetFLUXFAReportMessageRequest request)
FLUXResponseMessage fluxResponseMessage = fluxMessageHelper.generateFluxResponseMessageForFaReport(faReportValidationResult, fluxfaReportMessage);
XPathRepository.INSTANCE.clear(faReportFacts);
- exchangeServiceBean.evaluateAndSendToExchange(fluxResponseMessage, request, request.getType(), fluxMessageHelper.isCorrectUUID(messageGUID), MDC.getCopyOfContextMap());
+ exchangeServiceBean.evaluateAndSendToExchange(fluxResponseMessage, request, request.getPluginType(), fluxMessageHelper.isCorrectUUID(messageGUID), MDC.getCopyOfContextMap());
} catch (UnmarshalException e) {
log.error(" Error while trying to parse FLUXFAReportMessage received message! It is malformed! Reason : {{}}", e.getMessage());
@@ -196,7 +196,7 @@ public void evaluateOutgoingFaReport(SetFLUXFAReportMessageRequest request) {
if (faReportValidationResult != null && !faReportValidationResult.isError()) {
log.info(" The Validation of FLUXFAReportMessage is successful, forwarding message to Exchange");
sendToExchange(ExchangeModuleRequestMapper.createSendFaReportMessageRequest(request.getRequest(), "movement", logGuid, request.getFluxDataFlow(),
- request.getSenderOrReceiver(), request.getOnValue(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST"));
+ request.getSenderOrReceiver(), request.getOnValue(), "IMPLEMENTTODT_FROM_REQUEST", "IMPLEMENTTO_FROM_REQUEST", request.getAd() == null ? "IMPLEMENTTO_FROM_REQUEST" : request.getAd()));
} else {
log.info(" Validation resulted in errors. Not going to send msg to Exchange module..");
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBean.java
new file mode 100644
index 000000000..066f47c39
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/AlarmsServiceBean.java
@@ -0,0 +1,154 @@
+/*
+ *
+ * Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020.
+ *
+ * This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ * the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ *
+ */
+
+package eu.europa.ec.fisheries.uvms.rules.service.bean.alarms;
+
+import eu.europa.ec.fisheries.remote.RulesDomainModel;
+import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType;
+import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmReportType;
+import eu.europa.ec.fisheries.schema.rules.alarm.v1.AlarmStatusType;
+import eu.europa.ec.fisheries.schema.rules.module.v1.CreateAlarmsReportRequest;
+import eu.europa.ec.fisheries.schema.rules.module.v1.CreateTicketRequest;
+import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType;
+import eu.europa.ec.fisheries.schema.rules.ticket.v1.TicketType;
+import eu.europa.ec.fisheries.uvms.audit.model.exception.AuditModelMarshallException;
+import eu.europa.ec.fisheries.uvms.audit.model.mapper.AuditLogMapper;
+import eu.europa.ec.fisheries.uvms.commons.message.api.MessageException;
+import eu.europa.ec.fisheries.uvms.commons.notifications.NotificationMessage;
+import eu.europa.ec.fisheries.uvms.rules.message.consumer.RulesResponseConsumer;
+import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.RulesAuditProducerBean;
+import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditObjectTypeEnum;
+import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditOperationEnum;
+import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelException;
+import eu.europa.ec.fisheries.uvms.rules.movement.communication.MovementSender;
+import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportCountEvent;
+import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportEvent;
+import eu.europa.ec.fisheries.uvms.rules.service.exception.InputArgumentException;
+import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.ejb.EJB;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static eu.europa.ec.fisheries.uvms.rules.service.bean.alarms.RawMovementTypeMapper.enrichRawMovement;
+
+@Stateless
+@LocalBean
+@Slf4j
+public class AlarmsServiceBean {
+
+ @Inject
+ @AlarmReportEvent
+ private Event alarmReportEvent;
+
+ @Inject
+ @AlarmReportCountEvent
+ private Event alarmReportCountEvent;
+
+ @EJB
+ private RulesAuditProducerBean auditProducer;
+
+ @EJB
+ private RulesResponseConsumer consumer;
+
+ @EJB
+ private RulesDomainModel rulesDomainModel;
+
+ @Inject
+ private MovementSender movementSender;
+
+ public void createTickets(CreateTicketRequest request) throws RulesServiceException {
+ List ticketTypes = request.getTickets();
+ for (TicketType ticketType : ticketTypes) {
+ try {
+ rulesDomainModel.createTicket(ticketType);
+ } catch (RulesModelException e) {
+ throw new RulesServiceException("Error creating ticket",e);
+ }
+ }
+ }
+
+ public List createAlarmReport(CreateAlarmsReportRequest request) throws RulesServiceException {
+ validateAndEnrichAlarmReportsWithMovementInfo(request.getAlarm());
+ List reportTypeList = new ArrayList<>();
+ for (AlarmReportType alarmReport : request.getAlarm()) {
+ reportTypeList.add(createAlarmReport(alarmReport));
+ }
+ return reportTypeList;
+ }
+
+ private AlarmReportType createAlarmReport(AlarmReportType alarmReport) {
+ AlarmReportType createdAlarmReport = null;
+ try {
+ alarmReport.setStatus(AlarmStatusType.OPEN);
+ alarmReport.setUpdatedBy(alarmReport.getUpdatedBy());
+ alarmReport.setPluginType(alarmReport.getPluginType());
+ alarmReport.setInactivatePosition(false);
+
+ createdAlarmReport = rulesDomainModel.createAlarmReport(alarmReport);
+ // Notify long-polling clients of the new alarm report
+ alarmReportEvent.fire(new NotificationMessage("guid", createdAlarmReport.getGuid()));
+ // Notify long-polling clients of the change (no value since FE will need to fetch it)
+ alarmReportCountEvent.fire(new NotificationMessage("alarmCount", null));
+ sendAuditMessage(AuditObjectTypeEnum.ALARM, AuditOperationEnum.CREATE, createdAlarmReport.getGuid(), null, alarmReport.getUpdatedBy());
+ } catch (RulesModelException e) {
+ log.error("[ Failed to create alarm! ] {}", e.getMessage());
+ }
+ return createdAlarmReport;
+ }
+
+ private void sendAuditMessage(AuditObjectTypeEnum type, AuditOperationEnum operation, String affectedObject, String comment, String username) {
+ try {
+ String message = AuditLogMapper.mapToAuditLog(type.getValue(), operation.getValue(), affectedObject, comment, username);
+ auditProducer.sendModuleMessage(message, consumer.getDestination());
+ }
+ catch (AuditModelMarshallException | MessageException e) {
+ log.error("[ Error when sending message to Audit. ] {}", e.getMessage());
+ }
+ }
+
+ private void validateAndEnrichAlarmReportsWithMovementInfo(List alarmReports){
+ Map existingGuidListMap = alarmReports.stream()
+ .map(this::validateAndGetRowMovement)
+ .filter(not(RawMovementType::isGuidGenerated))
+ .collect(Collectors.toMap(RawMovementType::getGuid, Function.identity()));
+ if(existingGuidListMap.isEmpty()) return;
+
+ List movementBaseTypes = movementSender.findRawMovements(new ArrayList<>(existingGuidListMap.keySet()));
+ if(movementBaseTypes == null || movementBaseTypes.isEmpty()) return;
+
+ movementBaseTypes.forEach(mb -> enrichRawMovement(existingGuidListMap.get(mb.getGuid()),mb));
+ }
+
+ private RawMovementType validateAndGetRowMovement(AlarmReportType alarmReportType){
+ validate(alarmReportType);
+ return alarmReportType.getRawMovement();
+ }
+
+ private void validate(AlarmReportType alarmReportType) throws RulesServiceException {
+ if(alarmReportType == null) throw new InputArgumentException("AlarmReportType cannot be null");
+ if(alarmReportType.getAlarmItem().isEmpty()) throw new InputArgumentException("AlarmItem list was empty");
+ }
+
+ private static Predicate not(Predicate t) {
+ return t.negate();
+ }
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/RawMovementTypeMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/RawMovementTypeMapper.java
new file mode 100644
index 000000000..0299aeb48
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/alarms/RawMovementTypeMapper.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2020.
+ *
+ * This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+ * the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+ *
+ */
+
+package eu.europa.ec.fisheries.uvms.rules.service.bean.alarms;
+
+import eu.europa.ec.fisheries.schema.movement.v1.MovementBaseType;
+import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType;
+
+public class RawMovementTypeMapper {
+ public static void enrichRawMovement(RawMovementType rawMovementType, MovementBaseType movementBaseType) {
+ if(movementBaseType.getActivity() != null){
+ rawMovementType.setActivity(toActivityType(movementBaseType.getActivity()));
+ }
+ rawMovementType.setPosition(toPoint(movementBaseType.getPosition()));
+ rawMovementType.setPositionTime(movementBaseType.getPositionTime());
+ rawMovementType.setReportedCourse(movementBaseType.getReportedCourse());
+ rawMovementType.setReportedSpeed(movementBaseType.getReportedSpeed());
+ if(movementBaseType.getSource() != null){
+ rawMovementType.setSource(eu.europa.ec.fisheries.schema.rules.movement.v1.MovementSourceType.valueOf(movementBaseType.getSource().name()));
+ }
+ if(movementBaseType.getMovementType() != null){
+ rawMovementType.setMovementType(eu.europa.ec.fisheries.schema.rules.movement.v1.MovementTypeType.valueOf(movementBaseType.getMovementType().name()));
+ }
+ rawMovementType.setTripNumber(movementBaseType.getTripNumber());
+ rawMovementType.setStatus(movementBaseType.getStatus());
+ }
+
+ static eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityType toActivityType(eu.europa.ec.fisheries.schema.movement.v1.MovementActivityType movementActivityType){
+ eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityType activityType = new eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityType();
+ activityType.setCallback(movementActivityType.getCallback());
+ activityType.setMessageId(movementActivityType.getMessageId());
+ if(movementActivityType.getMessageType() != null){
+ activityType.setMessageType(eu.europa.ec.fisheries.schema.rules.movement.v1.MovementActivityTypeType.valueOf(movementActivityType.getMessageType().name()));
+ }
+ return activityType;
+ }
+ static eu.europa.ec.fisheries.schema.rules.movement.v1.MovementPoint toPoint(eu.europa.ec.fisheries.schema.movement.v1.MovementPoint movementPoint){
+ eu.europa.ec.fisheries.schema.rules.movement.v1.MovementPoint point = new eu.europa.ec.fisheries.schema.rules.movement.v1.MovementPoint();
+ point.setAltitude(movementPoint.getAltitude());
+ point.setLatitude(movementPoint.getLatitude());
+ point.setLongitude(movementPoint.getLongitude());
+ return point;
+ }
+
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java
index 790f72913..972466bec 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/asset/client/impl/AssetClientBean.java
@@ -66,8 +66,9 @@ public List findHistoryOfAssetBy(List
String ircs = ids.get("IRCS");
String extMark = ids.get("EXT_MARK");
String iccat = ids.get("ICCAT");
- log.debug("Find history of asset by reportDate: {}, cfr: {}, regCountry: {}, ircs: {}, extMark: {}, iccat: {} ", reportDate, cfr, regCountry, ircs, extMark, iccat);
- List assets = iAssetFacade.findHistoryOfAssetBy(reportDate, cfr, regCountry, ircs, extMark, iccat);
+ String uvi = ids.get("UVI");
+ log.debug("Find history of asset by reportDate: {}, cfr: {}, regCountry: {}, ircs: {}, extMark: {}, uvi: {}", reportDate, cfr, regCountry, ircs, extMark, iccat,uvi);
+ List assets = iAssetFacade.findHistoryOfAssetBy(reportDate, cfr, regCountry, ircs, extMark, iccat,uvi);
if (CollectionUtils.isNotEmpty(assets)) {
vesselTransportMeansDto.setAsset(assets.get(0));
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java
index 50e07d7c0..ef7132936 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/FLUXVesselPositionMapper.java
@@ -36,20 +36,17 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
@Slf4j
public class FLUXVesselPositionMapper {
private static final String ASSET_EXT_MARKING_CODE = "EXT_MARKING";
+ public static final String ASSET_EXT_MARK = "EXT_MARK";
private static final String ASSET_IRCS_CODE = "IRCS";
private static final String ASSET_UVI_CODE = "UVI";
private static final String ASSET_CFR_CODE = "CFR";
- private static final String MOVEMENTTYPE_POS = "POS";
- private static final String MOVEMENTTYPE_EXI = "EXI";
- private static final String MOVEMENTTYPE_ENT = "ENT";
- private static final String MOVEMENTTYPE_MAN = "MAN";
-
/**
* The transformations happening in the
* 1. Plugin From FLUXVesselPositionMessage to List
@@ -62,11 +59,11 @@ public class FLUXVesselPositionMapper {
* @param registerClassName
* @return
*/
- public static List mapToRawMovementTypes(FLUXVesselPositionMessage fluxVesselPositionMessage, String registerClassName, String pluginType) {
+ public static List mapToRawMovementTypes(FLUXVesselPositionMessage fluxVesselPositionMessage, String registerClassName, String pluginType, Map mapToMovementType) {
VesselTransportMeansType positionReport = fluxVesselPositionMessage.getVesselTransportMeans();
List rowMovements = new ArrayList<>();
for (VesselPositionEventType col : positionReport.getSpecifiedVesselPositionEvents()) {
- MovementBaseType baseMovement = mapResponse(col, positionReport,pluginType);
+ MovementBaseType baseMovement = mapResponse(col, positionReport,pluginType ,mapToMovementType);
RawMovementType rawMovement = MovementMapper.getInstance().getMapper().map(baseMovement, RawMovementType.class);
final eu.europa.ec.fisheries.schema.rules.asset.v1.AssetId assetId = rawMovement.getAssetId();
if (assetId != null && assetId.getAssetIdList() != null) {
@@ -83,13 +80,13 @@ public static List mapToRawMovementTypes(FLUXVesselPositionMess
return rowMovements;
}
- private static MovementBaseType mapResponse(VesselPositionEventType response, VesselTransportMeansType report, String pluginType) {
+ private static MovementBaseType mapResponse(VesselPositionEventType response, VesselTransportMeansType report, String pluginType, Map mapToMovementType) {
MovementBaseType movement = new MovementBaseType();
HashMap extractAssetIds = extractAssetIds(report.getIDS());
movement.setAssetId(mapToAssetId(extractAssetIds));
movement.setExternalMarking(extractAssetIds.get(ASSET_EXT_MARKING_CODE));
movement.setIrcs(extractAssetIds.get(ASSET_IRCS_CODE));
- movement.setMovementType(mapToMovementTypeFromPositionType(movement, response.getTypeCode()));
+ movement.setMovementType(mapToMovementTypeFromPositionType(response.getTypeCode(),mapToMovementType));
setFlagState(movement, report.getRegistrationVesselCountry());
movement.setPosition(mapToMovementPoint(response.getSpecifiedVesselGeographicalCoordinate()));
if (response.getObtainedOccurrenceDateTime() != null) {
@@ -125,31 +122,8 @@ private static void setCourseAndSpeed(VesselPositionEventType response, Movement
}
}
- private static MovementTypeType mapToMovementTypeFromPositionType(MovementBaseType movement, CodeType vessPosTypeCode) {
- MovementTypeType movType;
- if (vessPosTypeCode != null) {
- switch (vessPosTypeCode.getValue()) {
- case MOVEMENTTYPE_POS:
- movType = MovementTypeType.POS;
- break;
- case MOVEMENTTYPE_EXI:
- movType = MovementTypeType.EXI;
- break;
- case MOVEMENTTYPE_ENT:
- movType = MovementTypeType.ENT;
- break;
- case MOVEMENTTYPE_MAN:
- movType = MovementTypeType.MAN;
- break;
- default:
- movType = null;
- log.error("[ERROR] Movement type couldn't be mapped", vessPosTypeCode.getValue());
- }
- } else {
- movType = MovementTypeType.POS;
- log.error("[ERROR] Couldn't map to movementType, vessPosTypeCode was null!");
- }
- return movType;
+ private static MovementTypeType mapToMovementTypeFromPositionType(CodeType vessPosTypeCode, Map mapToMovementType) {
+ return Optional.ofNullable(vessPosTypeCode).map(CodeType::getValue).map(mapToMovementType::get).orElse(null);
}
private static MovementPoint mapToMovementPoint(VesselGeographicalCoordinateType coordinate) {
@@ -202,6 +176,9 @@ private static AssetId mapToAssetId(Map vesselIds) {
case ASSET_UVI_CODE:
assetIdList.add(mapToVesselId(AssetIdType.IMO, vesselId.getValue()));
break;
+ case ASSET_EXT_MARK:
+ case ASSET_EXT_MARKING_CODE:
+ break;
default:
log.error("VesselId type not mapped {}", vesselId.getKey());
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java
index 8a9ef2f8f..2d2c3d3a5 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementValidationServiceBean.java
@@ -574,11 +574,10 @@ public long getNumberOfOpenAlarmReports() throws RulesServiceException, RulesFau
@Override
public long getNumberOfOpenTickets(String userName) throws RulesServiceException, RulesFaultException {
try {
- long numberOfOpenTickets = rulesDomainModel.getNumberOfOpenTickets(userName);
- return numberOfOpenTickets;
+ return rulesDomainModel.getNumberOfOpenTickets(userName);
} catch (RulesModelException e) {
LOG.error("[ Error when getting number of open tickets ] {}", e.getMessage());
- throw new RulesServiceException("[ Error when getting number of open alarms. ]");
+ throw new RulesServiceException("[ Error when getting number of open alarms. ]",e);
}
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java
index 345c4352a..9b1d45089 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/MovementsRulesValidator.java
@@ -11,7 +11,6 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
*/
package eu.europa.ec.fisheries.uvms.rules.service.bean.movement;
-import javax.annotation.PostConstruct;
import javax.ejb.*;
import java.io.InputStream;
import java.util.List;
@@ -24,9 +23,9 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.uvms.rules.service.business.CustomRuleDto;
import eu.europa.ec.fisheries.uvms.rules.service.business.MovementFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.RawMovementFact;
+import eu.europa.ec.fisheries.uvms.rules.service.business.fact.MovementReportDocumentFact;
import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException;
import eu.europa.ec.fisheries.uvms.rules.service.mapper.CustomRuleParser;
-import lombok.extern.slf4j.Slf4j;
import org.drools.template.parser.DefaultTemplateContainer;
import org.drools.template.parser.TemplateContainer;
import org.drools.template.parser.TemplateDataListener;
@@ -34,11 +33,15 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import org.kie.api.builder.KieFileSystem;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
-@Slf4j
public class MovementsRulesValidator {
+
+ private final static Logger log = LoggerFactory.getLogger(MovementsRulesValidator.class);
+
// private static final String SANITY_RESOURCE_DRL_FILE = "/rules/SanityRules.drl";
private static final String CUSTOM_RULE_DRL_FILE = "src/main/resources/rules/CustomRules.drl";
private static final String CUSTOM_RULE_TEMPLATE = "/templates/CustomRulesTemplate." +
@@ -170,7 +173,7 @@ public void evaluate(MovementFact fact) {
}
@Lock(LockType.READ)
- public void evaluate(List factList, boolean justToAvoidErasure) {
+ public void evaluate(List factList) {
log.info("Verifying user defined rules");
KieSession ksession = getKieSession();
// TODO : decomment as soon as the "Unexpected global [validationService]" is resolved
@@ -184,7 +187,7 @@ public void evaluate(List factList, boolean justToAvoidErasure) {
@Lock(LockType.READ)
- public void evaluate(List facts) {
+ public void evaluateRawList(List facts) {
KieSession ksession = getKieSession();
ksession.setGlobal(LOGGER_STR, log);
for (RawMovementFact fact : facts) {
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java
index 2b7b3ce5e..7277d41b8 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/bean/movement/RulesMovementProcessorBean.java
@@ -10,13 +10,14 @@
* copy of the GNU General Public License along with the IFDM Suite. If not, see .
*/
- package eu.europa.ec.fisheries.uvms.rules.service.bean.movement;
+package eu.europa.ec.fisheries.uvms.rules.service.bean.movement;
import eu.europa.ec.fisheries.remote.RulesDomainModel;
import eu.europa.ec.fisheries.schema.config.module.v1.SettingsListResponse;
import eu.europa.ec.fisheries.schema.config.types.v1.SettingType;
import eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementRefType;
import eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementRefTypeType;
+import eu.europa.ec.fisheries.schema.exchange.movement.v1.MovementTypeType;
import eu.europa.ec.fisheries.schema.exchange.movement.v1.SetReportMovementType;
import eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType;
import eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType;
@@ -42,10 +43,12 @@
import eu.europa.ec.fisheries.schema.rules.customrule.v1.UpdateSubscriptionType;
import eu.europa.ec.fisheries.schema.rules.mobileterminal.v1.IdList;
import eu.europa.ec.fisheries.schema.rules.module.v1.GetTicketsAndRulesByMovementsResponse;
+import eu.europa.ec.fisheries.schema.rules.module.v1.SendFLUXMovementReportRequest;
import eu.europa.ec.fisheries.schema.rules.module.v1.SetFLUXMovementReportRequest;
import eu.europa.ec.fisheries.schema.rules.movement.v1.MovementSourceType;
import eu.europa.ec.fisheries.schema.rules.movement.v1.RawMovementType;
import eu.europa.ec.fisheries.schema.rules.previous.v1.PreviousReportType;
+import eu.europa.ec.fisheries.schema.rules.rule.v1.RawMsgType;
import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmListCriteria;
import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmQuery;
import eu.europa.ec.fisheries.schema.rules.search.v1.AlarmSearchKey;
@@ -76,6 +79,7 @@
import eu.europa.ec.fisheries.uvms.movement.model.exception.MovementModelException;
import eu.europa.ec.fisheries.uvms.movement.model.mapper.MovementModuleRequestMapper;
import eu.europa.ec.fisheries.uvms.movement.model.mapper.MovementModuleResponseMapper;
+import eu.europa.ec.fisheries.uvms.rules.dao.RulesDao;
import eu.europa.ec.fisheries.uvms.rules.message.consumer.RulesResponseConsumer;
import eu.europa.ec.fisheries.uvms.rules.message.producer.bean.*;
import eu.europa.ec.fisheries.uvms.rules.model.constant.AuditObjectTypeEnum;
@@ -87,16 +91,26 @@
import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMapperException;
import eu.europa.ec.fisheries.uvms.rules.model.exception.RulesModelMarshallException;
import eu.europa.ec.fisheries.uvms.rules.model.mapper.JAXBMarshaller;
+import eu.europa.ec.fisheries.uvms.rules.service.bean.RulePostProcessBean;
+import eu.europa.ec.fisheries.uvms.rules.service.bean.RulesConfigurationCache;
+import eu.europa.ec.fisheries.uvms.rules.service.bean.RulesEngineBean;
+import eu.europa.ec.fisheries.uvms.rules.service.bean.RulesExchangeServiceBean;
+import eu.europa.ec.fisheries.uvms.rules.service.bean.mdr.MDRCache;
+import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.MovementFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.PreviousReportFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.RawMovementFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.RulesUtil;
+import eu.europa.ec.fisheries.uvms.rules.service.business.ValidationResult;
+import eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType;
+import eu.europa.ec.fisheries.uvms.rules.service.constants.MDRAcronymType;
import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportCountEvent;
import eu.europa.ec.fisheries.uvms.rules.service.event.AlarmReportEvent;
import eu.europa.ec.fisheries.uvms.rules.service.event.TicketCountEvent;
import eu.europa.ec.fisheries.uvms.rules.service.event.TicketUpdateEvent;
import eu.europa.ec.fisheries.uvms.rules.service.exception.InputArgumentException;
import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesServiceException;
+import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesValidationException;
import eu.europa.ec.fisheries.uvms.rules.service.mapper.*;
import eu.europa.ec.fisheries.uvms.user.model.mapper.UserModuleRequestMapper;
import eu.europa.ec.fisheries.wsdl.asset.group.AssetGroup;
@@ -110,7 +124,10 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage;
+import un.unece.uncefact.data.standard.mdr.communication.ObjectRepresentation;
+import un.unece.uncefact.data.standard.unqualifieddatatype._18.IDType;
+import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
@@ -122,8 +139,13 @@
import java.nio.file.AccessDeniedException;
import java.util.*;
import java.util.concurrent.*;
+import java.util.stream.Collectors;
import static eu.europa.ec.fisheries.uvms.movement.model.exception.ErrorCode.MOVEMENT_DUPLICATE_ERROR;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.BusinessObjectType.RECEIVING_MOVEMENT_MSG;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.SENDER_RECEIVER;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.XML;
@Stateless
@@ -131,8 +153,11 @@
@Slf4j
public class RulesMovementProcessorBean {
- private static final double VICINITY_RADIUS = 0.05;
private static final long TWENTYFOUR_HOURS_IN_MILLISEC = 86400000;
+ private static final String MOVEMENTTYPE_POS = "POS";
+ private static final String MOVEMENTTYPE_EXI = "EXIT";
+ private static final String MOVEMENTTYPE_ENT = "ENTRY";
+ private static final String MOVEMENTTYPE_MAN = "MANUAL";
@EJB
private RulesResponseConsumer consumer;
@@ -167,6 +192,20 @@ public class RulesMovementProcessorBean {
@EJB
private RulesAuditProducerBean auditProducer;
+ @EJB
+ private RulesEngineBean rulesEngine;
+
+ @EJB
+ private RulePostProcessBean rulePostProcessBean;
+
+ @EJB
+ private RulesExchangeServiceBean exchangeServiceBean;
+
+ @EJB
+ private RulesConfigurationCache ruleModuleCache;
+
+ private RulesFLUXMessageHelper fluxMessageHelper;
+
@Inject
@TicketUpdateEvent
private Event ticketUpdateEvent;
@@ -183,6 +222,51 @@ public class RulesMovementProcessorBean {
@AlarmReportCountEvent
private Event alarmReportCountEvent;
+ private Map mapToMovementType;
+
+ @Inject
+ void setMdrCache(MDRCache mdrCache) {
+ mapToMovementType = new HashMap<>();
+ List mdrCacheEntries = mdrCache.getEntry(MDRAcronymType.FLUX_VESSEL_POSITION_TYPE);
+ mdrCacheEntries.stream().map(ObjectRepresentation::getFields)
+ .forEach(t -> t.forEach( s -> {
+ if ("code".equals(s.getColumnName())) {
+ String columnValue = s.getColumnValue();
+ switch (columnValue) {
+ case MOVEMENTTYPE_POS:
+ mapToMovementType.put(columnValue, MovementTypeType.POS);
+ break;
+ case MOVEMENTTYPE_EXI:
+ mapToMovementType.put(columnValue, MovementTypeType.EXI);
+ break;
+ case MOVEMENTTYPE_ENT:
+ mapToMovementType.put(columnValue, MovementTypeType.ENT);
+ break;
+ case MOVEMENTTYPE_MAN:
+ mapToMovementType.put(columnValue, MovementTypeType.MAN);
+ break;
+ default:
+ log.warn("Movement type couldn't be mapped: "+ columnValue);
+ }
+ }
+ }));
+ }
+
+ public void sendMovementReport(SendFLUXMovementReportRequest request, String messageGuid) throws RulesServiceException {
+ log.info("Sending Movement Report to exchange");
+ try {
+ String exchangeMessageText = ExchangeMovementMapper.mapToFluxMovementReport(request.getRequest(), request.getUsername(), request.getSenderOrReceiver(), request.getFluxDataFlow(), request.getLogGuid(),request.getAd());
+ exchangeProducer.sendModuleMessage(exchangeMessageText, consumer.getDestination());
+ } catch (ExchangeModelMapperException | MessageException e) {
+ log.error("Error while send movement report to exchange", e);
+ }
+ }
+
+ @PostConstruct
+ public void init() {
+ fluxMessageHelper = new RulesFLUXMessageHelper(ruleModuleCache);
+ }
+
public void setMovementReportReceived(SetFLUXMovementReportRequest request, String messageGuid) throws RulesServiceException {
FLUXVesselPositionMessage fluxVesselPositionMessage;
String pluginType = request.getType().name();
@@ -190,8 +274,7 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
String registeredPluginClassName = request.getRegisteredClassName();
try {
fluxVesselPositionMessage = JAXBUtils.unMarshallMessage(request.getRequest(), FLUXVesselPositionMessage.class, null);
- List movementReportsList = FLUXVesselPositionMapper.mapToRawMovementTypes(fluxVesselPositionMessage, registeredPluginClassName,pluginType);
-
+ List movementReportsList = FLUXVesselPositionMapper.mapToRawMovementTypes(fluxVesselPositionMessage, registeredPluginClassName,pluginType,mapToMovementType);
// If no movements were received then there is no sense to continue, so just going to update the exchange log status to FAILED!
if (CollectionUtils.isEmpty(movementReportsList)) {
log.warn("The list of rawMovements is EMPTY! Not going to proceed neither validation not sending to Movement Module!");
@@ -199,16 +282,36 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
sendBatchBackToExchange(request.getLogGuid(), movementReportsList, MovementRefTypeType.ALARM, userName);
return;
}
+
+ Map extraValues = new EnumMap<>(ExtraValueType.class);
+ extraValues.put(SENDER_RECEIVER, request.getSenderOrReceiver());
+ extraValues.put(XML, request.getRequest());
+ extraValues.put(DATA_FLOW, request.getFluxDataFlow());
+ Collection factsResults = rulesEngine.evaluate(RECEIVING_MOVEMENT_MSG,fluxVesselPositionMessage,extraValues,null);
+
+ final String reportId = fluxVesselPositionMessage.getFLUXReportDocument().getIDS().stream()
+ .filter(id -> "UUID".equals(id.getSchemeID()))
+ .map(IDType::getValue)
+ .findFirst()
+ .get();
+ ValidationResult validationResult = rulePostProcessBean.checkAndUpdateValidationResult(factsResults, request.getRequest(), reportId, RawMsgType.MOVEMENT);
+
+ if(validationResult.isError()){
+ exchangeServiceBean.updateExchangeMessage(request.getLogGuid(), fluxMessageHelper.calculateMessageValidationStatus(validationResult));
+ return;
+ }
// Decomment this one and comment the other when validation is working! Still work needs to be done after this!
- // processReceivedMovementsAsBatch(movementReportsList, pluginType, userName, request.getLogGuid());
- enrichAndSenMovementsAsBatch(movementReportsList, userName, request.getLogGuid());
+// MovementReportDocumentFact movementReportDocumentFact = MovementReportDocumentFactMapper.mapToMovementReportDocumentFact(fluxVesselPositionMessage);
+// EnrichedMovementWrapper enrichedWrapper = processReceivedMovementsAsBatch(movementReportsList, pluginType, userName, request.getLogGuid());
+ enrichAndSendMovementsAsBatch(validationResult, movementReportsList, userName, request.getLogGuid());
+// enrichAndSenMovementsAsBatch(null, movementReportsList, userName, request.getLogGuid());
// Send some response to Movement, if it originated from there (manual movement)
if (MovementSourceType.MANUAL.equals(movementReportsList.get(0).getSource())) {// A person has created a position
ProcessedMovementAck response = MovementModuleResponseMapper.mapProcessedMovementAck(eu.europa.ec.fisheries.schema.movement.common.v1.AcknowledgeTypeType.OK,
messageGuid, "Movement successfully processed");
movOutQueueProducer.sendMessageWithSpecificIds(JAXBMarshaller.marshallJaxBObjectToString(response), movOutQueueProducer.getDestination(), null, messageGuid, messageGuid);
}
- } catch (JAXBException | RulesModelMarshallException | MessageException e) {
+ } catch (JAXBException | MessageException | RulesValidationException | RulesModelMarshallException e) {
log.error("Error while processing received movement", e);
}
}
@@ -223,15 +326,14 @@ public void setMovementReportReceived(SetFLUXMovementReportRequest request, Stri
* @param exchangeLogGuid
* @throws RulesServiceException
*/
- private void enrichAndSenMovementsAsBatch(List rawMovements, String username, String exchangeLogGuid) throws RulesServiceException {
+ private void enrichAndSendMovementsAsBatch(ValidationResult validationResult,List rawMovements, String username, String exchangeLogGuid) throws RulesServiceException {
try {
// Enrich with MobilTerminal and Assets data. Get Mobile Terminal if it exists.
EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(rawMovements);
CreateMovementBatchResponse movementBatchResponse = sendBatchToMovement(enrichedWrapper.getAssetList(), rawMovements, username);
ExchangeLogStatusTypeType status;
if (movementBatchResponse != null && SimpleResponse.OK.equals(movementBatchResponse.getResponse())) {
- // Here when ready needs to happen the validation with the list returned from movements! movementBatchResponse.getMovements();
- status = ExchangeLogStatusTypeType.SUCCESSFUL;
+ status = ExchangeLogStatusTypeType.fromValue(fluxMessageHelper.calculateMessageValidationStatus(validationResult).value());
sendBatchBackToExchange(exchangeLogGuid, rawMovements, MovementRefTypeType.MOVEMENT, username);
} else {
status = ExchangeLogStatusTypeType.FAILED;
@@ -239,7 +341,7 @@ private void enrichAndSenMovementsAsBatch(List rawMovements, St
}
updateRequestMessageStatusInExchange(exchangeLogGuid, status);
} catch (MessageException | MobileTerminalModelMapperException | MobileTerminalUnmarshallException | JMSException | AssetModelMapperException e) {
- throw new RulesServiceException(e.getMessage());
+ throw new RulesServiceException(e.getMessage(), e);
}
}
@@ -249,12 +351,12 @@ private void processReceivedMovementsAsBatch(List rawMovements,
EnrichedMovementWrapper enrichedWrapper = enrichBatchWithMobileTerminalAndAssets(rawMovements);
List rawMovementFactList = RawMovementFactMapper.mapRawMovementFacts(rawMovements, enrichedWrapper.getMobileTerminalList(),
enrichedWrapper.getAssetList(), pluginType);
- movementValidator.evaluate(rawMovementFactList);
+ movementValidator.evaluateRawList(rawMovementFactList);
if (allFactsAreOk(rawMovementFactList)) { // For now it is always OK
// The collectMovementData actually is the method that sends the movements list to Movements module to be saved!
List movementFactList = collectBatchMovementData(enrichedWrapper.getMobileTerminalList(), enrichedWrapper.getAssetList(), rawMovements, username);
log.info(" Validating movement from Movement Module");
- movementValidator.evaluate(movementFactList, true);
+ movementValidator.evaluate(movementFactList);
// Tell Exchange that a movement Batch was persisted in Movement
ExchangeLogStatusTypeType status;
if (CollectionUtils.isNotEmpty(movementFactList)) {
@@ -330,14 +432,14 @@ private List collectConnectIds(List mobileTerminals)
}
private boolean allFactsAreOk(List rawMovementFactList) {
- boolean areAllOk = true;
+
for (RawMovementFact movementFact : rawMovementFactList) {
if (movementFact == null || !movementFact.isOk()) {
- areAllOk = false;
- break;
+ return false;
}
}
- return areAllOk;
+
+ return true;
}
private List getMobileTerminalByRawMovementsBatch(List rawMovements) throws MessageException, MobileTerminalModelMapperException, MobileTerminalUnmarshallException, JMSException {
@@ -638,7 +740,9 @@ private CreateMovementBatchResponse sendBatchToMovement(List asset, List<
try {
String createMovementRequest = MovementModuleRequestMapper.mapToCreateMovementBatchRequest(movementBatch, username);
log.debug("Send CreateMovementRequest message to Movement");
- String messageId = movementProducer.sendModuleMessage(createMovementRequest, consumer.getDestination());
+ warnOnMultipleConnectIds(connectIds);
+ String connectId = connectIds.get(0);
+ String messageId = movementProducer.sendModuleMessageInGroup(createMovementRequest, consumer.getDestination(), connectId);
TextMessage movJmsResponse = consumer.getMessage(messageId, TextMessage.class, 2400000L);
log.debug("Received response message");
movementSimpleResponse = MovementModuleResponseMapper.mapToCreateMovementBatchResponse(movJmsResponse);
@@ -658,6 +762,16 @@ private CreateMovementBatchResponse sendBatchToMovement(List asset, List<
}
}
+ private void warnOnMultipleConnectIds(List connectIds) {
+ if (connectIds.size() == 1) {
+ return;
+ }
+ Set uniqueConnectIds = new HashSet<>(connectIds);
+ if (uniqueConnectIds.size() > 1) {
+ log.warn("*** connectIds with {} different elements, the JMSXGroupId will be wrong! The first two elements are: {} ***", uniqueConnectIds.size(), uniqueConnectIds.stream().limit(2).collect(Collectors.joining(",","[","]")));
+ }
+ }
+
private List collectConnectIdsFromAssetList(List assets, List rawMovements) {
List connectIdsList = new ArrayList<>();
int index = 0;
@@ -1058,6 +1172,9 @@ public String reprocessAlarm(List alarmGuids, String username) throws Ru
continue;
}
+ if(alarm.getAlarmItem().stream().map(a -> a.getRuleGuid() == null).findAny().orElse(false)) {
+ throw new RulesServiceException("Cannot reprocess an alarm that is not rule originated");
+ }
// Mark the alarm as REPROCESSED before reprocessing. That will create a new alarm (if still wrong) with the items remaining.
alarm.setStatus(AlarmStatusType.REPROCESSED);
alarm = updateAlarmStatus(alarm);
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java
index 344bafdbc..ff5d4ea1b 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/AbstractFact.java
@@ -80,6 +80,106 @@ public AbstractFact() {
setFactType();
}
+ public boolean containsAtMostXTypesOfLocation(List locations,String type,int times){
+
+ if(CollectionUtils.isEmpty(locations)){
+ return true;
+ }
+
+ int i =0;
+
+ for(FLUXLocation location:locations){
+
+ if(location.getID() == null){
+ continue;
+ }
+
+ if(type.equals(location.getID().getSchemeID())){
+ i ++;
+ }
+
+ if (i > times){
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ public boolean hasDuplicateLocationType(List locations){
+ Map map = new HashMap<>();
+
+ if(CollectionUtils.isEmpty(locations)){
+ return false;
+ }
+
+ for(FLUXLocation location:locations){
+
+ if(location.getID() == null){
+ continue;
+ }
+
+ if(map.get(location.getID().getSchemeID()) == null){
+ map.put(location.getID().getSchemeID(),1);
+ } else {
+ return true;
+ }
+
+ }
+
+ return false;
+ }
+
+ public boolean fluxLocationsWithSameSchemeIdDontContainCharacteristicWithType(List locations, String type,String locationType) {
+ Map map = new HashMap<>();
+
+ List locationsWhichMatchType = locations.stream().filter(r -> r.getTypeCode() != null && locationType.equals(r.getTypeCode().getValue())).collect(Collectors.toList());
+ mapLocationsBySchemeID(locationsWhichMatchType, map);
+
+ // each location should have an ApplicableFLUXCharacteristic with specific type
+ // as long as its schemeID is used two or more times
+ List filteredLocations = locationsWhichMatchType.stream().filter(t -> t.getID() != null)
+ .filter(t -> map.get(t.getID().getSchemeID()) > 1)
+ .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty())
+ .collect(Collectors.toList());
+
+ if(filteredLocations.isEmpty()){
+ return false;
+ } else {
+ return !filteredLocations.stream().allMatch(t ->
+ t.getApplicableFLUXCharacteristics().get(0) != null && t.getApplicableFLUXCharacteristics().get(0).getTypeCode() != null
+ && t.getApplicableFLUXCharacteristics().get(0).getTypeCode().getValue().equals(type));
+ }
+ }
+ private void mapLocationsBySchemeID(List locations, Map map) {
+ for(FLUXLocation location:locations){
+ if(location.getID() == null){
+ continue;
+ }
+
+ if(map.get(location.getID().getSchemeID()) == null){
+ map.put(location.getID().getSchemeID(),1);
+ } else {
+ map.put(location.getID().getSchemeID(),map.get(location.getID().getSchemeID()) + 1);
+ }
+ }
+ }
+
+ public boolean fluxLocationContainsApplicableFLUXCharacteristic(List locations){
+ Map map = new HashMap<>();
+
+ if(CollectionUtils.isEmpty(locations)){
+ return true;
+ }
+
+ mapLocationsBySchemeID(locations, map);
+ //each location should have an ApplicableFLUXCharacteristic as long as its schemeID is used two or more times
+ return locations.stream().filter(t -> t.getID() != null)
+ .filter(t -> map.get(t.getID().getSchemeID()) > 1)
+ .allMatch( t-> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty());
+ }
+
public static int getNumOfInstances() {
return counter;
}
@@ -371,6 +471,17 @@ public boolean validateFormat(CodeType codeType) {
return isInvalid;
}
+ /**
+ * Returns true if the object is found in the collection.
+ *
+ */
+ public boolean containsObject(Object obj, Collection col) {
+ if (CollectionUtils.isEmpty(col)){
+ col = new ArrayList();
+ }
+ return CollectionUtils.exists(col, o -> o.equals(obj));
+ }
+
/**
* Returns true if at least one element is in both collections.
*
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java
index 84e483fdb..baf99f7f0 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaCatchFact.java
@@ -14,7 +14,10 @@
package eu.europa.ec.fisheries.uvms.rules.service.business.fact;
import java.math.BigDecimal;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
import eu.europa.ec.fisheries.schema.rules.template.v1.FactType;
import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
@@ -24,7 +27,9 @@
import org.apache.commons.lang3.StringUtils;
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.AAPProcess;
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.AAPProduct;
+import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXCharacteristic;
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FLUXLocation;
+import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FishingGear;
@Data
@EqualsAndHashCode(callSuper = false)
@@ -51,15 +56,17 @@ public class FaCatchFact extends AbstractFact {
private CodeType categoryCode;
private List appliedAAPProcessConversionFactorNumber;
private List specifiedFLUXLocations;
+ private List faCatchSpecifiedFLUXLocations;
private List specifiedFluxLocationRFMOCodeList;
private List appliedAAPProcess;
private List destinationFLUXLocations;
private List faCatchFluxLocationId;
private List fishActRelatedFluxLocationIds;
+ private List faCatchFluxCharacteristic;
+ private List usedFishingGears;
private boolean isSubActivity = false;
-
public boolean containsAtLeastOneGfcmGsaWithValidValue(List ids){
if(CollectionUtils.isEmpty(ids)){
return false;
@@ -105,5 +112,4 @@ public void setFactType() {
public boolean isSubActivity() {
return isSubActivity;
}
-
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java
index 68960bce3..d9c73a4eb 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FaQueryFact.java
@@ -36,6 +36,8 @@ public class FaQueryFact extends AbstractFact {
private List submittedFLUXPartyIds;
+ private List nonUniqueIdsList;
+
private DelimitedPeriod specifiedDelimitedPeriod;
private String sdpStartDateTimeString;
@@ -124,4 +126,13 @@ public List getSimpleFAQueryParameterTypeCodes() {
public void setSimpleFAQueryParameterTypeCodes(List simpleFAQueryParameterTypeCodes) {
this.simpleFAQueryParameterTypeCodes = simpleFAQueryParameterTypeCodes;
}
+
+ public List getNonUniqueIdsList() {
+ return nonUniqueIdsList;
+ }
+
+ public void setNonUniqueIdsList(List nonUniqueIdsList) {
+ this.nonUniqueIdsList = nonUniqueIdsList;
+ }
+
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java
index 3f638de75..f613060f8 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FishingActivityFact.java
@@ -15,8 +15,10 @@
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
import eu.europa.ec.fisheries.schema.rules.template.v1.FactType;
import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
@@ -53,10 +55,15 @@ public class FishingActivityFact extends AbstractFact {
private CodeType faReportDocumentTypeCode;
private List relatedFluxLocationRFMOCodeList;
private List specifiedFaCatch;
+ private List specifiedFishingGears;
private List relatedVesselTransportMeansRoleCodes;
private List relFishActRelatedVesselTransportMeansRoleCodes;
private List faRepDockSpecifiedVesselTransportMeansRoleCodes;
+ private List fishingActivityFluxCharacteristic;
+ private List fishingActivityRelatedFLUXLocations;
+
+ private FishingActivity thisFishingActivity;
public FishingActivityFact() {
setFactType();
@@ -90,6 +97,15 @@ public boolean validDelimitedPeriod(List relatedFishingActiviti
return isMatch;
}
+ public boolean hasUniqueFluxCharacteristics(List fluxCharacteristicsTypeCode){
+ if(fluxCharacteristicsTypeCode == null || fluxCharacteristicsTypeCode.isEmpty()){
+ return true;
+ }
+
+ HashSet listToSet = new HashSet(fluxCharacteristicsTypeCode);
+ return listToSet.size() == fluxCharacteristicsTypeCode.size();
+ }
+
public boolean rfmoProvided(List relatedFLUXLocations) {
if (CollectionUtils.isEmpty(relatedFLUXLocations)) {
return true;
@@ -158,4 +174,23 @@ public boolean allDurationMeasuresHaveUnitCodeProvidedWhenValueIsProvided(){
return true;
}
+
+ public boolean hasPositionLocationForFaTypeCode(String fishingActivityTypeCode) {
+ if(!isSubActivity() || org.apache.commons.lang3.StringUtils.isEmpty(fishingActivityTypeCode)){
+ return true;
+ }
+ if(thisFishingActivity != null && thisFishingActivity.getTypeCode() != null && fishingActivityTypeCode.equals(thisFishingActivity.getTypeCode().getValue())){
+ List relatedFluxLocations = collectRelatedFluxLocations(thisFishingActivity);
+ return anyFluxLocationTypeCodeContainsValue(relatedFluxLocations, "POSITION");
+ }
+ return true;
+ }
+
+ private List collectRelatedFluxLocations(FishingActivity relatedFishingActivity) {
+ List nonNullFlucLocations = new ArrayList<>();
+ if(relatedFishingActivity != null && CollectionUtils.isNotEmpty(relatedFishingActivity.getRelatedFLUXLocations())){
+ nonNullFlucLocations = relatedFishingActivity.getRelatedFLUXLocations().stream().filter(Objects::nonNull).collect(Collectors.toList());
+ }
+ return nonNullFlucLocations;
+ }
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FlapDocumentFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FlapDocumentFact.java
new file mode 100644
index 000000000..a7f93fcbf
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FlapDocumentFact.java
@@ -0,0 +1,18 @@
+package eu.europa.ec.fisheries.uvms.rules.service.business.fact;
+
+import eu.europa.ec.fisheries.schema.rules.template.v1.FactType;
+import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class FlapDocumentFact extends AbstractFact {
+
+ private IdType id;
+
+ @Override
+ public void setFactType() {
+ this.factType = FactType.FA_FLAP_DOCUMENT;
+ }
+}
\ No newline at end of file
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java
index d13973811..b2487e821 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/FluxFaReportMessageFact.java
@@ -32,11 +32,11 @@ public class FluxFaReportMessageFact extends AbstractFact {
private String creationDateTimeString;
private CodeType purposeCode;
private List ownerFluxPartyIds;
+ private List relatedOwnerFluxPartyIds;
private List faReportDocuments;
private List nonUniqueIdsList;
private List relatedFaQueryIDs;
-
public FluxFaReportMessageFact() {
setFactType();
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java
index 4b067d40c..c2c671b81 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/IdTypeFact.java
@@ -4,6 +4,8 @@
import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
import lombok.Data;
+import java.util.Arrays;
+
@Data
public class IdTypeFact extends AbstractFact {
@@ -19,6 +21,33 @@ public IdTypeFact(IdType id) {
setFactType();
}
+ /**
+ * Method to validate the last digit of the schemeId Value if schemeId type is UVI
+ *
+ * @param schemeIdValue the value of the schemeId
+ * @return true if the validation fails and false if succeeds
+ * Extract the digits from the String SchemeIdValue
+ * iterate through them to calculate the sum of each one being
+ * successively (individually) multiplied by 7,6,5,4,3,2.
+ * Last digit of the calculated sum is the 7th digit.
+ * see(14.5. Validation of the IMO number format (UVI) v2.5)
+ */
+ public boolean isLastCheckBitInvalidInUVISchemeId(String schemeIdValue) {
+ int[] digits = Arrays.stream(schemeIdValue.split("")).mapToInt(Integer::parseInt).toArray();
+ if (digits.length == 7) {
+ int lastDigit = digits[digits.length - 1];
+ int sum = 0;
+ for (int i = 1; i < digits.length; i++) {
+ sum += (digits.length + 1 - i) * digits[i - 1];
+ }
+ int lastDigitOfSum = Math.abs(sum) % 10;
+
+ return lastDigitOfSum != lastDigit;
+ }
+ return true;
+ }
+
+
@Override
public void setFactType() {
this.factType = FactType.SIMPLE_ID_TYPE_FACT;
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java
new file mode 100644
index 000000000..4c4d8fab9
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/MovementReportDocumentFact.java
@@ -0,0 +1,31 @@
+/*
+Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016.
+
+This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+
+*/
+
+package eu.europa.ec.fisheries.uvms.rules.service.business.fact;
+
+import eu.europa.ec.fisheries.schema.rules.template.v1.FactType;
+import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class MovementReportDocumentFact extends AbstractFact {
+
+ private boolean ok = true;
+ private Date creationDateTime;
+ private String creationDateTimeString;
+
+ @Override
+ public void setFactType() {
+ this.factType = FactType.MOVEMENT_REPORT_DOCUMENT;
+ }
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java
index 8dfb6fd88..ab42a55b3 100755
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/fact/VesselTransportMeansFact.java
@@ -25,12 +25,15 @@
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.ContactPerson;
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.StructuredAddress;
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.VesselPositionEvent;
+import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.VesselTransportMeans;
+import un.unece.uncefact.data.standard.unqualifieddatatype._20.IDType;
@Data
@EqualsAndHashCode(callSuper = false)
public class VesselTransportMeansFact extends AbstractFact {
private boolean isFromFaReport;
+ private boolean isFromParentFishingActivity;
private CodeType fishingActivityType;
private List ids;
private IdType registrationVesselCountryId;
@@ -41,6 +44,12 @@ public class VesselTransportMeansFact extends AbstractFact {
private List specifiedContactPersons;
private VesselTransportMeansDto transportMeans;
private List vesselPositionEvents;
+ private IdType specifiedVesselCountryId;
+ private List specifiedIds;
+ private IdType relatedVesselCountryId;
+ private List relatedIds;
+ private VesselTransportMeans relatedVesselTransportMeans;
+ private VesselTransportMeans specifiedVesselTransportMeans;
public VesselTransportMeansFact() {
setFactType();
@@ -56,6 +65,75 @@ public boolean containsAtLeastOneCorrectIdOfTheRequired(String schemeId){
return containsValidSchemeId;
}
+ public boolean containsAtLeastOneCorrectIdOfTheSpecified(String schemeId){
+ boolean containsValidSchemeId = false;
+ for (IdType id : specifiedIds) {
+ if(schemeId.equals(id.getSchemeId()) && StringUtils.isNotEmpty(id.getValue())){
+ containsValidSchemeId = true;
+ }
+ }
+ return containsValidSchemeId;
+ }
+
+ public boolean containsAtLeastOneCorrectIdOfTheRelated(String schemeId){
+ boolean containsValidSchemeId = false;
+
+ if(relatedIds == null || relatedIds.isEmpty()){
+ return true;
+ }
+
+ for (IdType id : relatedIds) {
+ if(schemeId.equals(id.getSchemeId()) && StringUtils.isNotEmpty(id.getValue())){
+ containsValidSchemeId = true;
+ }
+ }
+ return containsValidSchemeId;
+ }
+
+
+ public boolean hasValueForVesselTransports(VesselTransportMeans relatedVesselTransportMeans,String value1,String value2){
+ if(relatedVesselTransportMeans == null ){
+ return true;
+ }
+ boolean containsValue1 = false,containsValue2 = false;
+
+ for(IDType id :relatedVesselTransportMeans.getIDS()){
+ if(id == null || id.getSchemeID() == null){
+ continue;
+ }
+
+ if(value1.equals(id.getSchemeID())){
+ containsValue1 = true;
+ }
+
+ if(value2.equals(id.getSchemeID())){
+ containsValue2 = true;
+ }
+
+ }
+
+ return containsValue1 && containsValue2;
+ }
+
+ public boolean hasValueForVesselTransports(VesselTransportMeans relatedVesselTransportMeans,String value){
+ if(relatedVesselTransportMeans == null ){
+ return true;
+ }
+
+ for(IDType id :relatedVesselTransportMeans.getIDS()){
+ if(id == null || id.getSchemeID() == null){
+ continue;
+ }
+
+ if(value.equals(id.getSchemeID())){
+ return true;
+ }
+
+ }
+
+ return false;
+ }
+
@Override
public void setFactType() {
this.factType = FactType.VESSEL_TRANSPORT_MEANS;
@@ -67,4 +145,11 @@ public boolean getIsFromFaReport() {
public void setIsFromFaReport(boolean fromFaReport) {
isFromFaReport = fromFaReport;
}
+
+ public boolean getIsFromParentFishingActivity() {
+ return isFromParentFishingActivity;
+ }
+ public void setIsFromParentFishingActivity(boolean isFromParentFishingActivity) {
+ this.isFromParentFishingActivity = isFromParentFishingActivity;
+ }
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java
index 876778f22..262b2d44f 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityFaReportFactGenerator.java
@@ -19,6 +19,7 @@
import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType;
import eu.europa.ec.fisheries.uvms.rules.service.business.VesselTransportMeansDto;
+import eu.europa.ec.fisheries.uvms.rules.service.business.fact.FlapDocumentFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.fact.IdType;
import eu.europa.ec.fisheries.uvms.rules.service.business.fact.VesselTransportMeansFact;
import eu.europa.ec.fisheries.uvms.rules.service.constants.FaReportDocumentType;
@@ -169,6 +170,11 @@ private void enrichVesselTransoprtMeanFacts(List facts) {
matches.set(false);
}
break;
+ case "UVI":
+ if(!StringUtils.equals(factIdValue, asset.getUvi())){
+ matches.set(false);
+ }
+ break;
}
});
if(matches.get()){
@@ -204,8 +210,11 @@ private Collection addFacts(List fishingActivitie
facts.add(activityFactMapper.generateFishingActivityFact(fishingActivity, isSubActivity, faReportDocument, mainActivityType));
xPathUtil.appendWithoutWrapping(partialSpecFishActXpath);
- facts.addAll(activityFactMapper.generateFactForVesselTransportMeans(fishingActivity.getRelatedVesselTransportMeans(), facts, fishingActivity.getTypeCode()));
-
+ if(isSubActivity) {
+ facts.addAll(activityFactMapper.generateFactForVesselTransportMeans(fishingActivity.getRelatedVesselTransportMeans(), facts, fishingActivity.getTypeCode()));
+ } else {
+ facts.addAll(activityFactMapper.generateFactForVesselTransportMeansForParentFA(fishingActivity.getRelatedVesselTransportMeans(), facts, fishingActivity.getTypeCode()));
+ }
xPathUtil.appendWithoutWrapping(partialSpecFishActXpath);
addFactsForVesselTransportMeansStructuresAddress(facts, fishingActivity.getRelatedVesselTransportMeans(), RELATED_VESSEL_TRANSPORT_MEANS);
@@ -244,6 +253,9 @@ private Collection addFacts(List fishingActivitie
xPathUtil.appendWithoutWrapping(partialSpecFishActXpath).append(DESTINATION_VESSEL_STORAGE_CHARACTERISTIC);
facts.add(activityFactMapper.generateFactsForVesselStorageCharacteristic(fishingActivity.getDestinationVesselStorageCharacteristic()));
+ xPathUtil.appendWithoutWrapping(partialSpecFishActXpath);
+ facts.addAll(activityFactMapper.generateFactsForFlapDocuments(fishingActivity.getSpecifiedFLAPDocuments()));
+
xPathUtil.appendWithoutWrapping(partialSpecFishActXpath);
facts.addAll(addFacts(fishingActivity.getRelatedFishingActivities(), faReportDocument, true, fishingActivity.getTypeCode()));
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java
index 011e0241c..b7cbf4ab4 100755
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/ActivityQueryFactGenerator.java
@@ -15,8 +15,13 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import eu.europa.ec.fisheries.uvms.rules.entity.FADocumentID;
import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType;
+import eu.europa.ec.fisheries.uvms.rules.service.business.fact.IdType;
import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesValidationException;
import eu.europa.ec.fisheries.uvms.rules.service.mapper.fact.ActivityFactMapper;
import eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util.XPathStringWrapper;
@@ -25,6 +30,7 @@
import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FAQuery;
import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW;
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.FA_QUERY_AND_REPORT_IDS;
import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.SENDER_RECEIVER;
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.FA_QUERY;
import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.FLUXFA_QUERY_MESSAGE;
@@ -61,6 +67,7 @@ public List generateAllFacts() {
if (fluxfaQueryMessage != null) {
FAQuery faQuery = fluxfaQueryMessage.getFAQuery();
if (faQuery != null) {
+ activityFactMapper.getNonUniqueIdsList().addAll(extractNonUniqueIds());
xPathUtil.append(FLUXFA_QUERY_MESSAGE).append(FA_QUERY);
factList.add(activityFactMapper.generateFactsForFaQuery(faQuery));
@@ -75,6 +82,22 @@ public List generateAllFacts() {
return factList;
}
+ private List extractNonUniqueIds() {
+ @SuppressWarnings("unchecked")
+ List faDocumentIDS = Optional.ofNullable((List) extraValueMap.get(FA_QUERY_AND_REPORT_IDS)).orElse(new ArrayList<>());
+ return (faDocumentIDS)
+ .stream()
+ .map(this::toIdType)
+ .collect(Collectors.toList());
+ }
+
+ private IdType toIdType(FADocumentID d) {
+ IdType idType = new IdType();
+ idType.setValue(d.getUuid());
+ Optional.ofNullable(d.getType()).ifPresent(fId -> idType.setSchemeId(fId.name()));
+ return idType;
+ }
+
private void populateCreationDateTime(List factList) {
if (fluxfaQueryMessage != null && fluxfaQueryMessage.getFAQuery() != null) {
DateTime dateTimeOfCreationOfMessage = activityFactMapper.mapToJodaDateTime(fluxfaQueryMessage.getFAQuery().getSubmittedDateTime());
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java
new file mode 100644
index 000000000..80d22f9d6
--- /dev/null
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/generator/MovementFactGenerator.java
@@ -0,0 +1,72 @@
+/*
+Developed by the European Commission - Directorate General for Maritime Affairs and Fisheries @ European Union, 2015-2016.
+
+This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it
+and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of
+the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see .
+
+*/
+
+package eu.europa.ec.fisheries.uvms.rules.service.business.generator;
+
+import eu.europa.ec.fisheries.uvms.rules.service.business.AbstractFact;
+import eu.europa.ec.fisheries.uvms.rules.service.business.MessageType;
+import eu.europa.ec.fisheries.uvms.rules.service.exception.RulesValidationException;
+import eu.europa.ec.fisheries.uvms.rules.service.mapper.fact.MovementReportDocumentFactMapper;
+import eu.europa.ec.fisheries.uvms.rules.service.mapper.xpath.util.XPathStringWrapper;
+import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage;
+import un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._18.FLUXReportDocumentType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static eu.europa.ec.fisheries.uvms.rules.service.config.ExtraValueType.DATA_FLOW;
+import static eu.europa.ec.fisheries.uvms.rules.service.constants.XPathConstants.MOVEMENT_REPORT_DOCUMENT;
+
+public class MovementFactGenerator extends AbstractGenerator {
+
+ private MovementReportDocumentFactMapper movementReportDocumentFactMapper;
+ private XPathStringWrapper xPathUtil;
+ private FLUXVesselPositionMessage vesselPositionMessage;
+
+ public MovementFactGenerator(MessageType messageType) {
+ super(messageType);
+ xPathUtil = new XPathStringWrapper();
+ movementReportDocumentFactMapper = new MovementReportDocumentFactMapper(xPathUtil);
+ }
+
+ public MovementFactGenerator(MessageType messageType,XPathStringWrapper xPathUtil, MovementReportDocumentFactMapper movementReportDocumentFactMapper) {
+ super(messageType);
+ this.xPathUtil = xPathUtil;
+ this.movementReportDocumentFactMapper = movementReportDocumentFactMapper;
+ }
+
+ public MovementFactGenerator() {
+ super(MessageType.PUSH);
+ }
+
+ @Override
+ public List generateAllFacts() {
+ List facts = new ArrayList<>();
+ FLUXReportDocumentType fluxReportDocument = vesselPositionMessage.getFLUXReportDocument();
+
+ if (fluxReportDocument != null) {
+ facts.add(movementReportDocumentFactMapper.generateFactForMovementReportDocument(vesselPositionMessage));
+ }
+
+ String df = (String) extraValueMap.get(DATA_FLOW);
+ facts.forEach(fact -> fact.setMessageDataFlow(df));
+ return facts;
+ }
+
+ @Override
+ public void setBusinessObjectMessage(Object businessObject) throws RulesValidationException {
+
+ if (!(businessObject instanceof FLUXVesselPositionMessage)) {
+ throw new RulesValidationException("Business object does not match required type");
+ }
+ this.vesselPositionMessage = (FLUXVesselPositionMessage) businessObject;
+ }
+}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java
index 40dddb269..b8da4fea9 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/DrtPathHelper.java
@@ -34,12 +34,14 @@ public enum DrtPathHelper {
FISHING_ACTIVITY("/templates/FishingActivity.drt"),
FA_QUERY("/templates/FaQuery.drt"),
FA_QUERY_PARAMETER("/templates/FaQueryParameter.drt"),
+ MOVEMENT_REPORT_DOCUMENT("/templates/MovementReportDocument.drt"),
FA_RELOCATION("/templates/FaRelocation.drt"),
FA_RESPONSE("/templates/FaResponse.drt"),
FA_TRANSHIPMENT("/templates/FaTranshipment.drt"),
FA_APPLIED_AAP_PROCESS("/templates/FaAppliedAAPProcess.drt"),
FISHING_GEAR("/templates/FishingGear.drt"),
FISHING_TRIP("/templates/FishingTrip.drt"),
+ FA_FLAP_DOCUMENT("/templates/FaFlapDocument.drt"),
FLUX_CHARACTERISTIC("/templates/FluxCharacteristics.drt"),
FLUX_FA_REPORT_MESSAGE("/templates/FluxFaReportMessage.drt"),
FLUX_LOCATION("/templates/FluxLocation.drt"),
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java
index 000afefe1..35afec083 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/business/helper/RuleApplicabilityChecker.java
@@ -76,6 +76,9 @@ && isDateInRange(messageCreationDate, faBrForBrIdAndContext.getStartDate(), faBr
* @return
*/
public boolean isApplicable(String thisRulesBrId, String ruleContext, String messageDataFlow, DateTime messageCreationDate, MDRCacheRuleService mdrService) {
+ if (thisRulesBrId != null && thisRulesBrId.startsWith("MO-")) {
+ return true;
+ }
String msgContext = mdrService.findContextForDf(messageDataFlow);
if (StringUtils.isEmpty(msgContext)) {
return false;
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java
index 3aba6f994..e87807e7f 100755
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/config/BusinessObjectType.java
@@ -26,5 +26,6 @@ public enum BusinessObjectType {
RECEIVING_FA_RESPONSE_MSG,
FLUX_SALES_REPORT_MSG,
FLUX_SALES_RESPONSE_MSG,
- FLUX_SALES_QUERY_MSG
+ FLUX_SALES_QUERY_MSG,
+ RECEIVING_MOVEMENT_MSG
}
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java
index e614b8c36..c7f972fb1 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/constants/XPathConstants.java
@@ -21,6 +21,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
public class XPathConstants {
public static final String FLUXFA_REPORT_MESSAGE = "FLUXFAReportMessage";
+ public static final String MOVEMENT_REPORT_DOCUMENT = "FLUXVesselPositionMessage";
public static final String FLUXFA_QUERY_MESSAGE = "FLUXFAQueryMessage";
public static final String FA_REPORT_DOCUMENT = "FAReportDocument";
public static final String SPECIFIED_FISHING_ACTIVITY = "SpecifiedFishingActivity";
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java
index 5aed9d815..fde114989 100755
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/ExchangeMovementMapper.java
@@ -16,6 +16,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.schema.exchange.module.v1.ExchangeModuleMethod;
import eu.europa.ec.fisheries.schema.exchange.module.v1.ProcessedMovementResponse;
import eu.europa.ec.fisheries.schema.exchange.module.v1.ProcessedMovementResponseBatch;
+import eu.europa.ec.fisheries.schema.exchange.module.v1.SendFLUXMovementReportRequest;
import eu.europa.ec.fisheries.schema.exchange.movement.asset.v1.AssetId;
import eu.europa.ec.fisheries.schema.exchange.movement.asset.v1.AssetIdType;
import eu.europa.ec.fisheries.schema.exchange.movement.asset.v1.AssetType;
@@ -31,6 +32,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
import eu.europa.ec.fisheries.uvms.exchange.model.mapper.JAXBMarshaller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import un.unece.uncefact.data.standard.fluxvesselpositionmessage._4.FLUXVesselPositionMessage;
public class ExchangeMovementMapper {
@@ -130,6 +132,21 @@ public static String mapToProcessedMovementResponseBatch(List mapToResponseToFADocumentID(FLUXResponseMessage fluxRes
public FLUXFAReportMessage unMarshallAndValidateSchema(String request) throws UnmarshalException {
try {
- return JAXBUtils.unMarshallMessage(request, FLUXFAReportMessage.class, loadXSDSchema(FLUXFAREPORT_MESSAGE_3P1_XSD));
+ return JAXBUtils.unMarshallMessage(request, FLUXFAReportMessage.class, SCHEMA_MAP.get(FLUXFAREPORT_MESSAGE_3P1_XSD));
} catch (Exception e) {
throw new UnmarshalException(e.getCause().getLocalizedMessage());
}
@@ -211,7 +212,7 @@ public FLUXFAReportMessage unMarshallAndValidateSchema(String request) throws Un
public FLUXFAQueryMessage unMarshallFaQueryMessage(String request) throws UnmarshalException {
try {
- return JAXBUtils.unMarshallMessage(request, FLUXFAQueryMessage.class, loadXSDSchema(FLUXFAQUERY_MESSAGE_3P0_XSD));
+ return JAXBUtils.unMarshallMessage(request, FLUXFAQueryMessage.class, SCHEMA_MAP.get(FLUXFAQUERY_MESSAGE_3P0_XSD));
} catch (Exception e) {
throw new UnmarshalException(e.getCause().getLocalizedMessage());
}
@@ -219,25 +220,12 @@ public FLUXFAQueryMessage unMarshallFaQueryMessage(String request) throws Unmars
public FLUXResponseMessage unMarshallFluxResponseMessage(String request) throws UnmarshalException {
try {
- return JAXBUtils.unMarshallMessage(request, FLUXResponseMessage.class, loadXSDSchema(FLUXFARESPONSE_MESSAGE_6P0_XSD));
+ return JAXBUtils.unMarshallMessage(request, FLUXResponseMessage.class, SCHEMA_MAP.get(FLUXFARESPONSE_MESSAGE_6P0_XSD));
} catch (Exception e) {
throw new UnmarshalException(e.getCause().getLocalizedMessage());
}
}
- public Schema loadXSDSchema(String xsdLocation) throws UnmarshalException {
- SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- URL resource = RulesFLUXMessageHelper.class.getClassLoader().getResource(xsdLocation);
- if (resource != null) {
- try {
- return sf.newSchema(resource);
- } catch (SAXException e) {
- throw new UnmarshalException(e.getMessage(), e);
- }
- }
- throw new UnmarshalException("ERROR WHILE TRYING TO LOOKUP XSD SCHEMA");
- }
-
public String getIDs(FLUXResponseMessage fluxResponseMessageObj) {
String id = null;
if (fluxResponseMessageObj != null){
diff --git a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java
index 5a196976f..7cf9128be 100644
--- a/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java
+++ b/service/src/main/java/eu/europa/ec/fisheries/uvms/rules/service/mapper/fact/ActivityFactMapper.java
@@ -11,6 +11,7 @@ This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The
package eu.europa.ec.fisheries.uvms.rules.service.mapper.fact;
+import com.google.common.collect.Lists;
import eu.europa.ec.fisheries.uvms.commons.date.DateUtils;
import eu.europa.ec.fisheries.uvms.commons.date.XMLDateUtils;
import eu.europa.ec.fisheries.uvms.rules.dto.GearMatrix;
@@ -53,6 +54,7 @@ public class ActivityFactMapper {
private XPathStringWrapper xPathUtil;
private List faReportMessageIds = new ArrayList<>();
private List faRelatedReportIds = new ArrayList<>();
+ private List nonUniqueIdsList = new ArrayList<>();
private List faQueryIds = new ArrayList<>();
private List faResponseIds = new ArrayList<>();
private String senderReceiver = null;
@@ -114,6 +116,7 @@ public class ActivityFactMapper {
private static final String RELATED_FLUX_LOCATIONS_ID_PROP = "relatedFluxLocationIDs";
private static final String FMC_MARKER_CODE = "FMCMarkerCode";
+
public ActivityFactMapper() {
setxPathUtil(new XPathStringWrapper());
}
@@ -257,8 +260,8 @@ public List generateFactForFaReportDocuments(List
HashMap> tripsPerFaTypeFromFasInReports = new HashMap<>();
tripsPerFaTypeFromFasInReports.put(FishingActivityType.ARRIVAL, new ArrayList<>());
tripsPerFaTypeFromFasInReports.put(FishingActivityType.DEPARTURE, new ArrayList<>());
- if (CollectionUtils.isEmpty(faReportDocuments)){
+ if (CollectionUtils.isEmpty(faReportDocuments)) {
return tripsPerFaTypeFromFasInReports;
}
int reportIndex = 1;
for (FAReportDocument faReportDocument : faReportDocuments) {
- if(CollectionUtils.isNotEmpty(faReportDocument.getSpecifiedFishingActivities())){
+ if (CollectionUtils.isNotEmpty(faReportDocument.getSpecifiedFishingActivities())) {
String faRepoDocTypeCode = "";
String faReportPurposeCode = "";
un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType faReportDocumentTypeCode = faReportDocument.getTypeCode();
- if (faReportDocumentTypeCode != null){
+ if (faReportDocumentTypeCode != null) {
faRepoDocTypeCode = faReportDocumentTypeCode.getValue();
}
- if(faReportDocument.getRelatedFLUXReportDocument() != null && faReportDocument.getRelatedFLUXReportDocument().getPurposeCode() != null){
+ if (faReportDocument.getRelatedFLUXReportDocument() != null && faReportDocument.getRelatedFLUXReportDocument().getPurposeCode() != null) {
faReportPurposeCode = faReportDocument.getRelatedFLUXReportDocument().getPurposeCode().getValue();
}
for (FishingActivity fishingActivity : faReportDocument.getSpecifiedFishingActivities()) {
FishingActivityType activityType = fetchActivityType(fishingActivity.getTypeCode());
FishingTrip specifiedFishingTrip = fishingActivity.getSpecifiedFishingTrip();
- if(specifiedFishingTrip != null && CollectionUtils.isNotEmpty(specifiedFishingTrip.getIDS()) && "DECLARATION".equals(faRepoDocTypeCode) && !"5".equals(faReportPurposeCode) &&
- (FishingActivityType.DEPARTURE.equals(activityType) || FishingActivityType.ARRIVAL.equals(activityType))){
+ if (specifiedFishingTrip != null && CollectionUtils.isNotEmpty(specifiedFishingTrip.getIDS()) && "DECLARATION".equals(faRepoDocTypeCode) && !"5".equals(faReportPurposeCode) &&
+ (FishingActivityType.DEPARTURE.equals(activityType) || FishingActivityType.ARRIVAL.equals(activityType))) {
tripsPerFaTypeFromFasInReports.get(activityType).add(new FaReportDocumentFact.TripIdAndReportIndex(specifiedFishingTrip.getIDS().get(0).getValue(), reportIndex));
}
}
@@ -303,10 +306,10 @@ private Map
private FishingActivityType fetchActivityType(un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType typeCode) {
FishingActivityType faType = null;
- if(typeCode != null && StringUtils.isNotEmpty(typeCode.getValue())){
+ if (typeCode != null && StringUtils.isNotEmpty(typeCode.getValue())) {
try {
faType = FishingActivityType.valueOf(typeCode.getValue());
- } catch(IllegalArgumentException ex){
+ } catch (IllegalArgumentException ex) {
log.error(ex.getMessage());
}
}
@@ -316,6 +319,7 @@ private FishingActivityType fetchActivityType(un.unece.uncefact.data.standard.un
public FishingActivityFact generateFishingActivityFact(FishingActivity fishingActivity, boolean isSubActivity, FAReportDocument faReportDocument,
un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType mainActivityType) {
FishingActivityFact fishingActivityFact = new FishingActivityFact();
+ fishingActivityFact.setThisFishingActivity(fishingActivity);
fishingActivityFact.setSubActivity(isSubActivity);
fishingActivityFact.setFaReportDocumentTypeCode(mapToCodeType(faReportDocument != null ? faReportDocument.getTypeCode() : null));
@@ -324,13 +328,14 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc
if (CollectionUtils.isNotEmpty(fishingActivity.getSpecifiedDelimitedPeriods())) {
fishingActivityFact.setDelimitedPeriod(fishingActivity.getSpecifiedDelimitedPeriods().get(0));
}
+ xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD).storeInRepo(fishingActivityFact, "delimitedPeriod");
xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD, START_DATE).storeInRepo(fishingActivityFact, "delimitedPeriodStartTime");
xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_DELIMITED_PERIOD, END_DATE).storeInRepo(fishingActivityFact, "delimitedPeriodEndTime");
- if(mainActivityType != null){
+ if (mainActivityType != null) {
fishingActivityFact.setMainActivityType(mainActivityType.getValue());
- fishingActivityFact.setSpecifiedFaCatch(fishingActivity.getSpecifiedFACatches());
}
+ fishingActivityFact.setSpecifiedFaCatch(fishingActivity.getSpecifiedFACatches());
fishingActivityFact.setRelFishActRelatedVesselTransportMeansRoleCodes(mapToRelatedVTMCodes(fishingActivity.getRelatedFishingActivities()));
fishingActivityFact.setRelatedVesselTransportMeansRoleCodes(extractRoleCodes(fishingActivity.getRelatedVesselTransportMeans()));
fishingActivityFact.setFaRepDockSpecifiedVesselTransportMeansRoleCodes(extractRoleCodes(Collections.singletonList(faReportDocument.getSpecifiedVesselTransportMeans())));
@@ -338,6 +343,7 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc
xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FA_CATCH, TYPE_CODE).storeInRepo(fishingActivityFact, "specifiedFaCatch");
xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_VESSEL_TRANSPORT_MEANS, ROLE_CODE).storeInRepo(fishingActivityFact, "relatedVesselTransportMeansRoleCodes");
xPathUtil.appendWithoutWrapping(partialXpath).storeInRepo(fishingActivityFact, "relFishActRelatedVesselTransportMeansRoleCodes");
+ xPathUtil.appendWithoutWrapping(partialXpath).storeInRepo(fishingActivityFact, "fishingActivityWithCorrectIndex");
fishingActivityFact.setRelatedFishingTrip(mapRelatedFishingTrips(fishingActivity.getRelatedFishingActivities()));
xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FISHING_ACTIVITY, SPECIFIED_FISHING_TRIP).storeInRepo(fishingActivityFact, "relatedFishingTrip");
@@ -388,19 +394,33 @@ public FishingActivityFact generateFishingActivityFact(FishingActivity fishingAc
fishingActivityFact.setRelatedFluxLocationRFMOCodeList(getFLUXLocationRFMOCodes(fishingActivity.getRelatedFLUXLocations()));
xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FLUX_LOCATION, REGIONAL_FISHERIES_MANAGEMENT_ORGANIZATION_CODE).storeInRepo(fishingActivityFact, RELATED_FLUX_LOCATION_RFMO_CODE_LIST_PROP);
+ fishingActivityFact.setSpecifiedFishingGears(fishingActivity.getSpecifiedFishingGears());
+ xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FISHING_GEAR).storeInRepo(fishingActivityFact, "specifiedFishingGears");
+
+ if (CollectionUtils.isNotEmpty(fishingActivityFact.getRelatedFLUXLocations()) && !isSubActivity) {
+ fishingActivityFact.setFishingActivityRelatedFLUXLocations(fishingActivityFact.getRelatedFLUXLocations());
+ xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FLUX_LOCATION,ID).storeInRepo(fishingActivityFact, "fishingActivityRelatedFLUXLocations");
+ List fluxCharacteristics = getFluxCharacteristics(fishingActivityFact.getRelatedFLUXLocations());
+ fishingActivityFact.setFishingActivityFluxCharacteristic(fluxCharacteristics);
+ Integer actCharacteristicsIndex = getIndexForFluxCharacteristics(fishingActivityFact.getRelatedFLUXLocations());
+ xPathUtil.appendWithoutWrapping(partialXpath).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsIndex).append(APPLICABLE_FLUX_CHARACTERISTIC).storeInRepo(fishingActivityFact, "fishingActivityFluxCharacteristic");
+ Integer actCharacteristicsTypeIndex = getIndexForFluxCharacteristicsWithTypeCode(fishingActivityFact.getRelatedFLUXLocations());
+ xPathUtil.appendWithoutWrapping(partialXpath).appendWithIndex(RELATED_FLUX_LOCATION,actCharacteristicsTypeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(fishingActivityFact, "fishingActivityFluxCharacteristicTypeCode");
+ }
+
return fishingActivityFact;
}
private List mapToRelatedVTMCodes(List fishingActivities) {
List codes = new ArrayList<>();
- if(CollectionUtils.isEmpty(fishingActivities)){
+ if (CollectionUtils.isEmpty(fishingActivities)) {
return codes;
}
fishingActivities.forEach(fa -> {
List relatedVesselTransportMeans = fa.getRelatedVesselTransportMeans();
- if(CollectionUtils.isNotEmpty(relatedVesselTransportMeans)){
+ if (CollectionUtils.isNotEmpty(relatedVesselTransportMeans)) {
relatedVesselTransportMeans.forEach(vtm -> {
- if(vtm != null && vtm.getRoleCode() != null){
+ if (vtm != null && vtm.getRoleCode() != null) {
codes.add(mapToCodeType(vtm.getRoleCode()));
}
});
@@ -411,13 +431,13 @@ private List mapToRelatedVTMCodes(List fishingActivit
private List extractRoleCodes(List vesselTransportMeans) {
List roleCodes = new ArrayList<>();
- if(CollectionUtils.isEmpty(vesselTransportMeans)){
+ if (CollectionUtils.isEmpty(vesselTransportMeans)) {
return roleCodes;
}
vesselTransportMeans = vesselTransportMeans.stream()
.filter(Objects::nonNull)
.collect(Collectors.toList());
- vesselTransportMeans.forEach((trspMean)-> roleCodes.add(mapToCodeType(trspMean.getRoleCode())));
+ vesselTransportMeans.forEach((trspMean) -> roleCodes.add(mapToCodeType(trspMean.getRoleCode())));
return roleCodes;
}
@@ -429,7 +449,7 @@ public DateTime mapToJodaDateTime(DateTimeType creationDateTime) {
dateTimeOfCreationOfMessage = new DateTime(repDat);
} else if (creationDateTime.getDateTimeString() != null && org.apache.commons.lang3.StringUtils.isNotEmpty(creationDateTime.getDateTimeString().getValue())) {
try {
- Date parsedDate = DateUtils.parseToUTCDate(creationDateTime.getDateTimeString().getValue(),creationDateTime.getDateTimeString().getFormat());
+ Date parsedDate = DateUtils.parseToUTCDate(creationDateTime.getDateTimeString().getValue(), creationDateTime.getDateTimeString().getFormat());
dateTimeOfCreationOfMessage = new DateTime(parsedDate);
} catch (IllegalArgumentException e) {
log.warn("[WARN] Couldn't extract date from CreationDateTime of Message!", e);
@@ -448,7 +468,7 @@ public FluxFaReportMessageFact generateFactForFluxFaReportMessage(FLUXFAReportMe
fluxFaReportMessageFact.setSenderOrReceiver(senderReceiver);
- if(fluxfaReportMessage.getFLUXReportDocument() != null){
+ if (fluxfaReportMessage.getFLUXReportDocument() != null) {
fluxFaReportMessageFact.setCreationDateOfMessage(mapToJodaDateTime(fluxfaReportMessage.getFLUXReportDocument().getCreationDateTime()));
}
@@ -488,6 +508,12 @@ public FluxFaReportMessageFact generateFactForFluxFaReportMessage(FLUXFAReportMe
fluxFaReportMessageFact.setRelatedFaQueryIDs(faQueryIds);
xPathUtil.appendWithoutWrapping(partialXpath).append(REFERENCED_ID).storeInRepo(fluxFaReportMessageFact, "relatedFaQueryIDs");
+ if(fluxfaReportMessage.getFLUXReportDocument() != null && fluxfaReportMessage.getFAReportDocuments() != null && !fluxfaReportMessage.getFAReportDocuments().isEmpty()
+ && fluxfaReportMessage.getFAReportDocuments().get(0).getRelatedFLUXReportDocument() != null && fluxfaReportMessage.getFAReportDocuments().get(0).getRelatedFLUXReportDocument().getOwnerFLUXParty() != null) {
+ fluxFaReportMessageFact.setRelatedOwnerFluxPartyIds(mapToIdTypes(fluxfaReportMessage.getFAReportDocuments().get(0).getRelatedFLUXReportDocument().getOwnerFLUXParty().getIDS()));
+ xPathUtil.appendWithoutWrapping(partialXpath).append(FA_REPORT_DOCUMENT,RELATED_FLUX_REPORT_DOCUMENT, OWNER_FLUX_PARTY, ID).storeInRepo(fluxFaReportMessageFact, "relatedOwnerFluxPartyIds");
+ }
+
return fluxFaReportMessageFact;
}
@@ -512,11 +538,33 @@ public VesselTransportMeansFact generateFactForVesselTransportMean(VesselTranspo
xPathUtil.clear();
return null;
}
- VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, null);
+ VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, null,true);
vesselTransportMeansFact.setIsFromFaReport(isCommingFromFaReportDocument);
return vesselTransportMeansFact;
}
+ public List generateFactForVesselTransportMeansForParentFA(List vesselTransportMeans, List facts,
+ un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType) {
+ if (CollectionUtils.isEmpty(vesselTransportMeans)) {
+ xPathUtil.clear();
+ return emptyList();
+ }
+ List list = new ArrayList<>();
+ int index = 1;
+ String strToAppend = xPathUtil.getValue();
+ for (VesselTransportMeans vesselTransportMean : vesselTransportMeans) {
+ VesselTransportMeansFact vesselTransportMeansFact = generateFactForVesselTransportMean(vesselTransportMean, facts, fishActType, false);
+ vesselTransportMeansFact.setIsFromParentFishingActivity(true);
+ xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).storeInRepo(vesselTransportMeansFact, "RoleCode");
+ xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).append(ID).storeInRepo(vesselTransportMeansFact, "relatedIds");
+ xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).append(REGISTRATION_VESSEL_COUNTRY).append(ID).storeInRepo(vesselTransportMeansFact, "relatedVesselCountryId");
+ xPathUtil.appendWithoutWrapping(strToAppend).appendWithIndex(RELATED_VESSEL_TRANSPORT_MEANS, index).storeInRepo(vesselTransportMeansFact, "relatedVesselTransportMeans");
+ list.add(vesselTransportMeansFact);
+ index++;
+ }
+ return list;
+ }
+
public List generateFactForVesselTransportMeans(List vesselTransportMeans, List facts,
un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType) {
if (CollectionUtils.isEmpty(vesselTransportMeans)) {
@@ -528,14 +576,15 @@ public List generateFactForVesselTransportMeans(List facts,
- un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType) {
+ un.unece.uncefact.data.standard.unqualifieddatatype._20.CodeType fishActType,
+ boolean isSpecifiedVesselTransportMeans) {
if (vesselTransportMean == null) {
xPathUtil.clear();
return null;
@@ -546,7 +595,7 @@ public VesselTransportMeansFact generateFactForVesselTransportMean(VesselTranspo
String toBeAppendedAlways = xPathUtil.getValue();
// Generate facts for ID Types. This is done so that we can have the right xPath to the specific ID that failed!
- if(CollectionUtils.isNotEmpty(vesselTransportMean.getIDS())){
+ if (CollectionUtils.isNotEmpty(vesselTransportMean.getIDS())) {
generateFactsForSimpleIdTypes(facts, vesselTransportMean.getIDS(), toBeAppendedAlways);
}
@@ -585,6 +634,16 @@ public VesselTransportMeansFact generateFactForVesselTransportMean(VesselTranspo
xPathUtil.appendWithoutWrapping(toBeAppendedAlways);
generateFactsForVesselPositionEvents(vesselTransportMean.getSpecifiedVesselPositionEvents(), facts);
+ if(isSpecifiedVesselTransportMeans){
+ vesselTransportMeansFact.setSpecifiedIds(vesselTransportMeansFact.getIds());
+ vesselTransportMeansFact.setSpecifiedVesselCountryId(vesselTransportMeansFact.getRegistrationVesselCountryId());
+ vesselTransportMeansFact.setSpecifiedVesselTransportMeans(vesselTransportMean);
+ } else {
+ vesselTransportMeansFact.setRelatedIds(vesselTransportMeansFact.getIds());
+ vesselTransportMeansFact.setRelatedVesselCountryId(vesselTransportMeansFact.getRegistrationVesselCountryId());
+ vesselTransportMeansFact.setRelatedVesselTransportMeans(vesselTransportMean);
+ }
+
return vesselTransportMeansFact;
}
@@ -599,7 +658,7 @@ private void generateFactsForVesselPositionEvents(List spec
int index = 1;
for (VesselPositionEvent specifiedVesselPositionEvent : specifiedVesselPositionEvents) {
- if(specifiedVesselPositionEvent == null){
+ if (specifiedVesselPositionEvent == null) {
xPathUtil.clear();
continue;
}
@@ -633,7 +692,7 @@ private void generateFactsForVesselPositionEvents(List spec
}
private void generateFactsForSimpleIdTypes(List facts, List ids, String partialXpath) {
- if(CollectionUtils.isEmpty(ids)){
+ if (CollectionUtils.isEmpty(ids)) {
return;
}
int index = 1;
@@ -880,7 +939,7 @@ public List generateFactsForFaCatch(FishingActivity activity, bool
faCatchFact.setFishingActivityTypeCode(mapToCodeType(activity.getTypeCode()));
xPathUtil.appendWithoutWrapping(partialXPath).append(TYPE_CODE).storeInRepo(faCatchFact, FISHING_ACTIVITY_TYPE_CODE);
- faCatchFact.setFaReportDocumentTypeCode(mapToCodeType(faReportDocument!=null?faReportDocument.getTypeCode():null));
+ faCatchFact.setFaReportDocumentTypeCode(mapToCodeType(faReportDocument != null ? faReportDocument.getTypeCode() : null));
xPathUtil.append(FLUXFA_REPORT_MESSAGE, FA_REPORT_DOCUMENT).storeInRepo(faCatchFact, FA_REPORT_DOCUMENT_TYPE_CODE);
partialXPath = xPathUtil.appendWithoutWrapping(partialXPath1).appendWithIndex(SPECIFIED_FA_CATCH, index).getValue();
@@ -940,12 +999,26 @@ public List generateFactsForFaCatch(FishingActivity activity, bool
faCatchFact.setSpecifiedFLUXLocations(faCatch.getSpecifiedFLUXLocations());
xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION).storeInRepo(faCatchFact, "specifiedFLUXLocations");
+ if(CollectionUtils.isNotEmpty(faCatch.getSpecifiedFLUXLocations())){
+ faCatchFact.setFaCatchSpecifiedFLUXLocations(faCatch.getSpecifiedFLUXLocations());
+ xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION,ID).storeInRepo(faCatchFact, "faCatchSpecifiedFLUXLocations");
+ List fluxCharacteristics = getFluxCharacteristics(faCatch.getSpecifiedFLUXLocations());
+ faCatchFact.setFaCatchFluxCharacteristic(fluxCharacteristics);
+ Integer catchCharacteristicsIndex = getIndexForFluxCharacteristics(faCatch.getSpecifiedFLUXLocations());
+ xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,catchCharacteristicsIndex).append(APPLICABLE_FLUX_CHARACTERISTIC).storeInRepo(faCatchFact, "faCatchFluxCharacteristic");
+ Integer catchCharacteristicsTypeIndex = getIndexForFluxCharacteristicsWithTypeCode(faCatch.getSpecifiedFLUXLocations());
+ xPathUtil.appendWithoutWrapping(partialXPath).appendWithIndex(SPECIFIED_FLUX_LOCATION,catchCharacteristicsTypeIndex).append(APPLICABLE_FLUX_CHARACTERISTIC,TYPE_CODE).storeInRepo(faCatchFact, "faCatchFluxCharacteristicTypeCode");
+ }
+
+ faCatchFact.setUsedFishingGears(faCatch.getUsedFishingGears());
+ xPathUtil.appendWithoutWrapping(partialXPath).append(USED_FISHING_GEAR).storeInRepo(faCatchFact, "usedFishingGears");
+
if (faCatch.getSpecifiedFLUXLocations() != null) {
faCatchFact.setFaCatchFluxLocationId(mapFLUXLocationIDs(faCatch.getSpecifiedFLUXLocations()));
}
xPathUtil.appendWithoutWrapping(partialXPath).append(SPECIFIED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "faCatchFluxLocationId");
- if(CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)){
+ if (CollectionUtils.isNotEmpty(fishActRelatedFluxLocations)) {
faCatchFact.setFishActRelatedFluxLocationIds(mapFLUXLocationIDs(fishActRelatedFluxLocations));
}
xPathUtil.appendWithoutWrapping(partialXPath1).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fishActRelatedFluxLocationIds");
@@ -958,7 +1031,7 @@ public List generateFactsForFaCatch(FishingActivity activity, bool
xPathUtil.appendWithoutWrapping(partialXPath).append(RELATED_FLUX_LOCATION, ID).storeInRepo(faCatchFact, "fluxLocationId");
}
- if(faReportDocument != null && faReportDocument.getSpecifiedVesselTransportMeans() != null && faReportDocument.getSpecifiedVesselTransportMeans().getRegistrationVesselCountry() != null){
+ if (faReportDocument != null && faReportDocument.getSpecifiedVesselTransportMeans() != null && faReportDocument.getSpecifiedVesselTransportMeans().getRegistrationVesselCountry() != null) {
faCatchFact.setFarepDocSpecVesselTrpmRegVesselCountryId(mapToIdType(faReportDocument.getSpecifiedVesselTransportMeans().getRegistrationVesselCountry().getID()));
}
@@ -976,15 +1049,52 @@ public List generateFactsForFaCatch(FishingActivity activity, bool
return facts;
}
+ private List getFluxCharacteristics(List fishActRelatedFluxLocations){
+ return fishActRelatedFluxLocations.stream()
+ .filter(t -> t.getApplicableFLUXCharacteristics() != null && !t.getApplicableFLUXCharacteristics().isEmpty())
+ .map(r -> r.getApplicableFLUXCharacteristics()).flatMap(List::stream).collect(Collectors.toList());
+ }
+
+ private Integer getIndexForFluxCharacteristics(List fishActRelatedFluxLocations){
+
+ Integer index = 1;
+ for(FLUXLocation location:fishActRelatedFluxLocations){
+ if(location.getApplicableFLUXCharacteristics() != null && !location.getApplicableFLUXCharacteristics().isEmpty()){
+
+ index++;
+ }
+
+ }
+ if(index >= fishActRelatedFluxLocations.size()){
+ return 1;
+ }
+
+ return index;
+ }
+
+ private Integer getIndexForFluxCharacteristicsWithTypeCode(List fishActRelatedFluxLocations){
+
+ Integer index = 1;
+ for(FLUXLocation location:fishActRelatedFluxLocations){
+ if(location.getApplicableFLUXCharacteristics() != null && !location.getApplicableFLUXCharacteristics().isEmpty() && location.getApplicableFLUXCharacteristics().get(0).getTypeCode() != null){
+
+ return index;
+ }
+
+ index++;
+ }
+ return 1;
+ }
+
private void addFactsForAAPStock(List relatedAAPStocks, List facts) {
- if(CollectionUtils.isEmpty(relatedAAPStocks)){
+ if (CollectionUtils.isEmpty(relatedAAPStocks)) {
xPathUtil.clear();
return;
}
String partialXpath = xPathUtil.getValue();
int index = 1;
for (AAPStock relatedAAPStock : relatedAAPStocks) {
- if(relatedAAPStock == null){
+ if (relatedAAPStock == null) {
xPathUtil.clear();
continue;
}
@@ -997,7 +1107,7 @@ private void addFactsForAAPStock(List relatedAAPStocks, List facts) {
- if(CollectionUtils.isEmpty(faCatch.getAppliedAAPProcesses())) {
+ if (CollectionUtils.isEmpty(faCatch.getAppliedAAPProcesses())) {
xPathUtil.clear();
return;
}
@@ -1209,7 +1319,7 @@ public FaDepartureFact generateFactsForFaDeparture(FishingActivity fishingActivi
List specifiedFishingGears = fishingActivity.getSpecifiedFishingGears();
List roleCodes = new ArrayList<>();
- if(CollectionUtils.isNotEmpty(specifiedFishingGears)){
+ if (CollectionUtils.isNotEmpty(specifiedFishingGears)) {
for (FishingGear fishingGear : specifiedFishingGears) {
roleCodes.addAll(mapToCodeTypes(fishingGear.getRoleCodes()));
}
@@ -1226,7 +1336,7 @@ public FaDepartureFact generateFactsForFaDeparture(FishingActivity fishingActivi
for (FACatch faCatch : specifiedFACatches) {
CodeType codeType = mapToCodeType(faCatch.getTypeCode());
- if (codeType != null){
+ if (codeType != null) {
codeTypeList.add(codeType);
}
}
@@ -1405,12 +1515,14 @@ public FaFishingOperationFact generateFactsForFishingOperation(FishingActivity f
for (FishingActivity activity : relatedFishingActivities) {
List fishingGearRoleCodes1 = getFishingGearRoleCodes(activity.getSpecifiedFishingGears());
List fishingGearRoleCodes = faFishingOperationFact.getFishingGearRoleCodes();
- if (CollectionUtils.isNotEmpty(fishingGearRoleCodes)){
+ if (CollectionUtils.isNotEmpty(fishingGearRoleCodes)) {
fishingGearRoleCodes.addAll(fishingGearRoleCodes1);
}
faFishingOperationFact.setFishingGearRoleCodes(fishingGearRoleCodes);
xPathUtil.appendWithoutWrapping(partialXpath).append(RELATED_FISHING_ACTIVITY).appendWithIndex(VESSEL_RELATED_ACTIVITY_CODE, activityIndex)
.storeInRepo(faFishingOperationFact, FISHING_GEAR_ROLE_CODES_PROP);
+
+ activityIndex++;
}
faFishingOperationFact.setRelatedFishingActivitiesRelatedFLUXLocations(getRelatedFluxLocations(fishingActivity.getRelatedFishingActivities()));
@@ -1526,7 +1638,7 @@ private List getFishingActivityTypeCodeList(List fish
List fishingActivityTypeCodes = new ArrayList<>();
for (FishingActivity activity : fishingActivities) {
CodeType codeType = mapToCodeType(activity.getTypeCode());
- if(codeType != null){
+ if (codeType != null) {
fishingActivityTypeCodes.add(codeType);
}
}
@@ -1564,7 +1676,7 @@ public FaRelocationFact generateFactsForRelocation(FishingActivity fishingActivi
for (FLUXLocation fluxLocation : faCatch.getDestinationFLUXLocations()) {
fluxLocationTypeCodes.add(mapToCodeType(fluxLocation.getTypeCode()));
IdType idType = mapToIdType(fluxLocation.getID());
- if (idType != null){
+ if (idType != null) {
fluxLocationIds.add(idType);
}
destinationFluxLocations.add(fluxLocation);
@@ -1760,7 +1872,10 @@ public FaNotificationOfArrivalFact generateFactsForPriorNotificationOfArrival(Fi
}
faNotificationOfArrivalFact.setSpecifiedFACatchTypeCodes(codeTypeList);
xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FA_CATCH, TYPE_CODE).storeInRepo(faNotificationOfArrivalFact, "specifiedFACatchTypeCodes");
+ } else {
+ xPathUtil.appendWithoutWrapping(partialXpath).storeInRepo(faNotificationOfArrivalFact, SPECIFIED_FA_CATCHES);
}
+
faNotificationOfArrivalFact.setReasonCode(mapToCodeType(fishingActivity.getReasonCode()));
xPathUtil.appendWithoutWrapping(partialXpath).append(REASON_CODE).storeInRepo(faNotificationOfArrivalFact, REASON_CODE_PROP);
@@ -1769,7 +1884,7 @@ public FaNotificationOfArrivalFact generateFactsForPriorNotificationOfArrival(Fi
FishingTrip specifiedFishingTrip = fishingActivity.getSpecifiedFishingTrip();
if (specifiedFishingTrip != null) {
- if (CollectionUtils.isNotEmpty(specifiedFishingTrip.getSpecifiedDelimitedPeriods())){
+ if (CollectionUtils.isNotEmpty(specifiedFishingTrip.getSpecifiedDelimitedPeriods())) {
List specifiedDelimitedPeriods = specifiedFishingTrip.getSpecifiedDelimitedPeriods();
faNotificationOfArrivalFact.setDelimitedPeriods(specifiedDelimitedPeriods.get(0));
}
@@ -2018,6 +2133,9 @@ public FaQueryFact generateFactsForFaQuery(FAQuery faQuery) {
faQueryFact.setSimpleFAQueryParameterTypeCodes(codeTypes);
}
+ faQueryFact.setNonUniqueIdsList(nonUniqueIdsList);
+ xPathUtil.appendWithoutWrapping(partialXpath).append(FLUXFA_QUERY_MESSAGE, ID).storeInRepo(faQueryFact, "nonUniqueIdsList");
+
return faQueryFact;
}
@@ -2095,7 +2213,7 @@ public AbstractRelocationOrTranshipmentFact generateFactsForNotificationOrDeclar
return null;
}
AbstractRelocationOrTranshipmentFact faNotificationOfRelocationOrTranshipmentFact;
- if(FaReportDocumentType.DECLARATION.name().equals(faReportDocument.getTypeCode().getValue())){
+ if (FaReportDocumentType.DECLARATION.name().equals(faReportDocument.getTypeCode().getValue())) {
faNotificationOfRelocationOrTranshipmentFact = new FaDeclarationOfRelocationOrTranshipmentFact();
} else {
faNotificationOfRelocationOrTranshipmentFact = new FaNotificationOfRelocationOrTranshipmentFact();
@@ -2181,6 +2299,31 @@ public ValidationQualityAnalysisFact generateFactsForValidationQualityAnalysis(V
return qualityAnalysisFact;
}
+ public List generateFactsForFlapDocuments(List specifiedFLAPDocuments) {
+
+ if (CollectionUtils.isEmpty(specifiedFLAPDocuments)) {
+ xPathUtil.clear();
+ return Lists.newArrayList();
+ }
+
+ return specifiedFLAPDocuments.stream().filter(Objects::nonNull).map(this::generateFactForFlapDocument).collect(Collectors.toList());
+ }
+
+ private FlapDocumentFact generateFactForFlapDocument(FLAPDocument flapDocument) {
+ final String partialXpath = xPathUtil.getValue();
+
+ FlapDocumentFact flapDocumentFact = new FlapDocumentFact();
+ xPathUtil.appendWithoutWrapping(partialXpath).append(SPECIFIED_FLAP_DOCUMENT, ID).storeInRepo(flapDocumentFact, "id");
+ if (flapDocument.getID() != null) {
+ IdType idType = new IdType();
+ idType.setSchemeId(flapDocument.getID().getSchemeID());
+ idType.setValue(flapDocument.getID().getValue());
+ flapDocumentFact.setId(idType);
+ }
+
+ return flapDocumentFact;
+ }
+
private List mapFromTextTypeToString(List txTypeList) {
if (CollectionUtils.isEmpty(txTypeList)) {
return Collections.emptyList();
@@ -2197,7 +2340,7 @@ public eu.europa.ec.fisheries.uvms.rules.service.business.fact.CodeType mapToCod
return null;
}
boolean notBlankValue = StringUtils.isNotBlank(codeType.getValue());
- if (notBlankValue){
+ if (notBlankValue) {
eu.europa.ec.fisheries.uvms.rules.service.business.fact.CodeType codeType1 = new eu.europa.ec.fisheries.uvms.rules.service.business.fact.CodeType();
codeType1.setListId(codeType.getListID());
codeType1.setValue(codeType.getValue());
@@ -2212,7 +2355,7 @@ public MeasureType mapToMeasureType(QuantityType quantityType) {
}
boolean notNullValue = quantityType.getValue() != null;
- if (notNullValue){
+ if (notNullValue) {
MeasureType measureType1 = new MeasureType();
measureType1.setUnitCode(quantityType.getUnitCode());
measureType1.setValue(quantityType.getValue());
@@ -2247,7 +2390,7 @@ public List mapToIdTypes(List idTypes) {
IdType idType = mapToIdType(iDType);
if (idType != null) {
IdType idType1 = mapToIdType(iDType);
- if (idType1 != null){
+ if (idType1 != null) {
idTypeList.add(idType1);
}
}
@@ -2274,7 +2417,7 @@ public List mapToMeasureType(List list = new ArrayList<>();
for (un.unece.uncefact.data.standard.unqualifieddatatype._20.MeasureType measureType : measureTypes) {
MeasureType measureType1 = mapToMeasureType(measureType);
- if (measureType1 != null){
+ if (measureType1 != null) {
list.add(measureType1);
}
}
@@ -2596,7 +2739,7 @@ private List mapFluxLocationsToCodeTypes(List locations)
if (CollectionUtils.isNotEmpty(locations)) {
for (FLUXLocation fluxLocation : locations) {
CodeType codeType = mapToCodeType(fluxLocation.getTypeCode());
- if(codeType != null){
+ if (codeType != null) {
typeCodes.add(codeType);
}
}
@@ -2611,7 +2754,7 @@ private List mapDurationMeasure(List delimitedPeri
for (DelimitedPeriod delimitedPeriod : delimitedPeriods) {
if (delimitedPeriod.getDurationMeasure() != null) {
MeasureType measureType = mapToMeasureType(delimitedPeriod.getDurationMeasure());
- if (measureType != null){
+ if (measureType != null) {
measureTypes.add(measureType);
}
}
@@ -2652,7 +2795,7 @@ private List mapFromContactPartyToCodeType(List contactP
codeTypes = new ArrayList<>();
for (ContactParty contactParty : contactPartyList) {
List codeTypes1 = mapToCodeTypes(contactParty.getRoleCodes());
- if (CollectionUtils.isNotEmpty(codeTypes1)){
+ if (CollectionUtils.isNotEmpty(codeTypes1)) {
codeTypes.addAll(mapToCodeTypes(contactParty.getRoleCodes()));
}
}
@@ -2751,7 +2894,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List
case PACKAGING_UNIT_QUANTITY:
if (aapProduct.getPackagingUnitQuantity() != null) {
MeasureType measureType = mapToMeasureType(aapProduct.getPackagingUnitQuantity());
- if (measureType != null){
+ if (measureType != null) {
measureTypes.add(measureType);
}
}
@@ -2759,7 +2902,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List
case AVERAGE_WEIGHT_MEASURE:
if (aapProduct.getPackagingUnitAverageWeightMeasure() != null) {
MeasureType measureType = mapToMeasureType(aapProduct.getPackagingUnitAverageWeightMeasure());
- if (measureType != null){
+ if (measureType != null) {
measureTypes.add(measureType);
}
}
@@ -2767,7 +2910,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List
case WEIGHT_MEASURE:
if (aapProduct.getWeightMeasure() != null) {
MeasureType measureType = mapToMeasureType(aapProduct.getWeightMeasure());
- if (measureType != null){
+ if (measureType != null) {
measureTypes.add(measureType);
}
}
@@ -2775,7 +2918,7 @@ private void mapAapProductToMeasureType(String methodToChoose, List
case UNIT_QUANTITY:
if (aapProduct.getUnitQuantity() != null) {
MeasureType measureType = mapToMeasureType(aapProduct.getUnitQuantity());
- if (measureType != null){
+ if (measureType != null) {
measureTypes.add(measureType);
}
}
@@ -2796,7 +2939,7 @@ private List getAAPProductPackagingTypeCode(List appliedAA
for (AAPProduct aapProduct : aapProcess.getResultAAPProducts()) {
if (aapProduct.getPackagingTypeCode() != null) {
CodeType codeType = mapToCodeType(aapProduct.getPackagingTypeCode());
- if (codeType != null){
+ if (codeType != null) {
codeTypes.add(codeType);
}
}
@@ -2828,7 +2971,7 @@ private List mapToFLUXCharacteristicsTypeCodes(List getApplicableFLUXCharacteristicsValueQuantity(List getFLUXLocationTypeCodes(List fluxLocations
for (FLUXLocation fluxLocation : fluxLocations) {
if (fluxLocation.getTypeCode() != null) {
CodeType codeType = mapToCodeType(fluxLocation.getTypeCode());
- if (codeType != null){
+ if (codeType != null) {
codeTypes.add(codeType);
}
}
@@ -2876,7 +3019,7 @@ private List getFLUXLocationRFMOCodes(List fluxLocations
for (FLUXLocation fluxLocation : fluxLocations) {
if (fluxLocation.getRegionalFisheriesManagementOrganizationCode() != null) {
CodeType codeType = mapToCodeType(fluxLocation.getRegionalFisheriesManagementOrganizationCode());
- if (codeType != null){
+ if (codeType != null) {
codeTypes.add(codeType);
}
}
@@ -2934,7 +3077,7 @@ private List