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


The following commit(s) were added to refs/heads/unomi-1.5.x by this push:
     new 6392820  UNOMI-338 avoid update date with invalid custom timestamp 
(#161)
6392820 is described below

commit 639282078a96c972c9424701d260d6f5b2b1025a
Author: MT BENTERKI <[email protected]>
AuthorDate: Sun May 24 09:30:10 2020 +0200

    UNOMI-338 avoid update date with invalid custom timestamp (#161)
    
    (cherry picked from commit e1f49a01e4df82d3a015528fe1bfbb2ff16d3bde)
---
 .../baseplugin/actions/SetPropertyAction.java      | 23 +++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java
 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java
index 4134cec..d65e649 100644
--- 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java
@@ -22,7 +22,10 @@ import org.apache.unomi.api.actions.Action;
 import org.apache.unomi.api.actions.ActionExecutor;
 import org.apache.unomi.api.services.EventService;
 import org.apache.unomi.persistence.spi.PropertyHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
@@ -30,6 +33,7 @@ import java.util.Map;
 import java.util.TimeZone;
 
 public class SetPropertyAction implements ActionExecutor {
+    private static final Logger logger = 
LoggerFactory.getLogger(SetPropertyAction.class.getName());
 
     private EventService eventService;
 
@@ -69,7 +73,24 @@ public class SetPropertyAction implements ActionExecutor {
         if (propertyValue != null && propertyValue.equals("now")) {
             SimpleDateFormat format = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
             format.setTimeZone(TimeZone.getTimeZone("UTC"));
-            propertyValue = format.format(event.getTimeStamp());
+
+            Date date = new Date();
+            Date firstVisit = new Date();
+
+            try {
+                String propertyFirstVisit = (String) 
event.getProfile().getProperties().get("firstVisit");
+                if (propertyFirstVisit != null) {
+                    firstVisit = format.parse(propertyFirstVisit);
+                }
+
+                if (event.getTimeStamp().after(firstVisit)) {
+                    date = event.getTimeStamp();
+                }
+            } catch (ParseException e) {
+                logger.error("Error to parse date", e);
+            }
+
+            propertyValue = format.format(date);
         }
 
         if (storeInSession) {

Reply via email to