UNOMI-47 : Check if the nested property is present 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/1c5d74aa Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/1c5d74aa Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/1c5d74aa Branch: refs/heads/master Commit: 1c5d74aa5c2f98af8a632eb9be603e168f6df1be Parents: b6410c1 Author: Abdelkader Midani <[email protected]> Authored: Tue Aug 9 13:36:12 2016 +0200 Committer: Abdelkader Midani <[email protected]> Committed: Tue Aug 9 13:36:12 2016 +0200 ---------------------------------------------------------------------- .../unomi/persistence/spi/PropertyHelper.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1c5d74aa/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 0f839db..e70a09f 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 @@ -18,6 +18,7 @@ package org.apache.unomi.persistence.spi; import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.beanutils.NestedNullException; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.expression.DefaultResolver; import org.slf4j.Logger; @@ -44,12 +45,17 @@ public class PropertyHelper { 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; + try{ + 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; + } + } catch(NestedNullException ex){ + return false; } + } return false; }
