UNOMI-39 - send anonymous flag in context, added parameter in rest api
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/3f135d67 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/3f135d67 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/3f135d67 Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE Commit: 3f135d67156dd8741baa03a77d2e5224cbe7787e Parents: 94c27c0 Author: Thomas Draier <[email protected]> Authored: Mon Aug 22 17:58:30 2016 +0200 Committer: Thomas Draier <[email protected]> Committed: Mon Aug 22 17:58:30 2016 +0200 ---------------------------------------------------------------------- .../org/apache/unomi/api/ContextResponse.java | 18 ++++++++++++++++++ .../privacy/rest/PrivacyServiceEndPoint.java | 5 ++++- .../java/org/apache/unomi/web/ContextServlet.java | 17 ++++++++++++----- 3 files changed, 34 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/3f135d67/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 823cb25..b0a871c 100644 --- a/api/src/main/java/org/apache/unomi/api/ContextResponse.java +++ b/api/src/main/java/org/apache/unomi/api/ContextResponse.java @@ -48,6 +48,8 @@ public class ContextResponse implements Serializable { private Set<Condition> trackedConditions; + private boolean anonymousBrowsing; + /** * Retrieves the profile identifier associated with the profile of the user on behalf of which the client performed the context request. * @@ -185,4 +187,20 @@ public class ContextResponse implements Serializable { public void setTrackedConditions(Set<Condition> trackedConditions) { this.trackedConditions = trackedConditions; } + + /** + * Retrieves the current status of anonymous browsing, as set by the privacy service + * @return anonymous browsing status + */ + public boolean isAnonymousBrowsing() { + return anonymousBrowsing; + } + + /** + * Set the user anonymous browsing status + * @param anonymousBrowsing + */ + public void setAnonymousBrowsing(boolean anonymousBrowsing) { + this.anonymousBrowsing = anonymousBrowsing; + } } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/3f135d67/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 4964275..154f443 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 @@ -78,7 +78,10 @@ public class PrivacyServiceEndPoint { @POST @Path("/profiles/{profileId}/anonymousBrowsing") - public Response activateAnonymousBrowsing(@PathParam("profileId") String profileId) { + public Response activateAnonymousBrowsing(@PathParam("profileId") String profileId, @QueryParam("anonymizePastBrowsing") @DefaultValue("false") boolean past) { + if (past) { + privacyService.anonymizeBrowsingData(profileId); + } Boolean r = privacyService.setRequireAnonymousBrowsing(profileId, true); return r ? Response.ok().build() : Response.serverError().build(); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/3f135d67/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 7cb6c5d..c8987b6 100644 --- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java +++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java @@ -156,24 +156,29 @@ public class ContextServlet extends HttpServlet { session = profileService.loadSession(sessionId, timestamp); if (session != null) { sessionProfile = session.getProfile(); - if (!profile.isAnonymousProfile() && !sessionProfile.isAnonymousProfile() && !profile.getItemId().equals(sessionProfile.getItemId())) { + boolean anonymousProfile = sessionProfile.isAnonymousProfile(); + + if (!profile.isAnonymousProfile() && !anonymousProfile && !profile.getItemId().equals(sessionProfile.getItemId())) { // Session user has been switched, profile id in cookie is not uptodate profile = sessionProfile; HttpUtils.sendProfileCookie(profile, response, profileIdCookieName, profileIdCookieDomain); } - if (privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && sessionProfile.isAnonymousProfile()) { + + Boolean requireAnonymousBrowsing = privacyService.isRequireAnonymousBrowsing(profile.getItemId()); + + if (requireAnonymousBrowsing && anonymousProfile) { // User wants to browse anonymously, anonymous profile is already set. - } else if (privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && !sessionProfile.isAnonymousProfile()) { + } else if (requireAnonymousBrowsing && !anonymousProfile) { // User wants to browse anonymously, update the sessionProfile to anonymous profile sessionProfile = privacyService.getAnonymousProfile(profile); session.setProfile(sessionProfile); changes = EventService.SESSION_UPDATED; - } else if (!privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && sessionProfile.isAnonymousProfile()) { + } else if (!requireAnonymousBrowsing && anonymousProfile) { // User does not want to browse anonymously anymore, update the sessionProfile to real profile sessionProfile = profile; session.setProfile(sessionProfile); changes = EventService.SESSION_UPDATED; - } else if (!privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && !sessionProfile.isAnonymousProfile()) { + } else if (!requireAnonymousBrowsing && !anonymousProfile) { // User does not want to browse anonymously, use the real profile. Check that session contains the current profile. sessionProfile = profile; if (!session.getProfileId().equals(sessionProfile.getItemId())) { @@ -351,6 +356,8 @@ public class ContextServlet extends HttpServlet { data.setTrackedConditions(Collections.<Condition>emptySet()); } + data.setAnonymousBrowsing(privacyService.isRequireAnonymousBrowsing(profile.getItemId())); + return changes; }
