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 00da9d9d576c81cf0abdcc9b35c2983be3b4b6f1 Author: Serge Huber <[email protected]> AuthorDate: Wed Apr 21 18:25:11 2021 +0200 Fix build broken after cherry-pick --- api/pom.xml | 5 ++++- .../main/java/org/apache/unomi/api/Profile.java | 25 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index 74118a9..5741526 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -37,7 +37,10 @@ <version>2.2.11</version> <scope>provided</scope> </dependency> - + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> diff --git a/api/src/main/java/org/apache/unomi/api/Profile.java b/api/src/main/java/org/apache/unomi/api/Profile.java index ba75da9..7115bd5 100644 --- a/api/src/main/java/org/apache/unomi/api/Profile.java +++ b/api/src/main/java/org/apache/unomi/api/Profile.java @@ -17,6 +17,7 @@ package org.apache.unomi.api; +import org.apache.commons.lang3.StringUtils; import org.apache.unomi.api.segments.Scoring; import org.apache.unomi.api.segments.Segment; @@ -95,6 +96,30 @@ public class Profile extends Item { } /** + * Retrieves the value of the nested property identified by the specified name. + * + * @param name the name of the property to be retrieved, splited in the nested properties with "." + * @return the value of the property identified by the specified name + */ + public Object getNestedProperty(String name) { + if (!name.contains(".")) { + return getProperty(name); + } + + Map properties = this.properties; + String[] propertyPath = StringUtils.substringBeforeLast(name, ".").split("\\."); + String propertyName = StringUtils.substringAfterLast(name, "."); + + for (String property: propertyPath) { + properties = (Map) properties.get(property); + if (properties == null) { + return null; + } + } + return properties.get(propertyName); + } + + /** * Retrieves a Map of all property name - value pairs for this profile. * * @return a Map of all property name - value pairs for this profile
