UNOMI-39 - anonymous browsing : anonymize removed profile properties. implements default denied properties, copy allowed properties from profile to anonymous. Cleaned profile and segment queries.
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/685f67ff Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/685f67ff Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/685f67ff Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE Commit: 685f67ffa889b9dd329255cf74c6a4029ac82200 Parents: eee8d6f Author: Thomas Draier <[email protected]> Authored: Thu Aug 18 16:32:40 2016 +0200 Committer: Thomas Draier <[email protected]> Committed: Thu Aug 18 16:32:40 2016 +0200 ---------------------------------------------------------------------- .../unomi/api/services/PrivacyService.java | 8 +-- .../privacy/rest/PrivacyServiceEndPoint.java | 4 +- extensions/privacy-extension/services/pom.xml | 26 ++++++++++ .../privacy/internal/PrivacyServiceImpl.java | 53 ++++++++++++++------ .../resources/OSGI-INF/blueprint/blueprint.xml | 10 +++- .../main/resources/org.apache.unomi.privacy.cfg | 18 +++++++ kar/src/main/feature/feature.xml | 1 + .../AllEventToProfilePropertiesAction.java | 18 ++++--- .../actions/EventToProfilePropertyAction.java | 15 ++++-- .../baseplugin/actions/SetPropertyAction.java | 14 +++--- .../BooleanConditionESQueryBuilder.java | 2 +- .../resources/OSGI-INF/blueprint/blueprint.xml | 10 +++- pom.xml | 2 - .../services/services/ProfileServiceImpl.java | 5 +- .../services/services/SegmentServiceImpl.java | 19 ++++--- .../org/apache/unomi/web/ContextServlet.java | 27 +++++++--- .../unomi/web/EventsCollectorServlet.java | 2 +- 17 files changed, 169 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java b/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java index 6d22678..4dd9c64 100644 --- a/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java +++ b/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java @@ -27,13 +27,13 @@ import java.util.List; */ public interface PrivacyService { - String GLOBAL_ANONYMOUS_PROFILE_ID = "global-anonymous-profile"; - ServerInfo getServerInfo(); Boolean deleteProfile(String profileId); - String anonymizeBrowsingData(String profileId); + Boolean anonymizeProfile(String profileId); + + Boolean anonymizeBrowsingData(String profileId); Boolean deleteProfileData(String profileId); @@ -41,7 +41,7 @@ public interface PrivacyService { Boolean isRequireAnonymousBrowsing(String profileId); - Profile getAnonymousProfile(); + Profile getAnonymousProfile(Profile profile); List<String> getFilteredEventTypes(String profileId); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java ---------------------------------------------------------------------- diff --git a/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java index 6895305..5ef088c 100644 --- a/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java +++ b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java @@ -66,8 +66,8 @@ public class PrivacyServiceEndPoint { @POST @Path("/profiles/{profileId}/anonymize") - public void anonymizeBrowsingData(@PathParam("profileId") String profileId) { - privacyService.anonymizeBrowsingData(profileId); + public void anonymizeProfile(@PathParam("profileId") String profileId) { + privacyService.anonymizeProfile(profileId); } @GET http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/extensions/privacy-extension/services/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/privacy-extension/services/pom.xml b/extensions/privacy-extension/services/pom.xml index 9fad09c..b6c8d3c 100644 --- a/extensions/privacy-extension/services/pom.xml +++ b/extensions/privacy-extension/services/pom.xml @@ -66,6 +66,32 @@ </instructions> </configuration> </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>attach-artifacts</id> + <phase>package</phase> + <goals> + <goal>attach-artifact</goal> + </goals> + <configuration> + <artifacts> + <artifact> + <file> + src/main/resources/org.apache.unomi.privacy.cfg + </file> + <type>cfg</type> + <classifier>privacycfg</classifier> + </artifact> + </artifacts> + </configuration> + </execution> + </executions> + </plugin> + </plugins> </build> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java ---------------------------------------------------------------------- diff --git a/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java b/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java index e05d245..22ec95a 100644 --- a/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java +++ b/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java @@ -18,8 +18,6 @@ package org.apache.unomi.privacy.internal; import org.apache.unomi.api.*; -import org.apache.unomi.api.conditions.Condition; -import org.apache.unomi.api.services.DefinitionsService; import org.apache.unomi.api.services.EventService; import org.apache.unomi.api.services.PrivacyService; import org.apache.unomi.api.services.ProfileService; @@ -34,18 +32,14 @@ import java.util.*; public class PrivacyServiceImpl implements PrivacyService { private PersistenceService persistenceService; - private DefinitionsService definitionsService; private ProfileService profileService; private EventService eventService; + private List<String> defaultDeniedProperties; public void setPersistenceService(PersistenceService persistenceService) { this.persistenceService = persistenceService; } - public void setDefinitionsService(DefinitionsService definitionsService) { - this.definitionsService = definitionsService; - } - public void setProfileService(ProfileService profileService) { this.profileService = profileService; } @@ -54,6 +48,14 @@ public class PrivacyServiceImpl implements PrivacyService { this.eventService = eventService; } + public void setDefaultDeniedProperties(List<String> defaultDeniedProperties) { + this.defaultDeniedProperties = defaultDeniedProperties; + } + + public void setDefaultDeniedProperties(String defaultDeniedProperties) { + this.defaultDeniedProperties = Arrays.asList(defaultDeniedProperties.split(",")); + } + @Override public ServerInfo getServerInfo() { ServerInfo serverInfo = new ServerInfo(); @@ -88,15 +90,35 @@ public class PrivacyServiceImpl implements PrivacyService { } @Override - public String anonymizeBrowsingData(String profileId) { + public Boolean anonymizeProfile(String profileId) { + Profile profile = profileService.load(profileId); + if (profile == null) { + return false; + } + boolean res = profile.getProperties().keySet().removeAll(getDeniedProperties(profile.getItemId())); + + Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date()); + profileUpdated.setPersistent(false); + eventService.send(profileUpdated); + + profileService.save(profile); + + return res; + } + + @Override + public Boolean anonymizeBrowsingData(String profileId) { Profile profile = profileService.load(profileId); if (profile == null) { - return profileId; + return false; } List<Session> sessions = profileService.getProfileSessions(profileId, null, 0, -1, null).getList(); + if (sessions.isEmpty()) { + return false; + } for (Session session : sessions) { - Profile newProfile = getAnonymousProfile(); + Profile newProfile = getAnonymousProfile(session.getProfile()); session.setProfile(newProfile); persistenceService.save(session); List<Event> events = eventService.searchEvents(session.getItemId(), new String[0], null, 0, -1, null).getList(); @@ -105,7 +127,7 @@ public class PrivacyServiceImpl implements PrivacyService { } } - return profileId; + return true; } @Override @@ -135,10 +157,11 @@ public class PrivacyServiceImpl implements PrivacyService { return anonymous != null && anonymous; } - public Profile getAnonymousProfile() { - String id = UUID.randomUUID().toString(); - Profile anonymousProfile = new Profile(id); + public Profile getAnonymousProfile(Profile profile) { + Profile anonymousProfile = new Profile(UUID.randomUUID().toString()); anonymousProfile.getSystemProperties().put("isAnonymousProfile", true); + anonymousProfile.getProperties().putAll(profile.getProperties()); + anonymousProfile.getProperties().keySet().removeAll(getDeniedProperties(profile.getItemId())); profileService.save(anonymousProfile); return anonymousProfile; } @@ -165,7 +188,7 @@ public class PrivacyServiceImpl implements PrivacyService { @Override public List<String> getDeniedProperties(String profileId) { - return null; + return defaultDeniedProperties; } @Override http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/extensions/privacy-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/extensions/privacy-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/privacy-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 64b8db2..ea4df97 100644 --- a/extensions/privacy-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/extensions/privacy-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -17,8 +17,16 @@ --> <blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + <cm:property-placeholder persistent-id="org.apache.unomi.privacy" + update-strategy="reload"> + <cm:default-properties> + <cm:property name="defaultDeniedProperties" value="firstName,lastName"/> + </cm:default-properties> + </cm:property-placeholder> + <reference id="persistenceService" interface="org.apache.unomi.persistence.spi.PersistenceService"/> @@ -32,9 +40,9 @@ <bean id="privacyServiceImpl" class="org.apache.unomi.privacy.internal.PrivacyServiceImpl"> <property name="persistenceService" ref="persistenceService"/> - <property name="definitionsService" ref="definitionsService"/> <property name="eventService" ref="eventService" /> <property name="profileService" ref="profileService" /> + <property name="defaultDeniedProperties" value="${defaultDeniedProperties}" /> </bean> <service id="privacyService" ref="privacyServiceImpl" auto-export="interfaces"/> </blueprint> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/extensions/privacy-extension/services/src/main/resources/org.apache.unomi.privacy.cfg ---------------------------------------------------------------------- diff --git a/extensions/privacy-extension/services/src/main/resources/org.apache.unomi.privacy.cfg b/extensions/privacy-extension/services/src/main/resources/org.apache.unomi.privacy.cfg new file mode 100644 index 0000000..320273c --- /dev/null +++ b/extensions/privacy-extension/services/src/main/resources/org.apache.unomi.privacy.cfg @@ -0,0 +1,18 @@ +# +# 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. +# + +defaultDeniedProperties=firstName,lastName,email,phoneNumber,address,facebookId,googleId,linedInId,twitterId http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/kar/src/main/feature/feature.xml ---------------------------------------------------------------------- diff --git a/kar/src/main/feature/feature.xml b/kar/src/main/feature/feature.xml index 5e63b8b..fff6799 100644 --- a/kar/src/main/feature/feature.xml +++ b/kar/src/main/feature/feature.xml @@ -28,6 +28,7 @@ <configfile finalname="/etc/org.apache.unomi.plugins.request.cfg">mvn:org.apache.unomi/unomi-plugins-request/${project.version}/cfg/requestcfg</configfile> <configfile finalname="/etc/org.apache.unomi.services.cfg">mvn:org.apache.unomi/unomi-services/${project.version}/cfg/servicescfg</configfile> <configfile finalname="/etc/org.apache.unomi.thirdparty.cfg">mvn:org.apache.unomi/unomi-services/${project.version}/cfg/thirdpartycfg</configfile> + <configfile finalname="/etc/org.apache.unomi.privacy.cfg">mvn:org.apache.unomi/cxs-privacy-extension-services/${project.version}/cfg/privacycfg</configfile> <configfile finalname="/etc/org.apache.unomi.geonames.cfg">mvn:org.apache.unomi/cxs-geonames-services/${project.version}/cfg/geonamescfg</configfile> <configfile finalname="/etc/elasticsearch.yml">mvn:org.apache.unomi/unomi-persistence-elasticsearch-core/${project.version}/yml/elasticsearchconfig</configfile> <bundle start-level="75">mvn:commons-io/commons-io/2.4</bundle> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java index 33b79e9..850e489 100644 --- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java +++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java @@ -22,6 +22,7 @@ import org.apache.unomi.api.Event; 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 java.util.HashMap; @@ -30,16 +31,18 @@ import java.util.Map; public class AllEventToProfilePropertiesAction implements ActionExecutor { private ProfileService profileService; + private PrivacyService privacyService; public void setProfileService(ProfileService profileService) { this.profileService = profileService; } + public void setPrivacyService(PrivacyService privacyService) { + this.privacyService = privacyService; + } + @SuppressWarnings({ "unchecked", "rawtypes" }) public int execute(Action action, Event event) { - if (event.getProfile().isAnonymousProfile()) { - return EventService.NO_CHANGE; - } boolean changed = false; Map<String, Object> properties = new HashMap<String,Object>(); if (event.getProperties() != null) { @@ -58,12 +61,11 @@ public class AllEventToProfilePropertiesAction implements ActionExecutor { for (Map.Entry<String, Object> entry : properties.entrySet()) { if (event.getProfile().getProperty(entry.getKey()) == null || !event.getProfile().getProperty(entry.getKey()).equals(event.getProperty(entry.getKey()))) { String propertyMapping = profileService.getPropertyTypeMapping(entry.getKey()); - if (propertyMapping != null) { - event.getProfile().setProperty(propertyMapping, entry.getValue()); - } else { - event.getProfile().setProperty(entry.getKey(), entry.getValue()); + String propertyName = (propertyMapping != null) ? propertyMapping : entry.getKey(); + if (!event.getProfile().isAnonymousProfile() || !privacyService.getDeniedProperties(event.getProfileId()).contains(propertyName)) { + event.getProfile().setProperty(propertyName, entry.getValue()); + changed = true; } - changed = true; } } return changed ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE; http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EventToProfilePropertyAction.java ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EventToProfilePropertyAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EventToProfilePropertyAction.java index f8391d7..8efb43e 100644 --- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EventToProfilePropertyAction.java +++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EventToProfilePropertyAction.java @@ -21,18 +21,27 @@ import org.apache.unomi.api.Event; 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; /** * A action to copy an event property to a profile property */ public class EventToProfilePropertyAction implements ActionExecutor { + private PrivacyService privacyService; + + public void setPrivacyService(PrivacyService privacyService) { + this.privacyService = privacyService; + } + public int execute(Action action, Event event) { - if (event.getProfile().isAnonymousProfile()) { - return EventService.NO_CHANGE; - } String eventPropertyName = (String) action.getParameterValues().get("eventPropertyName"); String profilePropertyName = (String) action.getParameterValues().get("profilePropertyName"); + + if (event.getProfile().isAnonymousProfile() && privacyService.getDeniedProperties(event.getProfileId()).contains(profilePropertyName)) { + return EventService.NO_CHANGE; + } + if (event.getProfile().getProperty(profilePropertyName) == null || !event.getProfile().getProperty(profilePropertyName).equals(event.getProperty(eventPropertyName))) { event.getProfile().setProperty(profilePropertyName, event.getProperty(eventPropertyName)); return EventService.PROFILE_UPDATED; http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/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 0b1a877..e384960 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 @@ -21,6 +21,7 @@ import org.apache.unomi.api.Event; 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.persistence.spi.PropertyHelper; import java.text.SimpleDateFormat; @@ -28,17 +29,19 @@ import java.util.TimeZone; public class SetPropertyAction implements ActionExecutor { - public SetPropertyAction() { - } + private PrivacyService privacyService; - public String getActionId() { - return "setPropertyAction"; + public void setPrivacyService(PrivacyService privacyService) { + this.privacyService = privacyService; } public int execute(Action action, Event event) { boolean storeInSession = Boolean.TRUE.equals(action.getParameterValues().get("storeInSession")); - if (event.getProfile().isAnonymousProfile() && !storeInSession) { + String propertyName = (String) action.getParameterValues().get("setPropertyName"); + + if (event.getProfile().isAnonymousProfile() && !storeInSession + && privacyService.getDeniedProperties(event.getProfileId()).contains(propertyName)) { return EventService.NO_CHANGE; } @@ -54,7 +57,6 @@ public class SetPropertyAction implements ActionExecutor { format.setTimeZone(TimeZone.getTimeZone("UTC")); propertyValue = format.format(event.getTimeStamp()); } - String propertyName = (String) action.getParameterValues().get("setPropertyName"); Object target = storeInSession ? event.getSession() : event.getProfile(); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/BooleanConditionESQueryBuilder.java ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/BooleanConditionESQueryBuilder.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/BooleanConditionESQueryBuilder.java index c41309b..d69d939 100644 --- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/BooleanConditionESQueryBuilder.java +++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/BooleanConditionESQueryBuilder.java @@ -47,7 +47,7 @@ public class BooleanConditionESQueryBuilder implements ConditionESQueryBuilder { FilterBuilder[] l = new FilterBuilder[conditionCount]; for (int i = 0; i < conditionCount; i++) { - l[i] = dispatcher.buildFilter(conditions.get(i)); + l[i] = dispatcher.buildFilter(conditions.get(i), context); } return isAndOperator ? FilterBuilders.andFilter(l) : FilterBuilders.orFilter(l); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 125d52a..73144ec 100644 --- a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -22,6 +22,7 @@ <reference id="definitionsService" interface="org.apache.unomi.api.services.DefinitionsService"/> <reference id="persistenceService" interface="org.apache.unomi.persistence.spi.PersistenceService"/> <reference id="profileService" interface="org.apache.unomi.api.services.ProfileService"/> + <reference id="privacyService" interface="org.apache.unomi.api.services.PrivacyService"/> <reference id="segmentService" interface="org.apache.unomi.api.services.SegmentService"/> <reference id="eventService" interface="org.apache.unomi.api.services.EventService"/> @@ -149,6 +150,7 @@ </service-properties> <bean class="org.apache.unomi.plugins.baseplugin.actions.AllEventToProfilePropertiesAction"> <property name="profileService" ref="profileService"/> + <property name="privacyService" ref="privacyService"/> </bean> </service> @@ -156,14 +158,18 @@ <service-properties> <entry key="actionExecutorId" value="eventToProfileProperty"/> </service-properties> - <bean class="org.apache.unomi.plugins.baseplugin.actions.EventToProfilePropertyAction"/> + <bean class="org.apache.unomi.plugins.baseplugin.actions.EventToProfilePropertyAction"> + <property name="privacyService" ref="privacyService"/> + </bean> </service> <service auto-export="interfaces"> <service-properties> <entry key="actionExecutorId" value="setProperty"/> </service-properties> - <bean class="org.apache.unomi.plugins.baseplugin.actions.SetPropertyAction"/> + <bean class="org.apache.unomi.plugins.baseplugin.actions.SetPropertyAction"> + <property name="privacyService" ref="privacyService"/> + </bean> </service> <service auto-export="interfaces"> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index db4e1dd..24ee5c2 100644 --- a/pom.xml +++ b/pom.xml @@ -827,8 +827,6 @@ <module>plugins</module> <module>extensions</module> <module>kar</module> - <module>samples</module> - <module>package</module> </modules> <dependencies> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java index 521826e..bc716fb 100644 --- a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java @@ -249,10 +249,7 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList } public long getAllProfilesCount() { - Condition condition = new Condition(definitionsService.getConditionType("profilePropertyCondition")); - condition.setParameter("propertyName", "mergedWith"); - condition.setParameter("comparisonOperator", "missing"); - return persistenceService.queryCount(condition, Profile.ITEM_TYPE); + return persistenceService.getAllItemsCount(Profile.ITEM_TYPE); } public <T extends Profile> PartialList<T> search(Query query, final Class<T> clazz) { http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java index c82aad2..85c6dc3 100644 --- a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java @@ -418,7 +418,12 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList if (segment == null) { return new PartialList<Profile>(); } - return persistenceService.query(segment.getCondition(), sortBy, Profile.class, offset, size); + Condition segmentCondition = new Condition(definitionsService.getConditionType("profilePropertyCondition")); + segmentCondition.setParameter("propertyName", "segments"); + segmentCondition.setParameter("comparisonOperator", "equals"); + segmentCondition.setParameter("propertyValue", segmentID); + + return persistenceService.query(segmentCondition, sortBy, Profile.class, offset, size); } public long getMatchingIndividualsCount(String segmentID) { @@ -426,14 +431,12 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList return 0; } - Condition excludeMergedProfilesCondition = new Condition(definitionsService.getConditionType("profilePropertyCondition")); - excludeMergedProfilesCondition.setParameter("propertyName", "mergedWith"); - excludeMergedProfilesCondition.setParameter("comparisonOperator", "missing"); - Condition condition = new Condition(definitionsService.getConditionType("booleanCondition")); - condition.setParameter("operator", "and"); - condition.setParameter("subConditions", Arrays.asList(getSegmentDefinition(segmentID).getCondition(), excludeMergedProfilesCondition)); + Condition segmentCondition = new Condition(definitionsService.getConditionType("profilePropertyCondition")); + segmentCondition.setParameter("propertyName", "segments"); + segmentCondition.setParameter("comparisonOperator", "equals"); + segmentCondition.setParameter("propertyValue", segmentID); - return persistenceService.queryCount(condition, Profile.ITEM_TYPE); + return persistenceService.queryCount(segmentCondition, Profile.ITEM_TYPE); } public Boolean isProfileInSegment(Profile profile, String segmentId) { http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/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 e858e75..5051780 100644 --- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java +++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java @@ -143,7 +143,7 @@ public class ContextServlet extends HttpServlet { if (session != null) { profileId = session.getProfileId(); profile = profileService.load(profileId); - profile = checkMergedProfile(response, profile, session); + profile = checkMergedOrAnonymizedProfile(response, profile, session); } } if (profile == null) { @@ -161,7 +161,7 @@ public class ContextServlet extends HttpServlet { profileCreated = true; HttpUtils.sendProfileCookie(profile, response, profileIdCookieName, profileIdCookieDomain); } else { - profile = checkMergedProfile(response, profile, session); + profile = checkMergedOrAnonymizedProfile(response, profile, session); } } } else if ((cookieProfileId == null || !cookieProfileId.equals(profile.getItemId())) && !profile.isAnonymousProfile()) { @@ -198,9 +198,11 @@ public class ContextServlet extends HttpServlet { data.setProfileId(profile.isAnonymousProfile() ? cookieProfileId : profile.getItemId()); if (privacyService.isRequireAnonymousBrowsing(profile.getItemId())) { - profile = privacyService.getAnonymousProfile(); - session.setProfile(profile); - changes = EventService.SESSION_UPDATED; + if (!session.getProfile().isAnonymousProfile()) { + profile = privacyService.getAnonymousProfile(profile); + session.setProfile(profile); + changes = EventService.SESSION_UPDATED; + } } if(contextRequest != null){ @@ -239,10 +241,9 @@ public class ContextServlet extends HttpServlet { responseWriter.flush(); } - private Profile checkMergedProfile(ServletResponse response, Profile profile, Session session) { - String profileId; + private Profile checkMergedOrAnonymizedProfile(ServletResponse response, Profile profile, Session session) { if (profile != null && profile.getMergedWith() != null && !profile.isAnonymousProfile()) { - profileId = profile.getMergedWith(); + String profileId = profile.getMergedWith(); Profile profileToDelete = profile; profile = profileService.load(profileId); if (profile != null) { @@ -259,6 +260,16 @@ public class ContextServlet extends HttpServlet { profileService.save(profile); } } + if (profile != null && !profile.isAnonymousProfile() && privacyService.isRequireAnonymousBrowsing(profile.getItemId())) { + if (session == null || !session.getProfile().isAnonymousProfile()) { + profile = privacyService.getAnonymousProfile(profile); + if (session != null) { + session.setProfile(profile); + profileService.saveSession(session); + } + } + } + return profile; } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/685f67ff/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java ---------------------------------------------------------------------- diff --git a/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java b/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java index cf27e0a..8d2cb3b 100644 --- a/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java +++ b/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java @@ -128,7 +128,7 @@ public class EventsCollectorServlet extends HttpServlet { int changes = 0; if (privacyService.isRequireAnonymousBrowsing(profile.getItemId())) { - profile = privacyService.getAnonymousProfile(); + profile = privacyService.getAnonymousProfile(profile); session.setProfile(profile); changes = EventService.SESSION_UPDATED; }
