Repository: incubator-unomi
Updated Branches:
  refs/heads/UNOMI-180-CXS-GRAPHQLAPI cbe9086b3 -> 569533dec (forced update)


UNOMI-179 Event Persistence Non-transient

Changed the persistence field to be non-transient in the Event class.
Used ESEventMixIn to prevent that value from being saved in ES.  Updated
the Event constructor to accept persistent.

This feature allows the user to pass "persistent": false with their
events if the intent is only to trigger a rule / action downstream.

If "persistent" is not set it defaults to true.


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

Branch: refs/heads/UNOMI-180-CXS-GRAPHQLAPI
Commit: a61a29317ce628f98ce2ee1d34ff25329bd844cc
Parents: 9fcfd42
Author: Donald Hinshaw <[email protected]>
Authored: Thu May 3 13:44:39 2018 -0400
Committer: Donald Hinshaw <[email protected]>
Committed: Thu May 3 13:52:47 2018 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/unomi/api/Event.java   |  6 ++--
 .../elasticsearch/ESCustomObjectMapper.java     |  2 ++
 .../persistence/elasticsearch/ESEventMixIn.java | 29 ++++++++++++++++++++
 .../org/apache/unomi/web/ContextServlet.java    |  3 +-
 .../unomi/web/EventsCollectorServlet.java       |  3 +-
 5 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a61a2931/api/src/main/java/org/apache/unomi/api/Event.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/Event.java 
b/api/src/main/java/org/apache/unomi/api/Event.java
index b20662b..845a02a 100644
--- a/api/src/main/java/org/apache/unomi/api/Event.java
+++ b/api/src/main/java/org/apache/unomi/api/Event.java
@@ -61,7 +61,7 @@ public class Event extends Item implements TimestampedItem {
     private Item source;
     private Item target;
 
-    private transient boolean persistent = true;
+    private boolean persistent = true;
 
     private transient Map<String, Object> attributes = new LinkedHashMap<>();
 
@@ -114,8 +114,9 @@ public class Event extends Item implements TimestampedItem {
      * @param timestamp  the timestamp associated with the event if provided
      * @param properties the properties for this event if any
      */
-    public Event(String eventType, Session session, Profile profile, String 
scope, Item source, Item target, Map<String, Object> properties, Date 
timestamp) {
+    public Event(String eventType, Session session, Profile profile, String 
scope, Item source, Item target, Map<String, Object> properties, Date 
timestamp, boolean persistent) {
         this(eventType, session, profile, scope, source, target, timestamp);
+        this.persistent = persistent;
         if (properties != null) {
             this.properties = properties;
         }
@@ -205,7 +206,6 @@ public class Event extends Item implements TimestampedItem {
      *
      * @return {@code true} if this Event needs to be persisted, {@code false} 
otherwise
      */
-    @XmlTransient
     public boolean isPersistent() {
         return persistent;
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a61a2931/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESCustomObjectMapper.java
----------------------------------------------------------------------
diff --git 
a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESCustomObjectMapper.java
 
b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESCustomObjectMapper.java
index 66e0e89..0048398 100644
--- 
a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESCustomObjectMapper.java
+++ 
b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESCustomObjectMapper.java
@@ -17,6 +17,7 @@
 package org.apache.unomi.persistence.elasticsearch;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.unomi.api.Event;
 import org.apache.unomi.api.Item;
 import org.apache.unomi.persistence.spi.CustomObjectMapper;
 
@@ -31,6 +32,7 @@ public class ESCustomObjectMapper extends CustomObjectMapper {
     public ESCustomObjectMapper() {
         super();
         this.addMixIn(Item.class, ESItemMixIn.class);
+        this.addMixIn(Event.class, ESEventMixIn.class);
     }
 
     public static ObjectMapper getObjectMapper() {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a61a2931/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESEventMixIn.java
----------------------------------------------------------------------
diff --git 
a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESEventMixIn.java
 
b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESEventMixIn.java
new file mode 100644
index 0000000..76fb939
--- /dev/null
+++ 
b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ESEventMixIn.java
@@ -0,0 +1,29 @@
+/*
+ * 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.persistence.elasticsearch;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+/**
+ * This mixin is used in ESCustomObjectMapper to prevent the persistent 
parameter from being registered in ES
+ */
+public abstract class ESEventMixIn {
+
+    public ESEventMixIn() { }
+
+    @JsonIgnore abstract boolean isPersistent();
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a61a2931/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 d978d70..a3ed622 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -323,7 +323,8 @@ public class ContextServlet extends HttpServlet {
             for (Event event : contextRequest.getEvents()){
                 if(event.getEventType() != null) {
                     Profile sessionProfile = session.getProfile();
-                    Event eventToSend = new Event(event.getEventType(), 
session, sessionProfile, contextRequest.getSource().getScope(), 
event.getSource(), event.getTarget(), event.getProperties(), timestamp);
+                    Event eventToSend = new Event(event.getEventType(), 
session, sessionProfile, contextRequest.getSource().getScope(),
+                            event.getSource(), event.getTarget(), 
event.getProperties(), timestamp, event.isPersistent());
                     if (!eventService.isEventAllowed(event, thirdPartyId)) {
                         logger.debug("Event is not allowed : {}", 
event.getEventType());
                         continue;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/a61a2931/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 713e1e4..2f21354 100644
--- a/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
@@ -184,7 +184,8 @@ public class EventsCollectorServlet extends HttpServlet {
 
         for (Event event : events.getEvents()){
             if(event.getEventType() != null){
-                Event eventToSend = new Event(event.getEventType(), session, 
profile, event.getScope(), event.getSource(), event.getTarget(), 
event.getProperties(), timestamp);
+                Event eventToSend = new Event(event.getEventType(), session, 
profile, event.getScope(), event.getSource(),
+                        event.getTarget(), event.getProperties(), timestamp, 
event.isPersistent());
                 if (sessionProfile.isAnonymousProfile()) {
                     // Do not keep track of profile in event
                     eventToSend.setProfileId(null);

Reply via email to