You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by js...@apache.org on 2024/10/31 11:02:38 UTC
(unomi) branch UNOMI-862 created (now 99e116e9a)
This is an automated email from the ASF dual-hosted git repository.
jsinovassinnaik pushed a change to branch UNOMI-862
in repository https://gitbox.apache.org/repos/asf/unomi.git
at 99e116e9a UNOMI-862: fix scope check on migration
This branch includes the following new commits:
new 99e116e9a UNOMI-862: fix scope check on migration
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(unomi) 01/01: UNOMI-862: fix scope check on migration
Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jsinovassinnaik pushed a commit to branch UNOMI-862
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 99e116e9a503d117ac03e99166f324855d85bee2
Author: jsinovassin <js...@jahia.com>
AuthorDate: Thu Oct 31 12:02:03 2024 +0100
UNOMI-862: fix scope check on migration
---
.../java/org/apache/unomi/shell/migration/utils/HttpUtils.java | 2 +-
.../META-INF/cxs/migration/migrate-2.0.0-20-scopes.groovy | 8 +++++---
.../main/resources/requestBody/2.0.0/scope_search_by_item_id.json | 8 ++++++++
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/HttpUtils.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/HttpUtils.java
index 503714a18..faa341e8a 100644
--- a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/HttpUtils.java
+++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/HttpUtils.java
@@ -124,7 +124,7 @@ public class HttpUtils {
httpPost.addHeader("accept", "application/json");
if (jsonData != null) {
- StringEntity input = new StringEntity(jsonData);
+ StringEntity input = new StringEntity(jsonData, "UTF-8");
input.setContentType("application/json");
httpPost.setEntity(input);
}
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-20-scopes.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-20-scopes.groovy
index 7b291abcd..71868ad82 100644
--- a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-20-scopes.groovy
+++ b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-20-scopes.groovy
@@ -25,6 +25,7 @@ MigrationContext context = migrationContext
def jsonSlurper = new JsonSlurper()
String searchScopesRequest = MigrationUtils.resourceAsString(bundleContext,"requestBody/2.0.0/scope_search.json")
String saveScopeRequestBulk = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/scope_save_bulk.ndjson")
+String searchScopeById = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/scope_search_by_item_id.json")
String esAddress = context.getConfigString("esAddress")
String indexPrefix = context.getConfigString("indexPrefix")
String scopeIndex = indexPrefix + "-scope"
@@ -55,8 +56,9 @@ context.performMigrationStep("2.0.0-create-scopes-from-existing-events", () -> {
// check that the scope doesn't already exists
def scopeAlreadyExists = false
try {
- def existingScope = jsonSlurper.parseText(HttpUtils.executeGetRequest(context.getHttpClient(), esAddress + "/" + scopeIndex + "/_doc/" + bucket.key, null));
- scopeAlreadyExists = existingScope.found
+ context.printMessage("Check if " + bucket.key + " exists")
+ def existingScope = jsonSlurper.parseText(HttpUtils.executePostRequest(context.getHttpClient(), esAddress + "/" + scopeIndex + "/_search/", searchScopeById.replace("##scope##", bucket.key), null));
+ scopeAlreadyExists = existingScope.hits.total.value > 0
} catch (HttpRequestException e) {
// can happen in case response code > 400 due to item not exist in ElasticSearch
}
@@ -77,4 +79,4 @@ context.performMigrationStep("2.0.0-create-scopes-from-existing-events", () -> {
HttpUtils.executeGetRequest(context.getHttpClient(), esAddress + "/" + scopeIndex + "/_refresh", null)
}
}
-})
\ No newline at end of file
+})
diff --git a/tools/shell-commands/src/main/resources/requestBody/2.0.0/scope_search_by_item_id.json b/tools/shell-commands/src/main/resources/requestBody/2.0.0/scope_search_by_item_id.json
new file mode 100644
index 000000000..54362daf4
--- /dev/null
+++ b/tools/shell-commands/src/main/resources/requestBody/2.0.0/scope_search_by_item_id.json
@@ -0,0 +1,8 @@
+{
+ "query": {
+ "size": 1,
+ "term": {
+ "itemId": "##scope##"
+ }
+ }
+}