You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2020/08/20 13:16:31 UTC

[unomi] branch master updated: Use profile id session is in null to see if event has already been raised (#184)

This is an automated email from the ASF dual-hosted git repository.

shuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new 23dbf03  Use profile id session is in null to see if event has already been raised (#184)
23dbf03 is described below

commit 23dbf03ebd7889eeb80ab7ec2d369670461ad302
Author: liatiusim <62...@users.noreply.github.com>
AuthorDate: Thu Aug 20 16:14:27 2020 +0300

    Use profile id session is in null to see if event has already been raised (#184)
    
    * Use profile id if the session id is null when checking if event already raised
    
    * Add itest for checkout event existence with profile id
    
    Co-authored-by: Shir Bromberg <sb...@yotpo.com>
---
 .../test/java/org/apache/unomi/itests/AllITs.java  |  1 +
 .../org/apache/unomi/itests/EventServiceIT.java    | 68 ++++++++++++++++++++++
 .../services/impl/events/EventServiceImpl.java     |  8 ++-
 3 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/itests/src/test/java/org/apache/unomi/itests/AllITs.java b/itests/src/test/java/org/apache/unomi/itests/AllITs.java
index 7a870d9..1ae1c9d 100644
--- a/itests/src/test/java/org/apache/unomi/itests/AllITs.java
+++ b/itests/src/test/java/org/apache/unomi/itests/AllITs.java
@@ -39,6 +39,7 @@ import org.junit.runners.Suite.SuiteClasses;
         ProfileImportRankingIT.class,
         ProfileImportActorsIT.class,
         ProfileExportIT.class,
+        EventServiceIT.class,
         PropertiesUpdateActionIT.class,
         ModifyConsentIT.class,
         PatchIT.class,
diff --git a/itests/src/test/java/org/apache/unomi/itests/EventServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/EventServiceIT.java
new file mode 100644
index 0000000..160205a
--- /dev/null
+++ b/itests/src/test/java/org/apache/unomi/itests/EventServiceIT.java
@@ -0,0 +1,68 @@
+/*
+ * 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.itests;
+
+import org.apache.unomi.api.services.EventService;
+import org.apache.unomi.api.services.ProfileService;
+import org.apache.unomi.api.Event;
+import org.apache.unomi.api.Profile;
+
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerSuite;
+import org.ops4j.pax.exam.util.Filter;
+
+import javax.inject.Inject;
+import java.util.Date;
+import org.junit.Assert;
+
+
+/**
+ * An integration test for the event service
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerSuite.class)
+public class EventServiceIT extends BaseIT {
+
+    private final static String TEST_PROFILE_ID = "test-profile-id";
+
+    @Inject @Filter(timeout = 600000)
+    protected EventService eventService;
+
+    @Inject
+    @Filter(timeout = 600000)
+    protected ProfileService profileService;
+
+    @Test
+    public void test_EventExistenceWithProfileId() throws InterruptedException{
+        String eventId = "test-event-id2";
+        String profileId = "test-profile-id";
+        String eventType = "test-type";
+        Profile profile = new Profile(profileId);
+        Event event = new Event(eventId, eventType, null, profile, null, null, null, new Date());
+        profileService.save(profile);
+        eventService.send(event);
+        refreshPersistence();
+        Thread.sleep(2000);
+        boolean exist = eventService.hasEventAlreadyBeenRaised(event);
+        Assert.assertTrue(exist);
+    }
+
+}
diff --git a/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java
index 1e71df6..6d51f16 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java
@@ -348,7 +348,13 @@ public class EventServiceImpl implements EventService {
 
     public boolean hasEventAlreadyBeenRaised(Event event) {
         Event pastEvent = this.persistenceService.load(event.getItemId(), Event.class);
-        return pastEvent != null && pastEvent.getVersion() >= 1 && pastEvent.getSessionId().equals(event.getSessionId());
+        if (pastEvent != null && pastEvent.getVersion() >= 1) {
+            if ((pastEvent.getSessionId() != null && pastEvent.getSessionId().equals(event.getSessionId())) ||
+                    (pastEvent.getProfileId() != null && pastEvent.getProfileId().equals(event.getProfileId())))  {
+                return true;
+            }
+        }
+        return false;
     }
 
     public boolean hasEventAlreadyBeenRaised(Event event, boolean session) {