Repository: incubator-unomi
Updated Branches:
  refs/heads/feature-UNOMI-117 b30d3286f -> 8e6132d21


UNOMI-117 implement system tags to allow use of tags that will not be shown to 
the end user (e.g. to manage UI or elements), update migration to reflect 
systemTags changes, change compilation order to fix an issue with 
shell-commands bundle, add test to not override an object in ES if it exist yet


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

Branch: refs/heads/feature-UNOMI-117
Commit: 8e6132d219e110f6c9ded953154f6591f1d9052a
Parents: b30d328
Author: dgaillard <[email protected]>
Authored: Fri Sep 29 14:00:57 2017 +0200
Committer: dgaillard <[email protected]>
Committed: Fri Sep 29 14:00:57 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/unomi/api/Metadata.java     |  21 +-
 .../unomi/api/services/DefinitionsService.java  |  32 ++-
 .../unomi/api/services/ProfileService.java      |  14 +-
 itests/pom.xml                                  |   2 +-
 kar/src/main/feature/feature.xml                |   2 +-
 performance-tests/pom.xml                       |   2 +-
 pom.xml                                         |   2 +-
 .../unomi/rest/DefinitionsServiceEndPoint.java  |  48 +++-
 .../apache/unomi/rest/LocalizationHelper.java   |   2 +
 .../unomi/rest/ProfileServiceEndPoint.java      |  23 +-
 .../org/apache/unomi/rest/RESTActionType.java   |   9 +
 .../apache/unomi/rest/RESTConditionType.java    |   9 +
 samples/trainingplugin/pom.xml                  |   4 +-
 .../services/DefinitionsServiceImpl.java        |  30 ++-
 .../services/services/GoalsServiceImpl.java     |  26 ---
 .../services/services/ProfileServiceImpl.java   |  16 +-
 .../services/services/RulesServiceImpl.java     |   4 +-
 .../versions/master/custom-extensions.md        |   6 +-
 .../markdown/versions/master/login-sample.md    |   2 +-
 tools/pom.xml                                   |   2 +-
 tools/shell-commands/pom.xml                    |   3 +-
 .../unomi/shell/migration/actions/Migrate.java  |   3 +-
 .../shell/migration/impl/MigrationTo130.java    | 230 +++++++++++++++++++
 .../shell/migration/impl/MigrationTo200.java    | 194 ----------------
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   2 +-
 25 files changed, 427 insertions(+), 261 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/api/src/main/java/org/apache/unomi/api/Metadata.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/Metadata.java 
b/api/src/main/java/org/apache/unomi/api/Metadata.java
index 22216c9..4314a68 100644
--- a/api/src/main/java/org/apache/unomi/api/Metadata.java
+++ b/api/src/main/java/org/apache/unomi/api/Metadata.java
@@ -36,6 +36,7 @@ public class Metadata implements Comparable<Metadata> {
     private String description;
     private String scope;
     private Set<String> tags = new LinkedHashSet<>();
+    private Set<String> systemTags = new LinkedHashSet<>();
     private boolean enabled = true;
     private boolean missingPlugins = false;
     private boolean hidden = false;
@@ -156,13 +157,31 @@ public class Metadata implements Comparable<Metadata> {
     /**
      * Sets the tags.
      *
-     * @param tags the tag i ds
+     * @param tags the tag ids
      */
     public void setTags(Set<String> tags) {
         this.tags = tags;
     }
 
     /**
+     * Retrieves a set of {@link String} system tag names associated with this 
Metadata
+     *
+     * @return a set of {@link String} system tag names associated with this 
Metadata
+     */
+    public Set<String> getSystemTags() {
+        return systemTags;
+    }
+
+    /**
+     * Sets the system tags.
+     *
+     * @param systemTags the system tag ids
+     */
+    public void setSystemTags(Set<String> systemTags) {
+        this.systemTags = systemTags;
+    }
+
+    /**
      * Whether the associated entity is considered active by the context 
server, in particular to check if rules need to be created / triggered
      *
      * @return {@code true} if the associated entity is enabled, {@code false} 
otherwise

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java 
b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
index 655705a..f3d0afd 100644
--- a/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
@@ -41,14 +41,22 @@ public interface DefinitionsService {
     Collection<ConditionType> getAllConditionTypes();
 
     /**
-     * Retrieves the set of condition types with the specified tag also 
retrieving condition types from sub-tags if so specified.
+     * Retrieves the set of condition types with the specified tag.
      *
-     * @param tag                the tag marking the condition types we want 
to retrieve
+     * @param tag   the tag marking the condition types we want to retrieve
      * @return the set of condition types with the specified tag (and its 
sub-tags, if specified)
      */
     Set<ConditionType> getConditionTypesByTag(String tag);
 
     /**
+     * Retrieves the set of condition types with the specified system tag.
+     *
+     * @param tag   the system tag marking the condition types we want to 
retrieve
+     * @return the set of condition types with the specified tag (and its 
sub-tags, if specified)
+     */
+    Set<ConditionType> getConditionTypesBySystemTag(String tag);
+
+    /**
      * Retrieves the condition type associated with the specified identifier.
      *
      * @param id the identifier of the condition type to retrieve
@@ -78,14 +86,22 @@ public interface DefinitionsService {
     Collection<ActionType> getAllActionTypes();
 
     /**
-     * Retrieves the set of action types with the specified tag also 
retrieving action types from sub-tags if so specified.
+     * Retrieves the set of action types with the specified tag.
      *
-     * @param tag                the tag marking the action types we want to 
retrieve
-     * @return the set of action types with the specified tag (and its 
sub-tags, if specified)
+     * @param tag   the tag marking the action types we want to retrieve
+     * @return the set of action types with the specified tag
      */
     Set<ActionType> getActionTypeByTag(String tag);
 
     /**
+     * Retrieves the set of action types with the specified system tag.
+     *
+     * @param tag   the system tag marking the action types we want to retrieve
+     * @return the set of action types with the specified tag
+     */
+    Set<ActionType> getActionTypeBySystemTag(String tag);
+
+    /**
      * Retrieves the action type associated with the specified identifier.
      *
      * @param id the identifier of the action type to retrieve
@@ -115,10 +131,10 @@ public interface DefinitionsService {
     Collection<ValueType> getAllValueTypes();
 
     /**
-     * Retrieves the set of value types with the specified tag also retrieving 
value types from sub-tags if so specified.
+     * Retrieves the set of value types with the specified tag.
      *
-     * @param tag                the tag marking the value types we want to 
retrieve
-     * @return the set of value types with the specified tag (and its 
sub-tags, if specified)
+     * @param tag   the tag marking the value types we want to retrieve
+     * @return the set of value types with the specified tag
      */
     Set<ValueType> getValueTypeByTag(String tag);
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java 
b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
index c6daab8..c8917e3 100644
--- a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
@@ -256,16 +256,26 @@ public interface ProfileService {
     Map<String, Collection<PropertyType>> getAllPropertyTypes();
 
     /**
-     * Retrieves all property types with the specified tag also retrieving 
property types with sub-tags of the specified tag if so specified.
+     * Retrieves all property types with the specified tag
      *
      * TODO: move to a different class
      *
-     * @param tag                the tag name marking property types we want 
to retrieve
+     * @param tag   the tag name marking property types we want to retrieve
      * @return a Set of the property types with the specified tag
      */
     Set<PropertyType> getPropertyTypeByTag(String tag);
 
     /**
+     * Retrieves all property types with the specified system tag
+     *
+     * TODO: move to a different class
+     *
+     * @param tag   the system tag name marking property types we want to 
retrieve
+     * @return a Set of the property types with the specified system tag
+     */
+    Set<PropertyType> getPropertyTypeBySystemTag(String tag);
+
+    /**
      * TODO
      * @param fromPropertyTypeId fromPropertyTypeId
      * @return property type mapping

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/itests/pom.xml
----------------------------------------------------------------------
diff --git a/itests/pom.xml b/itests/pom.xml
index 7b5c5e6..2e0222e 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -21,7 +21,7 @@
     <parent>
         <groupId>org.apache.unomi</groupId>
         <artifactId>unomi-root</artifactId>
-        <version>1.2.0-incubating-SNAPSHOT</version>
+        <version>1.3.0-incubating-unomi_117-SNAPSHOT</version>
     </parent>
     <artifactId>unomi-itests</artifactId>
     <name>Apache Unomi :: Integration Tests</name>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/kar/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/kar/src/main/feature/feature.xml b/kar/src/main/feature/feature.xml
index bb672b4..0ef512c 100644
--- a/kar/src/main/feature/feature.xml
+++ b/kar/src/main/feature/feature.xml
@@ -16,7 +16,7 @@
   ~ limitations under the License.
   -->
 
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"; 
name="unomi-kar">
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1"; 
name="unomi-kar">
     <feature description="unomi-kar" version="${project.version}" 
name="unomi-kar"
              start-level="70">
         <feature>war</feature>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/performance-tests/pom.xml
----------------------------------------------------------------------
diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml
index 4429f3a..fb2d90e 100644
--- a/performance-tests/pom.xml
+++ b/performance-tests/pom.xml
@@ -20,7 +20,7 @@
     <parent>
         <groupId>org.apache.unomi</groupId>
         <artifactId>unomi-root</artifactId>
-        <version>1.2.0-incubating-SNAPSHOT</version>
+        <version>1.3.0-incubating-unomi_117-SNAPSHOT</version>
     </parent>
     <artifactId>unomi-performance-tests</artifactId>
     <name>Apache Unomi :: Performance Tests</name>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index fefee15..5a9db93 100644
--- a/pom.xml
+++ b/pom.xml
@@ -844,10 +844,10 @@
         <module>wab</module>
         <module>plugins</module>
         <module>extensions</module>
+        <module>tools</module>
         <module>kar</module>
         <module>samples</module>
         <module>package</module>
-        <module>tools</module>
     </modules>
 
     <dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/rest/src/main/java/org/apache/unomi/rest/DefinitionsServiceEndPoint.java
----------------------------------------------------------------------
diff --git 
a/rest/src/main/java/org/apache/unomi/rest/DefinitionsServiceEndPoint.java 
b/rest/src/main/java/org/apache/unomi/rest/DefinitionsServiceEndPoint.java
index 2fd415a..577bde3 100644
--- a/rest/src/main/java/org/apache/unomi/rest/DefinitionsServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/DefinitionsServiceEndPoint.java
@@ -72,11 +72,11 @@ public class DefinitionsServiceEndPoint {
     }
 
     /**
-     * Retrieves the set of condition types with the specified tags also 
retrieving condition types from sub-tags if so specified localized using the 
specified language.
+     * Retrieves the set of condition types with the specified tags.
      *
      * @param language  the language to use to localize.
      * @param tags      a comma-separated list of tag identifiers
-     * @return the set of condition types with the specified tag (and its 
sub-tags, if specified)
+     * @return the set of condition types with the specified tag
      */
     @GET
     @Path("/conditions/tags/{tags}")
@@ -90,6 +90,24 @@ public class DefinitionsServiceEndPoint {
     }
 
     /**
+     * Retrieves the set of condition types with the specified system tags.
+     *
+     * @param language  the language to use to localize.
+     * @param tags      a comma-separated list of tag identifiers
+     * @return the set of condition types with the specified tag
+     */
+    @GET
+    @Path("/conditions/systemTags/{tags}")
+    public Collection<RESTConditionType> 
getConditionTypesBySystemTag(@PathParam("tags") String tags, 
@HeaderParam("Accept-Language") String language) {
+        String[] tagsArray = tags.split(",");
+        Set<ConditionType> results = new LinkedHashSet<>();
+        for (String tag : tagsArray) {
+            
results.addAll(definitionsService.getConditionTypesBySystemTag(tag));
+        }
+        return localizationHelper.generateConditions(results, language);
+    }
+
+    /**
      * Retrieves the condition type associated with the specified identifier 
localized using the specified language.
      *
      * @param language the language to use to localize.
@@ -139,11 +157,11 @@ public class DefinitionsServiceEndPoint {
     }
 
     /**
-     * Retrieves the set of action types with the specified tags also 
retrieving action types from sub-tags if so specified localized using the 
specified language.
+     * Retrieves the set of action types with the specified tags.
      *
      * @param language  the language to use to localize.
      * @param tags      the tag marking the action types we want to retrieve
-     * @return the set of action types with the specified tag (and its 
sub-tags, if specified)
+     * @return the set of action types with the specified tag
      */
     @GET
     @Path("/actions/tags/{tags}")
@@ -157,6 +175,24 @@ public class DefinitionsServiceEndPoint {
     }
 
     /**
+     * Retrieves the set of action types with the specified system tags.
+     *
+     * @param language  the language to use to localize.
+     * @param tags      the tag marking the action types we want to retrieve
+     * @return the set of action types with the specified tag
+     */
+    @GET
+    @Path("/actions/systemTags/{tags}")
+    public Collection<RESTActionType> 
getActionTypeBySystemTag(@PathParam("tags") String tags, 
@HeaderParam("Accept-Language") String language) {
+        String[] tagsArray = tags.split(",");
+        Set<ActionType> results = new LinkedHashSet<>();
+        for (String tag : tagsArray) {
+            results.addAll(definitionsService.getActionTypeBySystemTag(tag));
+        }
+        return localizationHelper.generateActions(results, language);
+    }
+
+    /**
      * Retrieves the action type associated with the specified identifier 
localized using the specified language.
      *
      * @param language the language to use to localize.
@@ -205,11 +241,11 @@ public class DefinitionsServiceEndPoint {
     }
 
     /**
-     * Retrieves the set of value types with the specified tags also 
retrieving value types from sub-tags if so specified localized using the 
specified language.
+     * Retrieves the set of value types with the specified tags.
      *
      * @param language  the language to use to localize.
      * @param tags      the tag marking the value types we want to retrieve
-     * @return the set of value types with the specified tag (and its 
sub-tags, if specified)
+     * @return the set of value types with the specified tag
      */
     @GET
     @Path("/values/tags/{tags}")

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/rest/src/main/java/org/apache/unomi/rest/LocalizationHelper.java
----------------------------------------------------------------------
diff --git a/rest/src/main/java/org/apache/unomi/rest/LocalizationHelper.java 
b/rest/src/main/java/org/apache/unomi/rest/LocalizationHelper.java
index 880e16a..38a1203 100644
--- a/rest/src/main/java/org/apache/unomi/rest/LocalizationHelper.java
+++ b/rest/src/main/java/org/apache/unomi/rest/LocalizationHelper.java
@@ -92,6 +92,7 @@ public class LocalizationHelper {
         result.setDescription(conditionType.getMetadata().getDescription());
 
         result.setTags(conditionType.getMetadata().getTags());
+        result.setSystemTags(conditionType.getMetadata().getSystemTags());
 
         for (Parameter parameter : conditionType.getParameters()) {
             result.getParameters().add(generateParameter(parameter, language));
@@ -116,6 +117,7 @@ public class LocalizationHelper {
         result.setDescription(actionType.getMetadata().getDescription());
 
         result.setTags(actionType.getMetadata().getTags());
+        result.setSystemTags(actionType.getMetadata().getSystemTags());
 
         List<RESTParameter> parameters = new ArrayList<RESTParameter>();
         for (Parameter parameter : actionType.getParameters()) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
----------------------------------------------------------------------
diff --git 
a/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java 
b/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
index 156eb91..770f8b6 100644
--- a/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
@@ -501,7 +501,7 @@ public class ProfileServiceEndPoint {
     }
 
     /**
-     * Retrieves all property types with the specified tags also retrieving 
property types with sub-tags of the specified tags if so specified.
+     * Retrieves all property types with the specified tags.
      *
      * TODO: move to a different class
      * TODO: passing a list of tags via a comma-separated list is not very 
RESTful
@@ -522,6 +522,27 @@ public class ProfileServiceEndPoint {
     }
 
     /**
+     * Retrieves all property types with the specified tags.
+     *
+     * TODO: move to a different class
+     * TODO: passing a list of tags via a comma-separated list is not very 
RESTful
+     *
+     * @param tags      a comma-separated list of tag identifiers
+     * @param language  the value of the {@code Accept-Language} header to 
specify in which locale the properties description should be returned TODO 
unused
+     * @return a Set of the property types with the specified tag
+     */
+    @GET
+    @Path("/properties/systemTags/{tags}")
+    public Collection<PropertyType> 
getPropertyTypeBySystemTag(@PathParam("tags") String tags, 
@HeaderParam("Accept-Language") String language) {
+        String[] tagsArray = tags.split(",");
+        Set<PropertyType> results = new LinkedHashSet<>();
+        for (String tag : tagsArray) {
+            results.addAll(profileService.getPropertyTypeBySystemTag(tag));
+        }
+        return results;
+    }
+
+    /**
      * Persists the specified property type in the context server.
      *
      * TODO: move to a different class

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/rest/src/main/java/org/apache/unomi/rest/RESTActionType.java
----------------------------------------------------------------------
diff --git a/rest/src/main/java/org/apache/unomi/rest/RESTActionType.java 
b/rest/src/main/java/org/apache/unomi/rest/RESTActionType.java
index ef8a0f7..f29f229 100644
--- a/rest/src/main/java/org/apache/unomi/rest/RESTActionType.java
+++ b/rest/src/main/java/org/apache/unomi/rest/RESTActionType.java
@@ -30,6 +30,7 @@ public class RESTActionType {
     private String name;
     private String description;
     private Set<String> tags;
+    private Set<String> systemTags;
     private List<RESTParameter> parameters;
     protected Long version;
 
@@ -65,6 +66,14 @@ public class RESTActionType {
         this.tags = tags;
     }
 
+    public Set<String> getSystemTags() {
+        return systemTags;
+    }
+
+    public void setSystemTags(Set<String> systemTags) {
+        this.systemTags = systemTags;
+    }
+
     public List<RESTParameter> getParameters() {
         return parameters;
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/rest/src/main/java/org/apache/unomi/rest/RESTConditionType.java
----------------------------------------------------------------------
diff --git a/rest/src/main/java/org/apache/unomi/rest/RESTConditionType.java 
b/rest/src/main/java/org/apache/unomi/rest/RESTConditionType.java
index 30aa497..24d1332 100644
--- a/rest/src/main/java/org/apache/unomi/rest/RESTConditionType.java
+++ b/rest/src/main/java/org/apache/unomi/rest/RESTConditionType.java
@@ -29,6 +29,7 @@ public class RESTConditionType {
     private String name;
     private String description;
     private Set<String> tags = new LinkedHashSet<>();
+    private Set<String> systemTags = new LinkedHashSet<>();
     private List<RESTParameter> parameters = new ArrayList<RESTParameter>();
     protected Long version;
 
@@ -67,6 +68,14 @@ public class RESTConditionType {
         this.tags = tags;
     }
 
+    public Set<String> getSystemTags() {
+        return systemTags;
+    }
+
+    public void setSystemTags(Set<String> systemTags) {
+        this.systemTags = systemTags;
+    }
+
     public List<RESTParameter> getParameters() {
         return parameters;
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/samples/trainingplugin/pom.xml
----------------------------------------------------------------------
diff --git a/samples/trainingplugin/pom.xml b/samples/trainingplugin/pom.xml
index 34711a7..82d3984 100644
--- a/samples/trainingplugin/pom.xml
+++ b/samples/trainingplugin/pom.xml
@@ -21,7 +21,7 @@
     <parent>
         <artifactId>samples</artifactId>
         <groupId>org.apache.unomi</groupId>
-        <version>1.2.0-incubating-SNAPSHOT</version>
+        <version>1.3.0-incubating-unomi_117-SNAPSHOT</version>
     </parent>
     <artifactId>training-plugin</artifactId>
     <name>Apache Unomi :: Samples :: Training plugin</name>
@@ -33,7 +33,7 @@
         <dependency>
             <groupId>org.apache.unomi</groupId>
             <artifactId>unomi-api</artifactId>
-            <version>1.2.0-incubating-SNAPSHOT</version>
+            <version>1.3.0-incubating-unomi_117-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
     </dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java
 
b/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java
index 98270c7..7c4252e 100644
--- 
a/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java
+++ 
b/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java
@@ -130,7 +130,10 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
 
             try {
                 ConditionType conditionType = 
CustomObjectMapper.getObjectMapper().readValue(predefinedConditionURL, 
ConditionType.class);
-                setConditionType(conditionType);
+                // Register only if condition type does not exist yet
+                if (getConditionType(conditionType.getMetadata().getId()) == 
null) {
+                    setConditionType(conditionType);
+                }
             } catch (IOException e) {
                 logger.error("Error while loading condition definition " + 
predefinedConditionURL, e);
             }
@@ -149,7 +152,10 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
 
             try {
                 ActionType actionType = 
CustomObjectMapper.getObjectMapper().readValue(predefinedActionURL, 
ActionType.class);
-                setActionType(actionType);
+                // Register only if action type does not exist yet
+                if (getActionType(actionType.getMetadata().getId()) == null) {
+                    setActionType(actionType);
+                }
             } catch (Exception e) {
                 logger.error("Error while loading action definition " + 
predefinedActionURL, e);
             }
@@ -208,8 +214,16 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
     }
 
     public Set<ConditionType> getConditionTypesByTag(String tag) {
+        return getConditionTypesBy("metadata.tags", tag);
+    }
+
+    public Set<ConditionType> getConditionTypesBySystemTag(String tag) {
+        return getConditionTypesBy("metadata.systemTags", tag);
+    }
+
+    private Set<ConditionType> getConditionTypesBy(String fieldName, String 
fieldValue) {
         Set<ConditionType> conditionTypes = new LinkedHashSet<ConditionType>();
-        List<ConditionType> directConditionTypes = 
persistenceService.query("metadata.tags", tag,null, ConditionType.class);
+        List<ConditionType> directConditionTypes = 
persistenceService.query(fieldName, fieldValue,null, ConditionType.class);
         for (ConditionType type : directConditionTypes) {
             if (type.getParentCondition() != null) {
                 ParserHelper.resolveConditionType(this, 
type.getParentCondition());
@@ -250,8 +264,16 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
     }
 
     public Set<ActionType> getActionTypeByTag(String tag) {
+        return getActionTypesBy("metadata.tags", tag);
+    }
+
+    public Set<ActionType> getActionTypeBySystemTag(String tag) {
+        return getActionTypesBy("metadata.systemTags", tag);
+    }
+
+    private Set<ActionType> getActionTypesBy(String fieldName, String 
fieldValue) {
         Set<ActionType> actionTypes = new LinkedHashSet<ActionType>();
-        List<ActionType> directActionTypes = 
persistenceService.query("metadata.tags", tag,null, ActionType.class);
+        List<ActionType> directActionTypes = 
persistenceService.query(fieldName, fieldValue,null, ActionType.class);
         actionTypes.addAll(directActionTypes);
 
         return actionTypes;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/services/src/main/java/org/apache/unomi/services/services/GoalsServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/services/GoalsServiceImpl.java
 
b/services/src/main/java/org/apache/unomi/services/services/GoalsServiceImpl.java
index a12a768..ee8c6dc 100644
--- 
a/services/src/main/java/org/apache/unomi/services/services/GoalsServiceImpl.java
+++ 
b/services/src/main/java/org/apache/unomi/services/services/GoalsServiceImpl.java
@@ -57,8 +57,6 @@ public class GoalsServiceImpl implements GoalsService, 
SynchronousBundleListener
 
     private RulesService rulesService;
 
-    private Map<String, Set<Goal>> goalByTag = new HashMap<>();
-
     public void setBundleContext(BundleContext bundleContext) {
         this.bundleContext = bundleContext;
     }
@@ -121,20 +119,6 @@ public class GoalsServiceImpl implements GoalsService, 
SynchronousBundleListener
                     goal.getMetadata().setScope("systemscope");
                 }
                 if (getGoal(goal.getMetadata().getId()) == null) {
-                    for (String tag : goal.getMetadata().getTags()) {
-                        if (goalByTag.containsKey(tag)) {
-                            Set<Goal> goals = goalByTag.get(tag);
-                            if (goals == null) {
-                                goals = new LinkedHashSet<>();
-                            }
-                            goals.add(goal);
-                            goalByTag.put(tag, goals);
-                        } else {
-                            // we found a tag that is not defined, we will 
define it automatically
-                            logger.debug("Unknown tag " + tag + " used in goal 
definition " + predefinedGoalURL);
-                        }
-                    }
-
                     setGoal(goal);
                 }
             } catch (IOException e) {
@@ -539,16 +523,6 @@ public class GoalsServiceImpl implements GoalsService, 
SynchronousBundleListener
         return report;
     }
 
-    public Set<Goal> getGoalByTag(String tag) {
-        Set<Goal> goals = new LinkedHashSet<>();
-        Set<Goal> directGoals = goalByTag.get(tag);
-        if (directGoals != null) {
-            goals.addAll(directGoals);
-        }
-
-        return goals;
-    }
-
     // Campaign Event management methods
     @Override
     public PartialList<CampaignEvent> getEvents(Query query) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
 
b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
index b95363c..17e4ea5 100644
--- 
a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
+++ 
b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
@@ -640,8 +640,16 @@ public class ProfileServiceImpl implements ProfileService, 
SynchronousBundleList
     }
 
     public Set<PropertyType> getPropertyTypeByTag(String tag) {
+        return getPropertyTypesBy("metadata.tags", tag);
+    }
+
+    public Set<PropertyType> getPropertyTypeBySystemTag(String tag) {
+        return getPropertyTypesBy("metadata.systemTags", tag);
+    }
+
+    private Set<PropertyType> getPropertyTypesBy( String fieldName, String 
fieldValue) {
         Set<PropertyType> propertyTypes = new LinkedHashSet<PropertyType>();
-        Collection<PropertyType> directPropertyTypes = 
persistenceService.query("metadata.tags", tag, "rank", PropertyType.class);
+        Collection<PropertyType> directPropertyTypes = 
persistenceService.query(fieldName, fieldValue, "rank", PropertyType.class);
 
         if (directPropertyTypes != null) {
             propertyTypes.addAll(directPropertyTypes);
@@ -718,7 +726,11 @@ public class ProfileServiceImpl implements ProfileService, 
SynchronousBundleList
 
             try {
                 PersonaWithSessions persona = 
CustomObjectMapper.getObjectMapper().readValue(predefinedPersonaURL, 
PersonaWithSessions.class);
-                persistenceService.save(persona.getPersona());
+
+                String itemId = persona.getPersona().getItemId();
+                if (persistenceService.load(itemId, Persona.class) != null) {
+                    persistenceService.save(persona.getPersona());
+                }
 
                 List<PersonaSession> sessions = persona.getSessions();
                 for (PersonaSession session : sessions) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
 
b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
index 6c0ea0f..8c848a4 100644
--- 
a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
+++ 
b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
@@ -152,7 +152,9 @@ public class RulesServiceImpl implements RulesService, 
EventListenerService, Syn
 
             try {
                 Rule rule = 
CustomObjectMapper.getObjectMapper().readValue(predefinedSegmentURL, 
Rule.class);
-                setRule(rule);
+                if (getRule(rule.getMetadata().getId()) == null) {
+                    setRule(rule);
+                }
             } catch (IOException e) {
                 logger.error("Error while loading segment definition " + 
predefinedSegmentURL, e);
             }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/src/site/markdown/versions/master/custom-extensions.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/versions/master/custom-extensions.md 
b/src/site/markdown/versions/master/custom-extensions.md
index 866f4f9..e08cfca 100644
--- a/src/site/markdown/versions/master/custom-extensions.md
+++ b/src/site/markdown/versions/master/custom-extensions.md
@@ -29,7 +29,7 @@ An extension is simply a Maven project, with a Maven pom that 
looks like this:
         <parent>
             <groupId>org.apache.unomi</groupId>
             <artifactId>unomi-extensions</artifactId>
-            <version>1.2.0-incubating-SNAPSHOT</version>
+            <version>${project.version}</version>
         </parent>
     
         <modelVersion>4.0.0</modelVersion>
@@ -37,7 +37,7 @@ An extension is simply a Maven project, with a Maven pom that 
looks like this:
         <artifactId>unomi-extension-example</artifactId>
         <name>Apache Unomi :: Extensions :: Example</name>
         <description>Service implementation for the Apache Unomi Context 
Server extension that integrates with the Geonames database</description>
-        <version>1.2.0-incubating-SNAPSHOT</version>
+        <version>${project.version}</version>
         <packaging>bundle</packaging>
     
         <dependencies>
@@ -45,7 +45,7 @@ An extension is simply a Maven project, with a Maven pom that 
looks like this:
             <dependency>
                 <groupId>org.apache.unomi</groupId>
                 <artifactId>unomi-api</artifactId>
-                <version>1.2.0-incubating-SNAPSHOT</version>
+                <version>${project.version}</version>
                 <scope>provided</scope>
             </dependency>    
         </dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/src/site/markdown/versions/master/login-sample.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/versions/master/login-sample.md 
b/src/site/markdown/versions/master/login-sample.md
index ac5df25..7c55e78 100644
--- a/src/site/markdown/versions/master/login-sample.md
+++ b/src/site/markdown/versions/master/login-sample.md
@@ -38,7 +38,7 @@ Installing the sample
 
 2. Install the login sample using the following command:
 
-        bundle:install 
mvn:org.apache.unomi/login-integration-sample/1.2.0-incubating-SNAPSHOT
+        bundle:install 
mvn:org.apache.unomi/login-integration-sample/${project.version}
         
     when the bundle is successfully install you will get an bundle ID back we 
will call it BUNDLE_ID. 
     

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/tools/pom.xml
----------------------------------------------------------------------
diff --git a/tools/pom.xml b/tools/pom.xml
index 9a42616..cdad996 100644
--- a/tools/pom.xml
+++ b/tools/pom.xml
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.apache.unomi</groupId>
         <artifactId>unomi-root</artifactId>
-        <version>1.2.0-incubating-unomi_117-SNAPSHOT</version>
+        <version>1.3.0-incubating-unomi_117-SNAPSHOT</version>
     </parent>
 
     <artifactId>unomi-tools</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/tools/shell-commands/pom.xml
----------------------------------------------------------------------
diff --git a/tools/shell-commands/pom.xml b/tools/shell-commands/pom.xml
index 51f1f06..93b2e01 100644
--- a/tools/shell-commands/pom.xml
+++ b/tools/shell-commands/pom.xml
@@ -22,13 +22,12 @@
     <parent>
         <artifactId>unomi-tools</artifactId>
         <groupId>org.apache.unomi</groupId>
-        <version>1.2.0-incubating-unomi_117-SNAPSHOT</version>
+        <version>1.3.0-incubating-unomi_117-SNAPSHOT</version>
     </parent>
 
     <artifactId>shell-commands</artifactId>
     <name>Apache Unomi :: Tools :: Shell commands</name>
     <description>Provides the shell commands to interact with Apache Unomi 
Context Server</description>
-    <version>1.2.0-incubating-unomi_117-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
index 45d6471..f2e5ef2 100644
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
@@ -58,8 +58,7 @@ public class Migrate extends OsgiCommandSupport {
             if (fromVersion.compareTo(migration.getToVersion()) < 0) {
                 System.out.println("Starting migration to version " + 
migration.getToVersion());
                 migration.execute(session, httpClient);
-
-                System.out.println("Migration to version 2.0.0 done 
successfully");
+                System.out.println("Migration to version " + 
migration.getToVersion() + " done successfully");
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/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
new file mode 100644
index 0000000..a2cf255
--- /dev/null
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo130.java
@@ -0,0 +1,230 @@
+/*
+ * 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 LinkedHashMap<String, List<String>> tagsStructurePriorTo200;
+
+    @Override
+    public Version getFromVersion() {
+        return null;
+    }
+
+    @Override
+    public Version getToVersion() {
+        return new Version("1.3.0");
+    }
+
+    @Override
+    public void execute(CommandSession session, CloseableHttpClient 
httpClient) throws IOException {
+        try {
+            this.httpClient = httpClient;
+            this.session = session;
+            migrateTags();
+        } catch (IOException e) {
+            if (httpClient != null) {
+                httpClient.close();
+            }
+            throw e;
+        }
+    }
+
+    private void migrateTags() throws IOException {
+        initTagsStructurePriorTo200();
+        String hostAddress = ConsoleUtils.askUserWithDefaultAnswer(session, 
"Host address (default = http://localhost:9200): ", "http://localhost:9200";);
+        String tagsOperation = 
ConsoleUtils.askUserWithAuthorizedAnswer(session, "How to manage tags?\nno 
change: will keep tags in tags property\ncopy: will duplicate tags in 
systemTags property\nmove: will move tags in systemTags 
property\n(default/copy/move): ", Arrays.asList("no change", "copy", "move"));
+
+        String removeNamespaceOnSystemTags = "no";
+        if (tagsOperation.equals("copy") || tagsOperation.equals("move")) {
+            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) {
+            migrateTypeTags(hostAddress, type, tagsOperation, 
removeNamespaceOnSystemTags.equals("yes"));
+        }
+
+        migratePropertyTypesTags(hostAddress, tagsOperation, 
removeNamespaceOnSystemTags.equals("yes"));
+    }
+
+    private void migrateTypeTags(String hostAddress, String type, String 
tagsOperation, boolean removeNamespaceOnSystemTags) throws IOException {
+        JSONObject responseJSON = MigrationUtils.queryWithScroll(httpClient, 
hostAddress + "/context/" + type + "/_search");
+
+        migrateTagsInResult(responseJSON, hostAddress, type,10, true, 
tagsOperation, removeNamespaceOnSystemTags);
+    }
+
+    private void migratePropertyTypesTags(String hostAddress, String 
tagsOperation, boolean removeNamespaceOnSystemTags) throws IOException {
+        JSONObject responseJSON = 
MigrationUtils.queryWithScroll(httpClient,hostAddress + 
"/context/propertyType/_search");
+
+        migrateTagsInResult(responseJSON, hostAddress, "propertyType", 10, 
false, tagsOperation, removeNamespaceOnSystemTags);
+    }
+
+    private void migrateTagsInResult(JSONObject responseJSON, String 
hostAddress, String type, int currentOffset,
+                                     boolean tagsInMetadata, String 
tagsOperation, boolean removeNamespaceOnSystemTags) throws IOException {
+        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(MigrationUtils.continueQueryWithScroll(httpClient, 
hostAddress, responseJSON.getString("_scroll_id")), hostAddress, 
type,currentOffset + 10, tagsInMetadata, tagsOperation, 
removeNamespaceOnSystemTags);
+                }
+            }
+        }
+    }
+
+    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 (tagsStructurePriorTo200.containsKey(tag)) {
+                        
tagsAfterMigration.addAll(tagsStructurePriorTo200.get(tag));
+                    }
+                    tagsAfterMigration.add(tag);
+                }
+
+                
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
+                if (tagsOperation.equals("no change")) {
+                    
updatedHits.append("{\"doc\":{\"metadata\":{\"tags\":").append(new 
JSONArray(tagsAfterMigration)).append("}}}\n");
+                }
+                if (tagsOperation.equals("copy")) {
+                    Set<String> tags = 
removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration);
+                    
updatedHits.append("{\"doc\":{\"metadata\":{\"tags\":").append(new 
JSONArray(tagsAfterMigration))
+                            .append(",\"systemTags\":").append(new 
JSONArray(tags)).append("}}}\n");
+                }
+                if (tagsOperation.equals("move")) {
+                    Set<String> tags = 
removeNamespaceOnTags(removeNamespaceOnSystemTags, tagsAfterMigration);
+                    
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 initTagsStructurePriorTo200() {
+        tagsStructurePriorTo200 = new LinkedHashMap<>();
+        tagsStructurePriorTo200.put("landing", 
Collections.singletonList("campaign"));
+        tagsStructurePriorTo200.put("parameter", 
Collections.singletonList("campaign"));
+        tagsStructurePriorTo200.put("referrer", 
Collections.singletonList("campaign"));
+
+        tagsStructurePriorTo200.put("eventCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo200.put("profileCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo200.put("sessionCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo200.put("sourceEventCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo200.put("trackedCondition", 
Collections.singletonList("condition"));
+        tagsStructurePriorTo200.put("usableInPastEventCondition", 
Collections.singletonList("condition"));
+
+        tagsStructurePriorTo200.put("formMappingRule", 
Collections.<String>emptyList());
+
+        tagsStructurePriorTo200.put("downloadGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo200.put("formGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo200.put("funnelGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo200.put("landingPageGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo200.put("pageVisitGoal", 
Collections.singletonList("goal"));
+        tagsStructurePriorTo200.put("videoGoal", 
Collections.singletonList("goal"));
+
+        tagsStructurePriorTo200.put("aggregated", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo200.put("autocompleted", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo200.put("demographic", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo200.put("event", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo200.put("geographic", 
Collections.singletonList("profileTags"));
+        tagsStructurePriorTo200.put("logical", 
Collections.singletonList("profileTags"));
+
+        tagsStructurePriorTo200.put("profileProperties", 
Collections.singletonList("properties"));
+        tagsStructurePriorTo200.put("systemProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo200.put("basicProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo200.put("leadProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo200.put("contactProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo200.put("socialProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo200.put("personalProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+        tagsStructurePriorTo200.put("workProfileProperties", 
Arrays.asList("properties", "profileProperties"));
+
+        tagsStructurePriorTo200.put("sessionProperties", 
Collections.singletonList("properties"));
+        tagsStructurePriorTo200.put("geographicSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
+        tagsStructurePriorTo200.put("technicalSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java
deleted file mode 100644
index 99e2fb2..0000000
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java
+++ /dev/null
@@ -1,194 +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 MigrationTo200 implements Migration {
-
-    private CloseableHttpClient httpClient;
-    private CommandSession session;
-    private LinkedHashMap<String, List<String>> tagsStructurePriorTo200;
-
-    @Override
-    public Version getFromVersion() {
-        return null;
-    }
-
-    @Override
-    public Version getToVersion() {
-        return new Version("2.0.0");
-    }
-
-    @Override
-    public void execute(CommandSession session, CloseableHttpClient 
httpClient) throws IOException {
-        try {
-            this.httpClient = httpClient;
-            this.session = session;
-            migrateTags();
-        } catch (IOException e) {
-            if (httpClient != null) {
-                httpClient.close();
-            }
-            throw e;
-        }
-    }
-
-    private void migrateTags() throws IOException {
-        initTagsStructurePriorTo200();
-        String hostAddress = ConsoleUtils.askUserWithDefaultAnswer(session, 
"Host address (default = http://localhost:9200): ", "http://localhost:9200";);
-
-        List<String> typeToMigrate = Arrays.asList("actionType", 
"conditionType", "campaign", "goal", "rule", "scoring", "segment", "userList");
-        for (String type : typeToMigrate) {
-            migrateTypeTags(hostAddress, type);
-        }
-
-        migratePropertyTypesTags(hostAddress);
-    }
-
-    private void migrateTypeTags(String hostAddress, String type) throws 
IOException {
-        JSONObject responseJSON = MigrationUtils.queryWithScroll(httpClient, 
hostAddress + "/context/" + type + "/_search");
-
-        migrateTagsInResult(responseJSON, hostAddress, type,10, true);
-    }
-
-    private void migratePropertyTypesTags(String hostAddress) throws 
IOException {
-        JSONObject responseJSON = 
MigrationUtils.queryWithScroll(httpClient,hostAddress + 
"/context/propertyType/_search");
-
-        migrateTagsInResult(responseJSON, hostAddress, "propertyType", 10, 
false);
-    }
-
-    private void migrateTagsInResult(JSONObject responseJSON, String 
hostAddress, String type, int currentOffset, boolean tagsInMetadata) throws 
IOException {
-        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);
-                        } else if (!tagsInMetadata) {
-                            updateTagsForHit(updatedHits, 
hit.getString("_id"), hitSource, tagsInMetadata);
-                        }
-                    }
-                }
-                String jsonData = updatedHits.toString();
-                if (StringUtils.isNotBlank(jsonData)) {
-                    MigrationUtils.bulkUpdate(httpClient, hostAddress + 
"/context/" + type + "/_bulk", jsonData);
-                }
-
-                if (hitsObject.getInt("total") > currentOffset) {
-                    
migrateTagsInResult(MigrationUtils.continueQueryWithScroll(httpClient, 
hostAddress, responseJSON.getString("_scroll_id")), hostAddress, 
type,currentOffset + 10, tagsInMetadata);
-                }
-            }
-        }
-    }
-
-    private void updateTagsForHit(StringBuilder updatedHits, String hitId, 
JSONObject jsonObject, boolean tagsInMetadata) {
-        if (jsonObject.has("tags")) {
-            JSONArray hitTags = jsonObject.getJSONArray("tags");
-            Iterator<Object> tagsIterator = hitTags.iterator();
-            List<String> tagsBeforeMigration = new ArrayList<>();
-            List<String> tagsAfterMigration = new ArrayList<>();
-            if (tagsIterator.hasNext()) {
-                while (tagsIterator.hasNext()) {
-                    tagsBeforeMigration.add((String) tagsIterator.next());
-                }
-
-                for (String tag : tagsBeforeMigration) {
-                    if (tagsStructurePriorTo200.containsKey(tag) && 
!tagsAfterMigration.containsAll(tagsStructurePriorTo200.get(tag))) {
-                        
tagsAfterMigration.addAll(tagsStructurePriorTo200.get(tag));
-                    }
-
-                    if (!tagsAfterMigration.contains(tag)) {
-                        tagsAfterMigration.add(tag);
-                    }
-                }
-
-                
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
-                
updatedHits.append("{\"doc\":{\"metadata\":{\"tags\":").append(new 
JSONArray(tagsAfterMigration)).append("}}}\n");
-                if (!tagsInMetadata) {
-                    
updatedHits.append("{\"update\":{\"_id\":\"").append(hitId).append("\"}}\n");
-                    
updatedHits.append("{\"script\":\"ctx._source.remove(\\\"tags\\\")\"}\n");
-                }
-            }
-        }
-    }
-
-    private void initTagsStructurePriorTo200() {
-        tagsStructurePriorTo200 = new LinkedHashMap<>();
-        tagsStructurePriorTo200.put("landing", 
Collections.singletonList("campaign"));
-        tagsStructurePriorTo200.put("parameter", 
Collections.singletonList("campaign"));
-        tagsStructurePriorTo200.put("referrer", 
Collections.singletonList("campaign"));
-
-        tagsStructurePriorTo200.put("eventCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo200.put("profileCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo200.put("sessionCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo200.put("sourceEventCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo200.put("trackedCondition", 
Collections.singletonList("condition"));
-        tagsStructurePriorTo200.put("usableInPastEventCondition", 
Collections.singletonList("condition"));
-
-        tagsStructurePriorTo200.put("formMappingRule", 
Collections.<String>emptyList());
-
-        tagsStructurePriorTo200.put("downloadGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo200.put("formGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo200.put("funnelGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo200.put("landingPageGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo200.put("pageVisitGoal", 
Collections.singletonList("goal"));
-        tagsStructurePriorTo200.put("videoGoal", 
Collections.singletonList("goal"));
-
-        tagsStructurePriorTo200.put("aggregated", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo200.put("autocompleted", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo200.put("demographic", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo200.put("event", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo200.put("geographic", 
Collections.singletonList("profileTags"));
-        tagsStructurePriorTo200.put("logical", 
Collections.singletonList("profileTags"));
-
-        tagsStructurePriorTo200.put("profileProperties", 
Collections.singletonList("properties"));
-        tagsStructurePriorTo200.put("systemProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo200.put("basicProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo200.put("leadProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo200.put("contactProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo200.put("socialProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo200.put("personalProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-        tagsStructurePriorTo200.put("workProfileProperties", 
Arrays.asList("properties", "profileProperties"));
-
-        tagsStructurePriorTo200.put("sessionProperties", 
Collections.singletonList("properties"));
-        tagsStructurePriorTo200.put("geographicSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
-        tagsStructurePriorTo200.put("technicalSessionProperties", 
Arrays.asList("properties", "sessionProperties"));
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8e6132d2/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 562159f..7b31650 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,7 +21,7 @@
            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="migrateTo200" 
class="org.apache.unomi.shell.migration.impl.MigrationTo200"/>
+    <bean id="migrateTo200" 
class="org.apache.unomi.shell.migration.impl.MigrationTo130"/>
 
     <shell:command-bundle>
         <shell:command>

Reply via email to