You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2022/08/24 16:10:46 UTC

[unomi] 01/01: UNOMI-644 : update migration script to add scope to login event

This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a commit to branch add-system-site-scope
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit e5971ef81b802ecbba3cf78627c5127e2576ed96
Author: David Griffon <dg...@jahia.com>
AuthorDate: Wed Aug 24 18:10:32 2022 +0200

    UNOMI-644 : update migration script to add scope to login event
---
 .../unomi/itests/migration/Migrate16xTo200IT.java  |  18 ++++++++++++++++++
 .../resources/migration/snapshots_repository.zip   | Bin 880112 -> 868699 bytes
 ...copes.groovy => migrate-2.0.0-20-scopes.groovy} |   0
 .../requestBody/2.0.0/event_migrate.painless       |  11 ++++++++++-
 4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo200IT.java b/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo200IT.java
index 115182ed8..2eb4bcdef 100644
--- a/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo200IT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo200IT.java
@@ -79,6 +79,7 @@ public class Migrate16xTo200IT extends BaseIT {
         checkMergedProfilesAliases();
         checkProfileInterests();
         checkScopeHaveBeenCreated();
+        checkLoginEventWithScope();
         checkFormEventRestructured();
         checkViewEventRestructured();
         checkEventTypesNotPersistedAnymore();
@@ -145,6 +146,23 @@ public class Migrate16xTo200IT extends BaseIT {
         }
     }
 
+    private void checkLoginEventWithScope() {
+        List<Event> events = persistenceService.query("eventType", "view", null, Event.class);
+        List<String> digitallLoginEvent = Arrays.asList("4054a3e0-35ef-4256-999b-b9c05c1209f1", "f3f71ff8-2d6d-4b6c-8bdc-cb39905cddfe", "ff24ae6f-5a98-421e-aeb0-e86855b462ff");
+        for (Event loginEvent : events) {
+            if (loginEvent.getItemId().equals("5c4ac1df-f42b-4117-9432-12fdf9ecdf98")) {
+                Assert.assertEquals(loginEvent.getScope(), "systemsite");
+                Assert.assertEquals(loginEvent.getTarget().getScope(), "systemsite");
+                Assert.assertEquals(loginEvent.getSource().getScope(), "systemsite");
+            }
+            if (digitallLoginEvent.contains(loginEvent.getItemId())) {
+                Assert.assertEquals(loginEvent.getScope(), "digitall");
+                Assert.assertEquals(loginEvent.getTarget().getScope(), "digitall");
+                Assert.assertEquals(loginEvent.getSource().getScope(), "digitall");
+            }
+        }
+    }
+
     /**
      * Data set contains a view event (id: a4aa836b-c437-48ef-be02-6fbbcba3a1de) with two interests: football:50 and basketball:30
      * Data set contains a view event (id: 34d53399-f173-451f-8d48-f34f5d9618a9) with two URL Parameters: paramerter_test:value, multiple_paramerter_test:[value1, value2]
diff --git a/itests/src/test/resources/migration/snapshots_repository.zip b/itests/src/test/resources/migration/snapshots_repository.zip
index 58eb87e72..1252d50a1 100644
Binary files a/itests/src/test/resources/migration/snapshots_repository.zip and b/itests/src/test/resources/migration/snapshots_repository.zip differ
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-02-scopes.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-20-scopes.groovy
similarity index 100%
rename from tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-02-scopes.groovy
rename to tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-20-scopes.groovy
diff --git a/tools/shell-commands/src/main/resources/requestBody/2.0.0/event_migrate.painless b/tools/shell-commands/src/main/resources/requestBody/2.0.0/event_migrate.painless
index 5c8703dc8..800fa97b7 100644
--- a/tools/shell-commands/src/main/resources/requestBody/2.0.0/event_migrate.painless
+++ b/tools/shell-commands/src/main/resources/requestBody/2.0.0/event_migrate.painless
@@ -15,8 +15,17 @@
  * limitations under the License.
  */
 
+/* Handle login events */
+if ('login' == ctx._source.eventType) {
+    /* Look for empty scope */
+    if (ctx._source.scope == '') {
+         ctx._source.put('scope', 'systemsite');
+         ctx._source.source.put('scope', 'systemsite');
+         ctx._source.target.put('scope', 'systemsite');
+    }
+}
 /* Handle view events */
-if ('view' == ctx._source.eventType){
+if ('view' == ctx._source.eventType) {
 
     /* Check for interests */
     if (ctx._source.target != null && ctx._source.target.properties != null && ctx._source.target.properties.interests != null){