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/24 12:34:22 UTC

[unomi] branch unomi-1.5.x updated (0b81ba3 -> b3feb62)

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

shuber pushed a change to branch unomi-1.5.x
in repository https://gitbox.apache.org/repos/asf/unomi.git.


    from 0b81ba3  Improve scripting security (#179)
     new c914812  Expose scroll identifier on profile queries (#181)
     new d819763  Use profile id session is in null to see if event has already been raised (#184)
     new b3feb62  Fix build after cherry picks from master.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/unomi/api/query/Query.java     | 19 +++++++
 common/pom.xml                                     |  2 +-
 .../test/java/org/apache/unomi/itests/AllITs.java  |  3 +-
 .../{ProfileServiceIT.java => EventServiceIT.java} | 37 ++++++++-----
 .../org/apache/unomi/itests/ProfileServiceIT.java  | 60 ++++++++++++++++++++++
 .../ElasticSearchPersistenceServiceImpl.java       |  9 +++-
 .../unomi/persistence/spi/PersistenceService.java  | 20 ++++++++
 scripting/pom.xml                                  |  6 +--
 .../services/impl/events/EventServiceImpl.java     |  8 ++-
 .../services/impl/profiles/ProfileServiceImpl.java |  7 ++-
 10 files changed, 149 insertions(+), 22 deletions(-)
 copy itests/src/test/java/org/apache/unomi/itests/{ProfileServiceIT.java => EventServiceIT.java} (63%)


[unomi] 01/03: Expose scroll identifier on profile queries (#181)

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c9148125373f920c5d9adc7fd07d17069ce02109
Author: liatiusim <62...@users.noreply.github.com>
AuthorDate: Thu Aug 20 16:10:51 2020 +0300

    Expose scroll identifier on profile queries (#181)
    
    * Expose scroller id on profile queries
    
    * Add scroller itest
    
    * fix profile service it tests
    
    Co-authored-by: Shir Bromberg <sb...@yotpo.com>
    (cherry picked from commit 2f4f0fcdc95abf5efbef494283ccd791a573ccb3)
---
 .../java/org/apache/unomi/api/query/Query.java     | 19 +++++++
 .../org/apache/unomi/itests/ProfileServiceIT.java  | 60 ++++++++++++++++++++++
 .../ElasticSearchPersistenceServiceImpl.java       |  9 +++-
 .../unomi/persistence/spi/PersistenceService.java  | 20 ++++++++
 .../services/impl/profiles/ProfileServiceImpl.java |  7 ++-
 5 files changed, 111 insertions(+), 4 deletions(-)

diff --git a/api/src/main/java/org/apache/unomi/api/query/Query.java b/api/src/main/java/org/apache/unomi/api/query/Query.java
index ef74b72..48e0c1a 100644
--- a/api/src/main/java/org/apache/unomi/api/query/Query.java
+++ b/api/src/main/java/org/apache/unomi/api/query/Query.java
@@ -33,6 +33,8 @@ public class Query implements Serializable {
     private String sortby;
     private Condition condition;
     private boolean forceRefresh;
+    private String scrollTimeValidity;
+    private String scrollIdentifier;
 
     /**
      * Instantiates a new Query.
@@ -150,4 +152,21 @@ public class Query implements Serializable {
     public void setForceRefresh(boolean forceRefresh) {
         this.forceRefresh = forceRefresh;
     }
+
+    public String getScrollIdentifier() {
+        return scrollIdentifier;
+    }
+
+    public void setScrollIdentifier(String scrollIdentifier) {
+        this.scrollIdentifier = scrollIdentifier;
+    }
+
+    public String getScrollTimeValidity() {
+        return scrollTimeValidity;
+    }
+
+    public void setScrollTimeValidity(String scrollTimeValidity) {
+        this.scrollTimeValidity = scrollTimeValidity;
+    }
+
 }
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
index 2c996b7..db4e735 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
@@ -17,9 +17,17 @@
 package org.apache.unomi.itests;
 
 import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.query.Query;
 import org.apache.unomi.api.services.ProfileService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.api.PartialList;
+
+import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.junit.Before;
+
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerSuite;
@@ -42,6 +50,19 @@ public class ProfileServiceIT extends BaseIT {
     @Inject @Filter(timeout = 600000)
     protected ProfileService profileService;
 
+    @Inject
+    @Filter(timeout = 600000)
+    protected PersistenceService persistenceService;
+
+    @Inject
+    @Filter(timeout = 600000)
+    protected DefinitionsService definitionsService;
+
+    @Before
+    public void setUp() {
+        TestUtils.removeAllProfiles(definitionsService, persistenceService);
+    }
+
     @Test
     public void testProfileDelete() {
         Profile profile = new Profile();
@@ -52,4 +73,43 @@ public class ProfileServiceIT extends BaseIT {
         LOGGER.info("Profile deleted successfully.");
     }
 
+    @Test
+    public void testGetProfileWithScrolling() throws InterruptedException {
+        final String profileIdOne = "test-profile-id-one";
+        final String profileIdTwo = "test-profile-id-two";
+        final String profileIdThree = "test-profile-id-three";
+
+        Profile profileOne = new Profile();
+        Profile profileTwo = new Profile();
+        Profile profileThree = new Profile();
+
+        profileOne.setItemId(profileIdOne);
+        profileTwo.setItemId(profileIdTwo);
+        profileThree.setItemId(profileIdThree);
+
+        profileService.save(profileOne);
+        profileService.save(profileTwo);
+        profileService.save(profileThree);
+
+        Thread.sleep(4000); // Make sure Elastic is updated
+
+        Query query = new Query();
+        query.setLimit(2);
+        query.setScrollTimeValidity("10m");
+
+        PartialList<Profile> profiles = profileService.search(query, Profile.class);
+        assertEquals(2, profiles.getList().size());
+
+        Query queryCont = new Query();
+        queryCont.setScrollTimeValidity("10m");
+        queryCont.setScrollIdentifier(profiles.getScrollIdentifier());
+
+        profiles = profileService.search(queryCont, Profile.class);
+        assertEquals(1, profiles.getList().size());
+
+        queryCont.setScrollIdentifier(profiles.getScrollIdentifier());
+        profiles = profileService.search(queryCont, Profile.class);
+        assertEquals(0, profiles.getList().size());
+    }
+
 }
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 aef7b34..711a859 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
@@ -638,15 +638,19 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
 
     @Override
     public <T extends Item> PartialList<T> getAllItems(final Class<T> clazz, int offset, int size, String sortBy) {
+        return getAllItems(clazz, offset, size, sortBy, null);
+    }
+
+    @Override
+    public <T extends Item> PartialList<T> getAllItems(final Class<T> clazz, int offset, int size, String sortBy, String scrollTimeValidity) {
         long startTime = System.currentTimeMillis();
         try {
-            return query(QueryBuilders.matchAllQuery(), sortBy, clazz, offset, size, null, null);
+            return query(QueryBuilders.matchAllQuery(), sortBy, clazz, offset, size, null, scrollTimeValidity);
         } finally {
             if (metricsService != null && metricsService.isActivated()) {
                 metricsService.updateTimer(this.getClass().getName() + ".getAllItems", startTime);
             }
         }
-
     }
 
     @Override
@@ -1304,6 +1308,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
         }
     }
 
+
     @Override
     public <T extends Item> List<T> query(final Condition query, String sortBy, final Class<T> clazz) {
         return query(query, sortBy, clazz, 0, -1).getList();
diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
index 80bf444..0e41df3 100644
--- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
+++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
@@ -60,6 +60,26 @@ public interface PersistenceService {
     <T extends Item> PartialList<T> getAllItems(Class<T> clazz, int offset, int size, String sortBy);
 
     /**
+     * Retrieves all known items of the specified class, ordered according to the specified {@code sortBy} String and and paged: only {@code size} of them are retrieved,
+     * starting with the {@code offset}-th one.
+     *
+     * TODO: use a Query object instead of distinct parameters?
+     *
+     * @param <T>    the type of the {@link Item}s we want to retrieve
+     * @param clazz  the {@link Item} subclass of entities we want to retrieve
+     * @param offset zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
+     * @param size   a positive integer specifying how many matching items should be retrieved or {@code -1} if all of them should be retrieved
+     * @param sortBy an optional ({@code null} if no sorting is required) String of comma ({@code ,}) separated property names on which ordering should be performed, ordering
+     *               elements according to the property order in the
+     *               String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by
+     *               a column ({@code :}) and an order specifier: {@code asc} or {@code desc}.
+     * @param scrollTimeValidity  the time the scrolling query should stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as
+     *      *                     the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
+     * @return a {@link PartialList} of pages items with the given type
+     */
+    <T extends Item> PartialList<T> getAllItems(final Class<T> clazz, int offset, int size, String sortBy, String scrollTimeValidity);
+
+    /**
      * Persists the specified Item in the context server.
      *
      * @param item the item to persist
diff --git a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
index 42873ea..c0cc002 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
@@ -374,17 +374,20 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
     }
 
     private <T extends Item> PartialList<T> doSearch(Query query, Class<T> clazz) {
+        if (query.getScrollIdentifier() != null) {
+            return persistenceService.continueScrollQuery(clazz, query.getScrollIdentifier(), query.getScrollTimeValidity());
+        }
         if (query.getCondition() != null && definitionsService.resolveConditionType(query.getCondition())) {
             if (StringUtils.isNotBlank(query.getText())) {
                 return persistenceService.queryFullText(query.getText(), query.getCondition(), query.getSortby(), clazz, query.getOffset(), query.getLimit());
             } else {
-                return persistenceService.query(query.getCondition(), query.getSortby(), clazz, query.getOffset(), query.getLimit());
+                return persistenceService.query(query.getCondition(), query.getSortby(), clazz, query.getOffset(), query.getLimit(), query.getScrollTimeValidity());
             }
         } else {
             if (StringUtils.isNotBlank(query.getText())) {
                 return persistenceService.queryFullText(query.getText(), query.getSortby(), clazz, query.getOffset(), query.getLimit());
             } else {
-                return persistenceService.getAllItems(clazz, query.getOffset(), query.getLimit(), query.getSortby());
+                return persistenceService.getAllItems(clazz, query.getOffset(), query.getLimit(), query.getSortby(), query.getScrollTimeValidity());
             }
         }
     }


[unomi] 03/03: Fix build after cherry picks from master.

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b3feb62c9391794a07a8c91653dd5b6ae0ba94ed
Author: Serge Huber <sh...@jahia.com>
AuthorDate: Mon Aug 24 14:34:15 2020 +0200

    Fix build after cherry picks from master.
---
 common/pom.xml    | 2 +-
 scripting/pom.xml | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/pom.xml b/common/pom.xml
index 55e3d7d..47f4851 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -58,7 +58,7 @@
         <dependency>
             <groupId>org.apache.unomi</groupId>
             <artifactId>unomi-api</artifactId>
-            <version>2.0.0-SNAPSHOT</version>
+            <version>1.5.2-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
 
diff --git a/scripting/pom.xml b/scripting/pom.xml
index 61c10e6..8a8ce38 100644
--- a/scripting/pom.xml
+++ b/scripting/pom.xml
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.apache.unomi</groupId>
         <artifactId>unomi-root</artifactId>
-        <version>2.0.0-SNAPSHOT</version>
+        <version>1.5.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>unomi-scripting</artifactId>
@@ -45,7 +45,7 @@
         <dependency>
             <groupId>org.apache.unomi</groupId>
             <artifactId>unomi-api</artifactId>
-            <version>2.0.0-SNAPSHOT</version>
+            <version>1.5.2-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
 
@@ -58,7 +58,7 @@
 
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>osgi.core</artifactId>
+            <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>
         </dependency>
 


[unomi] 02/03: Use profile id session is in null to see if event has already been raised (#184)

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d819763ca20a0ff909b2c0cae705711b3a41947e
Author: liatiusim <62...@users.noreply.github.com>
AuthorDate: Thu Aug 20 15:14:27 2020 +0200

    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>
    
    (cherry picked from commit 23dbf03ebd7889eeb80ab7ec2d369670461ad302)
---
 .../test/java/org/apache/unomi/itests/AllITs.java  |  3 +-
 .../org/apache/unomi/itests/EventServiceIT.java    | 68 ++++++++++++++++++++++
 .../services/impl/events/EventServiceImpl.java     |  8 ++-
 3 files changed, 77 insertions(+), 2 deletions(-)

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 73245e7..c973f71 100644
--- a/itests/src/test/java/org/apache/unomi/itests/AllITs.java
+++ b/itests/src/test/java/org/apache/unomi/itests/AllITs.java
@@ -38,7 +38,8 @@ import org.junit.runners.Suite.SuiteClasses;
 	ProfileImportRankingIT.class,
 	ProfileImportActorsIT.class,
 	ProfileExportIT.class,
-	PropertiesUpdateActionIT.class,
+	EventServiceIT.class,
+    PropertiesUpdateActionIT.class,
 	ModifyConsentIT.class,
 	PatchIT.class,
 	ContextServletIT.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 a6e6bbc..e9ad5cb 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
@@ -282,7 +282,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) {