You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dr...@apache.org on 2017/11/03 15:33:06 UTC
[2/3] incubator-unomi git commit: UNOMI-134 : Added docs,
renamed classes/methods
UNOMI-134 : Added docs, renamed classes/methods
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/1ed3acd7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/1ed3acd7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/1ed3acd7
Branch: refs/heads/master
Commit: 1ed3acd795678a8ff356ddb3097824b826f0d2e8
Parents: e78cba3
Author: Thomas Draier <dr...@apache.org>
Authored: Thu Nov 2 16:47:58 2017 +0100
Committer: Thomas Draier <dr...@apache.org>
Committed: Thu Nov 2 16:47:58 2017 +0100
----------------------------------------------------------------------
.../org/apache/unomi/api/ContextRequest.java | 208 +--------------
.../org/apache/unomi/api/ContextResponse.java | 10 +-
.../unomi/api/PersonalizationStrategy.java | 28 ++
.../java/org/apache/unomi/api/SortStrategy.java | 24 --
.../api/services/PersonalizationService.java | 260 +++++++++++++++++++
.../apache/unomi/api/services/SortService.java | 30 ---
.../services/PersonalizationServiceImpl.java | 91 +++++++
.../services/services/SortServiceImpl.java | 65 -----
.../sorts/FilterPersonalizationStrategy.java | 59 +++++
.../services/sorts/FilterSortStrategy.java | 59 -----
.../sorts/RandomPersonalizationStrategy.java | 35 +++
.../services/sorts/RandomSortStrategy.java | 35 ---
.../sorts/ScorePersonalizationStrategy.java | 101 +++++++
.../unomi/services/sorts/ScoreSortStrategy.java | 101 -------
.../resources/OSGI-INF/blueprint/blueprint.xml | 23 +-
.../org/apache/unomi/web/ContextServlet.java | 29 +--
.../resources/OSGI-INF/blueprint/blueprint.xml | 4 +-
17 files changed, 613 insertions(+), 549 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/api/src/main/java/org/apache/unomi/api/ContextRequest.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/ContextRequest.java b/api/src/main/java/org/apache/unomi/api/ContextRequest.java
index 21c7f00..8d9dc99 100644
--- a/api/src/main/java/org/apache/unomi/api/ContextRequest.java
+++ b/api/src/main/java/org/apache/unomi/api/ContextRequest.java
@@ -21,6 +21,7 @@ import org.apache.unomi.api.actions.Action;
import org.apache.unomi.api.conditions.Condition;
import org.apache.unomi.api.rules.Rule;
import org.apache.unomi.api.services.EventListenerService;
+import org.apache.unomi.api.services.PersonalizationService;
import org.apache.unomi.api.services.ProfileService;
import org.apache.unomi.api.services.RulesService;
@@ -54,8 +55,8 @@ public class ContextRequest {
private List<String> requiredProfileProperties;
private List<String> requiredSessionProperties;
private List<Event> events;
- private List<FilteredContent> filters;
- private List<SortRequest> sorts;
+ private List<PersonalizationService.PersonalizedContent> filters;
+ private List<PersonalizationService.PersonalizationRequest> personalizations;
// the following overrides make it possible to override temporarily the current profile segments, properties or
// even session properties. This is useful for building UIs to temporarily override one of these parameters to
@@ -147,7 +148,7 @@ public class ContextRequest {
* @see ProfileService#matchCondition(Condition, Profile, Session) Details on how the filter conditions are evaluated
* @see ContextResponse#getFilteringResults() Details on how the evaluation results are returned to the client
*/
- public List<FilteredContent> getFilters() {
+ public List<PersonalizationService.PersonalizedContent> getFilters() {
return filters;
}
@@ -156,16 +157,16 @@ public class ContextRequest {
*
* @param filters the content filters to be evaluated
*/
- public void setFilters(List<FilteredContent> filters) {
+ public void setFilters(List<PersonalizationService.PersonalizedContent> filters) {
this.filters = filters;
}
- public List<SortRequest> getSorts() {
- return sorts;
+ public List<PersonalizationService.PersonalizationRequest> getPersonalizations() {
+ return personalizations;
}
- public void setSorts(List<SortRequest> sorts) {
- this.sorts = sorts;
+ public void setPersonalizations(List<PersonalizationService.PersonalizationRequest> personalizations) {
+ this.personalizations = personalizations;
}
/**
@@ -223,195 +224,4 @@ public class ContextRequest {
this.sessionPropertiesOverrides = sessionPropertiesOverrides;
}
- /**
- *
- */
- public static class SortRequest {
- private String id;
- private String strategy;
- private Map<String, Object> strategyOptions;
- private List<FilteredContent> contents;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getStrategy() {
- return strategy;
- }
-
- public void setStrategy(String strategy) {
- this.strategy = strategy;
- }
-
- public List<FilteredContent> getContents() {
- return contents;
- }
-
- public void setContents(List<FilteredContent> contents) {
- this.contents = contents;
- }
-
- public Map<String, Object> getStrategyOptions() {
- return strategyOptions;
- }
-
- public void setStrategyOptions(Map<String, Object> strategyOptions) {
- this.strategyOptions = strategyOptions;
- }
- }
-
- /**
- * A content filtering definition.
- */
- public static class FilteredContent {
- private String filterid;
- private List<Filter> filters;
- private Map<String,Object> properties;
-
- /**
- * Retrieves the filter identifier associated with this content filtering definition.
- *
- * @return the filter identifier associated with this content filtering definition
- */
- public String getFilterid() {
- return filterid;
- }
-
- /**
- * Sets the filter identifier associated with this content filtering definition.
- *
- * @param filterid the filter identifier associated with this content filtering definition
- */
- public void setFilterid(String filterid) {
- this.filterid = filterid;
- }
-
- /**
- * Retrieves the filters.
- *
- * @return the filters
- */
- public List<Filter> getFilters() {
- return filters;
- }
-
- /**
- * Sets the filters.
- *
- * @param filters the filters
- */
- public void setFilters(List<Filter> filters) {
- this.filters = filters;
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.properties = properties;
- }
- }
-
- /**
- * A filter definition for content filtering
- */
- public static class Filter {
- private List<Target> appliesOn;
- private Condition condition;
- private Map<String,Object> properties;
-
- /**
- * Retrieves the list of targets this filter applies on.
- *
- * @return the applies on
- */
- public List<Target> getAppliesOn() {
- return appliesOn;
- }
-
- /**
- * Specifies which targets this filter applies on.
- *
- * @param appliesOn the list of {@link ContextRequest.Target} this filter should be applied on
- */
- public void setAppliesOn(List<Target> appliesOn) {
- this.appliesOn = appliesOn;
- }
-
- /**
- * Retrieves the condition associated with this filter.
- *
- * @return the condition associated with this filter
- */
- public Condition getCondition() {
- return condition;
- }
-
- /**
- * Sets the condition associated with this filter.
- *
- * @param condition the condition associated with this filter
- */
- public void setCondition(Condition condition) {
- this.condition = condition;
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.properties = properties;
- }
- }
-
- /**
- * A target for content filtering.
- */
- public static class Target {
- private String target;
- private List<String> values;
-
- /**
- * Retrieves the target.
- *
- * @return the target
- */
- public String getTarget() {
- return target;
- }
-
- /**
- * Sets the target.
- *
- * @param target the target
- */
- public void setTarget(String target) {
- this.target = target;
- }
-
- /**
- * Retrieves the values.
- *
- * @return the values
- */
- public List<String> getValues() {
- return values;
- }
-
- /**
- * Sets the values.
- *
- * @param values the values
- */
- public void setValues(List<String> values) {
- this.values = values;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/api/src/main/java/org/apache/unomi/api/ContextResponse.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/ContextResponse.java b/api/src/main/java/org/apache/unomi/api/ContextResponse.java
index 2aefad7..0969cb4 100644
--- a/api/src/main/java/org/apache/unomi/api/ContextResponse.java
+++ b/api/src/main/java/org/apache/unomi/api/ContextResponse.java
@@ -48,7 +48,7 @@ public class ContextResponse implements Serializable {
private Map<String, Boolean> filteringResults;
- private Map<String, List<String>> sortResults;
+ private Map<String, List<String>> personalizations;
private Set<Condition> trackedConditions;
@@ -169,12 +169,12 @@ public class ContextResponse implements Serializable {
this.filteringResults = filteringResults;
}
- public Map<String, List<String>> getSortResults() {
- return sortResults;
+ public Map<String, List<String>> getPersonalizations() {
+ return personalizations;
}
- public void setSortResults(Map<String, List<String>> sortResults) {
- this.sortResults = sortResults;
+ public void setPersonalizations(Map<String, List<String>> personalizations) {
+ this.personalizations = personalizations;
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/api/src/main/java/org/apache/unomi/api/PersonalizationStrategy.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/PersonalizationStrategy.java b/api/src/main/java/org/apache/unomi/api/PersonalizationStrategy.java
new file mode 100644
index 0000000..9c76d41
--- /dev/null
+++ b/api/src/main/java/org/apache/unomi/api/PersonalizationStrategy.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.api;
+
+import org.apache.unomi.api.services.PersonalizationService;
+
+import java.util.List;
+
+/**
+ *
+ */
+public interface PersonalizationStrategy {
+ List<String> personalizeList(Profile profile, Session session, PersonalizationService.PersonalizationRequest personalizationRequest);
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/api/src/main/java/org/apache/unomi/api/SortStrategy.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/SortStrategy.java b/api/src/main/java/org/apache/unomi/api/SortStrategy.java
deleted file mode 100644
index c5d5acb..0000000
--- a/api/src/main/java/org/apache/unomi/api/SortStrategy.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.unomi.api;
-
-import java.util.List;
-
-public interface SortStrategy {
-
- List<String> sort(Profile profile, Session session, ContextRequest.SortRequest sortRequest);
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/api/src/main/java/org/apache/unomi/api/services/PersonalizationService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/services/PersonalizationService.java b/api/src/main/java/org/apache/unomi/api/services/PersonalizationService.java
new file mode 100644
index 0000000..36588a4
--- /dev/null
+++ b/api/src/main/java/org/apache/unomi/api/services/PersonalizationService.java
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.api.services;
+
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.Session;
+import org.apache.unomi.api.conditions.Condition;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A service to fulfill personalization request.
+ */
+public interface PersonalizationService {
+
+ /**
+ * Check if an item is visible for the specified profile and session
+ *
+ * @param profile The profile
+ * @param session The session
+ * @param personalizedContent Personalized content, containing a list of filters
+ * @return If the content is visible or not
+ */
+ boolean filter(Profile profile, Session session, PersonalizedContent personalizedContent);
+
+ /**
+ * Get the best match among a list of items, for the specified profile and session
+ *
+ * @param profile The profile
+ * @param session The session
+ * @param personalizationRequest Personalization request, containing the list of variants and the required strategy
+ * @return The id of the best-matching variant
+ */
+ String bestMatch(Profile profile, Session session, PersonalizationRequest personalizationRequest);
+
+ /**
+ * Get a personalized list, filtered and sorted, based on the profile and session
+ *
+ * @param profile The profile
+ * @param session The session
+ * @param personalizationRequest Personalization request, containing the list of variants and the required strategy
+ * @return List of ids, based on user profile
+ */
+ List<String> personalizeList(Profile profile, Session session, PersonalizationRequest personalizationRequest);
+
+ /**
+ * Personalization request
+ */
+ class PersonalizationRequest {
+ private String id;
+ private String strategy;
+ private Map<String, Object> strategyOptions;
+ private List<PersonalizedContent> contents;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getStrategy() {
+ return strategy;
+ }
+
+ public void setStrategy(String strategy) {
+ this.strategy = strategy;
+ }
+
+ public List<PersonalizedContent> getContents() {
+ return contents;
+ }
+
+ public void setContents(List<PersonalizedContent> contents) {
+ this.contents = contents;
+ }
+
+ public Map<String, Object> getStrategyOptions() {
+ return strategyOptions;
+ }
+
+ public void setStrategyOptions(Map<String, Object> strategyOptions) {
+ this.strategyOptions = strategyOptions;
+ }
+ }
+
+ /**
+ * A personalizated content definition.
+ */
+ class PersonalizedContent {
+ private String id;
+ private List<Filter> filters;
+ private Map<String,Object> properties;
+
+ /**
+ * Retrieves the filter identifier associated with this content filtering definition.
+ *
+ * @return the filter identifier associated with this content filtering definition
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the filter identifier associated with this content filtering definition.
+ *
+ * @param id the filter identifier associated with this content filtering definition
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * @deprecated
+ */
+ public void setFilterid(String filterid) {
+ this.id = filterid;
+ }
+
+ /**
+ * Retrieves the filters.
+ *
+ * @return the filters
+ */
+ public List<Filter> getFilters() {
+ return filters;
+ }
+
+ /**
+ * Sets the filters.
+ *
+ * @param filters the filters
+ */
+ public void setFilters(List<Filter> filters) {
+ this.filters = filters;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+ }
+
+ /**
+ * A filter definition for content filtering
+ */
+ class Filter {
+ private List<Target> appliesOn;
+ private Condition condition;
+ private Map<String,Object> properties;
+
+ /**
+ * Retrieves the list of targets this filter applies on.
+ *
+ * @return the applies on
+ */
+ public List<Target> getAppliesOn() {
+ return appliesOn;
+ }
+
+ /**
+ * Specifies which targets this filter applies on.
+ *
+ * @param appliesOn the list of {@link Target} this filter should be applied on
+ */
+ public void setAppliesOn(List<Target> appliesOn) {
+ this.appliesOn = appliesOn;
+ }
+
+ /**
+ * Retrieves the condition associated with this filter.
+ *
+ * @return the condition associated with this filter
+ */
+ public Condition getCondition() {
+ return condition;
+ }
+
+ /**
+ * Sets the condition associated with this filter.
+ *
+ * @param condition the condition associated with this filter
+ */
+ public void setCondition(Condition condition) {
+ this.condition = condition;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+ }
+
+ /**
+ * A target for content filtering.
+ */
+ class Target {
+ private String target;
+ private List<String> values;
+
+ /**
+ * Retrieves the target.
+ *
+ * @return the target
+ */
+ public String getTarget() {
+ return target;
+ }
+
+ /**
+ * Sets the target.
+ *
+ * @param target the target
+ */
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ /**
+ * Retrieves the values.
+ *
+ * @return the values
+ */
+ public List<String> getValues() {
+ return values;
+ }
+
+ /**
+ * Sets the values.
+ *
+ * @param values the values
+ */
+ public void setValues(List<String> values) {
+ this.values = values;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/api/src/main/java/org/apache/unomi/api/services/SortService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/services/SortService.java b/api/src/main/java/org/apache/unomi/api/services/SortService.java
deleted file mode 100644
index e169df7..0000000
--- a/api/src/main/java/org/apache/unomi/api/services/SortService.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.unomi.api.services;
-
-import org.apache.unomi.api.ContextRequest;
-import org.apache.unomi.api.Profile;
-import org.apache.unomi.api.Session;
-
-import java.util.List;
-
-public interface SortService {
-
- List<String> sort(Profile profile, Session session, ContextRequest.SortRequest sortRequest);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/services/PersonalizationServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/PersonalizationServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/PersonalizationServiceImpl.java
new file mode 100644
index 0000000..f968bf5
--- /dev/null
+++ b/services/src/main/java/org/apache/unomi/services/services/PersonalizationServiceImpl.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.services.services;
+
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.Session;
+import org.apache.unomi.api.PersonalizationStrategy;
+import org.apache.unomi.api.conditions.Condition;
+import org.apache.unomi.api.services.PersonalizationService;
+import org.apache.unomi.api.services.ProfileService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class PersonalizationServiceImpl implements PersonalizationService {
+
+ private BundleContext bundleContext;
+ private ProfileService profileService;
+
+ private Map<String, PersonalizationStrategy> personalizationStrategies = new ConcurrentHashMap<>();
+
+ public void setProfileService(ProfileService profileService) {
+ this.profileService = profileService;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public void addPersonalizationStrategy(ServiceReference<PersonalizationStrategy> personalizationStrategyRef) {
+ PersonalizationStrategy personalizationStrategy = bundleContext.getService(personalizationStrategyRef);
+ personalizationStrategies.put(personalizationStrategyRef.getProperty("personalizationStrategyId").toString(), personalizationStrategy);
+ }
+
+ public void removePersonalizationStrategy(ServiceReference<PersonalizationStrategy> personalizationStrategyRef) {
+ if (personalizationStrategyRef == null) {
+ return;
+ }
+ personalizationStrategies.remove(personalizationStrategyRef.getProperty("personalizationStrategyId").toString());
+ }
+
+ @Override
+ public boolean filter(Profile profile, Session session, PersonalizedContent personalizedContent) {
+ boolean result = true;
+ for (Filter filter : personalizedContent.getFilters()) {
+ Condition condition = filter.getCondition();
+ if (condition.getConditionType() != null) {
+ result &= profileService.matchCondition(condition, profile, session);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String bestMatch(Profile profile, Session session, PersonalizationRequest personalizationRequest) {
+ List<String> sorted = personalizeList(profile,session,personalizationRequest);
+ if (sorted.size() > 0) {
+ return sorted.get(0);
+ }
+ return null;
+ }
+
+ @Override
+ public List<String> personalizeList(Profile profile, Session session, PersonalizationRequest personalizationRequest) {
+ PersonalizationStrategy strategy = personalizationStrategies.get(personalizationRequest.getStrategy());
+
+ if (strategy != null) {
+ return strategy.personalizeList(profile, session, personalizationRequest);
+ }
+
+ throw new IllegalArgumentException("Unknown strategy : "+ personalizationRequest.getStrategy());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/services/SortServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/SortServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/SortServiceImpl.java
deleted file mode 100644
index ac9b3e1..0000000
--- a/services/src/main/java/org/apache/unomi/services/services/SortServiceImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.unomi.services.services;
-
-import org.apache.unomi.api.ContextRequest;
-import org.apache.unomi.api.Profile;
-import org.apache.unomi.api.Session;
-import org.apache.unomi.api.SortStrategy;
-import org.apache.unomi.api.services.SortService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class SortServiceImpl implements SortService {
-
- private BundleContext bundleContext;
-
- private Map<String, SortStrategy> sortStrategies = new ConcurrentHashMap<>();
-
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- }
-
- public void addSortStrategy(ServiceReference<SortStrategy> sortStrategyRef) {
- SortStrategy sortStrategy = bundleContext.getService(sortStrategyRef);
- sortStrategies.put(sortStrategyRef.getProperty("sortStrategyId").toString(), sortStrategy);
- }
-
- public void removeSortStrategy(ServiceReference<SortStrategy> sortStrategyRef) {
- if (sortStrategyRef == null) {
- return;
- }
- sortStrategies.remove(sortStrategyRef.getProperty("sortStrategyId").toString());
- }
-
-
- @Override
- public List<String> sort(Profile profile, Session session, ContextRequest.SortRequest sortRequest) {
- SortStrategy strategy = sortStrategies.get(sortRequest.getStrategy());
-
- if (strategy != null) {
- return strategy.sort(profile, session, sortRequest);
- }
-
- throw new IllegalArgumentException("Unknown strategy : "+sortRequest.getStrategy());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/sorts/FilterPersonalizationStrategy.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/sorts/FilterPersonalizationStrategy.java b/services/src/main/java/org/apache/unomi/services/sorts/FilterPersonalizationStrategy.java
new file mode 100644
index 0000000..b3e6bb4
--- /dev/null
+++ b/services/src/main/java/org/apache/unomi/services/sorts/FilterPersonalizationStrategy.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.services.sorts;
+
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.Session;
+import org.apache.unomi.api.PersonalizationStrategy;
+import org.apache.unomi.api.conditions.Condition;
+import org.apache.unomi.api.services.PersonalizationService;
+import org.apache.unomi.api.services.ProfileService;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FilterPersonalizationStrategy implements PersonalizationStrategy {
+
+ private ProfileService profileService;
+
+ public void setProfileService(ProfileService profileService) {
+ this.profileService = profileService;
+ }
+
+ @Override
+ public List<String> personalizeList(Profile profile, Session session, PersonalizationService.PersonalizationRequest personalizationRequest) {
+ List<String> sortedContent = new ArrayList<>();
+ for (PersonalizationService.PersonalizedContent personalizedContent : personalizationRequest.getContents()) {
+ boolean result = true;
+ for (PersonalizationService.Filter filter : personalizedContent.getFilters()) {
+ Condition condition = filter.getCondition();
+ result &= profileService.matchCondition(condition, profile, session);
+ }
+ if (result) {
+ sortedContent.add(personalizedContent.getId());
+ }
+ }
+
+ String fallback = (String) personalizationRequest.getStrategyOptions().get("fallback");
+ if (fallback != null && !sortedContent.contains(fallback)) {
+ sortedContent.add(fallback);
+ }
+
+ return sortedContent;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/sorts/FilterSortStrategy.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/sorts/FilterSortStrategy.java b/services/src/main/java/org/apache/unomi/services/sorts/FilterSortStrategy.java
deleted file mode 100644
index 5036bf5..0000000
--- a/services/src/main/java/org/apache/unomi/services/sorts/FilterSortStrategy.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.unomi.services.sorts;
-
-import org.apache.unomi.api.ContextRequest;
-import org.apache.unomi.api.Profile;
-import org.apache.unomi.api.Session;
-import org.apache.unomi.api.SortStrategy;
-import org.apache.unomi.api.conditions.Condition;
-import org.apache.unomi.api.services.ProfileService;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class FilterSortStrategy implements SortStrategy {
-
- private ProfileService profileService;
-
- public void setProfileService(ProfileService profileService) {
- this.profileService = profileService;
- }
-
- @Override
- public List<String> sort(Profile profile, Session session, ContextRequest.SortRequest sortRequest) {
- List<String> sortedContent = new ArrayList<>();
- for (ContextRequest.FilteredContent filteredContent : sortRequest.getContents()) {
- boolean result = true;
- for (ContextRequest.Filter filter : filteredContent.getFilters()) {
- Condition condition = filter.getCondition();
- result &= profileService.matchCondition(condition, profile, session);
- }
- if (result) {
- sortedContent.add(filteredContent.getFilterid());
- }
- }
-
- String fallback = (String) sortRequest.getStrategyOptions().get("fallback");
- if (fallback != null && !sortedContent.contains(fallback)) {
- sortedContent.add(fallback);
- }
-
- return sortedContent;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/sorts/RandomPersonalizationStrategy.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/sorts/RandomPersonalizationStrategy.java b/services/src/main/java/org/apache/unomi/services/sorts/RandomPersonalizationStrategy.java
new file mode 100644
index 0000000..3dd31f7
--- /dev/null
+++ b/services/src/main/java/org/apache/unomi/services/sorts/RandomPersonalizationStrategy.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.services.sorts;
+
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.Session;
+import org.apache.unomi.api.services.PersonalizationService;
+
+import java.util.Collections;
+import java.util.List;
+
+public class RandomPersonalizationStrategy extends FilterPersonalizationStrategy {
+
+ @Override
+ public List<String> personalizeList(Profile profile, Session session, PersonalizationService.PersonalizationRequest personalizationRequest) {
+ List<String> r = super.personalizeList(profile, session, personalizationRequest);
+ Collections.shuffle(r);
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/sorts/RandomSortStrategy.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/sorts/RandomSortStrategy.java b/services/src/main/java/org/apache/unomi/services/sorts/RandomSortStrategy.java
deleted file mode 100644
index ee25af0..0000000
--- a/services/src/main/java/org/apache/unomi/services/sorts/RandomSortStrategy.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.unomi.services.sorts;
-
-import org.apache.unomi.api.ContextRequest;
-import org.apache.unomi.api.Profile;
-import org.apache.unomi.api.Session;
-
-import java.util.Collections;
-import java.util.List;
-
-public class RandomSortStrategy extends FilterSortStrategy {
-
- @Override
- public List<String> sort(Profile profile, Session session, ContextRequest.SortRequest sortRequest) {
- List<String> r = super.sort(profile, session, sortRequest);
- Collections.shuffle(r);
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/sorts/ScorePersonalizationStrategy.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/sorts/ScorePersonalizationStrategy.java b/services/src/main/java/org/apache/unomi/services/sorts/ScorePersonalizationStrategy.java
new file mode 100644
index 0000000..bc90bf0
--- /dev/null
+++ b/services/src/main/java/org/apache/unomi/services/sorts/ScorePersonalizationStrategy.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.services.sorts;
+
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.Session;
+import org.apache.unomi.api.PersonalizationStrategy;
+import org.apache.unomi.api.conditions.Condition;
+import org.apache.unomi.api.services.PersonalizationService;
+import org.apache.unomi.api.services.ProfileService;
+
+import java.util.*;
+
+public class ScorePersonalizationStrategy implements PersonalizationStrategy {
+
+ private ProfileService profileService;
+
+ public void setProfileService(ProfileService profileService) {
+ this.profileService = profileService;
+ }
+
+ @Override
+ public List<String> personalizeList(Profile profile, Session session, PersonalizationService.PersonalizationRequest personalizationRequest) {
+ List<String> sortedContent = new ArrayList<>();
+ final Map<String,Integer> t = new HashMap<>();
+
+ Integer threshold = (Integer) personalizationRequest.getStrategyOptions().get("threshold");
+ if (threshold == null) {
+ threshold = 0;
+ }
+
+ for (PersonalizationService.PersonalizedContent personalizedContent : personalizationRequest.getContents()) {
+ int score = 0;
+
+ String interestList = (String) (personalizedContent.getProperties() != null ? personalizedContent.getProperties().get("interests") : null);
+ if (interestList != null) {
+ Map<String,Integer> interestValues = (Map<String, Integer>) profile.getProperties().get("interests");
+ for (String interest : interestList.split(" ")) {
+ if (interestValues.get(interest) != null) {
+ score += interestValues.get(interest);
+ }
+ }
+ }
+
+ String scoringPlanList = (String) (personalizedContent.getProperties() != null ? personalizedContent.getProperties().get("scoringPlans") : null);
+ if (scoringPlanList != null) {
+ Map<String,Integer> scoreValues = (Map<String, Integer>) profile.getScores();
+ for (String scoringPlan : scoringPlanList.split(" ")) {
+ if (scoreValues.get(scoringPlan) != null) {
+ score += scoreValues.get(scoringPlan);
+ }
+ }
+ }
+
+ for (PersonalizationService.Filter filter : personalizedContent.getFilters()) {
+ Condition condition = filter.getCondition();
+ if (condition.getConditionType() != null) {
+ if (profileService.matchCondition(condition, profile, session)) {
+ if (filter.getProperties().get("score") != null) {
+ score += (int) filter.getProperties().get("score");
+ } else {
+ score += 1;
+ }
+ }
+ }
+ }
+ if (score >= threshold) {
+ t.put(personalizedContent.getId(), score);
+ sortedContent.add(personalizedContent.getId());
+ }
+ }
+ Collections.sort(sortedContent, new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ return t.get(o2) - t.get(o1);
+ }
+ });
+
+ String fallback = (String) personalizationRequest.getStrategyOptions().get("fallback");
+ if (fallback != null && !sortedContent.contains(fallback)) {
+ sortedContent.add(fallback);
+ }
+
+ return sortedContent;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/java/org/apache/unomi/services/sorts/ScoreSortStrategy.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/sorts/ScoreSortStrategy.java b/services/src/main/java/org/apache/unomi/services/sorts/ScoreSortStrategy.java
deleted file mode 100644
index 65c99ea..0000000
--- a/services/src/main/java/org/apache/unomi/services/sorts/ScoreSortStrategy.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.unomi.services.sorts;
-
-import org.apache.unomi.api.ContextRequest;
-import org.apache.unomi.api.Profile;
-import org.apache.unomi.api.Session;
-import org.apache.unomi.api.SortStrategy;
-import org.apache.unomi.api.conditions.Condition;
-import org.apache.unomi.api.services.ProfileService;
-
-import java.util.*;
-
-public class ScoreSortStrategy implements SortStrategy {
-
- private ProfileService profileService;
-
- public void setProfileService(ProfileService profileService) {
- this.profileService = profileService;
- }
-
- @Override
- public List<String> sort(Profile profile, Session session, ContextRequest.SortRequest sortRequest) {
- List<String> sortedContent = new ArrayList<>();
- final Map<String,Integer> t = new HashMap<>();
-
- Integer threshold = (Integer) sortRequest.getStrategyOptions().get("threshold");
- if (threshold == null) {
- threshold = 0;
- }
-
- for (ContextRequest.FilteredContent filteredContent : sortRequest.getContents()) {
- int score = 0;
-
- String interestList = (String) (filteredContent.getProperties() != null ? filteredContent.getProperties().get("interests") : null);
- if (interestList != null) {
- Map<String,Integer> interestValues = (Map<String, Integer>) profile.getProperties().get("interests");
- for (String interest : interestList.split(" ")) {
- if (interestValues.get(interest) != null) {
- score += interestValues.get(interest);
- }
- }
- }
-
- String scoringPlanList = (String) (filteredContent.getProperties() != null ? filteredContent.getProperties().get("scoringPlans") : null);
- if (scoringPlanList != null) {
- Map<String,Integer> scoreValues = (Map<String, Integer>) profile.getScores();
- for (String scoringPlan : scoringPlanList.split(" ")) {
- if (scoreValues.get(scoringPlan) != null) {
- score += scoreValues.get(scoringPlan);
- }
- }
- }
-
- for (ContextRequest.Filter filter : filteredContent.getFilters()) {
- Condition condition = filter.getCondition();
- if (condition.getConditionType() != null) {
- if (profileService.matchCondition(condition, profile, session)) {
- if (filter.getProperties().get("score") != null) {
- score += (int) filter.getProperties().get("score");
- } else {
- score += 1;
- }
- }
- }
- }
- if (score >= threshold) {
- t.put(filteredContent.getFilterid(), score);
- sortedContent.add(filteredContent.getFilterid());
- }
- }
- Collections.sort(sortedContent, new Comparator<String>() {
- @Override
- public int compare(String o1, String o2) {
- return t.get(o2) - t.get(o1);
- }
- });
-
- String fallback = (String) sortRequest.getStrategyOptions().get("fallback");
- if (fallback != null && !sortedContent.contains(fallback)) {
- sortedContent.add(fallback);
- }
-
- return sortedContent;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index a5e788a..c18bedd 100644
--- a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -172,10 +172,11 @@
<service id="clusterService" ref="clusterServiceImpl" auto-export="interfaces"/>
- <bean id="sortServiceImpl" class="org.apache.unomi.services.services.SortServiceImpl">
+ <bean id="personalizationServiceImpl" class="org.apache.unomi.services.services.PersonalizationServiceImpl">
+ <property name="profileService" ref="profileServiceImpl"/>
<property name="bundleContext" ref="blueprintBundleContext"/>
</bean>
- <service id="sortService" ref="sortServiceImpl" auto-export="interfaces"/>
+ <service id="personalizationService" ref="personalizationServiceImpl" auto-export="interfaces"/>
<!-- We use a listener here because using the list directly for listening to proxies coming from the same bundle didn't seem to work -->
<reference-list id="eventListenerServices"
@@ -192,11 +193,11 @@
bind-method="bindExecutor" unbind-method="unbindExecutor" ref="rulesServiceImpl"/>
</reference-list>
- <reference-list id="sortStrategies"
- interface="org.apache.unomi.api.SortStrategy"
+ <reference-list id="personalizationStrategies"
+ interface="org.apache.unomi.api.PersonalizationStrategy"
availability="optional">
<reference-listener
- bind-method="addSortStrategy" unbind-method="removeSortStrategy" ref="sortServiceImpl"/>
+ bind-method="addPersonalizationStrategy" unbind-method="removePersonalizationStrategy" ref="personalizationServiceImpl"/>
</reference-list>
<!-- Property merge strategy executors -->
@@ -243,27 +244,27 @@
<service auto-export="interfaces">
<service-properties>
- <entry key="sortStrategyId" value="matching-first"/>
+ <entry key="personalizationStrategyId" value="matching-first"/>
</service-properties>
- <bean class="org.apache.unomi.services.sorts.FilterSortStrategy">
+ <bean class="org.apache.unomi.services.sorts.FilterPersonalizationStrategy">
<property name="profileService" ref="profileServiceImpl"/>
</bean>
</service>
<service auto-export="interfaces">
<service-properties>
- <entry key="sortStrategyId" value="random"/>
+ <entry key="personalizationStrategyId" value="random"/>
</service-properties>
- <bean class="org.apache.unomi.services.sorts.RandomSortStrategy">
+ <bean class="org.apache.unomi.services.sorts.RandomPersonalizationStrategy">
<property name="profileService" ref="profileServiceImpl"/>
</bean>
</service>
<service auto-export="interfaces">
<service-properties>
- <entry key="sortStrategyId" value="score-sorted"/>
+ <entry key="personalizationStrategyId" value="score-sorted"/>
</service-properties>
- <bean class="org.apache.unomi.services.sorts.ScoreSortStrategy">
+ <bean class="org.apache.unomi.services.sorts.ScorePersonalizationStrategy">
<property name="profileService" ref="profileServiceImpl"/>
</bean>
</service>
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
----------------------------------------------------------------------
diff --git a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
index 4bad376..9844375 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -53,7 +53,7 @@ public class ContextServlet extends HttpServlet {
private EventService eventService;
private RulesService rulesService;
private PrivacyService privacyService;
- private SortService sortService;
+ private PersonalizationService personalizationService;
private ConfigSharingService configSharingService;
private String profileIdCookieName = "context-profile-id";
@@ -354,26 +354,19 @@ public class ContextServlet extends HttpServlet {
processOverrides(contextRequest, profile, session);
- List<ContextRequest.FilteredContent> filterNodes = contextRequest.getFilters();
+ List<PersonalizationService.PersonalizedContent> filterNodes = contextRequest.getFilters();
if (filterNodes != null) {
data.setFilteringResults(new HashMap<String, Boolean>());
- for (ContextRequest.FilteredContent filteredContent : filterNodes) {
- boolean result = true;
- for (ContextRequest.Filter filter : filteredContent.getFilters()) {
- Condition condition = filter.getCondition();
- if (condition.getConditionType() != null) {
- result &= profileService.matchCondition(condition, profile, session);
- }
- }
- data.getFilteringResults().put(filteredContent.getFilterid(), result);
+ for (PersonalizationService.PersonalizedContent personalizedContent : filterNodes) {
+ data.getFilteringResults().put(personalizedContent.getId(), personalizationService.filter(profile, session, personalizedContent));
}
}
- List<ContextRequest.SortRequest> sorts = contextRequest.getSorts();
- if (sorts != null) {
- data.setSortResults(new HashMap<String, List<String>>());
- for (ContextRequest.SortRequest sort : sorts) {
- data.getSortResults().put(sort.getId(), sortService.sort(profile, session, sort));
+ List<PersonalizationService.PersonalizationRequest> personalizations = contextRequest.getPersonalizations();
+ if (personalizations != null) {
+ data.setPersonalizations(new HashMap<String, List<String>>());
+ for (PersonalizationService.PersonalizationRequest personalization : personalizations) {
+ data.getPersonalizations().put(personalization.getId(), personalizationService.personalizeList(profile, session, personalization));
}
}
@@ -462,8 +455,8 @@ public class ContextServlet extends HttpServlet {
this.privacyService = privacyService;
}
- public void setSortService(SortService sortService) {
- this.sortService = sortService;
+ public void setPersonalizationService(PersonalizationService personalizationService) {
+ this.personalizationService = personalizationService;
}
public void setConfigSharingService(ConfigSharingService configSharingService) {
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/1ed3acd7/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 295ff99..ef03abd 100644
--- a/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/wab/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -26,7 +26,7 @@
<reference id="eventService" interface="org.apache.unomi.api.services.EventService"/>
<reference id="rulesService" interface="org.apache.unomi.api.services.RulesService"/>
<reference id="privacyService" interface="org.apache.unomi.api.services.PrivacyService"/>
- <reference id="sortService" interface="org.apache.unomi.api.services.SortService"/>
+ <reference id="personalizationService" interface="org.apache.unomi.api.services.PersonalizationService"/>
<reference id="configSharingService" interface="org.apache.unomi.api.services.ConfigSharingService" />
<cm:property-placeholder persistent-id="org.apache.unomi.web"
@@ -44,7 +44,7 @@
<property name="eventService" ref="eventService"/>
<property name="rulesService" ref="rulesService"/>
<property name="privacyService" ref="privacyService" />
- <property name="sortService" ref="sortService"/>
+ <property name="personalizationService" ref="personalizationService"/>
<property name="configSharingService" ref="configSharingService"/>
<property name="profileIdCookieDomain" value="${web.contextserver.domain}" />
<property name="profileIdCookieName" value="${web.contextserver.profileIdCookieName}"/>