UNOMI-150 Fix migration script versions

Rename the old MigrationTo130 to MigrationTo121, change toVersion.
Rename MigrationTo130IndexTemplate to MigrationTo122, change toVersion.


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/a8650276
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/a8650276
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/a8650276

Branch: refs/heads/master
Commit: a86502769067dc8bf0990b5cc55057a3ae56dc7e
Parents: d7a8b2a
Author: Jarek Lipski <jlip...@jahia.com>
Authored: Thu Feb 8 13:17:57 2018 +0100
Committer: Jarek Lipski <jlip...@jahia.com>
Committed: Thu Feb 8 13:21:11 2018 +0100

----------------------------------------------------------------------
 .../shell/migration/impl/MigrationTo121.java    | 227 +++++++++++++++++++
 .../shell/migration/impl/MigrationTo122.java    |  74 ++++++
 .../shell/migration/impl/MigrationTo130.java    | 227 -------------------
 .../impl/MigrationTo130IndexTemplate.java       |  74 ------
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   8 +-
 5 files changed, 305 insertions(+), 305 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a8650276/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
new file mode 100644
index 0000000..a2b1111
--- /dev/null
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
@@ -0,0 +1,227 @@
+/*
+ * 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.
+ */
+package org.apache.unomi.shell.migration.impl;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.felix.service.command.CommandSession;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.unomi.shell.migration.Migration;
+import org.apache.unomi.shell.migration.utils.ConsoleUtils;
+import org.apache.unomi.shell.migration.utils.MigrationUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.osgi.framework.Version;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author dgaillard
+ */
+public class MigrationTo121 implements Migration {
+
+    private CloseableHttpClient httpClient;
+    private CommandSession session;
+    private String esAddress;
+    private LinkedHashMap<String, List<String>> tagsStructurePriorTo130;
+    private List propsTaggedAsPersonalIdentifier = Arrays.asList("firstName", 
"lastName", "email", "phoneNumber", "address", "facebookId", "googleId", 
"linkedInId", "twitterId");
+
+    @Override
+    public Version getFromVersion() {
+        return null;
+    }
+
+    @Override
+    public Version getToVersion() {
+        return new Version("1.2.1");
+    }
+
+    @Override
+    public void execute(CommandSession session, CloseableHttpClient 
httpClient, String esAddress) throws IOException {
+        try {
+            this.httpClient = httpClient;
+            this.session = session;
+            this.esAddress = esAddress;
+            migrateTags();
+        } catch (IOException e) {
+            if (httpClient != null) {
+                httpClient.close();
+            }
+            throw e;
+        }
+    }
+
+    private void migrateTags() throws IOException {
+        initTagsStructurePriorTo130();
+        String tagsOperation = 
ConsoleUtils.askUserWithAuthorizedAnswer(session, "How to manage tags?\n1. 
copy: will duplicate tags in systemTags property\n2. move: will move tags in 
systemTags property\n[1 - 2]: ", Arrays.asList("1", "2"));
+        String removeNamespaceOnSystemTags = 
ConsoleUtils.askUserWithAuthorizedAnswer(session, "As we will copy/move the 
tags, do you wish to remove existing namespace on tags before copy/move in 
systemTags? (e.g: hidden.) (yes/no): ", Arrays.asList("yes", "no"));
+
+        List<String> typeToMigrate = Arrays.asList("actionType", 
"conditionType", "campaign", "goal", "rule", "scoring", "segment", "userList");
+        for (String type : typeToMigrate) {
+            migrateTagsInResult(esAddress, type, 10, true, tagsOperation, 
removeNamespaceOnSystemTags.equals("yes"), null);
+        }
+
+        migrateTagsInResult(esAddress, "propertyType", 10, false, 
tagsOperation, removeNamespaceOnSystemTags.equals("yes"), null);
+    }
+
+    private void migrateTagsInResult(String hostAddress, String type, int 
currentOffset,
+                                     boolean tagsInMetadata, String 
tagsOperation, boolean removeNamespaceOnSystemTags, String scrollId) throws 
IOException {
+
+        JSONObject responseJSON;
+        if (StringUtils.isNotBlank(scrollId)) {
+            responseJSON = MigrationUtils.continueQueryWithScroll(httpClient, 
hostAddress, scrollId);
+        } else {
+            responseJSON = MigrationUtils.queryWithScroll(httpClient, 
hostAddress + "/context/" + type + "/_search");
+        }
+
+        if (responseJSON.has("hits")) {
+            JSONObject hitsObject = responseJSON.getJSONObject("hits");
+            if (hitsObject.has("hits")) {
+                JSONArray hits = hitsObject.getJSONArray("hits");
+
+                StringBuilder updatedHits = new StringBuilder();
+                Iterator<Object> hitsIterator = hits.iterator();
+                while (hitsIterator.hasNext()) {
+                    JSONObject hit = (JSONObject) hitsIterator.next();
+                    if (hit.has("_source")) {
+                        JSONObject hitSource = hit.getJSONObject("_source");
+                        if (tagsInMetadata && hitSource.has("metadata")) {
+                            JSONObject hitMetadata = 
hitSource.getJSONObject("metadata");
+                            updateTagsForHit(updatedHits, 
hit.getString("_id"), hitMetadata, tagsInMetadata, tagsOperation, 
removeNamespaceOnSystemTags);
+                        } else if (!tagsInMetadata) {
+                            updateTagsForHit(updatedHits, 
hit.getString("_id"), hitSource, tagsInMetadata, tagsOperation, 
removeNamespaceOnSystemTags);
+                        }
+                    }
+                }
+                String jsonData = updatedHits.toString();
+                if (StringUtils.isNotBlank(jsonData)) {
+                    MigrationUtils.bulkUpdate(httpClient, hostAddress + 
"/context/" + type + "/_bulk", jsonData);
+                }
+
+                if (hitsObject.getInt("total") > currentOffset) {
+                    migrateTagsInResult(hostAddress, type, currentOffset + 10, 
tagsInMetadata, tagsOperation, removeNamespaceOnSystemTags, 
responseJSON.getString("_scroll_id"));
+                }
+            }
+        }
+    }
+
+    private void updateTagsForHit(StringBuilder updatedHits, String hitId, 
JSONObject jsonObject,
+                                  boolean tagsInMetadata, String 
tagsOperation, boolean removeNamespaceOnSystemTags) {
+        if (jsonObject.has("tags")) {
+            JSONArray hitTags = jsonObject.getJSONArray("tags");
+            Iterator<Object> tagsIterator = hitTags.iterator();
+            Set<String> tagsBeforeMigration = new HashSet<>();
+            Set<String> tagsAfterMigration = new HashSet<>();
+            if (tagsIterator.hasNext()) {
+                while (tagsIterator.hasNext()) {
+                    tagsBeforeMigration.add((String) tagsIterator.next());
+                }
+
+                for (String tag : tagsBeforeMigration) {
+                    if (tagsStructurePriorTo130.containsKey(tag)) {
+                        
tagsAfterMigration.addAll(tagsStructurePriorTo130.get(tag));
+                    }
+                    tagsAfterMigration.add(tag);
+                }
+
+                
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
+                if (tagsOperation.equals("1")) {
+                    Set<String> tags = 
removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration);
+                    if (propsTaggedAsPersonalIdentifier.contains(hitId)) {
+                        tags.add("personalIdentifierProperties");
+                    }
+                    
updatedHits.append("{\"doc\":{\"metadata\":{\"tags\":").append(new 
JSONArray(tagsAfterMigration))
+                            .append(",\"systemTags\":").append(new 
JSONArray(tags)).append("}}}\n");
+                }
+                if (tagsOperation.equals("2")) {
+                    Set<String> tags = 
removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration);
+                    if (propsTaggedAsPersonalIdentifier.contains(hitId)) {
+                        tags.add("personalIdentifierProperties");
+                    }
+                    
updatedHits.append("{\"doc\":{\"metadata\":{\"systemTags\":").append(new 
JSONArray(tags)).append("}}}\n");
+                    if (tagsInMetadata) {
+                        
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
+                        
updatedHits.append("{\"script\":\"ctx._source.metadata.remove(\\\"tags\\\")\"}\n");
+                    }
+                }
+                if (!tagsInMetadata) {
+                    
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
+                    
updatedHits.append("{\"script\":\"ctx._source.remove(\\\"tags\\\")\"}\n");
+                }
+            }
+        }
+    }
+
+    private Set<String> removeNamespaceOnTags(boolean 
removeNamespaceOnSystemTags, Set<String> tagsAfterMigration) {
+        if (!removeNamespaceOnSystemTags) {
+            return tagsAfterMigration;
+        }
+
+        Set<String> tags = new HashSet<>();
+        for (String tag : tagsAfterMigration) {
+            if (StringUtils.startsWith(tag, "hidden.")) {
+                tags.add(StringUtils.substringAfter(tag, "hidden."));
+            } else {
+                tags.add(tag);
+            }
+        }
+        return tags;
+    }
+
+    private void initTagsStructurePriorTo130() {
+        tagsStructurePriorTo130 = new LinkedHashMap<>();
+        tagsStructurePriorTo130.put("landing", 
Collections.singletonList("campaign"));
+        tagsStructurePriorTo130.put("parameter", 
Collections.singletonList("campaign"));
+        tagsStructurePriorTo130.put("referrer", 
Collections.singletonList("campaign"));
+
+        tagsStructurePriorTo130.put("eventCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo130.put("profileCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo130.put("sessionCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo130.put("sourceEventCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo130.put("trackedCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo130.put("usableInPastEventCondition", 
Collections.singletonList("condition"));
+
+        tagsStructurePriorTo130.put("formMappingRule", 
Collections.<String>emptyList());
+
+        tagsStructurePriorTo130.put("downloadGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo130.put("formGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo130.put("funnelGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo130.put("landingPageGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo130.put("pageVisitGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo130.put("videoGoal", 
Collections.singletonList("goal"));
+
+        tagsStructurePriorTo130.put("aggregated", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo130.put("autocompleted", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo130.put("demographic", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo130.put("event", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo130.put("geographic", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo130.put("logical", 
Collections.singletonList("profileTags"));
+
+        tagsStructurePriorTo130.put("profileProperties", 
Collections.singletonList("properties"));
+        tagsStructurePriorTo130.put("systemProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo130.put("basicProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo130.put("leadProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo130.put("contactProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo130.put("socialProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo130.put("personalProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo130.put("workProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+
+        tagsStructurePriorTo130.put("sessionProperties", 
Collections.singletonList("properties"));
+        tagsStructurePriorTo130.put("geographicSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
+        tagsStructurePriorTo130.put("technicalSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a8650276/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
new file mode 100644
index 0000000..dec2a6a
--- /dev/null
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+package org.apache.unomi.shell.migration.impl;
+
+import org.apache.felix.service.command.CommandSession;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.unomi.shell.migration.Migration;
+import org.apache.unomi.shell.migration.utils.ConsoleUtils;
+import org.apache.unomi.shell.migration.utils.HttpRequestException;
+import org.apache.unomi.shell.migration.utils.HttpUtils;
+import org.osgi.framework.Version;
+
+import java.io.IOException;
+
+public class MigrationTo122 implements Migration {
+    private CloseableHttpClient httpClient;
+    private CommandSession session;
+    private String esAddress;
+
+    @Override
+    public Version getFromVersion() {
+        return null;
+    }
+
+    @Override
+    public Version getToVersion() {
+        return new Version("1.2.2");
+    }
+
+    @Override
+    public void execute(CommandSession session, CloseableHttpClient 
httpClient, String esAddress) throws IOException {
+        try {
+            this.httpClient = httpClient;
+            this.session = session;
+            this.esAddress = esAddress;
+            deleteOldIndexTemplate();
+        } catch (IOException e) {
+            if (httpClient != null) {
+                httpClient.close();
+            }
+            throw e;
+        }
+
+    }
+
+    private void deleteOldIndexTemplate() throws IOException {
+        String oldMonthlyIndexTemplate = "context_monthlyindex";
+        try {
+            ConsoleUtils.printMessage(session,"Deleting old monthly index 
template " + oldMonthlyIndexTemplate);
+            HttpUtils.executeDeleteRequest(httpClient, esAddress + 
"/_template/" + oldMonthlyIndexTemplate, null);
+        } catch (HttpRequestException e) {
+            if (e.getCode() == 404) {
+                ConsoleUtils.printMessage(session,"Old monthly index template 
not found, skipping deletion");
+            } else {
+                throw e;
+            }
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a8650276/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java
deleted file mode 100644
index 63e42fa..0000000
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * 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.
- */
-package org.apache.unomi.shell.migration.impl;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.felix.service.command.CommandSession;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.unomi.shell.migration.Migration;
-import org.apache.unomi.shell.migration.utils.ConsoleUtils;
-import org.apache.unomi.shell.migration.utils.MigrationUtils;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.osgi.framework.Version;
-
-import java.io.IOException;
-import java.util.*;
-
-/**
- * @author dgaillard
- */
-public class MigrationTo130 implements Migration {
-
-    private CloseableHttpClient httpClient;
-    private CommandSession session;
-    private String esAddress;
-    private LinkedHashMap<String, List<String>> tagsStructurePriorTo130;
-    private List propsTaggedAsPersonalIdentifier = Arrays.asList("firstName", 
"lastName", "email", "phoneNumber", "address", "facebookId", "googleId", 
"linkedInId", "twitterId");
-
-    @Override
-    public Version getFromVersion() {
-        return null;
-    }
-
-    @Override
-    public Version getToVersion() {
-        return new Version("1.3.0");
-    }
-
-    @Override
-    public void execute(CommandSession session, CloseableHttpClient 
httpClient, String esAddress) throws IOException {
-        try {
-            this.httpClient = httpClient;
-            this.session = session;
-            this.esAddress = esAddress;
-            migrateTags();
-        } catch (IOException e) {
-            if (httpClient != null) {
-                httpClient.close();
-            }
-            throw e;
-        }
-    }
-
-    private void migrateTags() throws IOException {
-        initTagsStructurePriorTo130();
-        String tagsOperation = 
ConsoleUtils.askUserWithAuthorizedAnswer(session, "How to manage tags?\n1. 
copy: will duplicate tags in systemTags property\n2. move: will move tags in 
systemTags property\n[1 - 2]: ", Arrays.asList("1", "2"));
-        String removeNamespaceOnSystemTags = 
ConsoleUtils.askUserWithAuthorizedAnswer(session, "As we will copy/move the 
tags, do you wish to remove existing namespace on tags before copy/move in 
systemTags? (e.g: hidden.) (yes/no): ", Arrays.asList("yes", "no"));
-
-        List<String> typeToMigrate = Arrays.asList("actionType", 
"conditionType", "campaign", "goal", "rule", "scoring", "segment", "userList");
-        for (String type : typeToMigrate) {
-            migrateTagsInResult(esAddress, type, 10, true, tagsOperation, 
removeNamespaceOnSystemTags.equals("yes"), null);
-        }
-
-        migrateTagsInResult(esAddress, "propertyType", 10, false, 
tagsOperation, removeNamespaceOnSystemTags.equals("yes"), null);
-    }
-
-    private void migrateTagsInResult(String hostAddress, String type, int 
currentOffset,
-                                     boolean tagsInMetadata, String 
tagsOperation, boolean removeNamespaceOnSystemTags, String scrollId) throws 
IOException {
-
-        JSONObject responseJSON;
-        if (StringUtils.isNotBlank(scrollId)) {
-            responseJSON = MigrationUtils.continueQueryWithScroll(httpClient, 
hostAddress, scrollId);
-        } else {
-            responseJSON = MigrationUtils.queryWithScroll(httpClient, 
hostAddress + "/context/" + type + "/_search");
-        }
-
-        if (responseJSON.has("hits")) {
-            JSONObject hitsObject = responseJSON.getJSONObject("hits");
-            if (hitsObject.has("hits")) {
-                JSONArray hits = hitsObject.getJSONArray("hits");
-
-                StringBuilder updatedHits = new StringBuilder();
-                Iterator<Object> hitsIterator = hits.iterator();
-                while (hitsIterator.hasNext()) {
-                    JSONObject hit = (JSONObject) hitsIterator.next();
-                    if (hit.has("_source")) {
-                        JSONObject hitSource = hit.getJSONObject("_source");
-                        if (tagsInMetadata && hitSource.has("metadata")) {
-                            JSONObject hitMetadata = 
hitSource.getJSONObject("metadata");
-                            updateTagsForHit(updatedHits, 
hit.getString("_id"), hitMetadata, tagsInMetadata, tagsOperation, 
removeNamespaceOnSystemTags);
-                        } else if (!tagsInMetadata) {
-                            updateTagsForHit(updatedHits, 
hit.getString("_id"), hitSource, tagsInMetadata, tagsOperation, 
removeNamespaceOnSystemTags);
-                        }
-                    }
-                }
-                String jsonData = updatedHits.toString();
-                if (StringUtils.isNotBlank(jsonData)) {
-                    MigrationUtils.bulkUpdate(httpClient, hostAddress + 
"/context/" + type + "/_bulk", jsonData);
-                }
-
-                if (hitsObject.getInt("total") > currentOffset) {
-                    migrateTagsInResult(hostAddress, type, currentOffset + 10, 
tagsInMetadata, tagsOperation, removeNamespaceOnSystemTags, 
responseJSON.getString("_scroll_id"));
-                }
-            }
-        }
-    }
-
-    private void updateTagsForHit(StringBuilder updatedHits, String hitId, 
JSONObject jsonObject,
-                                  boolean tagsInMetadata, String 
tagsOperation, boolean removeNamespaceOnSystemTags) {
-        if (jsonObject.has("tags")) {
-            JSONArray hitTags = jsonObject.getJSONArray("tags");
-            Iterator<Object> tagsIterator = hitTags.iterator();
-            Set<String> tagsBeforeMigration = new HashSet<>();
-            Set<String> tagsAfterMigration = new HashSet<>();
-            if (tagsIterator.hasNext()) {
-                while (tagsIterator.hasNext()) {
-                    tagsBeforeMigration.add((String) tagsIterator.next());
-                }
-
-                for (String tag : tagsBeforeMigration) {
-                    if (tagsStructurePriorTo130.containsKey(tag)) {
-                        
tagsAfterMigration.addAll(tagsStructurePriorTo130.get(tag));
-                    }
-                    tagsAfterMigration.add(tag);
-                }
-
-                
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
-                if (tagsOperation.equals("1")) {
-                    Set<String> tags = 
removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration);
-                    if (propsTaggedAsPersonalIdentifier.contains(hitId)) {
-                        tags.add("personalIdentifierProperties");
-                    }
-                    
updatedHits.append("{\"doc\":{\"metadata\":{\"tags\":").append(new 
JSONArray(tagsAfterMigration))
-                            .append(",\"systemTags\":").append(new 
JSONArray(tags)).append("}}}\n");
-                }
-                if (tagsOperation.equals("2")) {
-                    Set<String> tags = 
removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration);
-                    if (propsTaggedAsPersonalIdentifier.contains(hitId)) {
-                        tags.add("personalIdentifierProperties");
-                    }
-                    
updatedHits.append("{\"doc\":{\"metadata\":{\"systemTags\":").append(new 
JSONArray(tags)).append("}}}\n");
-                    if (tagsInMetadata) {
-                        
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
-                        
updatedHits.append("{\"script\":\"ctx._source.metadata.remove(\\\"tags\\\")\"}\n");
-                    }
-                }
-                if (!tagsInMetadata) {
-                    
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
-                    
updatedHits.append("{\"script\":\"ctx._source.remove(\\\"tags\\\")\"}\n");
-                }
-            }
-        }
-    }
-
-    private Set<String> removeNamespaceOnTags(boolean 
removeNamespaceOnSystemTags, Set<String> tagsAfterMigration) {
-        if (!removeNamespaceOnSystemTags) {
-            return tagsAfterMigration;
-        }
-
-        Set<String> tags = new HashSet<>();
-        for (String tag : tagsAfterMigration) {
-            if (StringUtils.startsWith(tag, "hidden.")) {
-                tags.add(StringUtils.substringAfter(tag, "hidden."));
-            } else {
-                tags.add(tag);
-            }
-        }
-        return tags;
-    }
-
-    private void initTagsStructurePriorTo130() {
-        tagsStructurePriorTo130 = new LinkedHashMap<>();
-        tagsStructurePriorTo130.put("landing", 
Collections.singletonList("campaign"));
-        tagsStructurePriorTo130.put("parameter", 
Collections.singletonList("campaign"));
-        tagsStructurePriorTo130.put("referrer", 
Collections.singletonList("campaign"));
-
-        tagsStructurePriorTo130.put("eventCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo130.put("profileCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo130.put("sessionCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo130.put("sourceEventCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo130.put("trackedCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo130.put("usableInPastEventCondition", 
Collections.singletonList("condition"));
-
-        tagsStructurePriorTo130.put("formMappingRule", 
Collections.<String>emptyList());
-
-        tagsStructurePriorTo130.put("downloadGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo130.put("formGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo130.put("funnelGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo130.put("landingPageGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo130.put("pageVisitGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo130.put("videoGoal", 
Collections.singletonList("goal"));
-
-        tagsStructurePriorTo130.put("aggregated", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo130.put("autocompleted", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo130.put("demographic", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo130.put("event", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo130.put("geographic", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo130.put("logical", 
Collections.singletonList("profileTags"));
-
-        tagsStructurePriorTo130.put("profileProperties", 
Collections.singletonList("properties"));
-        tagsStructurePriorTo130.put("systemProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo130.put("basicProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo130.put("leadProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo130.put("contactProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo130.put("socialProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo130.put("personalProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo130.put("workProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-
-        tagsStructurePriorTo130.put("sessionProperties", 
Collections.singletonList("properties"));
-        tagsStructurePriorTo130.put("geographicSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
-        tagsStructurePriorTo130.put("technicalSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a8650276/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130IndexTemplate.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130IndexTemplate.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130IndexTemplate.java
deleted file mode 100644
index 1aad590..0000000
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130IndexTemplate.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.
- */
-package org.apache.unomi.shell.migration.impl;
-
-import org.apache.felix.service.command.CommandSession;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.unomi.shell.migration.Migration;
-import org.apache.unomi.shell.migration.utils.ConsoleUtils;
-import org.apache.unomi.shell.migration.utils.HttpRequestException;
-import org.apache.unomi.shell.migration.utils.HttpUtils;
-import org.osgi.framework.Version;
-
-import java.io.IOException;
-
-public class MigrationTo130IndexTemplate implements Migration {
-    private CloseableHttpClient httpClient;
-    private CommandSession session;
-    private String esAddress;
-
-    @Override
-    public Version getFromVersion() {
-        return null;
-    }
-
-    @Override
-    public Version getToVersion() {
-        return new Version("1.3.0");
-    }
-
-    @Override
-    public void execute(CommandSession session, CloseableHttpClient 
httpClient, String esAddress) throws IOException {
-        try {
-            this.httpClient = httpClient;
-            this.session = session;
-            this.esAddress = esAddress;
-            deleteOldIndexTemplate();
-        } catch (IOException e) {
-            if (httpClient != null) {
-                httpClient.close();
-            }
-            throw e;
-        }
-
-    }
-
-    private void deleteOldIndexTemplate() throws IOException {
-        String oldMonthlyIndexTemplate = "context_monthlyindex";
-        try {
-            ConsoleUtils.printMessage(session,"Deleting old monthly index 
template " + oldMonthlyIndexTemplate);
-            HttpUtils.executeDeleteRequest(httpClient, esAddress + 
"/_template/" + oldMonthlyIndexTemplate, null);
-        } catch (HttpRequestException e) {
-            if (e.getCode() == 404) {
-                ConsoleUtils.printMessage(session,"Old monthly index template 
not found, skipping deletion");
-            } else {
-                throw e;
-            }
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a8650276/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml 
b/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 1fb63c4..38ec572 100644
--- a/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -21,8 +21,8 @@
            xmlns:shell="http://karaf.apache.org/xmlns/shell/v1.1.0";
            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>
 
-    <bean id="migrateTo130" 
class="org.apache.unomi.shell.migration.impl.MigrationTo130"/>
-    <bean id="migrateTo130IndexTemplate" 
class="org.apache.unomi.shell.migration.impl.MigrationTo130IndexTemplate"/>
+    <bean id="migrateTo121" 
class="org.apache.unomi.shell.migration.impl.MigrationTo121"/>
+    <bean id="migrateTo122" 
class="org.apache.unomi.shell.migration.impl.MigrationTo122"/>
 
     <shell:command-bundle>
         <shell:command>
@@ -30,8 +30,8 @@
                 <shell:property name="migrations">
                     <list>
                         <!-- Migration beans must be executed in the right 
order so you must place new bean at the end of this list -->
-                        <ref component-id="migrateTo130"/>
-                        <ref component-id="migrateTo130IndexTemplate"/>
+                        <ref component-id="migrateTo121"/>
+                        <ref component-id="migrateTo122"/>
                     </list>
                 </shell:property>
             </shell:action>

Reply via email to