You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dr...@apache.org on 2016/02/05 13:12:25 UTC

[1/4] incubator-unomi git commit: UNOMI-16 : Fixed elasticsearch startup, register mapping in starting event

Repository: incubator-unomi
Updated Branches:
  refs/heads/master 27b945978 -> 194c73ee2


UNOMI-16 : Fixed elasticsearch startup, register mapping in starting event


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

Branch: refs/heads/master
Commit: 194c73ee2cad0dee80c8658b9d65f493a772c8e8
Parents: 815ab75
Author: Thomas Draier <dr...@apache.org>
Authored: Fri Feb 5 11:22:07 2016 +0100
Committer: Thomas Draier <dr...@apache.org>
Committed: Fri Feb 5 11:32:20 2016 +0100

----------------------------------------------------------------------
 .../elasticsearch/ElasticSearchPersistenceServiceImpl.java       | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/194c73ee/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 042f5c1..a743237 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -342,7 +342,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
     @Override
     public void bundleChanged(BundleEvent event) {
         switch (event.getType()) {
-            case BundleEvent.STARTING:
+            case BundleEvent.STARTED:
                 if (event.getBundle() != null && event.getBundle().getRegisteredServices() != null) {
                     for (ServiceReference<?> reference : event.getBundle().getRegisteredServices()) {
                         Object service = bundleContext.getService(reference);
@@ -354,6 +354,8 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
                         }
                     }
                 }
+                break;
+            case BundleEvent.STARTING:
                 loadPredefinedMappings(event.getBundle().getBundleContext(), true);
                 break;
             case BundleEvent.STOPPING:


[4/4] incubator-unomi git commit: UNOMI-14 : Store merge information in system property . Switch profile id when user already has login information

Posted by dr...@apache.org.
UNOMI-14 : Store merge information in system property . Switch profile id when user already has login information


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

Branch: refs/heads/master
Commit: 8f4c6d0110b8fc726f3eee1c37f88945e0520bcb
Parents: 27b9459
Author: Thomas Draier <dr...@apache.org>
Authored: Tue Feb 2 17:06:35 2016 +0100
Committer: Thomas Draier <dr...@apache.org>
Committed: Fri Feb 5 11:32:20 2016 +0100

----------------------------------------------------------------------
 .../actions/MergeProfilesOnPropertyAction.java  | 157 ++++++++++++-------
 .../resources/META-INF/cxs/rules/login.json     |   9 +-
 .../META-INF/cxs/rules/newSession.json          |  24 ---
 .../META-INF/cxs/rules/sessionAssigned.json     |  59 +++++++
 .../services/services/RulesServiceImpl.java     |   6 +-
 5 files changed, 165 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8f4c6d01/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
index 9a7c979..64ca3e9 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
@@ -38,6 +38,7 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
 import java.util.List;
+import java.util.UUID;
 
 public class MergeProfilesOnPropertyAction implements ActionExecutor {
 
@@ -93,26 +94,31 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
 
     public int execute(Action action, Event event) {
 
-        final Profile profile = event.getProfile();
+        Profile profile = event.getProfile();
+        if (profile instanceof Persona) {
+            return EventService.NO_CHANGE;
+        }
 
         final String mergeProfilePropertyName = (String) action.getParameterValues().get("mergeProfilePropertyName");
-        final String mergeProfilePropertyValue = profile.getProperty(mergeProfilePropertyName) != null ? profile.getProperty(mergeProfilePropertyName).toString() : "";
-        final Session currentSession = event.getSession();
-
-        // store the profile id in case the merge change it to a previous one
-
-        if (profile instanceof Persona) {
+        if (StringUtils.isEmpty(mergeProfilePropertyName)) {
             return EventService.NO_CHANGE;
         }
 
+        final String mergeProfilePropertyValue = (String) action.getParameterValues().get("mergeProfilePropertyValue");
         if (StringUtils.isEmpty(mergeProfilePropertyValue)) {
             return EventService.NO_CHANGE;
         }
+
+        final String mergeProfilePreviousPropertyValue = profile.getSystemProperties().get(mergeProfilePropertyName) != null ? profile.getSystemProperties().get(mergeProfilePropertyName).toString() : "";
+
+        final Session currentSession = event.getSession();
+
+        // store the profile id in case the merge change it to a previous one
         String profileId = profile.getItemId();
 
         Condition propertyCondition = new Condition(definitionsService.getConditionType("eventPropertyCondition"));
         propertyCondition.setParameter("comparisonOperator", "equals");
-        propertyCondition.setParameter("propertyName", mergeProfilePropertyName);
+        propertyCondition.setParameter("propertyName", "systemProperties." + mergeProfilePropertyName);
         propertyCondition.setParameter("propertyValue", mergeProfilePropertyValue);
 
         Condition excludeMergedProfilesCondition = new Condition(definitionsService.getConditionType("eventPropertyCondition"));
@@ -125,66 +131,101 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
 
         final List<Profile> profiles = persistenceService.query(c, "properties.firstVisit", Profile.class);
 
-        // add current Profile to profiles to be merged
-        boolean add = true;
-        for (Profile p : profiles) {
-            add = add && !StringUtils.equals(p.getItemId(), profile.getItemId());
-        }
-        if (add) {
-            profiles.add(profile);
-        }
+        // Check if the user switched to another profile
+        if (!StringUtils.isEmpty(mergeProfilePreviousPropertyValue) && !mergeProfilePreviousPropertyValue.equals(mergeProfilePropertyValue)) {
+            if (profiles.size() > 0) {
+                // Take existing profile
+                profile = profiles.get(0);
+            } else {
+                // Create a new profile
+                profile = new Profile(UUID.randomUUID().toString());
+                profile.setProperty("firstVisit", currentSession.getTimeStamp());
+                profile.getSystemProperties().put(mergeProfilePropertyName, mergeProfilePropertyValue);
+            }
 
-        if (profiles.size() == 1) {
-            return EventService.NO_CHANGE;
-        }
+            logger.info("Different users, switch to " + profile.getItemId());
 
-        Profile masterProfile = profileService.mergeProfiles(profiles.get(0), profiles);
-
-        if (!masterProfile.getItemId().equals(profileId)) {
             HttpServletResponse httpServletResponse = (HttpServletResponse) event.getAttributes().get(Event.HTTP_RESPONSE_ATTRIBUTE);
-            sendProfileCookie(event.getSession().getProfile(), httpServletResponse);
-            final String masterProfileId = masterProfile.getItemId();
+            sendProfileCookie(profile, httpServletResponse);
 
             // At the end of the merge, we must set the merged profile as profile event to process other Actions
-            event.setProfileId(masterProfileId);
-            event.setProfile(masterProfile);
-
-            event.getActionPostExecutors().add(new ActionPostExecutor() {
-                @Override
-                public boolean execute() {
-                    try {
-                        for (Profile profile : profiles) {
-                            String profileId = profile.getItemId();
-                            if (!StringUtils.equals(profileId, masterProfileId)) {
-                                List<Session> sessions = persistenceService.query("profileId", profileId, null, Session.class);
-                                if (currentSession.getProfileId().equals(profileId) && !sessions.contains(currentSession)) {
-                                    sessions.add(currentSession);
-                                }
-                                for (Session session : sessions) {
-                                    persistenceService.update(session.getItemId(), session.getTimeStamp(), Session.class, "profileId", masterProfileId);
+            event.setProfileId(profile.getItemId());
+            event.setProfile(profile);
+
+            event.getSession().setProfile(profile);
+
+            eventService.send(new Event("sessionReassigned", event.getSession(), profile, event.getScope(), event, event.getSession(), event.getTimeStamp()));
+
+            return EventService.PROFILE_UPDATED + EventService.SESSION_UPDATED;
+        } else {
+            // Store the merge property identifier in the profile
+            profile.getSystemProperties().put(mergeProfilePropertyName, mergeProfilePropertyValue);
+
+            // add current Profile to profiles to be merged
+            boolean add = true;
+            for (Profile p : profiles) {
+                add = add && !StringUtils.equals(p.getItemId(), profile.getItemId());
+            }
+            if (add) {
+                profiles.add(profile);
+            }
+
+            if (profiles.size() == 1) {
+                return StringUtils.isEmpty(mergeProfilePreviousPropertyValue) ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;
+            }
+
+            // Use oldest profile for master profile
+            Profile masterProfile = profileService.mergeProfiles(profiles.get(0), profiles);
+
+            // Profile has changed
+            if (!masterProfile.getItemId().equals(profileId)) {
+                HttpServletResponse httpServletResponse = (HttpServletResponse) event.getAttributes().get(Event.HTTP_RESPONSE_ATTRIBUTE);
+                sendProfileCookie(event.getSession().getProfile(), httpServletResponse);
+                final String masterProfileId = masterProfile.getItemId();
+
+                // At the end of the merge, we must set the merged profile as profile event to process other Actions
+                event.setProfileId(masterProfileId);
+                event.setProfile(masterProfile);
+
+                event.getSession().setProfile(masterProfile);
+
+                event.getActionPostExecutors().add(new ActionPostExecutor() {
+                    @Override
+                    public boolean execute() {
+                        try {
+                            for (Profile profile : profiles) {
+                                String profileId = profile.getItemId();
+                                if (!StringUtils.equals(profileId, masterProfileId)) {
+                                    List<Session> sessions = persistenceService.query("profileId", profileId, null, Session.class);
+                                    if (currentSession.getProfileId().equals(profileId) && !sessions.contains(currentSession)) {
+                                        sessions.add(currentSession);
+                                    }
+                                    for (Session session : sessions) {
+                                        persistenceService.update(session.getItemId(), session.getTimeStamp(), Session.class, "profileId", masterProfileId);
+                                    }
+
+                                    List<Event> events = persistenceService.query("profileId", profileId, null, Event.class);
+                                    for (Event event : events) {
+                                        persistenceService.update(event.getItemId(), event.getTimeStamp(), Event.class, "profileId", masterProfileId);
+                                    }
+                                    // we must mark all the profiles that we merged into the master as merged with the master, and they will
+                                    // be deleted upon next load
+                                    profile.setMergedWith(masterProfileId);
+                                    persistenceService.update(profile.getItemId(), null, Profile.class, "mergedWith", masterProfileId);
                                 }
-
-                                List<Event> events = persistenceService.query("profileId", profileId, null, Event.class);
-                                for (Event event : events) {
-                                    persistenceService.update(event.getItemId(), event.getTimeStamp(), Event.class, "profileId", masterProfileId);
-                                }
-                                // we must mark all the profiles that we merged into the master as merged with the master, and they will
-                                // be deleted upon next load
-                                profile.setMergedWith(masterProfileId);
-                                persistenceService.update(profile.getItemId(), null, Profile.class, "mergedWith", masterProfileId);
                             }
+                        } catch (Exception e) {
+                            logger.error("unable to execute callback action, profile and session will not be saved", e);
+                            return false;
                         }
-                    } catch (Exception e) {
-                        logger.error("unable to execute callback action, profile and session will not be saved", e);
-                        return false;
+                        return true;
                     }
-                    return true;
-                }
-            });
-            return EventService.PROFILE_UPDATED;
+                });
+                return EventService.PROFILE_UPDATED + EventService.SESSION_UPDATED;
+            } else {
+                return StringUtils.isEmpty(mergeProfilePreviousPropertyValue) ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;
+            }
         }
-
-        return EventService.NO_CHANGE;
     }
 
     public void sendProfileCookie(Profile profile, ServletResponse response) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8f4c6d01/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/login.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/login.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/login.json
index 6ef3caa..de61572 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/login.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/login.json
@@ -21,15 +21,16 @@
     "actions": [
         {
             "parameterValues": {
-
+                "mergeProfilePropertyValue": "eventProperty::target.properties(j:nodename)",
+                "mergeProfilePropertyName": "mergeIdentifier"
             },
-            "type": "allEventToProfilePropertiesAction"
+            "type": "mergeProfilesOnPropertyAction"
         },
         {
             "parameterValues": {
-                "mergeProfilePropertyName": "j:nodename"
+
             },
-            "type": "mergeProfilesOnPropertyAction"
+            "type": "allEventToProfilePropertiesAction"
         }
     ]
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8f4c6d01/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/newSession.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/newSession.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/newSession.json
index 12bf580..6eca16e 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/newSession.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/newSession.json
@@ -24,30 +24,6 @@
                 "requestHeaderName": "User-Agent",
                 "sessionPropertyName": "userAgent"
             }
-        },
-        {
-            "parameterValues": {
-                "setPropertyName": "properties.previousVisit",
-                "setPropertyValue": "profileProperty::lastVisit",
-                "storeInSession": false
-            },
-            "type": "setPropertyAction"
-        },
-        {
-            "parameterValues": {
-                "setPropertyName": "properties.lastVisit",
-                "setPropertyValue": "now",
-                "storeInSession": false
-            },
-            "type": "setPropertyAction"
-        },
-        {
-            "parameterValues": {
-                "setPropertyName": "properties.nbOfVisits",
-                "setPropertyValue": "script::profile.properties.?nbOfVisits != null ? (profile.properties.nbOfVisits + 1) : 1",
-                "storeInSession": false
-            },
-            "type": "setPropertyAction"
         }
     ]
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8f4c6d01/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/sessionAssigned.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/sessionAssigned.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/sessionAssigned.json
new file mode 100644
index 0000000..9603b81
--- /dev/null
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/sessionAssigned.json
@@ -0,0 +1,59 @@
+{
+  "metadata": {
+    "id": "_ajhg9u2s5_sessionAssigned",
+    "name": "Session assigned to a profile",
+    "description": "Update profile visit information",
+    "readOnly":true
+  },
+
+  "condition": {
+    "type": "booleanCondition",
+    "parameterValues": {
+      "subConditions":[
+        {
+          "type": "eventTypeCondition",
+          "parameterValues": {
+            "eventTypeId": "sessionCreated"
+          }
+        },
+        {
+          "type": "eventTypeCondition",
+          "parameterValues": {
+            "eventTypeId": "sessionReassigned"
+          }
+        }
+
+        ],
+      "operator":"or"
+
+    }
+  },
+
+  "actions": [
+    {
+      "parameterValues": {
+        "setPropertyName": "properties.previousVisit",
+        "setPropertyValue": "profileProperty::lastVisit",
+        "storeInSession": false
+      },
+      "type": "setPropertyAction"
+    },
+    {
+      "parameterValues": {
+        "setPropertyName": "properties.lastVisit",
+        "setPropertyValue": "now",
+        "storeInSession": false
+      },
+      "type": "setPropertyAction"
+    },
+    {
+      "parameterValues": {
+        "setPropertyName": "properties.nbOfVisits",
+        "setPropertyValue": "script::profile.properties.?nbOfVisits != null ? (profile.properties.nbOfVisits + 1) : 1",
+        "storeInSession": false
+      },
+      "type": "setPropertyAction"
+    }
+  ]
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8f4c6d01/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 09cd0ec..aa25111 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
@@ -192,16 +192,14 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
 
         while (predefinedRuleEntries.hasMoreElements()) {
             URL predefinedSegmentURL = predefinedRuleEntries.nextElement();
-            logger.debug("Found predefined segment at " + predefinedSegmentURL + ", loading... ");
+            logger.debug("Found predefined rule at " + predefinedSegmentURL + ", loading... ");
 
             try {
                 Rule rule = CustomObjectMapper.getObjectMapper().readValue(predefinedSegmentURL, Rule.class);
                 if (rule.getMetadata().getScope() == null) {
                     rule.getMetadata().setScope("systemscope");
                 }
-                if (getRule(rule.getMetadata().getId()) == null) {
-                    setRule(rule);
-                }
+                setRule(rule);
             } catch (IOException e) {
                 logger.error("Error while loading segment definition " + predefinedSegmentURL, e);
             }


[2/4] incubator-unomi git commit: UNOMI-15 : Use token to authenticate third party servers

Posted by dr...@apache.org.
UNOMI-15 : Use token to authenticate third party servers


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

Branch: refs/heads/master
Commit: c9f2471561362f09c08dea91ae9578a25bebbc19
Parents: 8f4c6d0
Author: Thomas Draier <dr...@apache.org>
Authored: Wed Feb 3 14:32:19 2016 +0100
Committer: Thomas Draier <dr...@apache.org>
Committed: Fri Feb 5 11:32:20 2016 +0100

----------------------------------------------------------------------
 .../apache/unomi/api/services/EventService.java | 14 ++++
 kar/src/main/feature/feature.xml                |  1 +
 services/pom.xml                                |  7 ++
 .../services/services/EventServiceImpl.java     | 71 ++++++++++++++++++--
 .../services/services/ThirdPartyServer.java     | 67 ++++++++++++++++++
 .../resources/OSGI-INF/blueprint/blueprint.xml  | 14 +++-
 .../resources/org.apache.unomi.thirdparty.cfg   | 20 ++++++
 .../org/apache/unomi/web/ContextServlet.java    | 24 +++++--
 .../unomi/web/EventsCollectorServlet.java       | 13 ++--
 .../resources/OSGI-INF/blueprint/blueprint.xml  |  1 +
 10 files changed, 213 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/api/src/main/java/org/apache/unomi/api/services/EventService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/services/EventService.java b/api/src/main/java/org/apache/unomi/api/services/EventService.java
index fe81130..5e74e83 100644
--- a/api/src/main/java/org/apache/unomi/api/services/EventService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/EventService.java
@@ -56,6 +56,20 @@ public interface EventService {
     int send(Event event);
 
     /**
+     * Check if the sender is allowed to sent the speecified event. Restricted event must be explicitely allowed for a sender.
+     * @param event
+     * @param thirdPartyId
+     * @return
+     */
+    boolean isEventAllowed(Event event, String thirdPartyId);
+
+    /**
+     * Get the third party server name, if the request is originated from a known peer
+     * @return
+     */
+    String authenticateThirdPartyServer(String key, String ip);
+
+    /**
      * Retrieves the list of available event properties.
      *
      * @return a list of available event properties

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/kar/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/kar/src/main/feature/feature.xml b/kar/src/main/feature/feature.xml
index 72e3e7f..5e63b8b 100644
--- a/kar/src/main/feature/feature.xml
+++ b/kar/src/main/feature/feature.xml
@@ -27,6 +27,7 @@
         <configfile finalname="/etc/org.apache.unomi.persistence.elasticsearch.cfg">mvn:org.apache.unomi/unomi-persistence-elasticsearch-core/${project.version}/cfg/elasticsearchcfg</configfile>
         <configfile finalname="/etc/org.apache.unomi.plugins.request.cfg">mvn:org.apache.unomi/unomi-plugins-request/${project.version}/cfg/requestcfg</configfile>
         <configfile finalname="/etc/org.apache.unomi.services.cfg">mvn:org.apache.unomi/unomi-services/${project.version}/cfg/servicescfg</configfile>
+        <configfile finalname="/etc/org.apache.unomi.thirdparty.cfg">mvn:org.apache.unomi/unomi-services/${project.version}/cfg/thirdpartycfg</configfile>
         <configfile finalname="/etc/org.apache.unomi.geonames.cfg">mvn:org.apache.unomi/cxs-geonames-services/${project.version}/cfg/geonamescfg</configfile>
         <configfile finalname="/etc/elasticsearch.yml">mvn:org.apache.unomi/unomi-persistence-elasticsearch-core/${project.version}/yml/elasticsearchconfig</configfile>
         <bundle start-level="75">mvn:commons-io/commons-io/2.4</bundle>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/services/pom.xml
----------------------------------------------------------------------
diff --git a/services/pom.xml b/services/pom.xml
index ea3efce..03fd7b7 100644
--- a/services/pom.xml
+++ b/services/pom.xml
@@ -174,6 +174,13 @@
                                     <type>cfg</type>
                                     <classifier>servicescfg</classifier>
                                 </artifact>
+                                <artifact>
+                                    <file>
+                                        src/main/resources/org.apache.unomi.thirdparty.cfg
+                                    </file>
+                                    <type>cfg</type>
+                                    <classifier>thirdpartycfg</classifier>
+                                </artifact>
                             </artifacts>
                         </configuration>
                     </execution>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
index 4b207d9..22cdcda 100644
--- a/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
@@ -24,38 +24,72 @@ import org.apache.unomi.api.conditions.Condition;
 import org.apache.unomi.api.services.DefinitionsService;
 import org.apache.unomi.api.services.EventListenerService;
 import org.apache.unomi.api.services.EventService;
-import org.apache.unomi.api.services.ProfileService;
 import org.apache.unomi.persistence.spi.PersistenceService;
 import org.apache.unomi.persistence.spi.aggregate.TermsAggregate;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.*;
 
 public class EventServiceImpl implements EventService {
+    private static final Logger logger = LoggerFactory.getLogger(SegmentServiceImpl.class.getName());
 
     private List<EventListenerService> eventListeners = new ArrayList<EventListenerService>();
 
     private PersistenceService persistenceService;
 
-    private ProfileService profileService;
-
     private DefinitionsService definitionsService;
 
     private BundleContext bundleContext;
 
     private Set<String> predefinedEventTypeIds = new LinkedHashSet<String>();
 
+    private Set<String> restrictedEventTypeIds = new LinkedHashSet<String>();
+
+    private Map<String, ThirdPartyServer> thirdPartyServers = new HashMap<>();
+
+    public void setThirdPartyConfiguration(Map<String,String> thirdPartyConfiguration) {
+        this.thirdPartyServers = new HashMap<>();
+        for (Map.Entry<String, String> entry : thirdPartyConfiguration.entrySet()) {
+            String[] keys = StringUtils.split(entry.getKey(),'.');
+            if (keys[0].equals("thirdparty")) {
+                if (!thirdPartyServers.containsKey(keys[1])) {
+                    thirdPartyServers.put(keys[1], new ThirdPartyServer(keys[1]));
+                }
+                ThirdPartyServer thirdPartyServer = thirdPartyServers.get(keys[1]);
+                if (keys[2].equals("allowedEvents")) {
+                    thirdPartyServer.setAllowedEvents(new HashSet<>(Arrays.asList(StringUtils.split(entry.getValue(), ','))));
+                } else if (keys[2].equals("key")) {
+                    thirdPartyServer.setKey(entry.getValue());
+                } else if (keys[2].equals("ipAddresses")) {
+                    Set<InetAddress> inetAddresses = new HashSet<>();
+                    for (String ip : StringUtils.split(entry.getValue(), ',')) {
+                        try {
+                            inetAddresses.add(InetAddress.getByName(ip));
+                        } catch (UnknownHostException e) {
+                            logger.error("Cannot resolve address",e);
+                        }
+                    }
+                    thirdPartyServer.setIpAddresses(inetAddresses);
+                }
+            }
+        }
+    }
+
     public void setPredefinedEventTypeIds(Set<String> predefinedEventTypeIds) {
         this.predefinedEventTypeIds = predefinedEventTypeIds;
     }
 
-    public void setPersistenceService(PersistenceService persistenceService) {
-        this.persistenceService = persistenceService;
+    public void setRestrictedEventTypeIds(Set<String> restrictedEventTypeIds) {
+        this.restrictedEventTypeIds = restrictedEventTypeIds;
     }
 
-    public void setProfileService(ProfileService profileService) {
-        this.profileService = profileService;
+    public void setPersistenceService(PersistenceService persistenceService) {
+        this.persistenceService = persistenceService;
     }
 
     public void setDefinitionsService(DefinitionsService definitionsService) {
@@ -66,6 +100,29 @@ public class EventServiceImpl implements EventService {
         this.bundleContext = bundleContext;
     }
 
+    public boolean isEventAllowed(Event event, String thirdPartyId) {
+        if (restrictedEventTypeIds.contains(event.getEventType())) {
+            return thirdPartyServers.containsKey(thirdPartyId) && thirdPartyServers.get(thirdPartyId).getAllowedEvents().contains(event.getEventType());
+        }
+        return true;
+    }
+
+    public String authenticateThirdPartyServer(String key, String ip) {
+        if (key != null) {
+            for (Map.Entry<String, ThirdPartyServer> entry : thirdPartyServers.entrySet()) {
+                ThirdPartyServer server = entry.getValue();
+                try {
+                    if (server.getKey().equals(key) && server.getIpAddresses().contains(InetAddress.getByName(ip))) {
+                        return server.getId();
+                    }
+                } catch (UnknownHostException e) {
+                    logger.error("Cannot resolve address",e);
+                }
+            }
+        }
+        return null;
+    }
+
     public int send(Event event) {
         if (event.isPersistent()) {
             persistenceService.save(event);

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/services/src/main/java/org/apache/unomi/services/services/ThirdPartyServer.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/ThirdPartyServer.java b/services/src/main/java/org/apache/unomi/services/services/ThirdPartyServer.java
new file mode 100644
index 0000000..c4587d7
--- /dev/null
+++ b/services/src/main/java/org/apache/unomi/services/services/ThirdPartyServer.java
@@ -0,0 +1,67 @@
+/*
+ * 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.services.services;
+
+import java.net.InetAddress;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Representation of a third party server, containing key, ip address, and allowed events
+ */
+public class ThirdPartyServer {
+    private String id;
+
+    private String key;
+
+    private Set<InetAddress> ipAddresses;
+
+    private Set<String> allowedEvents = new HashSet<>();
+
+    public ThirdPartyServer(String id) {
+        this.id = id;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public Set<InetAddress> getIpAddresses() {
+        return ipAddresses;
+    }
+
+    public Set<String> getAllowedEvents() {
+        return allowedEvents;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public void setIpAddresses(Set<InetAddress> ipAddresses) {
+        this.ipAddresses = ipAddresses;
+    }
+
+    public void setAllowedEvents(Set<String> allowedEvents) {
+        this.allowedEvents = allowedEvents;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/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 7d3bc87..2af329c 100644
--- a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -46,7 +46,6 @@
 
     <bean id="eventServiceImpl" class="org.apache.unomi.services.services.EventServiceImpl">
         <property name="persistenceService" ref="persistenceService"/>
-        <property name="profileService" ref="profileServiceImpl"/>
         <property name="definitionsService" ref="definitionsServiceImpl"/>
         <property name="bundleContext" ref="blueprintBundleContext"/>
         <property name="predefinedEventTypeIds">
@@ -58,6 +57,19 @@
                 <value>profileUpdated</value>
             </set>
         </property>
+        <property name="restrictedEventTypeIds">
+            <set>
+                <value>login</value>
+                <value>facebookLogin</value>
+                <value>sessionCreated</value>
+                <value>sessionReassigned</value>
+                <value>profileUpdated</value>
+                <value>ruleFired</value>
+            </set>
+        </property>
+        <property name="thirdPartyConfiguration">
+            <cm:cm-properties persistent-id="org.apache.unomi.thirdparty" update="true" />
+        </property>
     </bean>
     <service id="eventService" ref="eventServiceImpl" auto-export="interfaces"/>
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/services/src/main/resources/org.apache.unomi.thirdparty.cfg
----------------------------------------------------------------------
diff --git a/services/src/main/resources/org.apache.unomi.thirdparty.cfg b/services/src/main/resources/org.apache.unomi.thirdparty.cfg
new file mode 100644
index 0000000..06c3278
--- /dev/null
+++ b/services/src/main/resources/org.apache.unomi.thirdparty.cfg
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+thirdparty.jahia.key=670c26d1cc413346c3b2fd9ce65dab41
+thirdparty.jahia.ipAddresses=127.0.0.1,::1
+thirdparty.jahia.allowedEvents=login,download

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
----------------------------------------------------------------------
diff --git a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
index 2e43302..5b8b333 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -23,6 +23,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.unomi.api.*;
 import org.apache.unomi.api.conditions.Condition;
 import org.apache.unomi.api.services.EventService;
+import org.apache.unomi.api.services.PrivacyService;
 import org.apache.unomi.api.services.ProfileService;
 import org.apache.unomi.api.services.RulesService;
 import org.apache.unomi.persistence.spi.CustomObjectMapper;
@@ -53,6 +54,7 @@ public class ContextServlet extends HttpServlet {
     private ProfileService profileService;
     private EventService eventService;
     private RulesService rulesService;
+    private PrivacyService privacyService;
 
     private String profileIdCookieName = "context-profile-id";
     private String profileIdCookieDomain;
@@ -253,17 +255,25 @@ public class ContextServlet extends HttpServlet {
 
     private int handleRequest(ContextRequest contextRequest, Profile profile, Session session, ContextResponse data, ServletRequest request, ServletResponse response, Date timestamp)
             throws IOException {
+        List<String> filteredEventTypes = privacyService.getFilteredEventTypes(profile.getItemId());
+
+        String thirdPartyId = eventService.authenticateThirdPartyServer(((HttpServletRequest)request).getHeader("X-Unomi-Peer"), request.getRemoteAddr());
+
         int changes = EventService.NO_CHANGE;
         // execute provided events if any
         if(contextRequest.getEvents() != null && !(profile instanceof Persona)) {
             for (Event event : contextRequest.getEvents()){
                 if(event.getEventType() != null) {
-                    Event eventToSend;
-                    if(event.getProperties() != null){
-                        eventToSend = new Event(event.getEventType(), session, profile, contextRequest.getSource().getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
-                    } else {
-                        eventToSend = new Event(event.getEventType(), session, profile, contextRequest.getSource().getScope(), event.getSource(), event.getTarget(), timestamp);
+                    Event eventToSend = new Event(event.getEventType(), session, profile, contextRequest.getSource().getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
+                    if (!eventService.isEventAllowed(event, thirdPartyId)) {
+                        logger.debug("Event is not allowed : {}", event.getEventType());
+                        continue;
+                    }
+                    if (filteredEventTypes != null && filteredEventTypes.contains(event.getEventType())) {
+                        logger.debug("Profile is filtering event type {}", event.getEventType());
+                        continue;
                     }
+
                     event.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
                     event.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);
                     logger.debug("Received event " + event.getEventType() + " for profile=" + profile.getItemId() + " session=" + session.getItemId() + " target=" + event.getTarget() + " timestamp=" + timestamp);
@@ -365,4 +375,8 @@ public class ContextServlet extends HttpServlet {
     public void setProfileIdCookieDomain(String profileIdCookieDomain) {
         this.profileIdCookieDomain = profileIdCookieDomain;
     }
+
+    public void setPrivacyService(PrivacyService privacyService) {
+        this.privacyService = privacyService;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
----------------------------------------------------------------------
diff --git a/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java b/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
index c34ead2..24aa727 100644
--- a/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
@@ -35,6 +35,7 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 public class EventsCollectorServlet extends HttpServlet {
     private static final Logger logger = LoggerFactory.getLogger(EventsCollectorServlet.class.getName());
@@ -130,16 +131,16 @@ public class EventsCollectorServlet extends HttpServlet {
             return;
         }
 
+        String thirdPartyId = eventService.authenticateThirdPartyServer(((HttpServletRequest)request).getHeader("X-Unomi-Peer"), request.getRemoteAddr());
+
         int changes = 0;
         for (Event event : events.getEvents()){
             if(event.getEventType() != null){
-                Event eventToSend;
-                if(event.getProperties() != null){
-                    eventToSend = new Event(event.getEventType(), session, profile, event.getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
-                } else {
-                    eventToSend = new Event(event.getEventType(), session, profile, event.getScope(), event.getSource(), event.getTarget(), timestamp);
+                Event eventToSend = new Event(event.getEventType(), session, profile, event.getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
+                if (!eventService.isEventAllowed(event, thirdPartyId)) {
+                    logger.debug("Event is not allowed : {}", event.getEventType());
+                    continue;
                 }
-
                 if (filteredEventTypes != null && filteredEventTypes.contains(event.getEventType())) {
                     logger.debug("Profile is filtering event type {}", event.getEventType());
                     continue;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c9f24715/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index eab2e9a..6103121 100644
--- a/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -38,6 +38,7 @@
         <property name="profileService" ref="profileService"/>
         <property name="eventService" ref="eventService"/>
         <property name="rulesService" ref="rulesService"/>
+        <property name="privacyService" ref="privacyService" />
         <property name="profileIdCookieDomain" value="${web.contextserver.domain}" />
     </bean>
 


[3/4] incubator-unomi git commit: UNOMI-16 : added elasticsearch mappings

Posted by dr...@apache.org.
UNOMI-16 : added elasticsearch mappings


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

Branch: refs/heads/master
Commit: 815ab75000d54655db0193f83f100c757ee4e046
Parents: c9f2471
Author: Thomas Draier <dr...@apache.org>
Authored: Wed Feb 3 18:34:34 2016 +0100
Committer: Thomas Draier <dr...@apache.org>
Committed: Fri Feb 5 11:32:20 2016 +0100

----------------------------------------------------------------------
 .../ElasticSearchPersistenceServiceImpl.java    |   8 +-
 .../META-INF/cxs/mappings/campaign.json         |  71 ++++++++++-
 .../META-INF/cxs/mappings/campaignevent.json    |  63 +++++++++-
 .../resources/META-INF/cxs/mappings/event.json  |  62 +++++++---
 .../resources/META-INF/cxs/mappings/goal.json   |  76 ++++++++++--
 .../META-INF/cxs/mappings/persona.json          |  28 ++---
 .../META-INF/cxs/mappings/personaSession.json   |  52 ++++----
 .../META-INF/cxs/mappings/profile.json          |  52 +++++---
 .../META-INF/cxs/mappings/propertyType.json     | 123 +++++++++++++++++--
 .../resources/META-INF/cxs/mappings/rule.json   |  79 +++++++++---
 .../META-INF/cxs/mappings/segment.json          |  70 ++++++++---
 .../META-INF/cxs/mappings/session.json          |  79 ++++++++----
 12 files changed, 602 insertions(+), 161 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 8d6c5fb..042f5c1 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -342,7 +342,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
     @Override
     public void bundleChanged(BundleEvent event) {
         switch (event.getType()) {
-            case BundleEvent.STARTED:
+            case BundleEvent.STARTING:
                 if (event.getBundle() != null && event.getBundle().getRegisteredServices() != null) {
                     for (ServiceReference<?> reference : event.getBundle().getRegisteredServices()) {
                         Object service = bundleContext.getService(reference);
@@ -414,13 +414,15 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
                     if (itemsMonthlyIndexed.contains(name)) {
                         createMapping(name, content.toString(), indexName + "-*");
                     } else if (indexNames.containsKey(name)) {
-                        createMapping(name, content.toString(), indexNames.get(name));
+                        if (client.admin().indices().prepareExists(indexNames.get(name)).execute().actionGet().isExists()) {
+                            createMapping(name, content.toString(), indexNames.get(name));
+                        }
                     } else {
                         createMapping(name, content.toString(), indexName);
                     }
                 }
             } catch (Exception e) {
-                logger.error("Error while loading segment definition " + predefinedMappingURL, e);
+                logger.error("Error while loading mapping definition " + predefinedMappingURL, e);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaign.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaign.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaign.json
index 2ddac89..c469be8 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaign.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaign.json
@@ -11,6 +11,75 @@
           }
         }
       }
-    ]
+    ],
+    "properties": {
+      "cost": {
+        "type": "double"
+      },
+      "currency": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "startDate": {
+        "type": "date",
+        "format": "dateOptionalTime"
+      },
+      "endDate": {
+        "type": "date",
+        "format": "dateOptionalTime"
+      },
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "primaryGoal": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "timezone": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
+        "properties": {
+          "description": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          },
+          "scope": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "tags": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    }
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaignevent.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaignevent.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaignevent.json
index 3c24541..e9ce4d3 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaignevent.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/campaignevent.json
@@ -11,6 +11,67 @@
           }
         }
       }
-    ]
+    ],
+    "properties": {
+      "campaignId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "cost": {
+        "type": "double"
+      },
+      "currency": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "eventDate": {
+        "type": "date",
+        "format": "dateOptionalTime"
+      },
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "timezone": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
+        "properties": {
+          "description": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          },
+          "scope": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    }
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/event.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/event.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/event.json
index 73af986..abe1dbc 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/event.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/event.json
@@ -1,21 +1,47 @@
 {
-    "event": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ],
-        "properties": {
-            "timeStamp": {
-                "type": "date"
-            }
+  "event": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
         }
+      }
+    ],
+    "properties": {
+      "eventType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "profileId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "scope": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "sessionId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "timeStamp": {
+        "type": "date",
+        "format": "dateOptionalTime"
+      }
     }
-}
\ No newline at end of file
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/goal.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/goal.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/goal.json
index d8bd37e..0fb7bcf 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/goal.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/goal.json
@@ -1,16 +1,66 @@
 {
-    "goal": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ]
+  "goal": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ],
+    "properties": {
+      "campaignId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
+        "properties": {
+          "description": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          },
+          "scope": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "tags": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
     }
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/persona.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/persona.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/persona.json
index 8c6ef0d..d04715f 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/persona.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/persona.json
@@ -1,16 +1,16 @@
 {
-    "persona": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ]
-    }
+  "persona": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ]
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/personaSession.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/personaSession.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/personaSession.json
index 7c8e0f5..6ba12aa 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/personaSession.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/personaSession.json
@@ -1,31 +1,31 @@
 {
-    "personaSession": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ],
+  "personaSession": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ],
+    "properties": {
+      "timeStamp": {
+        "type": "date"
+      },
+      "lastEventDate": {
+        "type": "date"
+      },
+      "properties": {
         "properties": {
-            "timeStamp": {
-                "type": "date"
-            },
-            "lastEventDate": {
-                "type": "date"
-            },
-            "properties": {
-                "properties": {
-                    "location": {
-                        "type": "geo_point"
-                    }
-                }
-            }
+          "location": {
+            "type": "geo_point"
+          }
         }
+      }
     }
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/profile.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/profile.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/profile.json
index b6dcce0..bfd6939 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/profile.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/profile.json
@@ -1,18 +1,40 @@
 {
-    "profile": {
-        "_all" : {"enabled" : true},
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding",
-                        "include_in_all" : true
-                    }
-                }
-            }
-        ]
+  "profile": {
+    "_all": {
+      "enabled": true
+    },
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding",
+            "include_in_all": true
+          }
+        }
+      }
+    ],
+    "properties": {
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding",
+        "include_in_all": true
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding",
+        "include_in_all": true
+      },
+      "properties": {
+        "properties": {
+          "firstVisit": {
+            "type": "date",
+            "format": "dateOptionalTime"
+          }
+        }
+      }
     }
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/propertyType.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/propertyType.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/propertyType.json
index 204cbea..88a958e 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/propertyType.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/propertyType.json
@@ -1,16 +1,113 @@
 {
-    "propertyType": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ]
+  "propertyType": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ],
+    "properties": {
+      "automaticMappingsFrom": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "dateRanges": {
+        "properties": {
+          "from": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "key": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "to": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      },
+      "defaultValue": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "mergeStrategy": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
+        "properties": {
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          }
+        }
+      },
+      "multivalued": {
+        "type": "boolean"
+      },
+      "numericRanges": {
+        "properties": {
+          "from": {
+            "type": "double"
+          },
+          "key": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "to": {
+            "type": "double"
+          }
+        }
+      },
+      "protected": {
+        "type": "boolean"
+      },
+      "rank": {
+        "type": "double"
+      },
+      "tags": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "target": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "type": {
+        "type": "string",
+        "analyzer": "folding"
+      }
     }
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/rule.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/rule.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/rule.json
index eb4b599..67263cf 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/rule.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/rule.json
@@ -1,22 +1,67 @@
 {
-    "rule": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ],
+  "rule": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ],
+    "properties": {
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
         "properties": {
-            "priority": {
-                "type": "long"
-            }
+          "description": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          },
+          "scope": {
+            "type": "string",
+            "analyzer": "folding"
+          }
         }
-
+      },
+      "priority": {
+        "type": "long"
+      },
+      "raiseEventOnlyOnceForProfile": {
+        "type": "boolean"
+      },
+      "raiseEventOnlyOnceForSession": {
+        "type": "boolean"
+      }
     }
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/segment.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/segment.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/segment.json
index 718ad55..c4527a5 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/segment.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/segment.json
@@ -1,16 +1,58 @@
 {
-    "segment": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ]
+  "segment": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ],
+    "properties": {
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
+        "properties": {
+          "description": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          },
+          "scope": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
     }
-}
\ No newline at end of file
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/815ab750/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/session.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/session.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/session.json
index 8f1c722..ef808ed 100644
--- a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/session.json
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/session.json
@@ -1,31 +1,58 @@
 {
-    "session": {
-        "dynamic_templates": [
-            {
-                "all": {
-                    "match": "*",
-                    "match_mapping_type": "string",
-                    "mapping": {
-                        "type": "string",
-                        "analyzer": "folding"
-                    }
-                }
-            }
-        ],
+  "session": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ],
+    "properties": {
+      "duration": {
+        "type": "long"
+      },
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "lastEventDate": {
+        "type": "date",
+        "format": "dateOptionalTime"
+      },
+      "profileId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "properties": {
         "properties": {
-            "timeStamp": {
-                "type": "date"
-            },
-            "lastEventDate": {
-                "type": "date"
-            },
-            "properties": {
-                "properties": {
-                    "location": {
-                        "type": "geo_point"
-                    }
-                }
-            }
+          "location": {
+            "type": "geo_point"
+          }
         }
+      },
+      "scope": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "size": {
+        "type": "long"
+      },
+      "systemProperties": {
+        "type": "object"
+      },
+      "timeStamp": {
+        "type": "date",
+        "format": "dateOptionalTime"
+      }
     }
+  }
 }
\ No newline at end of file