You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2016/09/21 11:55:42 UTC

[01/16] incubator-unomi git commit: UNOMI-48: Add/improve validation done at scoring/segment deletion

Repository: incubator-unomi
Updated Branches:
  refs/heads/UNOMI-28-ES-2-X-UPGRADE 3ebc65be1 -> 12641b9b3


UNOMI-48: Add/improve validation done at scoring/segment deletion


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/30a51a23
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/30a51a23
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/30a51a23

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 30a51a23dc73c6c6c794056aeeed2108c146bc60
Parents: 1c5d74a
Author: Quentin Lamerand <ql...@jahia.com>
Authored: Fri Aug 12 16:15:56 2016 +0200
Committer: Quentin Lamerand <ql...@jahia.com>
Committed: Fri Aug 12 16:15:56 2016 +0200

----------------------------------------------------------------------
 .../unomi/api/segments/DependentMetadata.java   |  53 +++++
 .../unomi/api/services/SegmentService.java      |  41 ++--
 .../cxs/conditions/scoringCondition.json        |  40 ++++
 .../unomi/rest/ScoringServiceEndPoint.java      |  29 ++-
 .../unomi/rest/SegmentServiceEndPoint.java      |  23 +-
 .../services/services/SegmentServiceImpl.java   | 230 ++++++++++++++++---
 6 files changed, 358 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/30a51a23/api/src/main/java/org/apache/unomi/api/segments/DependentMetadata.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/segments/DependentMetadata.java b/api/src/main/java/org/apache/unomi/api/segments/DependentMetadata.java
new file mode 100644
index 0000000..a6693f3
--- /dev/null
+++ b/api/src/main/java/org/apache/unomi/api/segments/DependentMetadata.java
@@ -0,0 +1,53 @@
+/*
+ * 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.segments;
+
+import org.apache.unomi.api.Metadata;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+import java.util.List;
+
+@XmlRootElement
+public class DependentMetadata implements Serializable {
+
+    private List<Metadata> segments;
+
+    private List<Metadata> scorings;
+
+    public DependentMetadata(List<Metadata> segments, List<Metadata> scorings) {
+        this.segments = segments;
+        this.scorings = scorings;
+    }
+
+    public List<Metadata> getSegments() {
+        return segments;
+    }
+
+    public void setSegments(List<Metadata> segments) {
+        this.segments = segments;
+    }
+
+    public List<Metadata> getScorings() {
+        return scorings;
+    }
+
+    public void setScorings(List<Metadata> scorings) {
+        this.scorings = scorings;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/30a51a23/api/src/main/java/org/apache/unomi/api/services/SegmentService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/services/SegmentService.java b/api/src/main/java/org/apache/unomi/api/services/SegmentService.java
index 8c1db29..a1affd6 100644
--- a/api/src/main/java/org/apache/unomi/api/services/SegmentService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/SegmentService.java
@@ -22,6 +22,7 @@ import org.apache.unomi.api.Metadata;
 import org.apache.unomi.api.PartialList;
 import org.apache.unomi.api.Profile;
 import org.apache.unomi.api.query.Query;
+import org.apache.unomi.api.segments.DependentMetadata;
 import org.apache.unomi.api.segments.Scoring;
 import org.apache.unomi.api.segments.Segment;
 import org.apache.unomi.api.segments.SegmentsAndScores;
@@ -88,25 +89,23 @@ public interface SegmentService {
     /**
      * Removes the segment definition identified by the specified identifier. We can specify that we want the operation to be validated beforehand so that we can
      * know if any other segment that might use the segment we're trying to delete as a condition might be impacted. If {@code validate} is set to {@code false}, no
-     * validation is performed. If set to {@code true}, we will first check if any segment depends on the one we're trying to delete and if so we will not delete the
-     * segment but rather return the list of the metadata of the impacted segments. If no dependents are found, then we properly delete the segment.
+     * validation is performed. If set to {@code true}, we will first check if any segment or scoring depends on the segment we're trying to delete and if so we will not delete the
+     * segment but rather return the list of the metadata of the impacted items. If no dependents are found, then we properly delete the segment.
      *
      * @param segmentId the identifier of the segment we want to delete
      * @param validate  whether or not to perform validation
-     * @return a list of impacted segment metadata if any or an empty list if no such impacted segments are found or validation was skipped
+     * @return a list of impacted segment metadata if any or an empty list if none were found or validation was skipped
      */
-    List<Metadata> removeSegmentDefinition(String segmentId, boolean validate);
+    DependentMetadata removeSegmentDefinition(String segmentId, boolean validate);
 
     /**
-     * Retrieves the list of segment metadata of segments depending on the segment identified by the specified identifier. A segment is depending on another one if it includes
-     * that segment as part of its condition for profile matching.
+     * Retrieves the list of Segment and Scoring metadata depending on the specified segment.
+     * A segment or scoring is depending on a segment if it includes a profileSegmentCondition with a test on this segment.
      *
-     * TODO: Rename to something clearer, maybe getDependentSegmentMetadata?
-     *
-     * @param segmentId the identifier of the segment which impact we want to evaluate
-     * @return a list of metadata of segments depending on the specified segment
+     * @param segmentId the segment identifier
+     * @return a list of Segment/Scoring Metadata depending on the specified segment
      */
-    List<Metadata> getImpactedSegmentMetadata(String segmentId);
+    DependentMetadata getSegmentDependentMetadata(String segmentId);
 
     /**
      * Retrieves a list of profiles matching the conditions defined by the segment identified by the specified identifier, ordered according to the specified {@code sortBy}
@@ -197,10 +196,24 @@ public interface SegmentService {
     void createScoringDefinition(String scope, String scoringId, String name, String description);
 
     /**
-     * Deletes the scoring identified by the specified identifier from the context server.
+     * Removes the scoring definition identified by the specified identifier. We can specify that we want the operation to be validated beforehand so that we can
+     * know if any other segment that might use the segment we're trying to delete as a condition might be impacted. If {@code validate} is set to {@code false}, no
+     * validation is performed. If set to {@code true}, we will first check if any segment or scoring depends on the scoring we're trying to delete and if so we will not delete the
+     * scoring but rather return the list of the metadata of the impacted items. If no dependents are found, then we properly delete the scoring.
+     *
+     * @param scoringId the identifier of the scoring we want to delete
+     * @param validate  whether or not to perform validation
+     * @return a list of impacted items metadata if any or an empty list if none were found or validation was skipped
+     */
+    DependentMetadata removeScoringDefinition(String scoringId, boolean validate);
+
+    /**
+     * Retrieves the list of Segment and Scoring metadata depending on the specified scoring.
+     * A segment or scoring is depending on a segment if it includes a scoringCondition with a test on this scoring.
      *
-     * @param scoringId the identifier of the scoring to be deleted
+     * @param scoringId the segment identifier
+     * @return a list of Segment/Scoring Metadata depending on the specified scoring
      */
-    void removeScoringDefinition(String scoringId);
+    DependentMetadata getScoringDependentMetadata(String scoringId);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/30a51a23/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/scoringCondition.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/scoringCondition.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/scoringCondition.json
new file mode 100644
index 0000000..6ef37fc
--- /dev/null
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/scoringCondition.json
@@ -0,0 +1,40 @@
+{
+  "metadata": {
+    "id": "scoringCondition",
+    "name": "scoringCondition",
+    "description": "",
+    "tags": [
+      "aggregated",
+      "profileCondition"
+    ],
+    "readOnly": true
+  },
+  "parentCondition": {
+    "type": "profilePropertyCondition",
+    "parameterValues": {
+      "propertyName": "script::'scores.'+scoringPlanId",
+      "propertyValueInteger": "parameter::scoreValue",
+      "comparisonOperator": "parameter::comparisonOperator"
+    }
+  },
+  "parameters": [
+    {
+      "id": "scoringPlanId",
+      "type": "string",
+      "multivalued": false,
+      "defaultValue": ""
+    },
+    {
+      "id": "scoreValue",
+      "type": "integer",
+      "multivalued": false,
+      "defaultValue": 0
+    },
+    {
+      "id": "comparisonOperator",
+      "type": "string",
+      "multivalued": false,
+      "defaultValue": "greaterThanOrEqualTo"
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/30a51a23/rest/src/main/java/org/apache/unomi/rest/ScoringServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/rest/src/main/java/org/apache/unomi/rest/ScoringServiceEndPoint.java b/rest/src/main/java/org/apache/unomi/rest/ScoringServiceEndPoint.java
index 0865b8d..e8307bd 100644
--- a/rest/src/main/java/org/apache/unomi/rest/ScoringServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/ScoringServiceEndPoint.java
@@ -22,6 +22,7 @@ import org.apache.unomi.api.Item;
 import org.apache.unomi.api.Metadata;
 import org.apache.unomi.api.PartialList;
 import org.apache.unomi.api.query.Query;
+import org.apache.unomi.api.segments.DependentMetadata;
 import org.apache.unomi.api.segments.Scoring;
 import org.apache.unomi.api.services.SegmentService;
 
@@ -117,14 +118,32 @@ public class ScoringServiceEndPoint {
     }
 
     /**
-     * Deletes the scoring identified by the specified identifier from the context server.
+     * Removes the scoring definition identified by the specified identifier. We can specify that we want the operation to be validated beforehand so that we can
+     * know if any other segment that might use the segment we're trying to delete as a condition might be impacted. If {@code validate} is set to {@code false}, no
+     * validation is performed. If set to {@code true}, we will first check if any segment or scoring depends on the scoring we're trying to delete and if so we will not delete the
+     * scoring but rather return the list of the metadata of the impacted items. If no dependents are found, then we properly delete the scoring.
      *
-     * @param scoringId the identifier of the scoring to be deleted
+     * @param scoringId the identifier of the scoring we want to delete
+     * @param validate  whether or not to perform validation
+     * @return a list of impacted items metadata if any or an empty list if none were found or validation was skipped
      */
-    @DELETE
+   @DELETE
     @Path("/{scoringID}")
-    public void removeScoringDefinition(@PathParam("scoringID") String scoringId) {
-        segmentService.removeScoringDefinition(scoringId);
+    public DependentMetadata removeScoringDefinition(@PathParam("scoringID") String scoringId, @QueryParam("validate") boolean validate) {
+        return segmentService.removeScoringDefinition(scoringId, validate);
+    }
+
+    /**
+     * Retrieves the list of Segment and Scoring metadata depending on the specified scoring.
+     * A segment or scoring is depending on a segment if it includes a scoringCondition with a test on this scoring.
+     *
+     * @param scoringId the segment identifier
+     * @return a list of Segment/Scoring Metadata depending on the specified scoring
+     */
+    @GET
+    @Path("/{scoringID}/impacted")
+    public DependentMetadata getScoringDependentMetadata(@PathParam("scoringID") String scoringId) {
+        return segmentService.getScoringDependentMetadata(scoringId);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/30a51a23/rest/src/main/java/org/apache/unomi/rest/SegmentServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/rest/src/main/java/org/apache/unomi/rest/SegmentServiceEndPoint.java b/rest/src/main/java/org/apache/unomi/rest/SegmentServiceEndPoint.java
index c74c370..7c1e573 100644
--- a/rest/src/main/java/org/apache/unomi/rest/SegmentServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/SegmentServiceEndPoint.java
@@ -22,6 +22,7 @@ import org.apache.unomi.api.Metadata;
 import org.apache.unomi.api.PartialList;
 import org.apache.unomi.api.Profile;
 import org.apache.unomi.api.query.Query;
+import org.apache.unomi.api.segments.DependentMetadata;
 import org.apache.unomi.api.segments.Segment;
 import org.apache.unomi.api.services.SegmentService;
 
@@ -110,18 +111,16 @@ public class SegmentServiceEndPoint {
     }
 
     /**
-     * Retrieves the list of segment metadata of segments depending on the segment identified by the specified identifier. A segment is depending on another one if it includes
-     * that segment as part of its condition for profile matching.
+     * Retrieves the list of Segment and Scoring metadata depending on the specified segment.
+     * A segment or scoring is depending on a segment if it includes a profileSegmentCondition with a test on this segment.
      *
-     * TODO: rename?
-     *
-     * @param segmentId the identifier of the segment which impact we want to evaluate
-     * @return a list of metadata of segments depending on the specified segment
+     * @param segmentId the segment identifier
+     * @return a list of Segment/Scoring Metadata depending on the specified segment
      */
     @GET
     @Path("/{segmentID}/impacted")
-    public List<Metadata> getSegmentImpacted(@PathParam("segmentID") String segmentId) {
-        return segmentService.getImpactedSegmentMetadata(segmentId);
+    public DependentMetadata getSegmentDependentMetadata(@PathParam("segmentID") String segmentId) {
+        return segmentService.getSegmentDependentMetadata(segmentId);
     }
 
     /**
@@ -162,16 +161,16 @@ public class SegmentServiceEndPoint {
     /**
      * Removes the segment definition identified by the specified identifier. We can specify that we want the operation to be validated beforehand so that we can
      * know if any other segment that might use the segment we're trying to delete as a condition might be impacted. If {@code validate} is set to {@code false}, no
-     * validation is performed. If set to {@code true}, we will first check if any segment depends on the one we're trying to delete and if so we will not delete the
-     * segment but rather return the list of the metadata of the impacted segments. If no dependents are found, then we properly delete the segment.
+     * validation is performed. If set to {@code true}, we will first check if any segment or scoring depends on the segment we're trying to delete and if so we will not delete the
+     * segment but rather return the list of the metadata of the impacted items. If no dependents are found, then we properly delete the segment.
      *
      * @param segmentId the identifier of the segment we want to delete
      * @param validate  whether or not to perform validation
-     * @return a list of impacted segment metadata if any or an empty list if no such impacted segments are found or validation was skipped
+     * @return a list of impacted segment metadata if any or an empty list if none were found or validation was skipped
      */
     @DELETE
     @Path("/{segmentID}")
-    public List<Metadata> removeSegmentDefinition(@PathParam("segmentID") String segmentId, @QueryParam("validate") boolean validate) {
+    public DependentMetadata removeSegmentDefinition(@PathParam("segmentID") String segmentId, @QueryParam("validate") boolean validate) {
         return segmentService.removeSegmentDefinition(segmentId, validate);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/30a51a23/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 6149f62..bd68971 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
@@ -21,13 +21,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import org.apache.unomi.api.*;
 import org.apache.unomi.api.actions.Action;
 import org.apache.unomi.api.conditions.Condition;
-import org.apache.unomi.api.conditions.ConditionType;
 import org.apache.unomi.api.query.Query;
 import org.apache.unomi.api.rules.Rule;
-import org.apache.unomi.api.segments.Scoring;
-import org.apache.unomi.api.segments.ScoringElement;
-import org.apache.unomi.api.segments.Segment;
-import org.apache.unomi.api.segments.SegmentsAndScores;
+import org.apache.unomi.api.segments.*;
 import org.apache.unomi.api.services.DefinitionsService;
 import org.apache.unomi.api.services.EventService;
 import org.apache.unomi.api.services.RulesService;
@@ -253,23 +249,26 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
         updateExistingProfilesForSegment(segment);
     }
 
-    private void checkIfSegmentIsImpacted(Segment segment, Condition condition, String segmentToDeleteId, Set<Segment> impactedSegments) {
+    private boolean checkSegmentDeletionImpact(Condition condition, String segmentToDeleteId) {
         if(condition != null) {
             @SuppressWarnings("unchecked")
             final List<Condition> subConditions = (List<Condition>) condition.getParameter("subConditions");
             if (subConditions != null) {
                 for (Condition subCondition : subConditions) {
-                    checkIfSegmentIsImpacted(segment, subCondition, segmentToDeleteId, impactedSegments);
+                    if (checkSegmentDeletionImpact(subCondition, segmentToDeleteId)) {
+                        return true;
+                    }
                 }
             } else if ("profileSegmentCondition".equals(condition.getConditionTypeId())) {
                 @SuppressWarnings("unchecked")
                 final List<String> referencedSegmentIds = (List<String>) condition.getParameter("segments");
 
                 if (referencedSegmentIds.indexOf(segmentToDeleteId) >= 0) {
-                    impactedSegments.add(segment);
+                    return true;
                 }
             }
         }
+        return false;
     }
 
     /**
@@ -280,13 +279,13 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
      * @param segmentId the segment id to remove in the condition
      * @return updated condition
      */
-    private Condition updateImpactedCondition(Condition condition, String segmentId) {
+    private Condition updateSegmentDependentCondition(Condition condition, String segmentId) {
         if ("booleanCondition".equals(condition.getConditionTypeId())) {
             @SuppressWarnings("unchecked")
             final List<Condition> subConditions = (List<Condition>) condition.getParameter("subConditions");
             List<Condition> updatedSubConditions = new LinkedList<>();
             for (Condition subCondition : subConditions) {
-                Condition updatedCondition = updateImpactedCondition(subCondition, segmentId);
+                Condition updatedCondition = updateSegmentDependentCondition(subCondition, segmentId);
                 if(updatedCondition != null) {
                     updatedSubConditions.add(updatedCondition);
                 }
@@ -316,26 +315,45 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
         return condition;
     }
 
-    private Set<Segment> getImpactedSegments(String segmentId) {
+    private Set<Segment> getSegmentDependentSegments(String segmentId) {
         Set<Segment> impactedSegments = new HashSet<>(this.allSegments.size());
         for (Segment segment : this.allSegments) {
-            checkIfSegmentIsImpacted(segment, segment.getCondition(), segmentId, impactedSegments);
+            if (checkSegmentDeletionImpact(segment.getCondition(), segmentId)) {
+                impactedSegments.add(segment);
+            }
         }
         return impactedSegments;
     }
 
-    public List<Metadata> getImpactedSegmentMetadata(String segmentId) {
-        List<Metadata> details = new LinkedList<>();
-        for (Segment definition : getImpactedSegments(segmentId)) {
-            details.add(definition.getMetadata());
+    private Set<Scoring> getSegmentDependentScorings(String segmentId) {
+        Set<Scoring> impactedScoring = new HashSet<>(this.allScoring.size());
+        for (Scoring scoring : this.allScoring) {
+            for (ScoringElement element : scoring.getElements()) {
+                if (checkSegmentDeletionImpact(element.getCondition(), segmentId)) {
+                    impactedScoring.add(scoring);
+                    break;
+                }
+            }
         }
+        return impactedScoring;
+    }
 
-        return details;
+    public DependentMetadata getSegmentDependentMetadata(String segmentId) {
+        List<Metadata> segments = new LinkedList<>();
+        List<Metadata> scorings = new LinkedList<>();
+        for (Segment definition : getSegmentDependentSegments(segmentId)) {
+            segments.add(definition.getMetadata());
+        }
+        for (Scoring definition : getSegmentDependentScorings(segmentId)) {
+            scorings.add(definition.getMetadata());
+        }
+        return new DependentMetadata(segments, scorings);
     }
 
-    public List<Metadata> removeSegmentDefinition(String segmentId, boolean validate) {
-        Set<Segment> impactedSegments = getImpactedSegments(segmentId);
-        if (!validate || impactedSegments.isEmpty()) {
+    public DependentMetadata removeSegmentDefinition(String segmentId, boolean validate) {
+        Set<Segment> impactedSegments = getSegmentDependentSegments(segmentId);
+        Set<Scoring> impactedScorings = getSegmentDependentScorings(segmentId);
+        if (!validate || (impactedSegments.isEmpty() && impactedScorings.isEmpty())) {
             // update profiles
             Condition segmentCondition = new Condition();
             segmentCondition.setConditionType(definitionsService.getConditionType("profilePropertyCondition"));
@@ -351,7 +369,7 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
 
             // update impacted segments
             for (Segment segment : impactedSegments) {
-                Condition updatedCondition = updateImpactedCondition(segment.getCondition(), segmentId);
+                Condition updatedCondition = updateSegmentDependentCondition(segment.getCondition(), segmentId);
                 segment.setCondition(updatedCondition);
                 if(updatedCondition == null) {
                     clearAutoGeneratedRules(persistenceService.query("linkedItems", segment.getMetadata().getId(), null, Rule.class), segment.getMetadata().getId());
@@ -360,16 +378,38 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
                 setSegmentDefinition(segment);
             }
 
+            // update impacted scorings
+            for (Scoring scoring : impactedScorings) {
+                List<ScoringElement> updatedScoringElements = new ArrayList<>();
+                for (ScoringElement scoringElement : scoring.getElements()) {
+                    Condition updatedCondition = updateSegmentDependentCondition(scoringElement.getCondition(), segmentId);
+                    if (updatedCondition != null) {
+                        scoringElement.setCondition(updatedCondition);
+                        updatedScoringElements.add(scoringElement);
+                    }
+                }
+                scoring.setElements(updatedScoringElements);
+                if (updatedScoringElements.isEmpty()) {
+                    clearAutoGeneratedRules(persistenceService.query("linkedItems", scoring.getMetadata().getId(), null, Rule.class), scoring.getMetadata().getId());
+                    scoring.getMetadata().setEnabled(false);
+                }
+                setScoringDefinition(scoring);
+            }
+
             persistenceService.remove(segmentId, Segment.class);
             List<Rule> previousRules = persistenceService.query("linkedItems", segmentId, null, Rule.class);
             clearAutoGeneratedRules(previousRules, segmentId);
         }
 
-        List<Metadata> metadata = new LinkedList<>();
+        List<Metadata> segments = new LinkedList<>();
+        List<Metadata> scorings = new LinkedList<>();
         for (Segment definition : impactedSegments) {
-            metadata.add(definition.getMetadata());
+            segments.add(definition.getMetadata());
+        }
+        for (Scoring definition : impactedScorings) {
+            scorings.add(definition.getMetadata());
         }
-        return metadata;
+        return new DependentMetadata(segments, scorings);
     }
 
 
@@ -504,10 +544,146 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
         setScoringDefinition(scoring);
     }
 
-    public void removeScoringDefinition(String scoringId) {
-        persistenceService.remove(scoringId, Scoring.class);
+    private boolean checkScoringDeletionImpact(Condition condition, String scoringToDeleteId) {
+        if(condition != null) {
+            @SuppressWarnings("unchecked")
+            final List<Condition> subConditions = (List<Condition>) condition.getParameter("subConditions");
+            if (subConditions != null) {
+                for (Condition subCondition : subConditions) {
+                    if (checkScoringDeletionImpact(subCondition, scoringToDeleteId)) {
+                        return true;
+                    }
+                }
+            } else if ("scoringCondition".equals(condition.getConditionTypeId())) {
+                if (scoringToDeleteId.equals(condition.getParameter("scoringPlanId"))) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Return an updated condition that do not contain a condition on the scoringId anymore
+     * it's remove the unnecessary boolean condition (if a condition is the only one of a boolean the boolean will be remove and the subcondition returned)
+     * it's return null when there is no more condition after (if the condition passed was only a scoring condition on the scoringId)
+     * @param condition the condition to update
+     * @param scoringId the scoring id to remove in the condition
+     * @return updated condition
+     */
+    private Condition updateScoringDependentCondition(Condition condition, String scoringId) {
+        if ("booleanCondition".equals(condition.getConditionTypeId())) {
+            @SuppressWarnings("unchecked")
+            final List<Condition> subConditions = (List<Condition>) condition.getParameter("subConditions");
+            List<Condition> updatedSubConditions = new LinkedList<>();
+            for (Condition subCondition : subConditions) {
+                Condition updatedCondition = updateScoringDependentCondition(subCondition, scoringId);
+                if(updatedCondition != null) {
+                    updatedSubConditions.add(updatedCondition);
+                }
+            }
+            if(!updatedSubConditions.isEmpty()){
+                if(updatedSubConditions.size() == 1) {
+                    return updatedSubConditions.get(0);
+                } else {
+                    condition.setParameter("subConditions", updatedSubConditions);
+                    return condition;
+                }
+            } else {
+                return null;
+            }
+        } else if ("scoringCondition".equals(condition.getConditionTypeId())
+                && scoringId.equals(condition.getParameter("scoringPlanId"))) {
+            return null;
+        }
+        return condition;
+    }
+
+    private Set<Segment> getScoringDependentSegments(String scoringId) {
+        Set<Segment> impactedSegments = new HashSet<>(this.allSegments.size());
+        for (Segment segment : this.allSegments) {
+            if (checkScoringDeletionImpact(segment.getCondition(), scoringId)) {
+                impactedSegments.add(segment);
+            }
+        }
+        return impactedSegments;
+    }
+
+    private Set<Scoring> getScoringDependentScorings(String scoringId) {
+        Set<Scoring> impactedScoring = new HashSet<>(this.allScoring.size());
+        for (Scoring scoring : this.allScoring) {
+            for (ScoringElement element : scoring.getElements()) {
+                if (checkScoringDeletionImpact(element.getCondition(), scoringId)) {
+                    impactedScoring.add(scoring);
+                    break;
+                }
+            }
+        }
+        return impactedScoring;
+    }
+
+    public DependentMetadata getScoringDependentMetadata(String scoringId) {
+        List<Metadata> segments = new LinkedList<>();
+        List<Metadata> scorings = new LinkedList<>();
+        for (Segment definition : getScoringDependentSegments(scoringId)) {
+            segments.add(definition.getMetadata());
+        }
+        for (Scoring definition : getScoringDependentScorings(scoringId)) {
+            scorings.add(definition.getMetadata());
+        }
+        return new DependentMetadata(segments, scorings);
+    }
+
+    public DependentMetadata removeScoringDefinition(String scoringId, boolean validate) {
+        Set<Segment> impactedSegments = getScoringDependentSegments(scoringId);
+        Set<Scoring> impactedScorings = getScoringDependentScorings(scoringId);
+        if (!validate || (impactedSegments.isEmpty() && impactedScorings.isEmpty())) {
+            // update profiles
+            updateExistingProfilesForRemovedScoring(scoringId);
+
+            // update impacted segments
+            for (Segment segment : impactedSegments) {
+                Condition updatedCondition = updateScoringDependentCondition(segment.getCondition(), scoringId);
+                segment.setCondition(updatedCondition);
+                if(updatedCondition == null) {
+                    clearAutoGeneratedRules(persistenceService.query("linkedItems", segment.getMetadata().getId(), null, Rule.class), segment.getMetadata().getId());
+                    segment.getMetadata().setEnabled(false);
+                }
+                setSegmentDefinition(segment);
+            }
+
+            // update impacted scorings
+            for (Scoring scoring : impactedScorings) {
+                List<ScoringElement> updatedScoringElements = new ArrayList<>();
+                for (ScoringElement scoringElement : scoring.getElements()) {
+                    Condition updatedCondition = updateScoringDependentCondition(scoringElement.getCondition(), scoringId);
+                    if (updatedCondition != null) {
+                        scoringElement.setCondition(updatedCondition);
+                        updatedScoringElements.add(scoringElement);
+                    }
+                }
+                scoring.setElements(updatedScoringElements);
+                if (updatedScoringElements.isEmpty()) {
+                    clearAutoGeneratedRules(persistenceService.query("linkedItems", scoring.getMetadata().getId(), null, Rule.class), scoring.getMetadata().getId());
+                    scoring.getMetadata().setEnabled(false);
+                }
+                setScoringDefinition(scoring);
+            }
+
+            persistenceService.remove(scoringId, Scoring.class);
+            List<Rule> previousRules = persistenceService.query("linkedItems", scoringId, null, Rule.class);
+            clearAutoGeneratedRules(previousRules, scoringId);
+        }
 
-        updateExistingProfilesForRemovedScoring(scoringId);
+        List<Metadata> segments = new LinkedList<>();
+        List<Metadata> scorings = new LinkedList<>();
+        for (Segment definition : impactedSegments) {
+            segments.add(definition.getMetadata());
+        }
+        for (Scoring definition : impactedScorings) {
+            scorings.add(definition.getMetadata());
+        }
+        return new DependentMetadata(segments, scorings);
     }
 
     public void updateAutoGeneratedRules(Metadata metadata, Condition condition) {


[16/16] incubator-unomi git commit: Fix NPE in monthly index creation

Posted by sh...@apache.org.
Fix NPE in monthly index creation


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/12641b9b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/12641b9b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/12641b9b

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 12641b9b3e72b130a5f05062680238cd4ca8a15f
Parents: 91c9c20
Author: Serge Huber <sh...@apache.org>
Authored: Wed Sep 21 13:55:25 2016 +0200
Committer: Serge Huber <sh...@apache.org>
Committed: Wed Sep 21 13:55:25 2016 +0200

----------------------------------------------------------------------
 .../elasticsearch/ElasticSearchPersistenceServiceImpl.java  | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/12641b9b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 34c0d9f..b5f1c7a 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -572,8 +572,13 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
                         indexBuilder.execute().actionGet();
                     } catch (IndexNotFoundException e) {
                         if (itemsMonthlyIndexed.contains(itemType)) {
-                            getMonthlyIndex(((TimestampedItem) item).getTimeStamp(), true);
-                            indexBuilder.execute().actionGet();
+                            Date timeStamp = ((TimestampedItem) item).getTimeStamp();
+                            if (timeStamp != null) {
+                                getMonthlyIndex(timeStamp, true);
+                                indexBuilder.execute().actionGet();
+                            } else {
+                                logger.warn("Missing time stamp on item " + item + " id=" + item.getItemId() + " can't create related monthly index !");
+                            }
                         }
                     }
                     return true;


[10/16] incubator-unomi git commit: Restored package compilation

Posted by sh...@apache.org.
Restored package compilation


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/6f46c923
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/6f46c923
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/6f46c923

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 6f46c9238c581a6d788edfbbd01c846f013d26c5
Parents: 3f135d6
Author: Thomas Draier <dr...@apache.org>
Authored: Thu Aug 25 16:52:42 2016 +0200
Committer: Thomas Draier <dr...@apache.org>
Committed: Thu Aug 25 16:52:42 2016 +0200

----------------------------------------------------------------------
 pom.xml | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/6f46c923/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 24ee5c2..db4e1dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -827,6 +827,8 @@
         <module>plugins</module>
         <module>extensions</module>
         <module>kar</module>
+        <module>samples</module>
+        <module>package</module>
     </modules>
 
     <dependencies>


[09/16] incubator-unomi git commit: UNOMI-39 - send anonymous flag in context, added parameter in rest api

Posted by sh...@apache.org.
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 <dr...@apache.org>
Authored: Mon Aug 22 17:58:30 2016 +0200
Committer: Thomas Draier <dr...@apache.org>
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;
     }
 


[05/16] incubator-unomi git commit: UNOMI-50 add entry point to query sessions in ProfileServiceEndPoint

Posted by sh...@apache.org.
UNOMI-50 add entry point to query sessions in ProfileServiceEndPoint


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/eee8d6f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/eee8d6f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/eee8d6f5

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: eee8d6f5585dc58b96462217cec4abe4f6cb71ba
Parents: 7e372f3
Author: dgaillard <dg...@jahia.com>
Authored: Wed Aug 17 17:56:01 2016 +0200
Committer: dgaillard <dg...@jahia.com>
Committed: Wed Aug 17 17:56:01 2016 +0200

----------------------------------------------------------------------
 .../org/apache/unomi/api/services/ProfileService.java    |  8 ++++++++
 .../org/apache/unomi/rest/ProfileServiceEndPoint.java    | 11 +++++++++++
 .../unomi/services/services/ProfileServiceImpl.java      |  8 ++++++++
 3 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/eee8d6f5/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
index ff48abf..c13036a 100644
--- a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
@@ -46,6 +46,14 @@ public interface ProfileService {
     <T extends Profile> PartialList<T> search(Query query, Class<T> clazz);
 
     /**
+     * Retrieves sessions matching the specified query.
+     *
+     * @param query a {@link Query} specifying which elements to retrieve
+     * @return a {@link PartialList} of sessions matching the specified query
+     */
+    PartialList<Session> searchSessions(Query query);
+
+    /**
      * Creates a String containing comma-separated values (CSV) formatted version of profiles matching the specified query.
      *
      * @param query the query specifying which profiles to export

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/eee8d6f5/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java b/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
index 43028fe..b806378 100644
--- a/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
@@ -516,4 +516,15 @@ public class ProfileServiceEndPoint {
         return profileService.deletePropertyType(propertyId);
     }
 
+    /**
+     * Retrieves sessions matching the specified query.
+     *
+     * @param query a {@link Query} specifying which elements to retrieve
+     * @return a {@link PartialList} of sessions matching the specified query
+     */
+    @POST
+    @Path("/search/sessions")
+    public PartialList<Session> searchSession(Query query) {
+        return profileService.searchSessions(query);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/eee8d6f5/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 432e1f6..521826e 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
@@ -256,6 +256,14 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
     }
 
     public <T extends Profile> PartialList<T> search(Query query, final Class<T> clazz) {
+        return doSearch(query, clazz);
+    }
+
+    public PartialList<Session> searchSessions(Query query) {
+        return doSearch(query, Session.class);
+    }
+
+    private <T extends Item> PartialList<T> doSearch(Query query, Class<T> clazz) {
         if (query.getCondition() != null && definitionsService.resolveConditionType(query.getCondition())) {
             if (StringUtils.isNotBlank(query.getText())) {
                 return persistenceService.queryFullText(query.getText(), query.getCondition(), query.getSortby(), clazz, query.getOffset(), query.getLimit());


[03/16] incubator-unomi git commit: UNOMI-51 : Scoring modifiers are ignored when the score value is updated

Posted by sh...@apache.org.
UNOMI-51 : Scoring modifiers are ignored when the score value is updated


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/9df17f70
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/9df17f70
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/9df17f70

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 9df17f70988988fc9dc4a1b7cb7c6826e2fe1a54
Parents: 30a51a2
Author: Abdelkader Midani <am...@jahia.com>
Authored: Wed Aug 10 16:17:04 2016 +0200
Committer: Abdelkader Midani <am...@jahia.com>
Committed: Fri Aug 12 16:29:32 2016 +0200

----------------------------------------------------------------------
 .../org/apache/unomi/services/services/SegmentServiceImpl.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/9df17f70/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 bd68971..c82aad2 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
@@ -851,7 +851,7 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
         scriptParams.put("scoringId", scoring.getItemId());
 
         for (Profile profileToRemove : previousProfiles) {
-            persistenceService.updateWithScript(profileToRemove.getItemId(), null, Profile.class, "ctx._source.scores.remove(scoringId)", scriptParams);
+            persistenceService.updateWithScript(profileToRemove.getItemId(), null, Profile.class, "if (ctx._source.systemProperties.scoreModifiers == null) { ctx._source.systemProperties.scoreModifiers=[:] } ; if (ctx._source.systemProperties.scoreModifiers.containsKey(scoringId)) { ctx._source.scores[scoringId] = ctx._source.systemProperties.scoreModifiers[scoringId] } else { ctx._source.scores.remove(scoringId) }", scriptParams);
         }
         if(scoring.getMetadata().isEnabled()) {
             String script = "if (ctx._source.scores == null) { ctx._source.scores=[:] } ; if (ctx._source.scores.containsKey(scoringId)) { ctx._source.scores[scoringId] += scoringValue } else { ctx._source.scores[scoringId] = scoringValue }";


[14/16] incubator-unomi git commit: UNOMI-55 fix typo issue

Posted by sh...@apache.org.
UNOMI-55 fix typo issue


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/f40318a9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/f40318a9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/f40318a9

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: f40318a99d49458579ced05762c417900cbdd6ae
Parents: c63d85e
Author: dgaillard <dg...@jahia.com>
Authored: Fri Sep 2 17:06:33 2016 +0200
Committer: dgaillard <dg...@jahia.com>
Committed: Fri Sep 2 17:06:33 2016 +0200

----------------------------------------------------------------------
 .../services/src/main/resources/org.apache.unomi.privacy.cfg       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f40318a9/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
index 320273c..4d4f3da 100644
--- 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
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-defaultDeniedProperties=firstName,lastName,email,phoneNumber,address,facebookId,googleId,linedInId,twitterId
+defaultDeniedProperties=firstName,lastName,email,phoneNumber,address,facebookId,googleId,linkedInId,twitterId


[07/16] incubator-unomi git commit: UNOMI-39 - anonymous browsing : do not store anonymous profile, keep only in session and event without id and personal data. Handle profile merge with anonymous browsing. Keep master profile in event to store personal

Posted by sh...@apache.org.
UNOMI-39 - anonymous browsing : do not store anonymous profile, keep only in session and event without id and personal data. Handle profile merge with anonymous browsing. Keep master profile in event to store personal properties, even when using anonymous browsing.


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/00761022
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/00761022
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/00761022

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 007610226bd9bb92e930e045e7ae632cba5a3db7
Parents: 685f67f
Author: Thomas Draier <dr...@apache.org>
Authored: Mon Aug 22 13:54:31 2016 +0200
Committer: Thomas Draier <dr...@apache.org>
Committed: Mon Aug 22 13:54:31 2016 +0200

----------------------------------------------------------------------
 .../privacy/rest/PrivacyServiceEndPoint.java    |  12 +-
 .../privacy/internal/PrivacyServiceImpl.java    |   4 +-
 .../AllEventToProfilePropertiesAction.java      |   6 +-
 .../actions/EventToProfilePropertyAction.java   |   4 -
 .../actions/MergeProfilesOnPropertyAction.java  |  32 +++-
 .../baseplugin/actions/SendEventAction.java     |   1 +
 .../baseplugin/actions/SetPropertyAction.java   |   5 -
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   1 +
 .../services/services/EventServiceImpl.java     |   2 +-
 .../services/services/ProfileServiceImpl.java   |   6 +
 .../org/apache/unomi/web/ContextServlet.java    | 148 ++++++++++---------
 .../unomi/web/EventsCollectorServlet.java       |  50 ++++---
 12 files changed, 148 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 5ef088c..4964275 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
@@ -71,21 +71,21 @@ public class PrivacyServiceEndPoint {
     }
 
     @GET
-    @Path("/profiles/{profileId}/anonymous")
-    public Boolean isAnonymous(@PathParam("profileId") String profileId) {
+    @Path("/profiles/{profileId}/anonymousBrowsing")
+    public Boolean isAnonymousBrowsing(@PathParam("profileId") String profileId) {
         return privacyService.isRequireAnonymousBrowsing(profileId);
     }
 
     @POST
-    @Path("/profiles/{profileId}/anonymous")
-    public Response activateAnonymousSurfing(@PathParam("profileId") String profileId) {
+    @Path("/profiles/{profileId}/anonymousBrowsing")
+    public Response activateAnonymousBrowsing(@PathParam("profileId") String profileId) {
         Boolean r = privacyService.setRequireAnonymousBrowsing(profileId, true);
         return r ? Response.ok().build() : Response.serverError().build();
     }
 
     @DELETE
-    @Path("/profiles/{profileId}/anonymous")
-    public Response deactivateAnonymousSurfing(@PathParam("profileId") String profileId) {
+    @Path("/profiles/{profileId}/anonymousBrowsing")
+    public Response deactivateAnonymousBrowsing(@PathParam("profileId") String profileId) {
         Boolean r = privacyService.setRequireAnonymousBrowsing(profileId, false);
         return r ? Response.ok().build() : Response.serverError().build();
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 22ec95a..ef2f03b 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
@@ -158,11 +158,11 @@ public class PrivacyServiceImpl implements PrivacyService {
     }
 
     public Profile getAnonymousProfile(Profile profile) {
-        Profile anonymousProfile = new Profile(UUID.randomUUID().toString());
+        Profile anonymousProfile = new Profile();
         anonymousProfile.getSystemProperties().put("isAnonymousProfile", true);
         anonymousProfile.getProperties().putAll(profile.getProperties());
         anonymousProfile.getProperties().keySet().removeAll(getDeniedProperties(profile.getItemId()));
-        profileService.save(anonymousProfile);
+//        profileService.save(anonymousProfile);
         return anonymousProfile;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 850e489..e11478f 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
@@ -62,10 +62,8 @@ public class AllEventToProfilePropertiesAction implements ActionExecutor {
             if (event.getProfile().getProperty(entry.getKey()) == null || !event.getProfile().getProperty(entry.getKey()).equals(event.getProperty(entry.getKey()))) {
                 String propertyMapping = profileService.getPropertyTypeMapping(entry.getKey());
                 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;
-                }
+                event.getProfile().setProperty(propertyName, entry.getValue());
+                changed = true;
             }
         }
         return changed ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 8efb43e..19dc57c 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
@@ -38,10 +38,6 @@ public class EventToProfilePropertyAction implements ActionExecutor {
         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/00761022/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
index 2edc98b..12def48 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java
@@ -28,6 +28,7 @@ import org.apache.unomi.api.actions.ActionPostExecutor;
 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;
 import org.apache.unomi.persistence.spi.PersistenceService;
 import org.slf4j.Logger;
@@ -56,6 +57,8 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
 
     private DefinitionsService definitionsService;
 
+    private PrivacyService privacyService;
+
     public void setCookieAgeInSeconds(int cookieAgeInSeconds) {
         this.cookieAgeInSeconds = cookieAgeInSeconds;
     }
@@ -88,6 +91,10 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
         return definitionsService;
     }
 
+    public void setPrivacyService(PrivacyService privacyService) {
+        this.privacyService = privacyService;
+    }
+
     public void setDefinitionsService(DefinitionsService definitionsService) {
         this.definitionsService = definitionsService;
     }
@@ -152,9 +159,9 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
             event.setProfileId(profile.getItemId());
             event.setProfile(profile);
 
-            event.getSession().setProfile(profile);
+            currentSession.setProfile(profile);
 
-            eventService.send(new Event("sessionReassigned", event.getSession(), profile, event.getScope(), event, event.getSession(), event.getTimeStamp()));
+            eventService.send(new Event("sessionReassigned", currentSession, profile, event.getScope(), event, currentSession, event.getTimeStamp()));
 
             return EventService.PROFILE_UPDATED + EventService.SESSION_UPDATED;
         } else {
@@ -175,19 +182,28 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
             }
 
             // Use oldest profile for master profile
-            Profile masterProfile = profileService.mergeProfiles(profiles.get(0), profiles);
+            final Profile masterProfile = profileService.mergeProfiles(profiles.get(0), profiles);
 
             // Profile has changed
             if (!masterProfile.getItemId().equals(profileId)) {
                 HttpServletResponse httpServletResponse = (HttpServletResponse) event.getAttributes().get(Event.HTTP_RESPONSE_ATTRIBUTE);
-                sendProfileCookie(event.getSession().getProfile(), httpServletResponse);
+                sendProfileCookie(currentSession.getProfile(), httpServletResponse);
                 final String masterProfileId = masterProfile.getItemId();
 
                 // At the end of the merge, we must set the merged profile as profile event to process other Actions
                 event.setProfileId(masterProfileId);
                 event.setProfile(masterProfile);
 
-                event.getSession().setProfile(masterProfile);
+                currentSession.setProfile(masterProfile);
+                if (privacyService.isRequireAnonymousBrowsing(profileId)) {
+                    privacyService.setRequireAnonymousBrowsing(masterProfileId, true);
+                }
+                final Boolean anonymousBrowsing = privacyService.isRequireAnonymousBrowsing(masterProfileId);
+                if (anonymousBrowsing) {
+                    currentSession.setProfile(privacyService.getAnonymousProfile(masterProfile));
+                    event.setProfileId(null);
+                    persistenceService.save(event);
+                }
 
                 event.getActionPostExecutors().add(new ActionPostExecutor() {
                     @Override
@@ -197,16 +213,16 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor {
                                 String profileId = profile.getItemId();
                                 if (!StringUtils.equals(profileId, masterProfileId)) {
                                     List<Session> sessions = persistenceService.query("profileId", profileId, null, Session.class);
-                                    if (currentSession.getProfileId().equals(profileId) && !sessions.contains(currentSession)) {
+                                    if (masterProfileId.equals(profileId) && !sessions.contains(currentSession)) {
                                         sessions.add(currentSession);
                                     }
                                     for (Session session : sessions) {
-                                        persistenceService.update(session.getItemId(), session.getTimeStamp(), Session.class, "profileId", masterProfileId);
+                                        persistenceService.update(session.getItemId(), session.getTimeStamp(), Session.class, "profileId", anonymousBrowsing ? null : masterProfileId);
                                     }
 
                                     List<Event> events = persistenceService.query("profileId", profileId, null, Event.class);
                                     for (Event event : events) {
-                                        persistenceService.update(event.getItemId(), event.getTimeStamp(), Event.class, "profileId", masterProfileId);
+                                        persistenceService.update(event.getItemId(), event.getTimeStamp(), Event.class, "profileId", anonymousBrowsing ? null : masterProfileId);
                                     }
                                     // we must mark all the profiles that we merged into the master as merged with the master, and they will
                                     // be deleted upon next load

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SendEventAction.java
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SendEventAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SendEventAction.java
index f94851e..9f52246 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SendEventAction.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SendEventAction.java
@@ -45,6 +45,7 @@ public class SendEventAction implements ActionExecutor {
 //            BeanUtils.populate(targetItem, target);
 
         Event subEvent = new Event(eventType, event.getSession(), event.getProfile(), event.getScope(), event, target, event.getTimeStamp());
+        subEvent.setProfileId(event.getProfileId());
         subEvent.getAttributes().putAll(event.getAttributes());
         subEvent.getProperties().putAll(eventProperties);
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 e384960..a731468 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
@@ -40,11 +40,6 @@ public class SetPropertyAction implements ActionExecutor {
 
         String propertyName = (String) action.getParameterValues().get("setPropertyName");
 
-        if (event.getProfile().isAnonymousProfile() && !storeInSession
-                && privacyService.getDeniedProperties(event.getProfileId()).contains(propertyName)) {
-            return EventService.NO_CHANGE;
-        }
-
         Object propertyValue = action.getParameterValues().get("setPropertyValue");
         Object propertyValueInteger = action.getParameterValues().get("setPropertyValueInteger");
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 73144ec..d6c1b10 100644
--- a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -216,6 +216,7 @@
             <property name="eventService" ref="eventService"/>
             <property name="persistenceService" ref="persistenceService"/>
             <property name="definitionsService" ref="definitionsService"/>
+            <property name="privacyService" ref="privacyService"/>
         </bean>
     </service>
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
index d6f0da4..70bd06d 100644
--- a/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
@@ -153,7 +153,7 @@ public class EventServiceImpl implements EventService {
                 profileUpdated.setPersistent(false);
                 profileUpdated.getAttributes().putAll(event.getAttributes());
                 changes |= send(profileUpdated);
-                if (session != null) {
+                if (session != null && session.getProfileId() != null) {
                     changes |= SESSION_UPDATED;
                     session.setProfile(event.getProfile());
                 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 bc716fb..22e6227 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
@@ -390,6 +390,9 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
     }
 
     public Profile save(Profile profile) {
+        if (profile.getItemId() == null) {
+            return null;
+        }
         persistenceService.save(profile);
         return persistenceService.load(profile.getItemId(), Profile.class);
     }
@@ -527,6 +530,9 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
     }
 
     public Session saveSession(Session session) {
+        if (session.getItemId() == null) {
+            return null;
+        }
         return persistenceService.save(session) ? session : null;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 5051780..7bedb67 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -66,13 +66,9 @@ public class ContextServlet extends HttpServlet {
         if (request.getParameter("timestamp") != null) {
             timestamp.setTime(Long.parseLong(request.getParameter("timestamp")));
         }
-        // first we must retrieve the context for the current visitor, and build a Javascript object to attach to the
-        // script output.
-        String profileId;
 
         HttpServletRequest httpServletRequest = (HttpServletRequest) request;
         String httpMethod = httpServletRequest.getMethod();
-//        logger.debug(HttpUtils.dumpRequestInfo(httpServletRequest));
 
         // set up CORS headers as soon as possible so that errors are not misconstrued on the client for CORS errors
         HttpUtils.setupCORSHeaders(httpServletRequest, response);
@@ -84,6 +80,7 @@ public class ContextServlet extends HttpServlet {
         }
 
         Profile profile = null;
+        Profile sessionProfile = null;
 
         String cookieProfileId = null;
         Cookie[] cookies = httpServletRequest.getCookies();
@@ -118,8 +115,6 @@ public class ContextServlet extends HttpServlet {
             return;
         }
 
-        boolean profileCreated = false;
-
         ContextRequest contextRequest = null;
         String scope = null;
         String stringPayload = HttpUtils.getPayload(httpServletRequest);
@@ -138,78 +133,94 @@ public class ContextServlet extends HttpServlet {
         int changes = EventService.NO_CHANGE;
 
         if (profile == null) {
+            boolean profileCreated = false;
+
+            // Not a persona, resolve profile now
+            if (cookieProfileId == null) {
+                // no profileId cookie was found, we generate a new one and create the profile in the profile service
+                profile = createNewProfile(null, response, timestamp);
+                profileCreated = true;
+            } else {
+                profile = profileService.load(cookieProfileId);
+                if (profile == null) {
+                    // this can happen if we have an old cookie but have reset the server,
+                    // or if we merged the profiles and somehow this cookie didn't get updated.
+                    profile = createNewProfile(null, response, timestamp);
+                    profileCreated = true;
+                } else {
+                    profile = checkMergedProfile(response, profile, session);
+                }
+            }
+
             if (sessionId != null) {
                 session = profileService.loadSession(sessionId, timestamp);
                 if (session != null) {
-                    profileId = session.getProfileId();
-                    profile = profileService.load(profileId);
-                    profile = checkMergedOrAnonymizedProfile(response, profile, session);
+                    sessionProfile = session.getProfile();
+
+                    if (privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && sessionProfile.isAnonymousProfile()) {
+                        // User wants to browse anonymously, anonymous profile is already set.
+                    } else if (privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && !sessionProfile.isAnonymousProfile()) {
+                        // 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()) {
+                        // 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()) {
+                        // 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())) {
+                            session.setProfile(sessionProfile);
+                            changes = EventService.SESSION_UPDATED;
+                        }
+                    }
                 }
             }
-            if (profile == null) {
-                // profile not stored in session
-                if (cookieProfileId == null) {
-                    // no profileId cookie was found, we generate a new one and create the profile in the profile service
-                    profile = createNewProfile(null, response, timestamp);
-                    profileCreated = true;
-                } else {
-                    profile = profileService.load(cookieProfileId);
-                    if (profile == null) {
-                        // this can happen if we have an old cookie but have reset the server,
-                        // or if we merged the profiles and somehow this cookie didn't get updated.
-                        profile = createNewProfile(null, response, timestamp);
-                        profileCreated = true;
-                        HttpUtils.sendProfileCookie(profile, response, profileIdCookieName, profileIdCookieDomain);
-                    } else {
-                        profile = checkMergedOrAnonymizedProfile(response, profile, session);
+
+            if (session == null) {
+                sessionProfile = privacyService.isRequireAnonymousBrowsing(profile.getItemId()) ? privacyService.getAnonymousProfile(profile) : profile;
+                session = new Session(sessionId, sessionProfile, timestamp, scope);
+
+                if (sessionId != null) {
+                    // Only save session and send event if a session id was provided, otherise keep transient session
+                    changes |= EventService.SESSION_UPDATED;
+                    Event event = new Event("sessionCreated", session, profile, scope, null, session, timestamp);
+                    if (sessionProfile.isAnonymousProfile()) {
+                        // Do not keep track of profile in event
+                        event.setProfileId(null);
                     }
+                    event.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
+                    event.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);
+                    logger.debug("Received event " + event.getEventType() + " for profile=" + profile.getItemId() + " session=" + session.getItemId() + " target=" + event.getTarget() + " timestamp=" + timestamp);
+                    changes |= eventService.send(event);
                 }
-            } else if ((cookieProfileId == null || !cookieProfileId.equals(profile.getItemId())) && !profile.isAnonymousProfile()) {
-                // profile if stored in session but not in cookie
-                HttpUtils.sendProfileCookie(profile, response, profileIdCookieName, profileIdCookieDomain);
             }
-            // associate profile with session
-            if (sessionId != null && session == null) {
-                session = new Session(sessionId, profile, timestamp, scope);
-                changes |= EventService.SESSION_UPDATED;
-                Event event = new Event("sessionCreated", session, profile, scope, null, session, timestamp);
-
-                event.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
-                event.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);
-                logger.debug("Received event " + event.getEventType() + " for profile=" + profile.getItemId() + " session=" + session.getItemId() + " target=" + event.getTarget() + " timestamp=" + timestamp);
-                changes |= eventService.send(event);
-            }
-        }
 
-        if (profileCreated) {
-            changes |= EventService.PROFILE_UPDATED;
+            if (profileCreated) {
+                changes |= EventService.PROFILE_UPDATED;
 
-            Event profileUpdated = new Event("profileUpdated", session, profile, scope, null, profile, timestamp);
-            profileUpdated.setPersistent(false);
-            profileUpdated.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
-            profileUpdated.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);
+                Event profileUpdated = new Event("profileUpdated", session, profile, scope, null, profile, timestamp);
+                profileUpdated.setPersistent(false);
+                profileUpdated.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
+                profileUpdated.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);
 
-            logger.debug("Received event {} for profile={} {} target={} timestamp={}", profileUpdated.getEventType(), profile.getItemId(),
-                    session != null ? " session=" + session.getItemId() : "", profileUpdated.getTarget(), timestamp);
-            changes |= eventService.send(profileUpdated);
+                logger.debug("Received event {} for profile={} {} target={} timestamp={}", profileUpdated.getEventType(), profile.getItemId(),
+                        session != null ? " session=" + session.getItemId() : "", profileUpdated.getTarget(), timestamp);
+                changes |= eventService.send(profileUpdated);
+            }
         }
 
         ContextResponse data = new ContextResponse();
-        data.setProfileId(profile.isAnonymousProfile() ? cookieProfileId : profile.getItemId());
-
-        if (privacyService.isRequireAnonymousBrowsing(profile.getItemId())) {
-            if (!session.getProfile().isAnonymousProfile()) {
-                profile = privacyService.getAnonymousProfile(profile);
-                session.setProfile(profile);
-                changes = EventService.SESSION_UPDATED;
-            }
-        }
+        data.setProfileId(profile.getItemId());
 
-        if(contextRequest != null){
+        if (contextRequest != null){
             changes |= handleRequest(contextRequest, profile, session, data, request, response, timestamp);
         }
 
-        if ((changes & EventService.PROFILE_UPDATED) == EventService.PROFILE_UPDATED && profile != null) {
+        if ((changes & EventService.PROFILE_UPDATED) == EventService.PROFILE_UPDATED) {
             profileService.save(profile);
         }
         if ((changes & EventService.SESSION_UPDATED) == EventService.SESSION_UPDATED && session != null) {
@@ -241,8 +252,8 @@ public class ContextServlet extends HttpServlet {
         responseWriter.flush();
     }
 
-    private Profile checkMergedOrAnonymizedProfile(ServletResponse response, Profile profile, Session session) {
-        if (profile != null && profile.getMergedWith() != null && !profile.isAnonymousProfile()) {
+    private Profile checkMergedProfile(ServletResponse response, Profile profile, Session session) {
+        if (profile.getMergedWith() != null && !privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && !profile.isAnonymousProfile()) {
             String profileId = profile.getMergedWith();
             Profile profileToDelete = profile;
             profile = profileService.load(profileId);
@@ -260,15 +271,6 @@ 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;
     }
@@ -284,7 +286,7 @@ public class ContextServlet extends HttpServlet {
         if(contextRequest.getEvents() != null && !(profile instanceof Persona)) {
             for (Event event : contextRequest.getEvents()){
                 if(event.getEventType() != null) {
-                    Event eventToSend = new Event(event.getEventType(), session, profile, contextRequest.getSource().getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
+                    Event eventToSend = new Event(event.getEventType(), session, session.getProfile(), contextRequest.getSource().getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
                     if (!eventService.isEventAllowed(event, thirdPartyId)) {
                         logger.debug("Event is not allowed : {}", event.getEventType());
                         continue;
@@ -296,7 +298,7 @@ public class ContextServlet extends HttpServlet {
 
                     event.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
                     event.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);
-                    logger.debug("Received event " + event.getEventType() + " for profile=" + profile.getItemId() + " session=" + session.getItemId() + " target=" + event.getTarget() + " timestamp=" + timestamp);
+                    logger.debug("Received event " + event.getEventType() + " for profile=" + session.getProfileId() + " session=" + session.getItemId() + " target=" + event.getTarget() + " timestamp=" + timestamp);
                     changes |= eventService.send(eventToSend);
                 }
             }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/00761022/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 8d2cb3b..2b97f56 100644
--- a/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/EventsCollectorServlet.java
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -74,8 +75,6 @@ public class EventsCollectorServlet extends HttpServlet {
 
         HttpUtils.setupCORSHeaders(request, response);
 
-        Profile profile = null;
-
         String sessionId = request.getParameter("sessionId");
         if (sessionId == null) {
             logger.error("No sessionId found in incoming request, aborting processing. See debug level for more information");
@@ -91,21 +90,34 @@ public class EventsCollectorServlet extends HttpServlet {
             return;
         }
 
-        String profileId = session.getProfileId();
-        if (profileId == null) {
-            logger.error("No profileId found in session={}, aborting request !", session.getItemId());
-            return;
-        }
+        String profileIdCookieName = "context-profile-id";
 
-        profile = profileService.load(profileId);
-        if (profile == null || profile instanceof Persona) {
-            logger.error("No valid profile found or persona found for profileId={}, aborting request !", profileId);
-            return;
+        Profile sessionProfile = session.getProfile();
+        Profile profile = null;
+        if (sessionProfile.getItemId() != null) {
+            // Reload up-to-date profile
+            profile = profileService.load(sessionProfile.getItemId());
+            if (profile == null || profile instanceof Persona) {
+                logger.error("No valid profile found or persona found for profileId={}, aborting request !", session.getProfileId());
+                return;
+            }
+        } else {
+            // Session uses anonymous profile, try to find profile from cookie
+            Cookie[] cookies = request.getCookies();
+            for (Cookie cookie : cookies) {
+                if (profileIdCookieName.equals(cookie.getName())) {
+                    profile = profileService.load(cookie.getValue());
+                }
+            }
+            if (profile == null) {
+                logger.error("No valid profile found or persona found for profileId={}, aborting request !", session.getProfileId());
+                return;
+            }
         }
 
         String payload = HttpUtils.getPayload(request);
         if (payload == null){
-            logger.error("No event payload found for request, aborting !", profileId);
+            logger.error("No event payload found for request, aborting !");
             return;
         }
 
@@ -127,17 +139,16 @@ public class EventsCollectorServlet extends HttpServlet {
 
         int changes = 0;
 
-        if (privacyService.isRequireAnonymousBrowsing(profile.getItemId())) {
-            profile = privacyService.getAnonymousProfile(profile);
-            session.setProfile(profile);
-            changes = EventService.SESSION_UPDATED;
-        }
-
         List<String> filteredEventTypes = privacyService.getFilteredEventTypes(profile.getItemId());
 
         for (Event event : events.getEvents()){
             if(event.getEventType() != null){
                 Event eventToSend = new Event(event.getEventType(), session, profile, event.getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
+                if (sessionProfile.isAnonymousProfile()) {
+                    // Do not keep track of profile in event
+                    eventToSend.setProfileId(null);
+                }
+
                 if (!eventService.isEventAllowed(event, thirdPartyId)) {
                     logger.debug("Event is not allowed : {}", event.getEventType());
                     continue;
@@ -149,12 +160,11 @@ public class EventsCollectorServlet extends HttpServlet {
 
                 eventToSend.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
                 eventToSend.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);
-                logger.debug("Received event " + event.getEventType() + " for profile=" + profile.getItemId() + " session=" + session.getItemId() + " target=" + event.getTarget() + " timestamp=" + timestamp);
+                logger.debug("Received event " + event.getEventType() + " for profile=" + sessionProfile.getItemId() + " session=" + session.getItemId() + " target=" + event.getTarget() + " timestamp=" + timestamp);
                 int eventChanged = eventService.send(eventToSend);
                 //if the event execution changes the profile
                 if ((eventChanged & EventService.PROFILE_UPDATED) == EventService.PROFILE_UPDATED) {
                     profile = eventToSend.getProfile();
-                    session.setProfile(profile);
                 }
                 changes |= eventChanged;
             }



[04/16] incubator-unomi git commit: UNOMI-53 : goalMatchCondition : comparisonOperator as a parameter

Posted by sh...@apache.org.
UNOMI-53 : goalMatchCondition : comparisonOperator as a parameter


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/7e372f3a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/7e372f3a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/7e372f3a

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 7e372f3ac0e0275987400bf1521faf3a640bc9b5
Parents: 44fd045
Author: Abdelkader Midani <am...@jahia.com>
Authored: Fri Aug 12 16:29:00 2016 +0200
Committer: Abdelkader Midani <am...@jahia.com>
Committed: Fri Aug 12 16:29:32 2016 +0200

----------------------------------------------------------------------
 .../META-INF/cxs/conditions/goalMatchCondition.json          | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/7e372f3a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/goalMatchCondition.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/goalMatchCondition.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/goalMatchCondition.json
index 36a57ba..6c4e796 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/goalMatchCondition.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/goalMatchCondition.json
@@ -13,7 +13,7 @@
     "type": "profilePropertyCondition",
     "parameterValues": {
       "propertyName": "script::'systemProperties.goals.'+goalId+'TargetReached'",
-      "comparisonOperator": "exists"
+      "comparisonOperator": "parameter::comparisonOperator"
     }
   },
 
@@ -22,6 +22,12 @@
       "id": "goalId",
       "type": "string",
       "multivalued": false
+    },
+    {
+      "id": "comparisonOperator",
+      "type": "string",
+      "multivalued": false,
+      "defaultValue": "exists"
     }
   ]
 }
\ No newline at end of file


[02/16] incubator-unomi git commit: UNOMI-52 : Review conditions tags

Posted by sh...@apache.org.
UNOMI-52 : Review conditions tags


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/44fd0459
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/44fd0459
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/44fd0459

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 44fd0459b364c4cfe3572d6632f839fa958a254c
Parents: 9df17f7
Author: Abdelkader Midani <am...@jahia.com>
Authored: Thu Aug 11 10:03:59 2016 +0200
Committer: Abdelkader Midani <am...@jahia.com>
Committed: Fri Aug 12 16:29:32 2016 +0200

----------------------------------------------------------------------
 .../resources/META-INF/cxs/conditions/newVisitorCondition.json     | 2 +-
 .../META-INF/cxs/conditions/returningVisitorCondition.json         | 2 +-
 .../META-INF/cxs/conditions/sessionDurationCondition.json          | 2 +-
 .../META-INF/cxs/conditions/sessionPropertyCondition.json          | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/44fd0459/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/newVisitorCondition.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/newVisitorCondition.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/newVisitorCondition.json
index 27db6f3..6bdb2f6 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/newVisitorCondition.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/newVisitorCondition.json
@@ -4,7 +4,7 @@
     "name": "newVisitorCondition",
     "description": "",
     "tags": [
-      "demographic",
+      "event",
       "sessionCondition"
     ],
     "readOnly": true

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/44fd0459/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/returningVisitorCondition.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/returningVisitorCondition.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/returningVisitorCondition.json
index e314241..2ecf315 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/returningVisitorCondition.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/returningVisitorCondition.json
@@ -4,7 +4,7 @@
     "name": "returningVisitorCondition",
     "description": "",
     "tags": [
-      "demographic",
+      "event",
       "sessionCondition"
     ],
     "readOnly": true

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/44fd0459/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionDurationCondition.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionDurationCondition.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionDurationCondition.json
index c57d204..f55b85c 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionDurationCondition.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionDurationCondition.json
@@ -4,7 +4,7 @@
     "name": "sessionDurationCondition",
     "description": "",
     "tags": [
-      "demographic",
+      "event",
       "sessionCondition"
     ],
     "readOnly": true

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/44fd0459/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionPropertyCondition.json
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionPropertyCondition.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionPropertyCondition.json
index c01dac5..3c3328a 100644
--- a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionPropertyCondition.json
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/sessionPropertyCondition.json
@@ -4,7 +4,7 @@
     "name": "sessionPropertyCondition",
     "description": "",
     "tags": [
-      "demographic",
+      "event",
       "sessionCondition"
     ],
     "readOnly": true


[15/16] incubator-unomi git commit: Merge remote-tracking branch 'origin/master' into UNOMI-28-ES-2-X-UPGRADE

Posted by sh...@apache.org.
Merge remote-tracking branch 'origin/master' into UNOMI-28-ES-2-X-UPGRADE

# Conflicts:
#	persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
#	plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/BooleanConditionESQueryBuilder.java


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/91c9c20b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/91c9c20b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/91c9c20b

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 91c9c20bf427be8012163f10962c968d4f78a417
Parents: 3ebc65b f40318a
Author: Serge Huber <sh...@apache.org>
Authored: Wed Sep 14 17:44:45 2016 +0200
Committer: Serge Huber <sh...@apache.org>
Committed: Wed Sep 14 17:44:45 2016 +0200

----------------------------------------------------------------------
 .../org/apache/unomi/api/ContextResponse.java   |  18 ++
 .../java/org/apache/unomi/api/PropertyType.java |  16 +-
 .../unomi/api/segments/DependentMetadata.java   |  53 ++++
 .../unomi/api/services/PrivacyService.java      |   8 +-
 .../unomi/api/services/ProfileService.java      |  16 ++
 .../unomi/api/services/SegmentService.java      |  41 ++-
 .../META-INF/cxs/mappings/userList.json         |  44 ++-
 .../privacy/rest/PrivacyServiceEndPoint.java    |  19 +-
 extensions/privacy-extension/services/pom.xml   |  26 ++
 .../privacy/internal/PrivacyServiceImpl.java    |  63 +++--
 .../resources/OSGI-INF/blueprint/blueprint.xml  |  10 +-
 .../main/resources/org.apache.unomi.privacy.cfg |  18 ++
 kar/src/main/feature/feature.xml                |   1 +
 .../ElasticSearchPersistenceServiceImpl.java    |  34 ++-
 .../META-INF/cxs/mappings/scoring.json          |  62 +++++
 .../persistence/spi/PersistenceService.java     |   9 +-
 .../AllEventToProfilePropertiesAction.java      |  16 +-
 .../actions/EventToProfilePropertyAction.java   |  11 +-
 .../actions/MergeProfilesOnPropertyAction.java  |  32 ++-
 .../baseplugin/actions/SendEventAction.java     |   1 +
 .../baseplugin/actions/SetPropertyAction.java   |  13 +-
 .../cxs/conditions/goalMatchCondition.json      |   8 +-
 .../cxs/conditions/newVisitorCondition.json     |   2 +-
 .../conditions/returningVisitorCondition.json   |   2 +-
 .../cxs/conditions/scoringCondition.json        |  40 +++
 .../conditions/sessionDurationCondition.json    |   2 +-
 .../conditions/sessionPropertyCondition.json    |   2 +-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |  11 +-
 .../unomi/rest/ProfileServiceEndPoint.java      |  23 +-
 .../unomi/rest/ScoringServiceEndPoint.java      |  29 +-
 .../unomi/rest/SegmentServiceEndPoint.java      |  23 +-
 .../services/services/EventServiceImpl.java     |   9 +-
 .../services/services/ProfileServiceImpl.java   |  98 ++++++-
 .../services/services/SegmentServiceImpl.java   | 266 ++++++++++++++++---
 .../org/apache/unomi/web/ContextServlet.java    | 155 ++++++-----
 .../unomi/web/EventsCollectorServlet.java       |  50 ++--
 36 files changed, 976 insertions(+), 255 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/91c9c20b/kar/src/main/feature/feature.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/91c9c20b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
----------------------------------------------------------------------
diff --cc persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index f2242b4,9e59f63..34c0d9f
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@@ -331,7 -280,9 +331,10 @@@ public class ElasticSearchPersistenceSe
  
                      internalCreateIndex(indexName, indexMappings);
                  } else {
 +                    logger.info("Found index {}, ElasticSearch started successfully.", indexName);
+                     for (Map.Entry<String, String> entry : mappings.entrySet()) {
+                         createMapping(entry.getKey(), entry.getValue());
+                     }
                  }
  
                  client.admin().indices().preparePutTemplate(indexName + "_monthlyindex")


[12/16] incubator-unomi git commit: UNOMI-32 : Improved profile updates to only merge specified properties. Send event only if profile is modifed. Also merge proeprty types on save.

Posted by sh...@apache.org.
UNOMI-32 : Improved profile updates to only merge specified properties. Send event only if profile is modifed.  Also merge proeprty types on save.


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/ec58db2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/ec58db2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/ec58db2c

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: ec58db2c9edc75ea5d5acbf2d0bc902a724748bc
Parents: b2cb9ee
Author: Thomas Draier <dr...@apache.org>
Authored: Fri Aug 26 11:41:54 2016 +0200
Committer: Thomas Draier <dr...@apache.org>
Committed: Fri Aug 26 11:41:54 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/unomi/api/PropertyType.java | 16 ++--
 .../unomi/api/services/ProfileService.java      |  8 ++
 .../unomi/rest/ProfileServiceEndPoint.java      | 12 +--
 .../services/services/ProfileServiceImpl.java   | 77 ++++++++++++++++++--
 4 files changed, 94 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ec58db2c/api/src/main/java/org/apache/unomi/api/PropertyType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/PropertyType.java b/api/src/main/java/org/apache/unomi/api/PropertyType.java
index ab58990..4d5bf6f 100644
--- a/api/src/main/java/org/apache/unomi/api/PropertyType.java
+++ b/api/src/main/java/org/apache/unomi/api/PropertyType.java
@@ -44,12 +44,12 @@ public class PropertyType extends MetadataItem {
     private List<NumericRange> numericRanges = new ArrayList<>();
     private List<IpRange> ipRanges = new ArrayList<>();
     private Set<String> automaticMappingsFrom = new HashSet<>();
-    private double rank;
+    private Double rank;
     private String mergeStrategy;
     private Set<Tag> tags = new TreeSet<Tag>();
     private Set<String> tagIds = new LinkedHashSet<String>();
-    private boolean multivalued;
-    private boolean protekted = false;
+    private Boolean multivalued;
+    private Boolean protekted;
 
     /**
      * Instantiates a new Property type.
@@ -210,7 +210,7 @@ public class PropertyType extends MetadataItem {
      *
      * @return the rank of this PropertyType for ordering purpose
      */
-    public double getRank() {
+    public Double getRank() {
         return rank;
     }
 
@@ -219,7 +219,7 @@ public class PropertyType extends MetadataItem {
      *
      * @param rank the rank of this PropertyType for ordering purpose
      */
-    public void setRank(double rank) {
+    public void setRank(Double rank) {
         this.rank = rank;
     }
 
@@ -300,7 +300,7 @@ public class PropertyType extends MetadataItem {
      *
      * @return {@code true} if properties of this type should be multi-valued, {@code false} otherwise
      */
-    public boolean isMultivalued() {
+    public Boolean isMultivalued() {
         return multivalued;
     }
 
@@ -309,7 +309,7 @@ public class PropertyType extends MetadataItem {
      *
      * @param multivalued {@code true} if properties of this type should be multi-valued, {@code false} otherwise
      */
-    public void setMultivalued(boolean multivalued) {
+    public void setMultivalued(Boolean multivalued) {
         this.multivalued = multivalued;
     }
 
@@ -320,7 +320,7 @@ public class PropertyType extends MetadataItem {
      *
      * @return {@code true} if properties of this type are protected, {@code false} otherwise
      */
-    public boolean isProtected() {
+    public Boolean isProtected() {
         return protekted;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ec58db2c/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
index c13036a..a998e5e 100644
--- a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
@@ -106,6 +106,14 @@ public interface ProfileService {
     Profile save(Profile profile);
 
     /**
+     * Merge the specified profile properties in an existing profile,or save new profile if it does not exist yet
+     *
+     * @param profile the profile to be saved
+     * @return the newly saved profile
+     */
+    boolean saveOrmerge(Profile profile);
+
+    /**
      * Removes the profile (or persona if the {@code persona} parameter is set to {@code true}) identified by the specified identifier.
      *
      * @param profileId the identifier of the profile or persona to delete

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ec58db2c/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java b/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
index b806378..038178d 100644
--- a/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/ProfileServiceEndPoint.java
@@ -193,11 +193,13 @@ public class ProfileServiceEndPoint {
     @POST
     @Path("/")
     public Profile save(Profile profile) {
-        // TODO: check that the profile was actually updated correctly before sending the event
-        Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date());
-        profileUpdated.setPersistent(false);
-        eventService.send(profileUpdated);
-        return profileService.save(profile);
+        if (profileService.saveOrmerge(profile)) {
+            Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date());
+            profileUpdated.setPersistent(false);
+            eventService.send(profileUpdated);
+        }
+
+        return profile;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ec58db2c/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 22e6227..aee8832 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
@@ -17,6 +17,8 @@
 
 package org.apache.unomi.services.services;
 
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.unomi.api.*;
 import org.apache.unomi.api.conditions.Condition;
@@ -278,12 +280,13 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
 
     @Override
     public boolean setPropertyType(PropertyType property) {
-        PropertyType previous = null;
-        if ((previous = persistenceService.load(property.getItemId(), PropertyType.class)) != null) {
-            previous.getAutomaticMappingsFrom().addAll(property.getAutomaticMappingsFrom());
-            property = previous;
+        PropertyType previousProperty = persistenceService.load(property.getItemId(), PropertyType.class);
+        if (previousProperty == null) {
+            return persistenceService.save(property);
+        } else if (merge(previousProperty, property)) {
+            return persistenceService.save(previousProperty);
         }
-        return persistenceService.save(property);
+        return false;
     }
 
     @Override
@@ -362,7 +365,7 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
 
     // TODO may be moved this in a specific Export Utils Class and improve it to handle date format, ...
     private void handleExportProperty(StringBuilder sb, Object propertyValue, PropertyType propertyType) {
-        if (propertyValue instanceof Collection && propertyType != null && propertyType.isMultivalued()) {
+        if (propertyValue instanceof Collection && propertyType != null && propertyType.isMultivalued() != null && propertyType.isMultivalued() ) {
             Collection propertyValues = (Collection) propertyValue;
             Collection encodedValues = new ArrayList(propertyValues.size());
             for (Object value : propertyValues) {
@@ -397,6 +400,17 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
         return persistenceService.load(profile.getItemId(), Profile.class);
     }
 
+    public boolean saveOrmerge(Profile profile) {
+        Profile previousProfile = persistenceService.load(profile.getItemId(), Profile.class);
+        if (previousProfile == null) {
+            return persistenceService.save(profile);
+        } else if (merge(previousProfile, profile)) {
+            return persistenceService.save(previousProfile);
+        }
+
+        return false;
+    }
+
     public Persona savePersona(Persona profile) {
         if (persistenceService.load(profile.getItemId(), Persona.class) == null) {
             Session session = new PersonaSession(UUID.randomUUID().toString(), profile, new Date());
@@ -736,4 +750,55 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
         }
     }
 
+    private <T> boolean merge(T target, T object) {
+        if (object != null) {
+            try {
+                Map<String,Object> objectValues = PropertyUtils.describe(object);
+                Map<String,Object> targetValues = PropertyUtils.describe(target);
+                if (merge(targetValues, objectValues)) {
+                    BeanUtils.populate(target, targetValues);
+                    return true;
+                }
+            } catch (ReflectiveOperationException e) {
+                logger.error("Cannot merge properties",e);
+            }
+        }
+        return false;
+    }
+
+    private boolean merge(Map<String,Object> target, Map<String,Object> object) {
+        boolean changed = false;
+        for (Map.Entry<String, Object> previousEntry : object.entrySet()) {
+            if (previousEntry.getValue() != null) {
+                if (previousEntry.getValue() instanceof Collection) {
+                    Collection currentCollection = (Collection) target.get(previousEntry.getKey());
+                    if (currentCollection != null) {
+                        if (!currentCollection.containsAll((Collection) previousEntry.getValue())) {
+                            changed |= currentCollection.addAll((Collection) previousEntry.getValue());
+                        }
+                    } else {
+                        target.put(previousEntry.getKey(), previousEntry.getValue());
+                        changed = true;
+                    }
+                } else if (previousEntry.getValue() instanceof Map) {
+                    Map<String,Object> currentMap = (Map) target.get(previousEntry.getKey());
+                    if (currentMap == null) {
+                        target.put(previousEntry.getKey(), previousEntry.getValue());
+                        changed = true;
+                    } else {
+                        changed |= merge(currentMap, (Map) previousEntry.getValue());
+                    }
+                } else if (previousEntry.getValue().getClass().getPackage().getName().equals("java.lang")) {
+                    if (previousEntry.getValue() != null && !previousEntry.getValue().equals(target.get(previousEntry.getKey()))) {
+                        target.put(previousEntry.getKey(), previousEntry.getValue());
+                        changed = true;
+                    }
+                } else {
+                    changed |= merge(target.get(previousEntry.getKey()), previousEntry.getValue());
+                }
+            }
+        }
+        return changed;
+    }
+
 }


[13/16] incubator-unomi git commit: UNOMI-54 : Add mappings for scoring and userList + add score mapping in profile

Posted by sh...@apache.org.
UNOMI-54 : Add mappings for scoring and userList + add score mapping in profile


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/c63d85e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/c63d85e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/c63d85e3

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: c63d85e39ea6eb801bd7f3636420051d5b33fa39
Parents: ec58db2
Author: Quentin Lamerand <ql...@jahia.com>
Authored: Fri Aug 26 15:19:08 2016 +0200
Committer: Quentin Lamerand <ql...@jahia.com>
Committed: Fri Aug 26 15:19:08 2016 +0200

----------------------------------------------------------------------
 .../META-INF/cxs/mappings/userList.json         | 44 +++++++++++++-
 .../ElasticSearchPersistenceServiceImpl.java    | 35 +++++++----
 .../META-INF/cxs/mappings/scoring.json          | 62 ++++++++++++++++++++
 .../persistence/spi/PersistenceService.java     |  9 ++-
 .../services/services/EventServiceImpl.java     |  7 ++-
 .../services/services/ProfileServiceImpl.java   |  2 +-
 .../services/services/SegmentServiceImpl.java   | 15 +++++
 7 files changed, 156 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c63d85e3/extensions/lists-extension/services/src/main/resources/META-INF/cxs/mappings/userList.json
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/resources/META-INF/cxs/mappings/userList.json b/extensions/lists-extension/services/src/main/resources/META-INF/cxs/mappings/userList.json
index 8a8b9de..3bb8ae0 100644
--- a/extensions/lists-extension/services/src/main/resources/META-INF/cxs/mappings/userList.json
+++ b/extensions/lists-extension/services/src/main/resources/META-INF/cxs/mappings/userList.json
@@ -11,6 +11,48 @@
           }
         }
       }
-    ]
+    ],
+    "properties": {
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
+        "properties": {
+          "description": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          },
+          "scope": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    }
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c63d85e3/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 7bf2f14..9e59f63 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -279,6 +279,10 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
                     }
 
                     internalCreateIndex(indexName, indexMappings);
+                } else {
+                    for (Map.Entry<String, String> entry : mappings.entrySet()) {
+                        createMapping(entry.getKey(), entry.getValue());
+                    }
                 }
 
                 client.admin().indices().preparePutTemplate(indexName + "_monthlyindex")
@@ -416,17 +420,10 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
                 while ((l = reader.readLine()) != null) {
                     content.append(l);
                 }
-                mappings.put(name, content.toString());
+                String mappingSource = content.toString();
+                mappings.put(name, mappingSource);
                 if (createMapping) {
-                    if (itemsMonthlyIndexed.contains(name)) {
-                        createMapping(name, content.toString(), indexName + "-*");
-                    } else if (indexNames.containsKey(name)) {
-                        if (client.admin().indices().prepareExists(indexNames.get(name)).execute().actionGet().isExists()) {
-                            createMapping(name, content.toString(), indexNames.get(name));
-                        }
-                    } else {
-                        createMapping(name, content.toString(), indexName);
-                    }
+                    createMapping(name, mappingSource);
                 }
             } catch (Exception e) {
                 logger.error("Error while loading mapping definition " + predefinedMappingURL, e);
@@ -685,17 +682,29 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
     }
 
 
-    private boolean createMapping(final String type, final String source, final String indexName) {
+    private void createMapping(final String type, final String source, final String indexName) {
         client.admin().indices()
                 .preparePutMapping(indexName)
                 .setType(type)
                 .setSource(source)
                 .execute().actionGet();
-        return true;
     }
 
     @Override
-    public Map<String, Map<String, Object>> getMapping(final String itemType) {
+    public void createMapping(String type, String source) {
+        if (itemsMonthlyIndexed.contains(type)) {
+            createMapping(type, source, indexName + "-*");
+        } else if (indexNames.containsKey(type)) {
+            if (client.admin().indices().prepareExists(indexNames.get(type)).execute().actionGet().isExists()) {
+                createMapping(type, source, indexNames.get(type));
+            }
+        } else {
+            createMapping(type, source, indexName);
+        }
+    }
+
+    @Override
+    public Map<String, Map<String, Object>> getPropertiesMapping(final String itemType) {
         return new InClassLoaderExecute<Map<String, Map<String, Object>>>() {
             @SuppressWarnings("unchecked")
             protected Map<String, Map<String, Object>> execute(Object... args) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c63d85e3/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/scoring.json
----------------------------------------------------------------------
diff --git a/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/scoring.json b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/scoring.json
new file mode 100644
index 0000000..b62d0a6
--- /dev/null
+++ b/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/scoring.json
@@ -0,0 +1,62 @@
+{
+  "scoring": {
+    "dynamic_templates": [
+      {
+        "all": {
+          "match": "*",
+          "match_mapping_type": "string",
+          "mapping": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    ],
+    "properties": {
+      "itemId": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "itemType": {
+        "type": "string",
+        "analyzer": "folding"
+      },
+      "metadata": {
+        "properties": {
+          "description": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "enabled": {
+            "type": "boolean"
+          },
+          "hidden": {
+            "type": "boolean"
+          },
+          "id": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "missingPlugins": {
+            "type": "boolean"
+          },
+          "name": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "readOnly": {
+            "type": "boolean"
+          },
+          "scope": {
+            "type": "string",
+            "analyzer": "folding"
+          },
+          "tags": {
+            "type": "string",
+            "analyzer": "folding"
+          }
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c63d85e3/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
----------------------------------------------------------------------
diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
index fc64d55..90b0efc 100644
--- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
+++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
@@ -168,7 +168,14 @@ public interface PersistenceService {
      * @param itemType
      * @return
      */
-    Map<String, Map<String, Object>> getMapping(String itemType);
+    Map<String, Map<String, Object>> getPropertiesMapping(String itemType);
+
+    /**
+     * Create mapping
+     * @param type
+     * @param source
+     */
+    void createMapping(String type, String source);
 
     /**
      * TODO

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c63d85e3/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
index 70bd06d..2a39eb1 100644
--- a/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/services/EventServiceImpl.java
@@ -18,7 +18,10 @@
 package org.apache.unomi.services.services;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.unomi.api.*;
+import org.apache.unomi.api.Event;
+import org.apache.unomi.api.EventProperty;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Session;
 import org.apache.unomi.api.actions.ActionPostExecutor;
 import org.apache.unomi.api.conditions.Condition;
 import org.apache.unomi.api.services.DefinitionsService;
@@ -164,7 +167,7 @@ public class EventServiceImpl implements EventService {
 
     @Override
     public List<EventProperty> getEventProperties() {
-        Map<String, Map<String, Object>> mappings = persistenceService.getMapping(Event.ITEM_TYPE);
+        Map<String, Map<String, Object>> mappings = persistenceService.getPropertiesMapping(Event.ITEM_TYPE);
         List<EventProperty> props = new ArrayList<>(mappings.size());
         getEventProperties(mappings, props, "");
         return props;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c63d85e3/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 aee8832..4e680fc 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
@@ -299,7 +299,7 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
         Set<PropertyType> filteredProperties = new LinkedHashSet<PropertyType>();
         // TODO: here we limit the result to the definition we have, but what if some properties haven't definition but exist in ES mapping ?
         Set<PropertyType> profileProperties = getPropertyTypeByTag(tagId, true);
-        Map<String, Map<String, Object>> itemMapping = persistenceService.getMapping(itemType);
+        Map<String, Map<String, Object>> itemMapping = persistenceService.getPropertiesMapping(itemType);
 
         if (itemMapping == null || itemMapping.isEmpty() || itemMapping.get("properties") == null || itemMapping.get("properties").get("properties") == null) {
             return filteredProperties;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/c63d85e3/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 85c6dc3..7263b28 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
@@ -532,6 +532,21 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
         // make sure we update the name and description metadata that might not match, so first we remove the entry from the map
         persistenceService.save(scoring);
 
+        persistenceService.createMapping(Profile.ITEM_TYPE, String.format(
+                "{\n" +
+                "    \"profile\": {\n" +
+                "        \"properties\" : {\n" +
+                "            \"scores\": {\n" +
+                "                \"properties\": {\n" +
+                "                    \"%s\": {\n" +
+                "                        \"type\": \"long\"\n" +
+                "                    }\n" +
+                "                }\n" +
+                "            }\n" +
+                "        }\n" +
+                "    }\n" +
+                "}\n", scoring.getItemId()));
+
         updateExistingProfilesForScoring(scoring);
     }
 


[08/16] incubator-unomi git commit: UNOMI-39 - switch profile if it has been updated in the session

Posted by sh...@apache.org.
UNOMI-39 - switch profile if it has been updated in the session


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/94c27c0d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/94c27c0d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/94c27c0d

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: 94c27c0da2aa22b08827e4daa689c666c57744d9
Parents: 0076102
Author: Thomas Draier <dr...@apache.org>
Authored: Mon Aug 22 16:02:21 2016 +0200
Committer: Thomas Draier <dr...@apache.org>
Committed: Mon Aug 22 16:02:21 2016 +0200

----------------------------------------------------------------------
 wab/src/main/java/org/apache/unomi/web/ContextServlet.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/94c27c0d/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 7bedb67..7cb6c5d 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -156,7 +156,11 @@ 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())) {
+                        // 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()) {
                         // User wants to browse anonymously, anonymous profile is already set.
                     } else if (privacyService.isRequireAnonymousBrowsing(profile.getItemId()) && !sessionProfile.isAnonymousProfile()) {


[06/16] incubator-unomi git commit: UNOMI-39 - anonymous browsing : anonymize removed profile properties. implements default denied properties, copy allowed properties from profile to anonymous. Cleaned profile and segment queries.

Posted by sh...@apache.org.
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 <dr...@apache.org>
Authored: Thu Aug 18 16:32:40 2016 +0200
Committer: Thomas Draier <dr...@apache.org>
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;
         }


[11/16] incubator-unomi git commit: UNOMI-39 - clear goals and past events when anonymized. Send event when anonymous flag is switched. Use uptodate proile in session

Posted by sh...@apache.org.
UNOMI-39 - clear goals and past events when anonymized. Send event when anonymous flag is switched. Use uptodate proile in session


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/b2cb9ee0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/b2cb9ee0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/b2cb9ee0

Branch: refs/heads/UNOMI-28-ES-2-X-UPGRADE
Commit: b2cb9ee0dd55b5566d0e7770f5744f9c0d50c733
Parents: 6f46c92
Author: Thomas Draier <dr...@apache.org>
Authored: Thu Aug 25 18:42:34 2016 +0200
Committer: Thomas Draier <dr...@apache.org>
Committed: Thu Aug 25 18:42:34 2016 +0200

----------------------------------------------------------------------
 .../apache/unomi/privacy/internal/PrivacyServiceImpl.java   | 8 ++++++++
 wab/src/main/java/org/apache/unomi/web/ContextServlet.java  | 9 +++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b2cb9ee0/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 ef2f03b..ce97f52 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
@@ -144,6 +144,14 @@ public class PrivacyServiceImpl implements PrivacyService {
             return false;
         }
         profile.getSystemProperties().put("requireAnonymousProfile", anonymous);
+        if (anonymous) {
+            profile.getSystemProperties().remove("goals");
+            profile.getSystemProperties().remove("pastEvents");
+        }
+        Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date());
+        profileUpdated.setPersistent(false);
+        eventService.send(profileUpdated);
+
         profileService.save(profile);
         return true;
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b2cb9ee0/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 c8987b6..2d536d9 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -182,9 +182,9 @@ public class ContextServlet extends HttpServlet {
                         // 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())) {
-                            session.setProfile(sessionProfile);
                             changes = EventService.SESSION_UPDATED;
                         }
+                        session.setProfile(sessionProfile);
                     }
                 }
             }
@@ -295,7 +295,8 @@ public class ContextServlet extends HttpServlet {
         if(contextRequest.getEvents() != null && !(profile instanceof Persona)) {
             for (Event event : contextRequest.getEvents()){
                 if(event.getEventType() != null) {
-                    Event eventToSend = new Event(event.getEventType(), session, session.getProfile(), contextRequest.getSource().getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
+                    Profile sessionProfile = session.getProfile();
+                    Event eventToSend = new Event(event.getEventType(), session, sessionProfile, contextRequest.getSource().getScope(), event.getSource(), event.getTarget(), event.getProperties(), timestamp);
                     if (!eventService.isEventAllowed(event, thirdPartyId)) {
                         logger.debug("Event is not allowed : {}", event.getEventType());
                         continue;
@@ -304,6 +305,10 @@ public class ContextServlet extends HttpServlet {
                         logger.debug("Profile is filtering event type {}", event.getEventType());
                         continue;
                     }
+                    if (sessionProfile.isAnonymousProfile()) {
+                        // Do not keep track of profile in event
+                        event.setProfileId(null);
+                    }
 
                     event.getAttributes().put(Event.HTTP_REQUEST_ATTRIBUTE, request);
                     event.getAttributes().put(Event.HTTP_RESPONSE_ATTRIBUTE, response);