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

jsinovassinnaik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new 12d5cbc9c UNOMI-787 : migrate view event page path property (#640)
12d5cbc9c is described below

commit 12d5cbc9cf4c617aab29cc724b00d595fee6e710
Author: jsinovassin <58434978+jsinovas...@users.noreply.github.com>
AuthorDate: Fri Aug 11 11:03:30 2023 +0200

    UNOMI-787 : migrate view event page path property (#640)
    
    * UNOMI-787 : migrate view event page path property
---
 .../unomi/itests/migration/Migrate16xTo220IT.java  |  10 +++++++
 .../resources/migration/snapshots_repository.zip   | Bin 3886208 -> 3908941 
bytes
 .../migrate-2.4.0-15-viewEventPagePath.groovy      |  30 +++++++++++++++++++++
 .../2.4.0/base_update_by_query_request.json        |  27 +++++++++++++++++++
 .../2.4.0/view_event_page_path_migrate.painless    |  24 +++++++++++++++++
 5 files changed, 91 insertions(+)

diff --git 
a/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo220IT.java 
b/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo220IT.java
index 7dc321268..cddb44f49 100644
--- 
a/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo220IT.java
+++ 
b/itests/src/test/java/org/apache/unomi/itests/migration/Migrate16xTo220IT.java
@@ -98,6 +98,7 @@ public class Migrate16xTo220IT extends BaseIT {
         checkForMappingUpdates();
         checkEventSessionRollover2_2_0();
         checkIndexReductions2_2_0();
+        checkPagePathForEventView();
     }
 
     /**
@@ -332,4 +333,13 @@ public class Migrate16xTo220IT extends BaseIT {
         JsonNode jsonNode = 
objectMapper.readTree(HttpUtils.executePostRequest(httpClient, 
"http://localhost:9400"; + "/" + index + "/_count", requestBody, null));
         return jsonNode.get("count").asInt();
     }
+
+    /**
+     * Data set contains 2 events that had a value in properties.path:
+     * The properties.path should have been moved to 
properties.pageInfo.pagePath
+     */
+    private void checkPagePathForEventView() {
+        Assert.assertEquals(2, 
persistenceService.query("target.properties.pageInfo.pagePath", 
"/path/to/migrate/to/pageInfo", null, Event.class).size());
+        Assert.assertEquals(0, persistenceService.query("properties.path", 
"/path/to/migrate/to/pageInfo", null, Event.class).size());
+    }
 }
diff --git a/itests/src/test/resources/migration/snapshots_repository.zip 
b/itests/src/test/resources/migration/snapshots_repository.zip
index 38a4e9bfe..705a6241f 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.4.0-15-viewEventPagePath.groovy
 
b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.4.0-15-viewEventPagePath.groovy
new file mode 100644
index 000000000..faaac944d
--- /dev/null
+++ 
b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.4.0-15-viewEventPagePath.groovy
@@ -0,0 +1,30 @@
+import org.apache.unomi.shell.migration.service.MigrationContext
+import org.apache.unomi.shell.migration.utils.HttpUtils
+import org.apache.unomi.shell.migration.utils.MigrationUtils
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+MigrationContext context = migrationContext
+String esAddress = context.getConfigString("esAddress")
+String indexPrefix = context.getConfigString("indexPrefix")
+
+context.performMigrationStep("2.4.0-migrate-view-event-page-path", () -> {
+    String updatePathScript = 
MigrationUtils.getFileWithoutComments(bundleContext, 
"requestBody/2.4.0/view_event_page_path_migrate.painless")
+    String baseSettings = MigrationUtils.resourceAsString(bundleContext, 
"requestBody/2.4.0/base_update_by_query_request.json")
+    HttpUtils.executePostRequest(context.getHttpClient(), 
"${esAddress}/${indexPrefix}-event/_update_by_query", 
baseSettings.replace('#painless', updatePathScript), null)
+})
diff --git 
a/tools/shell-commands/src/main/resources/requestBody/2.4.0/base_update_by_query_request.json
 
b/tools/shell-commands/src/main/resources/requestBody/2.4.0/base_update_by_query_request.json
new file mode 100644
index 000000000..80399c8c9
--- /dev/null
+++ 
b/tools/shell-commands/src/main/resources/requestBody/2.4.0/base_update_by_query_request.json
@@ -0,0 +1,27 @@
+{
+  "script": {
+    "source": "#painless",
+    "lang": "painless"
+  },
+  "query": {
+    "bool": {
+      "must": [
+        {
+          "match": {
+            "itemType": "event"
+          }
+        },
+        {
+          "match": {
+            "eventType": "view"
+          }
+        },
+        {
+          "exists": {
+            "field": "target.properties.path"
+          }
+        }
+      ]
+    }
+  }
+}
diff --git 
a/tools/shell-commands/src/main/resources/requestBody/2.4.0/view_event_page_path_migrate.painless
 
b/tools/shell-commands/src/main/resources/requestBody/2.4.0/view_event_page_path_migrate.painless
new file mode 100644
index 000000000..7ac82e437
--- /dev/null
+++ 
b/tools/shell-commands/src/main/resources/requestBody/2.4.0/view_event_page_path_migrate.painless
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+if (ctx._source.target != null && ctx._source.target.properties != null && 
ctx._source.target.properties.path != null) {
+    if (ctx._source.target.properties.pageInfo == null) {
+        ctx._source.target.properties.put('pageInfo', new HashMap());
+    }
+    ctx._source.target.properties.pageInfo.put('pagePath', 
ctx._source.target.properties.path);
+    ctx._source.target.properties.remove('path');
+}

Reply via email to