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 2017/02/24 08:34:44 UTC

[2/3] incubator-unomi git commit: UNOMI-84 : Handle boolean property type

UNOMI-84 : Handle boolean property type


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

Branch: refs/heads/master
Commit: 9ed047c8acf5caa0ca023ffceead0dd3cbb5254d
Parents: 3ecd61c
Author: Abdelkader Midani <am...@jahia.com>
Authored: Mon Feb 20 19:10:39 2017 +0100
Committer: Abdelkader Midani <am...@jahia.com>
Committed: Mon Feb 20 19:10:39 2017 +0100

----------------------------------------------------------------------
 .../unomi/persistence/spi/PropertyHelper.java   | 20 ++++++++++++++++++++
 .../baseplugin/actions/SetPropertyAction.java   | 14 ++++++++++++--
 .../META-INF/cxs/actions/setPropertyAction.json |  5 +++++
 .../resources/META-INF/cxs/values/boolean.json  |  3 +++
 4 files changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9ed047c8/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java
----------------------------------------------------------------------
diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java
index e70a09f..ff7d0c0 100644
--- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java
+++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java
@@ -109,4 +109,24 @@ public class PropertyHelper {
         return null;
     }
 
+    public static Boolean getBooleanValue(Object setPropertyValueBoolean) {
+
+        if (setPropertyValueBoolean instanceof Boolean) {
+            return((Boolean)setPropertyValueBoolean);
+        } else if (setPropertyValueBoolean instanceof Number) {
+            if (((Number)setPropertyValueBoolean).intValue() >= 1) {
+                return  new Boolean(true);
+            } else {
+                return  new Boolean(false);
+            }
+        } else {
+            if (((String)setPropertyValueBoolean).equalsIgnoreCase("true") || ((String)setPropertyValueBoolean).equalsIgnoreCase("on") ||
+                    ((String)setPropertyValueBoolean).equalsIgnoreCase("yes") || ((String)setPropertyValueBoolean).equalsIgnoreCase("1")) {
+                return  new Boolean(true);
+            } else {
+                return  new Boolean(false);
+            }
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9ed047c8/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetPropertyAction.java
----------------------------------------------------------------------
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 f50de42..3771114 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
@@ -18,10 +18,12 @@
 package org.apache.unomi.plugins.baseplugin.actions;
 
 import org.apache.unomi.api.Event;
+import org.apache.unomi.api.PropertyType;
 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.api.services.PrivacyService;
+import org.apache.unomi.api.services.ProfileService;
 import org.apache.unomi.persistence.spi.PropertyHelper;
 
 import java.text.SimpleDateFormat;
@@ -30,11 +32,16 @@ import java.util.TimeZone;
 public class SetPropertyAction implements ActionExecutor {
 
     private PrivacyService privacyService;
+    private ProfileService profileService;
 
     public void setPrivacyService(PrivacyService privacyService) {
         this.privacyService = privacyService;
     }
 
+    public void setProfileService(ProfileService profileService) {
+        this.profileService = profileService;
+    }
+
     public int execute(Action action, Event event) {
         boolean storeInSession = Boolean.TRUE.equals(action.getParameterValues().get("storeInSession"));
 
@@ -46,14 +53,18 @@ public class SetPropertyAction implements ActionExecutor {
         }
         Object propertyValueInteger = action.getParameterValues().get("setPropertyValueInteger");
         Object setPropertyValueMultiple = action.getParameterValues().get("setPropertyValueMultiple");
+        Object setPropertyValueBoolean = action.getParameterValues().get("setPropertyValueBoolean");
 
         if (propertyValue == null) {
             if (propertyValueInteger != null) {
                 propertyValue = PropertyHelper.getInteger(propertyValueInteger);
             }
-            if(setPropertyValueMultiple != null) {
+            if (setPropertyValueMultiple != null) {
                propertyValue = setPropertyValueMultiple;
             }
+            if (setPropertyValueBoolean != null) {
+                propertyValue = PropertyHelper.getBooleanValue(setPropertyValueBoolean);
+            }
         }
         if (propertyValue != null && propertyValue.equals("now")) {
             SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
@@ -61,7 +72,6 @@ public class SetPropertyAction implements ActionExecutor {
             propertyValue = format.format(event.getTimeStamp());
         }
 
-
         Object target = storeInSession ? event.getSession() : event.getProfile();
 
         if (PropertyHelper.setProperty(target, propertyName, propertyValue, (String) action.getParameterValues().get("setPropertyStrategy"))) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9ed047c8/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/setPropertyAction.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/setPropertyAction.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/setPropertyAction.json
index ff72333..c076eb7 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/setPropertyAction.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/setPropertyAction.json
@@ -21,6 +21,11 @@
       "multivalued": false
     },
     {
+      "id": "setPropertyValueBoolean",
+      "type": "boolean",
+      "multivalued": false
+    },
+    {
       "id": "setPropertyValueInteger",
       "type": "integer",
       "multivalued": false

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9ed047c8/services/src/main/resources/META-INF/cxs/values/boolean.json
----------------------------------------------------------------------
diff --git a/services/src/main/resources/META-INF/cxs/values/boolean.json b/services/src/main/resources/META-INF/cxs/values/boolean.json
new file mode 100644
index 0000000..237d86d
--- /dev/null
+++ b/services/src/main/resources/META-INF/cxs/values/boolean.json
@@ -0,0 +1,3 @@
+{
+  "id": "boolean"
+}
\ No newline at end of file