Repository: incubator-unomi
Updated Branches:
  refs/heads/master 45d4fb092 -> 7742b30ae


UNOMI-47 : Add the ability to remove a property on the profile


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

Branch: refs/heads/master
Commit: 7742b30aee11c8afee3a6039c4ca227f08310cdb
Parents: 45d4fb0
Author: Abdelkader Midani <[email protected]>
Authored: Fri Aug 5 12:49:41 2016 +0200
Committer: Abdelkader Midani <[email protected]>
Committed: Fri Aug 5 12:50:55 2016 +0200

----------------------------------------------------------------------
 .../apache/unomi/persistence/spi/PropertyHelper.java | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/7742b30a/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 5b24a62..0f839db 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
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 
@@ -38,6 +39,20 @@ public class PropertyHelper {
 
     public static boolean setProperty(Object target, String propertyName, 
Object propertyValue, String setPropertyStrategy) {
         try {
+            String parentPropertyName =  null;
+            Object parentTarget = null;
+            if(setPropertyStrategy!=null && 
setPropertyStrategy.equals("remove")){
+                if(resolver.hasNested(propertyName)) {
+                    parentPropertyName = propertyName.substring(0, 
propertyName.lastIndexOf('.'));
+                    Object parentPropertyValue = 
PropertyUtils.getNestedProperty(target, parentPropertyName);
+                    if(parentPropertyValue instanceof HashMap){
+                        
((HashMap)parentPropertyValue).remove(propertyName.substring(propertyName.lastIndexOf('.')+1));
+                        PropertyUtils.setNestedProperty(target, 
parentPropertyName, parentPropertyValue);
+                        return true;
+                    }
+                }
+                return false;
+            }
             while (resolver.hasNested(propertyName)) {
                 Object v = PropertyUtils.getProperty(target, 
resolver.next(propertyName));
                 if (v == null) {

Reply via email to