Repository: incubator-unomi
Updated Branches:
  refs/heads/master 358c4df04 -> ad73b222e


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/videoViewEventCondition.json
----------------------------------------------------------------------
diff --git 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/videoViewEventCondition.json
 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/videoViewEventCondition.json
index 0828adc..cc74144 100644
--- 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/videoViewEventCondition.json
+++ 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/videoViewEventCondition.json
@@ -1,5 +1,16 @@
 {
-  "id": "videoViewEventCondition",
+  "metadata": {
+    "id": "videoViewEventCondition",
+    "name": "videoViewEventCondition",
+    "description": "",
+    "tags": [
+      "event",
+      "eventCondition",
+      "usableInPastEventCondition",
+      "trackedCondition"
+    ],
+    "readOnly": true
+  },
   "parentCondition": {
     "type": "booleanCondition",
     "parameterValues": {
@@ -27,15 +38,9 @@
           }
         }
       ],
-      "operator" : "and"
+      "operator": "and"
     }
   },
-  "tags": [
-    "event",
-    "eventCondition",
-    "usableInPastEventCondition",
-    "trackedCondition"
-  ],
   "parameters": [
     {
       "id": "videoId",

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/plugins/hover-event/src/main/resources/META-INF/cxs/conditions/hoverEventCondition.json
----------------------------------------------------------------------
diff --git 
a/plugins/hover-event/src/main/resources/META-INF/cxs/conditions/hoverEventCondition.json
 
b/plugins/hover-event/src/main/resources/META-INF/cxs/conditions/hoverEventCondition.json
index 50ade9a..711eb61 100644
--- 
a/plugins/hover-event/src/main/resources/META-INF/cxs/conditions/hoverEventCondition.json
+++ 
b/plugins/hover-event/src/main/resources/META-INF/cxs/conditions/hoverEventCondition.json
@@ -1,17 +1,26 @@
 {
+  "metadata": {
     "id": "hoverEventCondition",
-    "queryBuilder": "hoverEventConditionESQueryBuilder",
-    "tags": [ "event", "eventCondition", "usableInPastEventCondition" ],
-    "parameters": [
-        {
-            "id": "targetId",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "targetPath",
-            "type": "string",
-            "multivalued": false
-        }
-    ]
+    "name": "hoverEventCondition",
+    "description": "",
+    "tags": [
+      "event",
+      "eventCondition",
+      "usableInPastEventCondition"
+    ],
+    "readOnly": true
+  },
+  "queryBuilder": "hoverEventConditionESQueryBuilder",
+  "parameters": [
+    {
+      "id": "targetId",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "targetPath",
+      "type": "string",
+      "multivalued": false
+    }
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
----------------------------------------------------------------------
diff --git 
a/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json 
b/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
index 256ebff..c2c9152 100644
--- a/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
+++ b/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
@@ -1,39 +1,45 @@
 {
+  "metadata": {
     "id": "sendMailAction",
-    "actionExecutor": "sendMail",
-    "tags": [ "event" ],
-    "parameters": [
-        {
-            "id": "from",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "to",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "cc",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "bcc",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "subject",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "template",
-            "type": "string",
-            "multivalued": false,
-                    "defaultValue": "Hello 
$profile.properties.(\"j:firstName\")$ 
$profile.properties.(\"j:lastName\")$,\nHow are you doing today?"
-        }
-
-    ]
+    "name": "sendMailAction",
+    "description": "",
+    "tags": [
+      "event"
+    ],
+    "readOnly": true
+  },
+  "actionExecutor": "sendMail",
+  "parameters": [
+    {
+      "id": "from",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "to",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "cc",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "bcc",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "subject",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "template",
+      "type": "string",
+      "multivalued": false,
+      "defaultValue": "Hello $profile.properties.(\"j:firstName\")$ 
$profile.properties.(\"j:lastName\")$,\nHow are you doing today?"
+    }
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/plugins/request/src/main/resources/META-INF/cxs/actions/requestHeaderToProfilePropertyAction.json
----------------------------------------------------------------------
diff --git 
a/plugins/request/src/main/resources/META-INF/cxs/actions/requestHeaderToProfilePropertyAction.json
 
b/plugins/request/src/main/resources/META-INF/cxs/actions/requestHeaderToProfilePropertyAction.json
index e00b989..adce6c9 100644
--- 
a/plugins/request/src/main/resources/META-INF/cxs/actions/requestHeaderToProfilePropertyAction.json
+++ 
b/plugins/request/src/main/resources/META-INF/cxs/actions/requestHeaderToProfilePropertyAction.json
@@ -1,28 +1,35 @@
 {
+  "metadata": {
     "id": "requestHeaderToProfilePropertyAction",
-    "actionExecutor": "requestHeaderToProfileProperty",
-    "tags": [ "event" ],
-    "parameters": [
-        {
-            "id": "requestHeaderName",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "profilePropertyName",
-            "type": "string",
-            "multivalued": false,
-            "choiceListInitializerFilter": "(initializerId=propertyType)"
-        },
-        {
-            "id": "sessionPropertyName",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "storeAsList",
-            "type": "boolean",
-            "multivalued": false
-        }
-    ]
+    "name": "requestHeaderToProfilePropertyAction",
+    "description": "",
+    "tags": [
+      "event"
+    ],
+    "readOnly": true
+  },
+  "actionExecutor": "requestHeaderToProfileProperty",
+  "parameters": [
+    {
+      "id": "requestHeaderName",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "profilePropertyName",
+      "type": "string",
+      "multivalued": false,
+      "choiceListInitializerFilter": "(initializerId=propertyType)"
+    },
+    {
+      "id": "sessionPropertyName",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "storeAsList",
+      "type": "boolean",
+      "multivalued": false
+    }
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/plugins/request/src/main/resources/META-INF/cxs/actions/requestParameterToProfilePropertyAction.json
----------------------------------------------------------------------
diff --git 
a/plugins/request/src/main/resources/META-INF/cxs/actions/requestParameterToProfilePropertyAction.json
 
b/plugins/request/src/main/resources/META-INF/cxs/actions/requestParameterToProfilePropertyAction.json
index df5804d..740b041 100644
--- 
a/plugins/request/src/main/resources/META-INF/cxs/actions/requestParameterToProfilePropertyAction.json
+++ 
b/plugins/request/src/main/resources/META-INF/cxs/actions/requestParameterToProfilePropertyAction.json
@@ -1,28 +1,35 @@
 {
+  "metadata": {
     "id": "requestParameterToProfilePropertyAction",
-    "actionExecutor": "requestParameterToProfileProperty",
-    "tags": [ "event" ],
-    "parameters": [
-        {
-            "id": "requestParameterName",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "profilePropertyName",
-            "type": "string",
-            "multivalued": false,
-            "choiceListInitializerFilter": "(initializerId=propertyType)"
-        },
-        {
-            "id": "sessionPropertyName",
-            "type": "string",
-            "multivalued": false
-        },
-        {
-            "id": "storeAsList",
-            "type": "boolean",
-            "multivalued": false
-        }
-    ]
+    "name": "requestParameterToProfilePropertyAction",
+    "description": "",
+    "tags": [
+      "event"
+    ],
+    "readOnly": true
+  },
+  "actionExecutor": "requestParameterToProfileProperty",
+  "parameters": [
+    {
+      "id": "requestParameterName",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "profilePropertyName",
+      "type": "string",
+      "multivalued": false,
+      "choiceListInitializerFilter": "(initializerId=propertyType)"
+    },
+    {
+      "id": "sessionPropertyName",
+      "type": "string",
+      "multivalued": false
+    },
+    {
+      "id": "storeAsList",
+      "type": "boolean",
+      "multivalued": false
+    }
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/plugins/request/src/main/resources/META-INF/cxs/actions/setRemoteHostInfoAction.json
----------------------------------------------------------------------
diff --git 
a/plugins/request/src/main/resources/META-INF/cxs/actions/setRemoteHostInfoAction.json
 
b/plugins/request/src/main/resources/META-INF/cxs/actions/setRemoteHostInfoAction.json
index d0b13ad..803b2e5 100644
--- 
a/plugins/request/src/main/resources/META-INF/cxs/actions/setRemoteHostInfoAction.json
+++ 
b/plugins/request/src/main/resources/META-INF/cxs/actions/setRemoteHostInfoAction.json
@@ -1,7 +1,14 @@
 {
+  "metadata": {
     "id": "setRemoteHostInfoAction",
-    "actionExecutor": "setRemoteHostInfo",
-    "tags": [ "event" ],
-    "parameters": [
-    ]
+    "name": "setRemoteHostInfoAction",
+    "description": "",
+    "tags": [
+      "event"
+    ],
+    "readOnly": true
+  },
+  "actionExecutor": "setRemoteHostInfo",
+  "parameters": [
+  ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/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 1d504d3..365124c 100644
--- a/rest/src/main/java/org/apache/unomi/rest/DefinitionsServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/DefinitionsServiceEndPoint.java
@@ -143,6 +143,28 @@ public class DefinitionsServiceEndPoint {
     }
 
     /**
+     * Stores the condition type
+     *
+     * @param conditionType the condition type to store
+     */
+    @POST
+    @Path("/conditions")
+    public void setConditionType(ConditionType conditionType) {
+        definitionsService.setConditionType(conditionType);
+    }
+
+    /**
+     * Removes the condition type
+     *
+     * @param conditionTypeId the identifier of the action type to delete
+     */
+    @DELETE
+    @Path("/conditions/{conditionTypeId}")
+    public void removeConditionType(@PathParam("conditionTypeId") String 
conditionTypeId) {
+        definitionsService.removeConditionType(conditionTypeId);
+    }
+
+    /**
      * Retrieves all known action types localized using the specified language.
      *
      * @param language the language to use to localize.
@@ -189,6 +211,28 @@ public class DefinitionsServiceEndPoint {
     }
 
     /**
+     * Stores the action type
+     *
+     * @param actionType the action type to store
+     */
+    @POST
+    @Path("/actions")
+    public void setActionType(ActionType actionType) {
+        definitionsService.setActionType(actionType);
+    }
+
+    /**
+     * Removes the action type
+     *
+     * @param actionTypeId the identifier of the action type to delete
+     */
+    @DELETE
+    @Path("/actions/{actionTypeId}")
+    public void removeActionType(@PathParam("actionTypeId") String 
actionTypeId) {
+        definitionsService.removeActionType(actionTypeId);
+    }
+
+    /**
      * Retrieves all known value types localized using the specified language.
      *
      * @param language the language to use to localize.

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/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 55a4337..3052972 100644
--- a/rest/src/main/java/org/apache/unomi/rest/LocalizationHelper.java
+++ b/rest/src/main/java/org/apache/unomi/rest/LocalizationHelper.java
@@ -18,24 +18,19 @@
 package org.apache.unomi.rest;
 
 import org.apache.unomi.api.Parameter;
-import org.apache.unomi.api.PluginType;
 import org.apache.unomi.api.Tag;
 import org.apache.unomi.api.ValueType;
 import org.apache.unomi.api.actions.ActionType;
 import org.apache.unomi.api.conditions.ConditionType;
 import org.apache.unomi.api.conditions.initializers.ChoiceListInitializer;
 import org.apache.unomi.api.conditions.initializers.ChoiceListValue;
-import org.apache.unomi.api.conditions.initializers.I18nSupport;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.ResourceBundle;
+import java.util.*;
 
 /**
  * A helper class to provide localized versions of context server entities.
@@ -92,16 +87,15 @@ public class LocalizationHelper {
      */
     public RESTConditionType generateCondition(ConditionType conditionType, 
String language) {
         RESTConditionType result = new RESTConditionType();
-        result.setId(conditionType.getId());
+        result.setId(conditionType.getItemId());
 
-        ResourceBundle bundle = 
resourceBundleHelper.getResourceBundle(conditionType, language);
-        result.setName(resourceBundleHelper.getResourceBundleValue(bundle, 
conditionType.getNameKey()));
-        
result.setDescription(resourceBundleHelper.getResourceBundleValue(bundle, 
conditionType.getDescriptionKey()));
+        result.setName(conditionType.getMetadata().getName());
+        result.setDescription(conditionType.getMetadata().getDescription());
 
-        result.setTags(conditionType.getTagIDs());
+        result.setTags(conditionType.getMetadata().getTags());
 
         for (Parameter parameter : conditionType.getParameters()) {
-            result.getParameters().add(generateParameter(parameter, bundle));
+            result.getParameters().add(generateParameter(parameter, language));
         }
 
         return result;
@@ -116,17 +110,16 @@ public class LocalizationHelper {
      */
     public RESTActionType generateAction(ActionType actionType, String 
language) {
         RESTActionType result = new RESTActionType();
-        result.setId(actionType.getId());
+        result.setId(actionType.getItemId());
 
-        ResourceBundle bundle = 
resourceBundleHelper.getResourceBundle(actionType, language);
-        result.setName(resourceBundleHelper.getResourceBundleValue(bundle, 
actionType.getNameKey()));
-        
result.setDescription(resourceBundleHelper.getResourceBundleValue(bundle, 
actionType.getDescriptionKey()));
+        result.setName(actionType.getMetadata().getName());
+        result.setDescription(actionType.getMetadata().getDescription());
 
-        result.setTags(actionType.getTagIds());
+        result.setTags(actionType.getMetadata().getTags());
 
         List<RESTParameter> parameters = new ArrayList<RESTParameter>();
         for (Parameter parameter : actionType.getParameters()) {
-            parameters.add(generateParameter(parameter, bundle));
+            parameters.add(generateParameter(parameter, language));
         }
         result.setParameters(parameters);
 
@@ -137,44 +130,34 @@ public class LocalizationHelper {
      * Creates a {@link RESTParameter} based on the specified {@link 
Parameter} and localized using the specified {@link ResourceBundle}.
      *
      * @param parameter the {@link Parameter} to be localized
-     * @param bundle    the {@link ResourceBundle} used to localize the {@link 
Parameter}'s choice list values if needed
+     * @param language
      * @return a {@link RESTParameter} based on the specified {@link 
ActionType} and localized using the specified {@link ResourceBundle}
      */
-    public RESTParameter generateParameter(Parameter parameter, ResourceBundle 
bundle) {
+    public RESTParameter generateParameter(Parameter parameter, String 
language) {
         RESTParameter result = new RESTParameter();
         result.setId(parameter.getId());
         result.setDefaultValue(parameter.getDefaultValue());
         result.setMultivalued(parameter.isMultivalued());
         result.setType(parameter.getType());
-
-        localizeChoiceListValues(bundle, result.getChoiceListValues(), 
parameter.getChoiceListInitializerFilter());
+        
result.setChoiceListValues(generateChoiceListValues(parameter.getChoiceListInitializerFilter(),
 language));
 
         return result;
     }
 
-    public void localizeChoiceListValues(ResourceBundle bundle, 
List<ChoiceListValue> result, String choiceListInitializerFilter) {
+    public List<ChoiceListValue> generateChoiceListValues(String 
choiceListInitializerFilter, String language) {
+        List<ChoiceListValue> result = new ArrayList<ChoiceListValue>();
         if (choiceListInitializerFilter != null && 
choiceListInitializerFilter.length() > 0) {
             try {
                 Collection<ServiceReference<ChoiceListInitializer>> 
matchingChoiceListInitializerReferences = 
bundleContext.getServiceReferences(ChoiceListInitializer.class, 
choiceListInitializerFilter);
                 for (ServiceReference<ChoiceListInitializer> 
choiceListInitializerReference : matchingChoiceListInitializerReferences) {
                     ChoiceListInitializer choiceListInitializer = 
bundleContext.getService(choiceListInitializerReference);
-                    List<ChoiceListValue> options = 
choiceListInitializer.getValues(bundle.getLocale());
-                    if (choiceListInitializer instanceof I18nSupport) {
-                        for (ChoiceListValue value : options) {
-                            if (value instanceof PluginType) {
-                                
result.add(value.localizedCopy(resourceBundleHelper.getResourceBundleValue(resourceBundleHelper.getResourceBundle((PluginType)
 value, bundle.getLocale().getLanguage()), value.getName())));
-                            } else {
-                                
result.add(value.localizedCopy(resourceBundleHelper.getResourceBundleValue(bundle,
 value.getName())));
-                            }
-                        }
-                    } else {
-                        result.addAll(options);
-                    }
+                    result.addAll(choiceListInitializer.getValues(null));
                 }
             } catch (InvalidSyntaxException e) {
                 logger.error("Invalid filter", e);
             }
         }
+        return result;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/actions/incrementTweetNumberAction.json
----------------------------------------------------------------------
diff --git 
a/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/actions/incrementTweetNumberAction.json
 
b/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/actions/incrementTweetNumberAction.json
index e65b644..473cda8 100644
--- 
a/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/actions/incrementTweetNumberAction.json
+++ 
b/samples/tweet-button-plugin/src/main/resources/META-INF/cxs/actions/incrementTweetNumberAction.json
@@ -1,8 +1,13 @@
 {
-  "id": "incrementTweetNumberAction",
+  "metadata": {
+    "id": "incrementTweetNumberAction",
+    "name": "incrementTweetNumberAction",
+    "description": "",
+    "tags": [
+      "event"
+    ],
+    "readOnly": true
+  },
   "actionExecutor": "incrementTweetNumber",
-  "tags": [
-    "event"
-  ],
   "parameters": []
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/services/src/main/java/org/apache/unomi/services/conditions/initializers/ComparisonOperatorChoiceListInitializer.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/conditions/initializers/ComparisonOperatorChoiceListInitializer.java
 
b/services/src/main/java/org/apache/unomi/services/conditions/initializers/ComparisonOperatorChoiceListInitializer.java
index 3d98548..467ecf8 100644
--- 
a/services/src/main/java/org/apache/unomi/services/conditions/initializers/ComparisonOperatorChoiceListInitializer.java
+++ 
b/services/src/main/java/org/apache/unomi/services/conditions/initializers/ComparisonOperatorChoiceListInitializer.java
@@ -19,7 +19,6 @@ package org.apache.unomi.services.conditions.initializers;
 
 import org.apache.unomi.api.conditions.initializers.ChoiceListInitializer;
 import org.apache.unomi.api.conditions.initializers.ChoiceListValue;
-import org.apache.unomi.api.conditions.initializers.I18nSupport;
 import org.osgi.framework.BundleContext;
 
 import java.util.ArrayList;
@@ -28,7 +27,7 @@ import java.util.List;
 /**
  * Initializer for the set of available comparison operators.
  */
-public class ComparisonOperatorChoiceListInitializer implements 
ChoiceListInitializer, I18nSupport {
+public class ComparisonOperatorChoiceListInitializer implements 
ChoiceListInitializer {
 
     private List<ChoiceListValue> operators;
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/services/src/main/java/org/apache/unomi/services/conditions/initializers/EventTypeIdChoiceListInitializer.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/conditions/initializers/EventTypeIdChoiceListInitializer.java
 
b/services/src/main/java/org/apache/unomi/services/conditions/initializers/EventTypeIdChoiceListInitializer.java
index 005d19e..3076ff8 100644
--- 
a/services/src/main/java/org/apache/unomi/services/conditions/initializers/EventTypeIdChoiceListInitializer.java
+++ 
b/services/src/main/java/org/apache/unomi/services/conditions/initializers/EventTypeIdChoiceListInitializer.java
@@ -19,14 +19,13 @@ package org.apache.unomi.services.conditions.initializers;
 
 import org.apache.unomi.api.conditions.initializers.ChoiceListInitializer;
 import org.apache.unomi.api.conditions.initializers.ChoiceListValue;
-import org.apache.unomi.api.conditions.initializers.I18nSupport;
 import org.apache.unomi.api.services.EventService;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
-public class EventTypeIdChoiceListInitializer implements 
ChoiceListInitializer, I18nSupport {
+public class EventTypeIdChoiceListInitializer implements ChoiceListInitializer 
{
 
     EventService eventService;
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/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 f4b39c2..7744652 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
@@ -26,6 +26,7 @@ import org.apache.unomi.api.conditions.Condition;
 import org.apache.unomi.api.conditions.ConditionType;
 import org.apache.unomi.api.services.DefinitionsService;
 import org.apache.unomi.persistence.spi.CustomObjectMapper;
+import org.apache.unomi.persistence.spi.PersistenceService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -41,13 +42,13 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
 
     private static final Logger logger = 
LoggerFactory.getLogger(DefinitionsServiceImpl.class.getName());
 
+    private PersistenceService persistenceService;
+
     private Map<String, Tag> tags = new HashMap<>();
     private Set<Tag> rootTags = new LinkedHashSet<>();
     private Map<String, ConditionType> conditionTypeById = new HashMap<>();
     private Map<String, ActionType> actionTypeById = new HashMap<>();
     private Map<String, ValueType> valueTypeById = new HashMap<>();
-    private Map<Tag, Set<ConditionType>> conditionTypeByTag = new HashMap<>();
-    private Map<Tag, Set<ActionType>> actionTypeByTag = new HashMap<>();
     private Map<Tag, Set<ValueType>> valueTypeByTag = new HashMap<>();
     private Map<Long, List<PluginType>> pluginTypes = new HashMap<>();
     private Map<String, PropertyMergeStrategyType> 
propertyMergeStrategyTypeById = new HashMap<>();
@@ -61,6 +62,10 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
         this.bundleContext = bundleContext;
     }
 
+    public void setPersistenceService(PersistenceService persistenceService) {
+        this.persistenceService = persistenceService;
+    }
+
     public void postConstruct() {
         logger.debug("postConstruct {" + bundleContext.getBundle() + "}");
 
@@ -99,19 +104,7 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
         List<PluginType> types = 
pluginTypes.get(bundleContext.getBundle().getBundleId());
         if (types != null) {
             for (PluginType type : types) {
-                if (type instanceof ActionType) {
-                    ActionType actionType = (ActionType) type;
-                    actionTypeById.remove(actionType.getId());
-                    for (Tag tag : actionType.getTags()) {
-                        actionTypeByTag.get(tag).remove(actionType);
-                    }
-                } else if (type instanceof ConditionType) {
-                    ConditionType conditionType = (ConditionType) type;
-                    conditionTypeById.remove(conditionType.getId());
-                    for (Tag tag : conditionType.getTags()) {
-                        conditionTypeByTag.get(tag).remove(conditionType);
-                    }
-                } else if (type instanceof ValueType) {
+                if (type instanceof ValueType) {
                     ValueType valueType = (ValueType) type;
                     valueTypeById.remove(valueType.getId());
                     for (Tag tag : valueType.getTags()) {
@@ -163,40 +156,18 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
         if (predefinedConditionEntries == null) {
             return;
         }
-        ArrayList<PluginType> pluginTypeArrayList = (ArrayList<PluginType>) 
pluginTypes.get(bundleContext.getBundle().getBundleId());
+
         while (predefinedConditionEntries.hasMoreElements()) {
             URL predefinedConditionURL = 
predefinedConditionEntries.nextElement();
-            logger.debug("Found predefined conditions at " + 
predefinedConditionURL + ", loading... ");
+            logger.debug("Found predefined condition at " + 
predefinedConditionURL + ", loading... ");
 
             try {
                 ConditionType conditionType = 
CustomObjectMapper.getObjectMapper().readValue(predefinedConditionURL, 
ConditionType.class);
-                
conditionType.setPluginId(bundleContext.getBundle().getBundleId());
-                conditionTypeById.put(conditionType.getId(), conditionType);
-                pluginTypeArrayList.add(conditionType);
-                for (String tagId : conditionType.getTagIDs()) {
-                    Tag tag = tags.get(tagId);
-                    if (tag != null) {
-                        conditionType.getTags().add(tag);
-                        Set<ConditionType> conditionTypes = 
conditionTypeByTag.get(tag);
-                        if (conditionTypes == null) {
-                            conditionTypes = new 
LinkedHashSet<ConditionType>();
-                        }
-                        conditionTypes.add(conditionType);
-                        conditionTypeByTag.put(tag, conditionTypes);
-                    } else {
-                        // we found a tag that is not defined, we will define 
it automatically
-                        logger.warn("Unknown tag " + tagId + " used in 
condition definition " + predefinedConditionURL);
-                    }
-                }
-            } catch (Exception e) {
+                setConditionType(conditionType);
+            } catch (IOException e) {
                 logger.error("Error while loading condition definition " + 
predefinedConditionURL, e);
             }
         }
-        for (ConditionType type : conditionTypeById.values()) {
-            if (type.getParentCondition() != null) {
-                ParserHelper.resolveConditionType(this, 
type.getParentCondition());
-            }
-        }
     }
 
     private void loadPredefinedActionTypes(BundleContext bundleContext) {
@@ -211,24 +182,7 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
 
             try {
                 ActionType actionType = 
CustomObjectMapper.getObjectMapper().readValue(predefinedActionURL, 
ActionType.class);
-                
actionType.setPluginId(bundleContext.getBundle().getBundleId());
-                actionTypeById.put(actionType.getId(), actionType);
-                pluginTypeArrayList.add(actionType);
-                for (String tagId : actionType.getTagIds()) {
-                    Tag tag = tags.get(tagId);
-                    if (tag != null) {
-                        actionType.getTags().add(tag);
-                        Set<ActionType> actionTypes = actionTypeByTag.get(tag);
-                        if (actionTypes == null) {
-                            actionTypes = new LinkedHashSet<>();
-                        }
-                        actionTypes.add(actionType);
-                        actionTypeByTag.put(tag, actionTypes);
-                    } else {
-                        // we found a tag that is not defined, we will define 
it automatically
-                        logger.warn("Unknown tag " + tagId + " used in action 
definition " + predefinedActionURL);
-                    }
-                }
+                setActionType(actionType);
             } catch (Exception e) {
                 logger.error("Error while loading action definition " + 
predefinedActionURL, e);
             }
@@ -289,20 +243,29 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
         return completeTag;
     }
 
-    public Collection<ConditionType> getAllConditionTypes() {
-        return conditionTypeById.values();
-    }
-
     public Map<Long, List<PluginType>> getTypesByPlugin() {
         return pluginTypes;
     }
 
+    public Collection<ConditionType> getAllConditionTypes() {
+        Collection<ConditionType> all = 
persistenceService.getAllItems(ConditionType.class);
+        for (ConditionType type : all) {
+            if (type != null && type.getParentCondition() != null) {
+                ParserHelper.resolveConditionType(this, 
type.getParentCondition());
+            }
+        }
+        return all;
+    }
+
     public Set<ConditionType> getConditionTypesByTag(Tag tag, boolean 
includeFromSubtags) {
         Set<ConditionType> conditionTypes = new LinkedHashSet<ConditionType>();
-        Set<ConditionType> directConditionTypes = conditionTypeByTag.get(tag);
-        if (directConditionTypes != null) {
-            conditionTypes.addAll(directConditionTypes);
+        List<ConditionType> directConditionTypes = 
persistenceService.query("metadata.tags",tag.getId(),null, ConditionType.class);
+        for (ConditionType type : directConditionTypes) {
+            if (type.getParentCondition() != null) {
+                ParserHelper.resolveConditionType(this, 
type.getParentCondition());
+            }
         }
+        conditionTypes.addAll(directConditionTypes);
         if (includeFromSubtags) {
             for (Tag subTag : tag.getSubTags()) {
                 Set<ConditionType> childConditionTypes = 
getConditionTypesByTag(subTag, true);
@@ -313,19 +276,35 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
     }
 
     public ConditionType getConditionType(String id) {
-        return conditionTypeById.get(id);
+        ConditionType type = conditionTypeById.get(id);
+        if (type == null) {
+            type = persistenceService.load(id, ConditionType.class);
+            conditionTypeById.put(id, type);
+        }
+        if (type != null && type.getParentCondition() != null) {
+            ParserHelper.resolveConditionType(this, type.getParentCondition());
+        }
+        return type;
+    }
+
+    public void removeConditionType(String id) {
+        persistenceService.remove(id, ConditionType.class);
+        conditionTypeById.remove(id);
+    }
+
+    public void setConditionType(ConditionType conditionType) {
+        conditionTypeById.put(conditionType.getMetadata().getId(), 
conditionType);
+        persistenceService.save(conditionType);
     }
 
     public Collection<ActionType> getAllActionTypes() {
-        return actionTypeById.values();
+        return persistenceService.getAllItems(ActionType.class);
     }
 
     public Set<ActionType> getActionTypeByTag(Tag tag, boolean 
includeFromSubtags) {
         Set<ActionType> actionTypes = new LinkedHashSet<ActionType>();
-        Set<ActionType> directActionTypes = actionTypeByTag.get(tag);
-        if (directActionTypes != null) {
-            actionTypes.addAll(directActionTypes);
-        }
+        List<ActionType> directActionTypes = 
persistenceService.query("metadata.tags",tag.getId(),null, ActionType.class);
+        actionTypes.addAll(directActionTypes);
         if (includeFromSubtags) {
             for (Tag subTag : tag.getSubTags()) {
                 Set<ActionType> childActionTypes = getActionTypeByTag(subTag, 
true);
@@ -336,7 +315,22 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
     }
 
     public ActionType getActionType(String id) {
-        return actionTypeById.get(id);
+        ActionType type = actionTypeById.get(id);
+        if (type == null) {
+            type = persistenceService.load(id, ActionType.class);
+            actionTypeById.put(id, type);
+        }
+        return type;
+    }
+
+    public void removeActionType(String id) {
+        persistenceService.remove(id, ActionType.class);
+        actionTypeById.remove(id);
+    }
+
+    public void setActionType(ActionType actionType) {
+        actionTypeById.put(actionType.getMetadata().getId(), actionType);
+        persistenceService.save(actionType);
     }
 
     public Collection<ValueType> getAllValueTypes() {
@@ -442,7 +436,7 @@ public class DefinitionsServiceImpl implements 
DefinitionsService, SynchronousBu
                 }
             }
             throw new IllegalArgumentException();
-        } else if (rootCondition.getConditionType() != null && 
rootCondition.getConditionType().getTagIDs().contains(tagId)) {
+        } else if (rootCondition.getConditionType() != null && 
rootCondition.getConditionType().getMetadata().getTags().contains(tagId)) {
             return rootCondition;
         } else {
             return null;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/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 d280f9a..65553fb 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
@@ -103,32 +103,6 @@ public class GoalsServiceImpl implements GoalsService, 
SynchronousBundleListener
     }
 
     private void processBundleStop(BundleContext bundleContext) {
-        if (bundleContext == null) {
-            return;
-        }
-        List<PluginType> types = 
definitionsService.getTypesByPlugin().get(bundleContext.getBundle().getBundleId());
-        List<String> removedConditions = new ArrayList<String>();
-        if (types != null) {
-            for (PluginType type : types) {
-                if (type instanceof ConditionType) {
-                    removedConditions.add(((ConditionType) type).getId());
-                }
-            }
-        }
-        if (!removedConditions.isEmpty()) {
-            for (Goal goal : persistenceService.getAllItems(Goal.class)) {
-                List<String> conditions = 
ParserHelper.getConditionTypeIds(goal.getTargetEvent());
-                if (goal.getStartEvent() != null) {
-                    
conditions.addAll(ParserHelper.getConditionTypeIds(goal.getStartEvent()));
-                }
-
-                if (!Collections.disjoint(conditions, removedConditions)) {
-                    logger.info("Disable goal " + goal.getItemId());
-                    goal.getMetadata().setEnabled(false);
-                    setGoal(goal);
-                }
-            }
-        }
     }
 
     private void loadPredefinedGoals(BundleContext bundleContext) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/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 aa25111..722c55c 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
@@ -118,29 +118,6 @@ public class RulesServiceImpl implements RulesService, 
EventListenerService, Syn
         }
         loadPredefinedRules(bundleContext);
 
-        List<PluginType> types = 
definitionsService.getTypesByPlugin().get(bundleContext.getBundle().getBundleId());
-        List<String> addedConditions = new ArrayList<String>();
-        List<String> addedActions = new ArrayList<String>();
-        if (types != null) {
-            for (PluginType type : types) {
-                if (type instanceof ConditionType) {
-                    addedConditions.add(((ConditionType) type).getId());
-                } else if (type instanceof ActionType) {
-                    addedActions.add(((ActionType) type).getId());
-                }
-            }
-        }
-        if (!addedConditions.isEmpty() || !addedActions.isEmpty()) {
-            for (Rule rule : persistenceService.query("missingPlugins", 
"true", null, Rule.class)) {
-                boolean succeed = 
ParserHelper.resolveConditionType(definitionsService, rule.getCondition()) &&
-                        ParserHelper.resolveActionTypes(definitionsService, 
rule.getActions());
-                if (succeed) {
-                    logger.info("Enable rule " + rule.getItemId());
-                    rule.getMetadata().setMissingPlugins(false);
-                    setRule(rule);
-                }
-            }
-        }
         if (bundleContext.getBundle().getRegisteredServices() != null) {
             for (ServiceReference<?> reference : 
bundleContext.getBundle().getRegisteredServices()) {
                 Object service = bundleContext.getService(reference);
@@ -155,32 +132,6 @@ public class RulesServiceImpl implements RulesService, 
EventListenerService, Syn
         if (bundleContext == null) {
             return;
         }
-        List<PluginType> types = 
definitionsService.getTypesByPlugin().get(bundleContext.getBundle().getBundleId());
-        List<String> removedConditions = new ArrayList<String>();
-        List<String> removedActions = new ArrayList<String>();
-        if (types != null) {
-            for (PluginType type : types) {
-                if (type instanceof ConditionType) {
-                    removedConditions.add(((ConditionType) type).getId());
-                } else if (type instanceof ActionType) {
-                    removedActions.add(((ActionType) type).getId());
-                }
-            }
-        }
-        if (!removedConditions.isEmpty() || !removedActions.isEmpty()) {
-            for (Rule rule : persistenceService.getAllItems(Rule.class)) {
-                List<String> conditions = 
ParserHelper.getConditionTypeIds(rule.getCondition());
-                List<String> actions = new ArrayList<String>();
-                for (Action action : rule.getActions()) {
-                    actions.add(action.getActionTypeId());
-                }
-                if (!Collections.disjoint(conditions, removedConditions) || 
!Collections.disjoint(actions, removedActions)) {
-                    logger.info("Disable rule " + rule.getItemId());
-                    rule.getMetadata().setMissingPlugins(true);
-                    setRule(rule);
-                }
-            }
-        }
         
actionExecutorDispatcher.removeExecutors(bundleContext.getBundle().getBundleId());
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
 
b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
index e74995b..4efbec4 100644
--- 
a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
+++ 
b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
@@ -148,51 +148,12 @@ public class SegmentServiceImpl implements 
SegmentService, SynchronousBundleList
         }
         loadPredefinedSegments(bundleContext);
         loadPredefinedScorings(bundleContext);
-
-        List<PluginType> types = 
definitionsService.getTypesByPlugin().get(bundleContext.getBundle().getBundleId());
-        List<String> addedConditions = new ArrayList<String>();
-        if (types != null) {
-            for (PluginType type : types) {
-                if (type instanceof ConditionType) {
-                    addedConditions.add(((ConditionType) type).getId());
-                }
-            }
-        }
-        if (!addedConditions.isEmpty()) {
-            for (Segment segment : persistenceService.query("missingPlugins", 
"true", null, Segment.class)) {
-                boolean succeed = 
ParserHelper.resolveConditionType(definitionsService, segment.getCondition());
-                if (succeed) {
-                    logger.info("Enable segment " + segment.getItemId());
-                    segment.getMetadata().setMissingPlugins(false);
-                    setSegmentDefinition(segment);
-                }
-            }
-        }
     }
 
     private void processBundleStop(BundleContext bundleContext) {
         if (bundleContext == null) {
             return;
         }
-        List<PluginType> types = 
definitionsService.getTypesByPlugin().get(bundleContext.getBundle().getBundleId());
-        List<String> removedConditions = new ArrayList<String>();
-        if (types != null) {
-            for (PluginType type : types) {
-                if (type instanceof ConditionType) {
-                    removedConditions.add(((ConditionType) type).getId());
-                }
-            }
-        }
-        if (!removedConditions.isEmpty()) {
-            for (Segment segment : 
persistenceService.getAllItems(Segment.class)) {
-                List<String> conditions = 
ParserHelper.getConditionTypeIds(segment.getCondition());
-                if (!Collections.disjoint(conditions, removedConditions)) {
-                    logger.info("Disable segment " + segment.getItemId());
-                    segment.getMetadata().setMissingPlugins(true);
-                    setSegmentDefinition(segment);
-                }
-            }
-        }
     }
 
     private void loadPredefinedSegments(BundleContext bundleContext) {
@@ -563,7 +524,8 @@ public class SegmentServiceImpl implements SegmentService, 
SynchronousBundleList
     }
 
     private void getAutoGeneratedRules(Metadata metadata, Condition condition, 
Condition parentCondition, List<Rule> rules) {
-        if 
(condition.getConditionType().getTagIDs().contains("eventCondition") && 
!condition.getConditionType().getTagIDs().contains("profileCondition")) {
+        Set<String> tags = 
condition.getConditionType().getMetadata().getTags();
+        if (tags.contains("eventCondition") && 
!tags.contains("profileCondition")) {
             try {
                 Map<String,Object> m = new HashMap<>(3);
                 m.put("scope",metadata.getScope());

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ad73b222/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml 
b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 2af329c..ef28738 100644
--- a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -40,6 +40,7 @@
 
     <bean id="definitionsServiceImpl" 
class="org.apache.unomi.services.services.DefinitionsServiceImpl"
           init-method="postConstruct" destroy-method="preDestroy">
+        <property name="persistenceService" ref="persistenceService"/>
         <property name="bundleContext" ref="blueprintBundleContext"/>
     </bean>
     <service id="definitionsService" ref="definitionsServiceImpl" 
auto-export="interfaces"/>


Reply via email to