http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateAggregate.java
 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateAggregate.java
new file mode 100644
index 0000000..037727a
--- /dev/null
+++ 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateAggregate.java
@@ -0,0 +1,77 @@
+/*
+ * 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.persistence.spi.aggregate;
+
+public class DateAggregate extends BaseAggregate{
+    public static final DateAggregate SECOND = new DateAggregate("1s");
+    public static final DateAggregate MINUTE = new DateAggregate("1m");
+    public static final DateAggregate HOUR = new DateAggregate("1h");
+    public static final DateAggregate DAY = new DateAggregate("1d");
+    public static final DateAggregate WEEK = new DateAggregate("1w");
+    public static final DateAggregate MONTH = new DateAggregate("1M");
+    public static final DateAggregate QUARTER = new DateAggregate("1q");
+    public static final DateAggregate YEAR = new DateAggregate("1y");
+    private static final String DEFAULT_INTERVAL = "1M";
+    private String interval;
+    private String format;
+    public DateAggregate(String field) {
+        super(field);
+        this.interval = DEFAULT_INTERVAL;
+    }
+    public DateAggregate(String field, String interval) {
+        super(field);
+        this.interval = (interval != null && interval.length() > 0) ? interval 
: DEFAULT_INTERVAL;
+    }
+    public DateAggregate(String field, String interval, String format) {
+        super(field);
+        this.interval = (interval != null && interval.length() > 0) ? interval 
: DEFAULT_INTERVAL;
+        this.format = format;
+    }
+
+    public static DateAggregate seconds(int sec) {
+        return new DateAggregate(sec + "s");
+    }
+
+    public static DateAggregate minutes(int min) {
+        return new DateAggregate(min + "m");
+    }
+
+    public static DateAggregate hours(int hours) {
+        return new DateAggregate(hours + "h");
+    }
+
+    public static DateAggregate days(int days) {
+        return new DateAggregate(days + "d");
+    }
+
+    public static DateAggregate weeks(int weeks) {
+        return new DateAggregate(weeks + "w");
+    }
+
+    public String getInterval() {
+        return interval;
+    }
+
+    public String getFormat() {
+        return format;
+    }
+
+    public void setFormat(String format) {
+        this.format = format;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateRangeAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateRangeAggregate.java
 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateRangeAggregate.java
new file mode 100644
index 0000000..66daa51
--- /dev/null
+++ 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/DateRangeAggregate.java
@@ -0,0 +1,50 @@
+/*
+ * 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.persistence.spi.aggregate;
+
+import org.apache.unomi.api.query.DateRange;
+
+import java.util.List;
+
+public class DateRangeAggregate extends BaseAggregate{
+
+    private String format;
+    private List<DateRange> dateRanges;
+
+    public DateRangeAggregate(String field, String format, List<DateRange> 
dateRanges) {
+        super(field);
+        this.format = format;
+        this.dateRanges = dateRanges;
+    }
+
+    public List<DateRange> getDateRanges() {
+        return dateRanges;
+    }
+
+    public void setDateRanges(List<DateRange> dateRanges) {
+        this.dateRanges = dateRanges;
+    }
+
+    public String getFormat() {
+        return format;
+    }
+
+    public void setFormat(String format) {
+        this.format = format;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/IpRangeAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/IpRangeAggregate.java
 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/IpRangeAggregate.java
new file mode 100644
index 0000000..d5cc849
--- /dev/null
+++ 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/IpRangeAggregate.java
@@ -0,0 +1,39 @@
+/*
+ * 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.persistence.spi.aggregate;
+
+import org.apache.unomi.api.query.IpRange;
+
+import java.util.List;
+
+public class IpRangeAggregate extends BaseAggregate{
+    private List<IpRange> ranges;
+
+    public IpRangeAggregate(String field, List<IpRange> ranges) {
+        super(field);
+        this.ranges = ranges;
+    }
+
+    public List<IpRange> getRanges() {
+        return ranges;
+    }
+
+    public void setRanges(List<IpRange> ranges) {
+        this.ranges = ranges;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/NumericRangeAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/NumericRangeAggregate.java
 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/NumericRangeAggregate.java
new file mode 100644
index 0000000..65fbf60
--- /dev/null
+++ 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/NumericRangeAggregate.java
@@ -0,0 +1,39 @@
+/*
+ * 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.persistence.spi.aggregate;
+
+import org.apache.unomi.api.query.NumericRange;
+
+import java.util.List;
+
+public class NumericRangeAggregate extends BaseAggregate{
+    private List<NumericRange> ranges;
+
+    public NumericRangeAggregate(String field, List<NumericRange> ranges) {
+        super(field);
+        this.ranges = ranges;
+    }
+
+    public List<NumericRange> getRanges() {
+        return ranges;
+    }
+
+    public void setRanges(List<NumericRange> ranges) {
+        this.ranges = ranges;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/TermsAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/TermsAggregate.java
 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/TermsAggregate.java
new file mode 100644
index 0000000..a0591f5
--- /dev/null
+++ 
b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/aggregate/TermsAggregate.java
@@ -0,0 +1,24 @@
+/*
+ * 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.persistence.spi.aggregate;
+
+public class TermsAggregate extends BaseAggregate{
+    public TermsAggregate(String field) {
+        super(field);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/CustomObjectMapper.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/CustomObjectMapper.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/CustomObjectMapper.java
deleted file mode 100644
index a59d66c..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/CustomObjectMapper.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi;
-
-import com.fasterxml.jackson.core.Version;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
-import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
-
-import org.oasis_open.contextserver.api.*;
-import org.oasis_open.contextserver.api.campaigns.Campaign;
-import org.oasis_open.contextserver.api.campaigns.events.CampaignEvent;
-import org.oasis_open.contextserver.api.conditions.Condition;
-import org.oasis_open.contextserver.api.goals.Goal;
-import org.oasis_open.contextserver.api.rules.Rule;
-import org.oasis_open.contextserver.api.segments.Scoring;
-import org.oasis_open.contextserver.api.segments.Segment;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TimeZone;
-
-/**
- * Custom object mapper to be able to configure Jackson to our needs.
- */
-public class CustomObjectMapper extends ObjectMapper {
-
-    private static final long serialVersionUID = 4578277612897061535L;
-
-    private static class Holder {
-        static final CustomObjectMapper INSTANCE = new CustomObjectMapper();
-    }
-
-    public CustomObjectMapper() {
-        super();
-        super.registerModule(new JaxbAnnotationModule());
-        configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
-        ISO8601DateFormat dateFormat = new ISO8601DateFormat();
-        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-        setDateFormat(dateFormat);
-        SimpleModule deserializerModule =
-              new SimpleModule("PropertyTypedObjectDeserializerModule",
-                  new Version(1, 0, 0, null, 
"org.oasis_open.contextserver.rest", "deserializer"));
-
-        PropertyTypedObjectDeserializer propertyTypedObjectDeserializer = new 
PropertyTypedObjectDeserializer();
-        propertyTypedObjectDeserializer.registerMapping("type=.*Condition", 
Condition.class);
-        deserializerModule.addDeserializer(Object.class, 
propertyTypedObjectDeserializer);
-
-        ItemDeserializer itemDeserializer = new ItemDeserializer();
-        deserializerModule.addDeserializer(Item.class, itemDeserializer);
-
-
-        Map<String,Class<? extends Item>> classes = new HashMap<>();
-        classes.put(Campaign.ITEM_TYPE,Campaign.class);
-        classes.put(CampaignEvent.ITEM_TYPE,CampaignEvent.class);
-        classes.put(Event.ITEM_TYPE,Event.class);
-        classes.put(Goal.ITEM_TYPE,Goal.class);
-        classes.put(Persona.ITEM_TYPE,Persona.class);
-        classes.put(Rule.ITEM_TYPE,Rule.class);
-        classes.put(Scoring.ITEM_TYPE,Scoring.class);
-        classes.put(Segment.ITEM_TYPE,Segment.class);
-        classes.put(Session.ITEM_TYPE, Session.class);
-        for (Map.Entry<String, Class<? extends Item>> entry : 
classes.entrySet()) {
-            
propertyTypedObjectDeserializer.registerMapping("itemType="+entry.getKey(), 
entry.getValue());
-            itemDeserializer.registerMapping(entry.getKey(), entry.getValue());
-        }
-        propertyTypedObjectDeserializer.registerMapping("itemType=.*", 
CustomItem.class);
-
-
-       super.registerModule(deserializerModule);
-    }
-
-    public static ObjectMapper getObjectMapper() {
-        return Holder.INSTANCE;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/ItemDeserializer.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/ItemDeserializer.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/ItemDeserializer.java
deleted file mode 100644
index cc8d7db..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/ItemDeserializer.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.ObjectCodec;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.oasis_open.contextserver.api.CustomItem;
-import org.oasis_open.contextserver.api.Item;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public class ItemDeserializer extends StdDeserializer<Item> {
-
-    private static final long serialVersionUID = -7040054009670771266L;
-    private Map<String,Class<? extends Item>> classes = new HashMap<>();
-
-    public ItemDeserializer() {
-        super(Item.class);
-    }
-
-    public void registerMapping(String type, Class<? extends Item> clazz) {
-        classes.put(type, clazz);
-    }
-
-    @Override
-    public Item deserialize(JsonParser jp, DeserializationContext ctxt) throws 
IOException, JsonProcessingException {
-        ObjectCodec codec = jp.getCodec();
-        ObjectNode treeNode = codec.readTree(jp);
-        String type = treeNode.get("itemType").textValue();
-        Class<? extends Item> objectClass = classes.get(type);
-        if (objectClass == null) {
-            objectClass = CustomItem.class;
-        } else {
-            treeNode.remove("itemType");
-        }
-        Item item = codec.treeToValue(treeNode, objectClass);
-        item.setItemId(treeNode.get("itemId").asText());
-        return item;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PersistenceService.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PersistenceService.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PersistenceService.java
deleted file mode 100644
index f88c0c9..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PersistenceService.java
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi;
-
-import org.oasis_open.contextserver.api.Item;
-import org.oasis_open.contextserver.api.PartialList;
-import org.oasis_open.contextserver.api.conditions.Condition;
-import org.oasis_open.contextserver.persistence.spi.aggregate.BaseAggregate;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A service to provide persistence and retrieval of context server entities.
- */
-public interface PersistenceService {
-
-    /**
-     * Retrieves all known items of the specified class.
-     * <em>WARNING</em>: this method can be quite computationally intensive 
and calling the paged version {@link #getAllItems(Class, int, int, String)} is 
preferred.
-     *
-     * @param <T>   the type of the {@link Item}s we want to retrieve
-     * @param clazz the {@link Item} subclass of entities we want to retrieve
-     * @return a list of all known items with the given type
-     */
-    <T extends Item> List<T> getAllItems(Class<T> clazz);
-
-    /**
-     * Retrieves all known items of the specified class, ordered according to 
the specified {@code sortBy} String and and paged: only {@code size} of them 
are retrieved,
-     * starting with the {@code offset}-th one.
-     *
-     * TODO: use a Query object instead of distinct parameters?
-     *
-     * @param <T>    the type of the {@link Item}s we want to retrieve
-     * @param clazz  the {@link Item} subclass of entities we want to retrieve
-     * @param offset zero or a positive integer specifying the position of the 
first item in the total ordered collection of matching items
-     * @param size   a positive integer specifying how many matching items 
should be retrieved or {@code -1} if all of them should be retrieved
-     * @param sortBy an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *               elements according to the property order in the
-     *               String, considering each in turn and moving on to the 
next one in case of equality of all preceding ones. Each property name is 
optionally followed by
-     *               a column ({@code :}) and an order specifier: {@code asc} 
or {@code desc}.
-     * @return a {@link PartialList} of pages items with the given type
-     */
-    <T extends Item> PartialList<T> getAllItems(Class<T> clazz, int offset, 
int size, String sortBy);
-
-    /**
-     * Persists the specified Item in the context server.
-     *
-     * @param item the item to persist
-     * @return {@code true} if the item was properly persisted, {@code false} 
otherwise
-     */
-    boolean save(Item item);
-
-    /**
-     * Updates the item of the specified class and identified by the specified 
identifier with new property values provided as name - value pairs in the 
specified Map.
-     *
-     * @param itemId   the identifier of the item we want to update
-     * @param dateHint a Date helping in identifying where the item is located
-     * @param clazz    the Item subclass of the item to update
-     * @param source   a Map with entries specifying as key the property name 
to update and as value its new value
-     * @return {@code true} if the update was successful, {@code false} 
otherwise
-     */
-    boolean update(String itemId, Date dateHint, Class<?> clazz, Map<?, ?> 
source);
-
-    /**
-     * Updates the item of the specified class and identified by the specified 
identifier with a new property value for the specified property name. Same as
-     * {@code update(itemId, dateHint, clazz, 
Collections.singletonMap(propertyName, propertyValue))}
-     *
-     * @param itemId        the identifier of the item we want to update
-     * @param dateHint      a Date helping in identifying where the item is 
located
-     * @param clazz         the Item subclass of the item to update
-     * @param propertyName  the name of the property to update
-     * @param propertyValue the new value of the property
-     * @return {@code true} if the update was successful, {@code false} 
otherwise
-     */
-    boolean update(String itemId, Date dateHint, Class<?> clazz, String 
propertyName, Object propertyValue);
-
-    /**
-     * Updates the item of the specified class and identified by the specified 
identifier with a new property value for the specified property name. Same as
-     * {@code update(itemId, dateHint, clazz, 
Collections.singletonMap(propertyName, propertyValue))}
-     *
-     * @param itemId        the identifier of the item we want to update
-     * @param dateHint      a Date helping in identifying where the item is 
located
-     * @param clazz         the Item subclass of the item to update
-     * @param script        inline script
-     * @param scriptParams  script params
-     * @return {@code true} if the update was successful, {@code false} 
otherwise
-     */
-    boolean update(String itemId, Date dateHint, Class<?> clazz, String 
script, Map<String, Object> scriptParams);
-
-    /**
-     * Retrieves the item identified with the specified identifier and with 
the specified Item subclass if it exists.
-     *
-     * @param <T>    the type of the Item subclass we want to retrieve
-     * @param itemId the identifier of the item we want to retrieve
-     * @param clazz  the {@link Item} subclass of the item we want to retrieve
-     * @return the item identified with the specified identifier and with the 
specified Item subclass if it exists, {@code null} otherwise
-     */
-    <T extends Item> T load(String itemId, Class<T> clazz);
-
-    /**
-     * Retrieves the item identified with the specified identifier and with 
the specified Item subclass if it exists.
-     *
-     * @param <T>      the type of the Item subclass we want to retrieve
-     * @param itemId   the identifier of the item we want to retrieve
-     * @param dateHint a Date helping in identifying where the item is located
-     * @param clazz    the {@link Item} subclass of the item we want to 
retrieve
-     * @return the item identified with the specified identifier and with the 
specified Item subclass if it exists, {@code null} otherwise
-     */
-    <T extends Item> T load(String itemId, Date dateHint, Class<T> clazz);
-
-    /**
-     * Deletes the item identified with the specified identifier and with the 
specified Item subclass if it exists.
-     *
-     * @param <T>    the type of the Item subclass we want to delete
-     * @param itemId the identifier of the item we want to delete
-     * @param clazz  the {@link Item} subclass of the item we want to delete
-     * @return {@code true} if the deletion was successful, {@code false} 
otherwise
-     */
-    <T extends Item> boolean remove(String itemId, Class<T> clazz);
-
-    /**
-     * Deletes items with the specified Item subclass matching the specified 
{@link Condition}.
-     *
-     * @param <T>   the type of the Item subclass we want to delete
-     * @param query a {@link Condition} identifying which elements we want to 
delete
-     * @param clazz the {@link Item} subclass of the items we want to delete
-     * @return {@code true} if the deletion was successful, {@code false} 
otherwise
-     */
-    <T extends Item> boolean removeByQuery(Condition query, Class<T> clazz);
-
-    /**
-     * Persists the specified query under the specified name.
-     *
-     * @param queryName the name under which the specified query should be 
recorded
-     * @param query     the query to be recorded
-     * @return {@code true} if the query was properly saved, {@code false} 
otherwise
-     */
-    boolean saveQuery(String queryName, Condition query);
-
-    /**
-     * Deletes the query identified by the specified name.
-     *
-     * @param queryName the name under which the specified query was recorded
-     * @return {@code true} if the deletion was successful, {@code false} 
otherwise
-     */
-    boolean removeQuery(String queryName);
-
-    /**
-     * TODO
-     *
-     * @param itemType
-     * @return
-     */
-    Map<String, Map<String, Object>> getMapping(String itemType);
-
-    /**
-     * TODO
-     *
-     * @param item
-     * @return
-     */
-    List<String> getMatchingSavedQueries(Item item);
-
-    /**
-     * Checks whether the specified item satisfies the provided condition.
-     *
-     * TODO: rename to isMatching?
-     *
-     * @param query the condition we're testing the specified item against
-     * @param item  the item we're checking against the specified condition
-     * @return {@code true} if the item satisfies the condition, {@code false} 
otherwise
-     */
-    boolean testMatch(Condition query, Item item);
-
-    /**
-     * Same as {@code query(fieldName, fieldValue, sortBy, clazz, 0, 
-1).getList()}
-     *
-     * @see #query(Condition, String, Class, int, int)
-     */
-    <T extends Item> List<T> query(String fieldName, String fieldValue, String 
sortBy, Class<T> clazz);
-
-    /**
-     * Retrieves a list of items with the specified field having the specified 
values.
-     *
-     * @param <T>         the type of the Item subclass we want to retrieve
-     * @param fieldName   the name of the field which we want items to have 
the specified values
-     * @param fieldValues the values the items to retrieve should have for the 
specified field
-     * @param sortBy      an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *                    elements according to the property order in the
-     *                    String, considering each in turn and moving on to 
the next one in case of equality of all preceding ones. Each property name is 
optionally followed by
-     *                    a column ({@code :}) and an order specifier: {@code 
asc} or {@code desc}.
-     * @param clazz       the {@link Item} subclass of the items we want to 
retrieve
-     * @return a list of items matching the specified criteria
-     */
-    <T extends Item> List<T> query(String fieldName, String[] fieldValues, 
String sortBy, Class<T> clazz);
-
-    /**
-     * Retrieves a list of items with the specified field having the specified 
value.
-     *
-     * @param <T>        the type of the Item subclass we want to retrieve
-     * @param fieldName  the name of the field which we want items to have the 
specified value
-     * @param fieldValue the value the items to retrieve should have for the 
specified field
-     * @param sortBy     an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *                   elements according to the property order in the
-     *                   String, considering each in turn and moving on to the 
next one in case of equality of all preceding ones. Each property name is 
optionally followed by
-     *                   a column ({@code :}) and an order specifier: {@code 
asc} or {@code desc}.
-     * @param clazz      the {@link Item} subclass of the items we want to 
retrieve
-     * @return a {@link PartialList} of items matching the specified criteria
-     */
-    <T extends Item> PartialList<T> query(String fieldName, String fieldValue, 
String sortBy, Class<T> clazz, int offset, int size);
-
-    /**
-     * Retrieves a list of items with the specified field having the specified 
value and having at least a field with the specified full text value in it, 
ordered according to the
-     * specified {@code sortBy} String and and paged: only {@code size} of 
them are retrieved, starting with the {@code offset}-th one.
-     *
-     * @param <T>        the type of the Item subclass we want to retrieve
-     * @param fieldName  the name of the field which we want items to have the 
specified value
-     * @param fieldValue the value the items to retrieve should have for the 
specified field
-     * @param fulltext   the text that the item must have in one of its fields 
to be considered a match
-     * @param sortBy     an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *                   elements according to the property order in the
-     *                   String, considering each in turn and moving on to the 
next one in case of equality of all preceding ones. Each property name is 
optionally followed by
-     *                   a column ({@code :}) and an order specifier: {@code 
asc} or {@code desc}.
-     * @param clazz      the {@link Item} subclass of the items we want to 
retrieve
-     * @param offset     zero or a positive integer specifying the position of 
the first item in the total ordered collection of matching items
-     * @param size       a positive integer specifying how many matching items 
should be retrieved or {@code -1} if all of them should be retrieved
-     * @return a {@link PartialList} of items matching the specified criteria
-     */
-    <T extends Item> PartialList<T> queryFullText(String fieldName, String 
fieldValue, String fulltext, String sortBy, Class<T> clazz, int offset, int 
size);
-
-    /**
-     * Retrieves a list of items having at least a field with the specified 
full text value in it, ordered according to the specified {@code sortBy} String 
and and paged: only
-     * {@code size} of them are retrieved, starting with the {@code offset}-th 
one.
-     *
-     * @param <T>      the type of the Item subclass we want to retrieve
-     * @param fulltext the text that the item must have in one of its fields 
to be considered a match
-     * @param sortBy   an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *                 elements according to the property order in the
-     *                 String, considering each in turn and moving on to the 
next one in case of equality of all preceding ones. Each property name is 
optionally followed by
-     *                 a column ({@code :}) and an order specifier: {@code 
asc} or {@code desc}.
-     * @param clazz    the {@link Item} subclass of the items we want to 
retrieve
-     * @param offset   zero or a positive integer specifying the position of 
the first item in the total ordered collection of matching items
-     * @param size     a positive integer specifying how many matching items 
should be retrieved or {@code -1} if all of them should be retrieved
-     * @return a {@link PartialList} of items matching the specified criteria
-     */
-    <T extends Item> PartialList<T> queryFullText(String fulltext, String 
sortBy, Class<T> clazz, int offset, int size);
-
-    /**
-     * Same as {@code query(query, sortBy, clazz, 0, -1).getList()}
-     *
-     * @see #query(Condition, String, Class, int, int)
-     */
-    <T extends Item> List<T> query(Condition query, String sortBy, Class<T> 
clazz);
-
-    /**
-     * Retrieves a list of items satisfying the specified {@link Condition}, 
ordered according to the specified {@code sortBy} String and and paged: only 
{@code size} of them
-     * are retrieved, starting with the {@code offset}-th one.
-     *
-     * @param <T>    the type of the Item subclass we want to retrieve
-     * @param query  the {@link Condition} the items must satisfy to be 
retrieved
-     * @param sortBy an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *               elements according to the property order in the
-     *               String, considering each in turn and moving on to the 
next one in case of equality of all preceding ones. Each property name is 
optionally followed by
-     *               a column ({@code :}) and an order specifier: {@code asc} 
or {@code desc}.
-     * @param clazz  the {@link Item} subclass of the items we want to retrieve
-     * @param offset zero or a positive integer specifying the position of the 
first item in the total ordered collection of matching items
-     * @param size   a positive integer specifying how many matching items 
should be retrieved or {@code -1} if all of them should be retrieved
-     * @return a {@link PartialList} of items matching the specified criteria
-     */
-    <T extends Item> PartialList<T> query(Condition query, String sortBy, 
Class<T> clazz, int offset, int size);
-
-    /**
-     * Retrieves the same items as {@code query(query, sortBy, clazz, 0, -1)} 
with the added constraints that the matching elements must also have at least a 
field matching the
-     * specified full text query.
-     *
-     * @param <T>      the type of the Item subclass we want to retrieve
-     * @param fulltext the text that the item must have in one of its fields 
to be considered a match
-     * @param query    the {@link Condition} the items must satisfy to be 
retrieved
-     * @param sortBy   an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *                 elements according to the property order in the
-     *                 String, considering each in turn and moving on to the 
next one in case of equality of all preceding ones. Each property name is 
optionally followed by
-     *                 a column ({@code :}) and an order specifier: {@code 
asc} or {@code desc}.
-     * @param clazz    the {@link Item} subclass of the items we want to 
retrieve
-     * @param offset   zero or a positive integer specifying the position of 
the first item in the total ordered collection of matching items
-     * @param size     a positive integer specifying how many matching items 
should be retrieved or {@code -1} if all of them should be retrieved
-     * @return a {@link PartialList} of items matching the specified criteria
-     */
-    <T extends Item> PartialList<T> queryFullText(String fulltext, Condition 
query, String sortBy, Class<T> clazz, int offset, int size);
-
-    /**
-     * Retrieves the number of items of the specified type as defined by the 
Item subclass public field {@code ITEM_TYPE} and matching the specified {@link 
Condition}.
-     *
-     * @param query    the condition the items must satisfy
-     * @param itemType the String representation of the item type we want to 
retrieve the count of, as defined by its class' {@code ITEM_TYPE} field
-     * @return the number of items of the specified type
-     * @see Item Item for a discussion of {@code ITEM_TYPE}
-     */
-    long queryCount(Condition query, String itemType);
-
-    /**
-     * Retrieves the number of items with the specified type as defined by the 
Item subclass public field {@code ITEM_TYPE}.
-     *
-     * @param itemType the String representation of the item type we want to 
retrieve the count of, as defined by its class' {@code ITEM_TYPE} field
-     * @return the number of items of the specified type
-     * @see Item Item for a discussion of {@code ITEM_TYPE}
-     */
-    long getAllItemsCount(String itemType);
-
-    /**
-     * Retrieves the number of items with the specified type as defined by the 
Item subclass public field {@code ITEM_TYPE} matching the optional specified 
condition and
-     * aggregated according to the specified {@link BaseAggregate}.
-     *
-     * @param filter    the condition the items must match or {@code null} if 
no filtering is needed
-     * @param aggregate an aggregate specifying how matching items must be 
bundled
-     * @param itemType  the String representation of the item type we want to 
retrieve the count of, as defined by its class' {@code ITEM_TYPE} field
-     * @return a Map associating aggregation dimension name as key and 
cardinality for that dimension as value
-     */
-    Map<String, Long> aggregateQuery(Condition filter, BaseAggregate 
aggregate, String itemType);
-
-    /**
-     * Updates the persistence's engine indices if needed.
-     */
-    void refresh();
-
-    /**
-     * Purges all data in the context server up to the specified date, not 
included.
-     *
-     * @param date the date (not included) before which we want to erase all 
data
-     */
-    void purge(Date date);
-
-    /**
-     * Retrieves all items of the specified Item subclass which specified 
ranged property is within the specified bounds, ordered according to the 
specified {@code sortBy} String
-     * and and paged: only {@code size} of them are retrieved, starting with 
the {@code offset}-th one.
-     *
-     * @param <T>    the type of the Item subclass we want to retrieve
-     * @param s      the name of the range property we want items to retrieve 
to be included between the specified start and end points
-     * @param from   the beginning of the range we want to consider
-     * @param to     the end of the range we want to consider
-     * @param sortBy an optional ({@code null} if no sorting is required) 
String of comma ({@code ,}) separated property names on which ordering should 
be performed, ordering
-     *               elements according to the property order in the String, 
considering each in turn and moving on to the next one in case of equality of 
all preceding ones.
-     *               Each property name is optionally followed by a column 
({@code :}) and an order specifier: {@code asc} or {@code desc}.
-     * @param clazz  the {@link Item} subclass of the items we want to retrieve
-     * @param offset zero or a positive integer specifying the position of the 
first item in the total ordered collection of matching items
-     * @param size   a positive integer specifying how many matching items 
should be retrieved or {@code -1} if all of them should be retrieved
-     * @return a {@link PartialList} of items matching the specified criteria
-     */
-    <T extends Item> PartialList<T> rangeQuery(String s, String from, String 
to, String sortBy, Class<T> clazz, int offset, int size);
-
-    /**
-     * Retrieves the specified metrics for the specified field of items of the 
specified type as defined by the Item subclass public field {@code ITEM_TYPE} 
and matching the
-     * specified {@link Condition}.
-     *
-     * @param condition the condition the items must satisfy
-     * @param metrics   a String array which metrics should be computed 
(possible values: {@code sum} for the sum of the values,  {@code avg} for the 
average of the values, {@code
-     *                  min} for the minimum value and {@code max} for the 
maximum value)
-     * @param field     the name of the field for which the metrics should be 
computed
-     * @param type      the String representation of the item type we want to 
retrieve the count of, as defined by its class' {@code ITEM_TYPE} field
-     * @return a Map associating computed metric name as key to its associated 
value
-     */
-    Map<String, Double> getSingleValuesMetrics(Condition condition, String[] 
metrics, String field, String type);
-
-    /**
-     * Creates an index with the specified name in the persistence engine.
-     *
-     * TODO: remove from API?
-     *
-     * @param indexName the index name
-     * @return {@code true} if the operation was successful, {@code false} 
otherwise
-     */
-    boolean createIndex(final String indexName);
-
-    /**
-     * Removes the index with the specified name.
-     *
-     * TODO: remove from API?
-     *
-     * @param indexName the index name
-     * @return {@code true} if the operation was successful, {@code false} 
otherwise
-     */
-    boolean removeIndex(final String indexName);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyHelper.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyHelper.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyHelper.java
deleted file mode 100644
index aedb6f9..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyHelper.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi;
-
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.beanutils.expression.DefaultResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-
-/**
- * Created by toto on 20/05/15.
- */
-public class PropertyHelper {
-
-    private static final Logger logger = 
LoggerFactory.getLogger(PropertyHelper.class.getName());
-    private static DefaultResolver resolver = new DefaultResolver();
-
-    public static boolean setProperty(Object target, String propertyName, 
Object propertyValue, String setPropertyStrategy) {
-        try {
-            while (resolver.hasNested(propertyName)) {
-                Object v = PropertyUtils.getProperty(target, 
resolver.next(propertyName));
-                if (v == null) {
-                    v = new LinkedHashMap<>();
-                    PropertyUtils.setProperty(target, 
resolver.next(propertyName), v);
-                }
-                propertyName = resolver.remove(propertyName);
-                target = v;
-            }
-
-            if (setPropertyStrategy != null && 
setPropertyStrategy.equals("addValue")) {
-                Object previousValue = PropertyUtils.getProperty(target, 
propertyName);
-                List<Object> values = new ArrayList<>();
-                if (previousValue != null && previousValue instanceof List) {
-                    values.addAll((List) previousValue);
-                } else if (previousValue != null) {
-                    values.add(previousValue);
-                }
-                if (!values.contains(propertyValue)) {
-                    values.add(propertyValue);
-                    BeanUtils.setProperty(target, propertyName, values);
-                    return true;
-                }
-            } else if (propertyValue != null && 
!propertyValue.equals(BeanUtils.getProperty(target, propertyName))) {
-                if (setPropertyStrategy == null ||
-                        setPropertyStrategy.equals("alwaysSet") ||
-                        (setPropertyStrategy.equals("setIfMissing") && 
BeanUtils.getProperty(target, propertyName) == null)) {
-                    BeanUtils.setProperty(target, propertyName, propertyValue);
-                    return true;
-                }
-            }
-        } catch (IllegalAccessException | InvocationTargetException | 
NoSuchMethodException e) {
-            logger.error("Cannot set property", e);
-        }
-        return false;
-    }
-
-    public static Integer getInteger(Object value) {
-        if (value instanceof Number) {
-            return ((Number)value).intValue();
-        } else {
-            try {
-                return Integer.parseInt(value.toString());
-            } catch (NumberFormatException e) {
-                // Not a number
-            }
-        }
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyTypedObjectDeserializer.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyTypedObjectDeserializer.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyTypedObjectDeserializer.java
deleted file mode 100644
index 7d21cc4..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/PropertyTypedObjectDeserializer.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi;
-
-import com.fasterxml.jackson.core.*;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import java.io.IOException;
-import java.util.*;
-
-/**
- * This Jackson deserializer makes it possible to register field matching
- * regular expressions that can be matched to class names, as in the following
- * example:
- *
- *            SimpleModule deserializerModule =
- *                  new SimpleModule("PropertyTypedObjectDeserializerModule",
- *                      new Version(1, 0, 0, null, 
"org.oasis_open.contextserver.rest", "deserializer"));
- *            PropertyTypedObjectDeserializer propertyTypedObjectDeserializer 
= new PropertyTypedObjectDeserializer();
- *            
propertyTypedObjectDeserializer.registerMapping("type=.*Condition", 
Condition.class);
- *            deserializerModule.addDeserializer(Object.class, 
propertyTypedObjectDeserializer);
- *            objectMapper.registerModule(deserializerModule);
- *
- * In this example any JSON object that has a "type" property that matches the
- * ".*Condition" regular expression will be parsed and mapped to a Condition 
class
- *
- * Note that there exists a way to map properties as type identifiers in 
Jackson,
- * but this feature is very limited and requires hardcoding possible values.
- * This deserializer is much more flexible and powerful.
- */
-public class PropertyTypedObjectDeserializer extends UntypedObjectDeserializer 
{
-
-    private static final long serialVersionUID = -2561171359946902967L;
-
-    private Map<String, Class<? extends Object>> registry =
-            new LinkedHashMap<String, Class<? extends Object>>();
-
-    private Map<String,Set<String>> fieldValuesToMatch = new 
LinkedHashMap<String,Set<String>>();
-
-    public void registerMapping(String matchExpression,
-                                Class<? extends Object> mappedClass) {
-        registry.put(matchExpression, mappedClass);
-        String[] fieldParts = matchExpression.split("=");
-        Set<String> valuesToMatch = fieldValuesToMatch.get(fieldParts[0]);
-        if (valuesToMatch == null) {
-            valuesToMatch = new LinkedHashSet<String>();
-        }
-        valuesToMatch.add(fieldParts[1]);
-        fieldValuesToMatch.put(fieldParts[0], valuesToMatch);
-    }
-
-    @Override
-    public Object deserialize(
-            JsonParser jp, DeserializationContext ctxt)
-            throws IOException, JsonProcessingException {
-        if (jp.getCurrentTokenId() != JsonTokenId.ID_START_OBJECT) {
-            return super.deserialize(jp, ctxt);
-        }
-        ObjectCodec codec = jp.getCodec();
-        TreeNode treeNode = codec.readTree(jp);
-        Class<? extends Object> objectClass = null;
-        if (treeNode instanceof ObjectNode) {
-            ObjectNode root = (ObjectNode) treeNode;
-            Iterator<Map.Entry<String, JsonNode>> elementsIterator =
-                    root.fields();
-            while (elementsIterator.hasNext()) {
-                Map.Entry<String, JsonNode> element = elementsIterator.next();
-                String name = element.getKey();
-                if (fieldValuesToMatch.containsKey(name)) {
-                    Set<String> valuesToMatch = fieldValuesToMatch.get(name);
-                    for (String valueToMatch : valuesToMatch) {
-                        if (element.getValue().asText().matches(valueToMatch)) 
{
-                            objectClass = registry.get(name + "=" + 
valueToMatch);
-                            break;
-                        }
-                    }
-                    if (objectClass != null) {
-                        break;
-                    }
-                }
-            }
-            if (objectClass == null) {
-                objectClass = HashMap.class;
-            }
-        } else {
-
-        }
-        if (objectClass == null) {
-            return super.deserialize(codec.treeAsTokens(treeNode), ctxt);
-        }
-        return codec.treeToValue(treeNode, objectClass);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/BaseAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/BaseAggregate.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/BaseAggregate.java
deleted file mode 100644
index 5d0c437..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/BaseAggregate.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi.aggregate;
-
-public abstract class BaseAggregate {
-    private String field;
-
-    public BaseAggregate(String field) {
-        this.field = field;
-    }
-
-    public String getField() {
-        return field;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateAggregate.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateAggregate.java
deleted file mode 100644
index d3b3fc3..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateAggregate.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi.aggregate;
-
-public class DateAggregate extends BaseAggregate{
-    private static final String DEFAULT_INTERVAL = "1M";
-    public static final DateAggregate SECOND = new DateAggregate("1s");
-    public static final DateAggregate MINUTE = new DateAggregate("1m");
-    public static final DateAggregate HOUR = new DateAggregate("1h");
-    public static final DateAggregate DAY = new DateAggregate("1d");
-    public static final DateAggregate WEEK = new DateAggregate("1w");
-    public static final DateAggregate MONTH = new DateAggregate("1M");
-    public static final DateAggregate QUARTER = new DateAggregate("1q");
-    public static final DateAggregate YEAR = new DateAggregate("1y");
-    public static DateAggregate seconds(int sec) {
-        return new DateAggregate(sec + "s");
-    }
-    public static DateAggregate minutes(int min) {
-        return new DateAggregate(min + "m");
-    }
-    public static DateAggregate hours(int hours) {
-        return new DateAggregate(hours + "h");
-    }
-    public static DateAggregate days(int days) {
-        return new DateAggregate(days + "d");
-    }
-    public static DateAggregate weeks(int weeks) {
-        return new DateAggregate(weeks + "w");
-    }
-
-    private String interval;
-
-    private String format;
-
-    public DateAggregate(String field) {
-        super(field);
-        this.interval = DEFAULT_INTERVAL;
-    }
-
-    public DateAggregate(String field, String interval) {
-        super(field);
-        this.interval = (interval != null && interval.length() > 0) ? interval 
: DEFAULT_INTERVAL;
-    }
-
-    public DateAggregate(String field, String interval, String format) {
-        super(field);
-        this.interval = (interval != null && interval.length() > 0) ? interval 
: DEFAULT_INTERVAL;
-        this.format = format;
-    }
-
-    public String getInterval() {
-        return interval;
-    }
-
-    public String getFormat() {
-        return format;
-    }
-
-    public void setFormat(String format) {
-        this.format = format;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateRangeAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateRangeAggregate.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateRangeAggregate.java
deleted file mode 100644
index 7e62c67..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/DateRangeAggregate.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi.aggregate;
-
-import org.oasis_open.contextserver.api.query.DateRange;
-
-import java.util.List;
-
-public class DateRangeAggregate extends BaseAggregate{
-
-    public DateRangeAggregate(String field, String format, List<DateRange> 
dateRanges) {
-        super(field);
-        this.format = format;
-        this.dateRanges = dateRanges;
-    }
-
-    private String format;
-
-    private List<DateRange> dateRanges;
-
-    public List<DateRange> getDateRanges() {
-        return dateRanges;
-    }
-
-    public void setDateRanges(List<DateRange> dateRanges) {
-        this.dateRanges = dateRanges;
-    }
-
-    public String getFormat() {
-        return format;
-    }
-
-    public void setFormat(String format) {
-        this.format = format;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/IpRangeAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/IpRangeAggregate.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/IpRangeAggregate.java
deleted file mode 100644
index e7181d5..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/IpRangeAggregate.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi.aggregate;
-
-import org.oasis_open.contextserver.api.query.IpRange;
-
-import java.util.List;
-
-public class IpRangeAggregate extends BaseAggregate{
-    public IpRangeAggregate(String field, List<IpRange> ranges) {
-        super(field);
-        this.ranges = ranges;
-    }
-
-    private List<IpRange> ranges;
-
-    public List<IpRange> getRanges() {
-        return ranges;
-    }
-
-    public void setRanges(List<IpRange> ranges) {
-        this.ranges = ranges;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/NumericRangeAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/NumericRangeAggregate.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/NumericRangeAggregate.java
deleted file mode 100644
index 6e29b23..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/NumericRangeAggregate.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi.aggregate;
-
-import org.oasis_open.contextserver.api.query.NumericRange;
-
-import java.util.List;
-
-public class NumericRangeAggregate extends BaseAggregate{
-    public NumericRangeAggregate(String field, List<NumericRange> ranges) {
-        super(field);
-        this.ranges = ranges;
-    }
-
-    private List<NumericRange> ranges;
-
-    public List<NumericRange> getRanges() {
-        return ranges;
-    }
-
-    public void setRanges(List<NumericRange> ranges) {
-        this.ranges = ranges;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/TermsAggregate.java
----------------------------------------------------------------------
diff --git 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/TermsAggregate.java
 
b/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/TermsAggregate.java
deleted file mode 100644
index 260e03b..0000000
--- 
a/persistence-spi/src/main/java/org/oasis_open/contextserver/persistence/spi/aggregate/TermsAggregate.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oasis_open.contextserver.persistence.spi.aggregate;
-
-public class TermsAggregate extends BaseAggregate{
-    public TermsAggregate(String field) {
-        super(field);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/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
new file mode 100644
index 0000000..341db32
--- /dev/null
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/AllEventToProfilePropertiesAction.java
@@ -0,0 +1,68 @@
+/*
+ * 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.plugins.baseplugin.actions;
+
+import org.apache.commons.beanutils.BeanUtilsBean;
+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.ProfileService;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class AllEventToProfilePropertiesAction implements ActionExecutor {
+
+    private ProfileService profileService;
+
+    public void setProfileService(ProfileService profileService) {
+        this.profileService = profileService;
+    }
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public int execute(Action action, Event event) {
+        boolean changed = false;
+        Map<String, Object> properties = new HashMap<String,Object>();
+        if (event.getProperties() != null) {
+            properties.putAll(event.getProperties());
+        }
+
+
+        try {
+            Object targetProperties = 
BeanUtilsBean.getInstance().getPropertyUtils().getProperty(event.getTarget(), 
"properties");
+            if (targetProperties instanceof Map) {
+                properties.putAll( (Map)targetProperties );
+            }
+        } catch (Exception e) {
+            // Ignore
+        }
+        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());
+                }
+                changed = true;
+            }
+        }
+        return changed ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileAgeAction.java
----------------------------------------------------------------------
diff --git 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileAgeAction.java
 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileAgeAction.java
new file mode 100644
index 0000000..cf3c199
--- /dev/null
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileAgeAction.java
@@ -0,0 +1,44 @@
+/*
+ * 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.plugins.baseplugin.actions;
+
+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.joda.time.DateTime;
+import org.joda.time.Years;
+
+/**
+ * An action that sets the age of a profile based on his birth date
+ */
+public class EvaluateProfileAgeAction implements ActionExecutor {
+
+    @Override
+    public int execute(Action action, Event event) {
+        boolean updated = false;
+        if(event.getProfile().getProperty("birthDate") != null) {
+            Integer y = Years.yearsBetween(new 
DateTime(event.getProfile().getProperty("birthDate")), new 
DateTime()).getYears();
+            if(event.getProfile().getProperty("age") == null || 
event.getProfile().getProperty("age") != y){
+                updated = true;
+                event.getProfile().setProperty("age", y);
+            }
+        }
+        return updated ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileSegmentsAction.java
----------------------------------------------------------------------
diff --git 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileSegmentsAction.java
 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileSegmentsAction.java
new file mode 100644
index 0000000..cd7ac85
--- /dev/null
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EvaluateProfileSegmentsAction.java
@@ -0,0 +1,58 @@
+/*
+ * 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.plugins.baseplugin.actions;
+
+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.segments.SegmentsAndScores;
+import org.apache.unomi.api.services.EventService;
+import org.apache.unomi.api.services.SegmentService;
+
+import java.util.Map;
+import java.util.Set;
+
+public class EvaluateProfileSegmentsAction implements ActionExecutor {
+
+    private SegmentService segmentService;
+
+    public SegmentService getSegmentService() {
+        return segmentService;
+    }
+
+    public void setSegmentService(SegmentService segmentService) {
+        this.segmentService = segmentService;
+    }
+
+    @Override
+    public int execute(Action action, Event event) {
+        boolean updated = false;
+        SegmentsAndScores segmentsAndScoringForProfile = 
segmentService.getSegmentsAndScoresForProfile(event.getProfile());
+        Set<String> segments = segmentsAndScoringForProfile.getSegments();
+        if (!segments.equals(event.getProfile().getSegments())) {
+            event.getProfile().setSegments(segments);
+            updated = true;
+        }
+        Map<String, Integer> scores = segmentsAndScoringForProfile.getScores();
+        if (!scores.equals(event.getProfile().getScores())) {
+            event.getProfile().setScores(scores);
+            updated = true;
+        }
+        return updated ? EventService.PROFILE_UPDATED : EventService.NO_CHANGE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/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
new file mode 100644
index 0000000..2e7617c
--- /dev/null
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/EventToProfilePropertyAction.java
@@ -0,0 +1,39 @@
+/*
+ * 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.plugins.baseplugin.actions;
+
+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;
+
+/**
+ * A action to copy an event property to a profile property
+ */
+public class EventToProfilePropertyAction implements ActionExecutor {
+
+    public int execute(Action action, Event event) {
+        String eventPropertyName = (String) 
action.getParameterValues().get("eventPropertyName");
+        String profilePropertyName = (String) 
action.getParameterValues().get("profilePropertyName");
+        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;
+        }
+        return EventService.NO_CHANGE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/IncrementInterestsValuesAction.java
----------------------------------------------------------------------
diff --git 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/IncrementInterestsValuesAction.java
 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/IncrementInterestsValuesAction.java
new file mode 100644
index 0000000..b2c4484
--- /dev/null
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/IncrementInterestsValuesAction.java
@@ -0,0 +1,63 @@
+/*
+ * 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.plugins.baseplugin.actions;
+
+import org.apache.commons.beanutils.PropertyUtils;
+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 java.util.HashMap;
+import java.util.Map;
+
+public class IncrementInterestsValuesAction implements ActionExecutor {
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public int execute(Action action, Event event) {
+        boolean modified = false;
+
+        try {
+            Map<String, Object> interests = (Map<String, Object>) 
PropertyUtils.getProperty(event, "target.properties.interests");
+            if (interests != null) {
+                for (Map.Entry<String, Object> s : interests.entrySet()) {
+                    int value = (Integer) s.getValue();
+
+                    HashMap<String, Object> profileInterests = 
(HashMap<String, Object>) event.getProfile().getProperty("interests");
+                    if(profileInterests != null){
+                        profileInterests = new HashMap<String, 
Object>(profileInterests);
+                        int oldValue = 
(profileInterests.containsKey(s.getKey())) ? (Integer) 
profileInterests.get(s.getKey()) : 0;
+                        profileInterests.put(s.getKey(), value + oldValue);
+                    }else {
+                        profileInterests = new HashMap<String, Object>();
+                        profileInterests.put(s.getKey(), value);
+                    }
+                    event.getProfile().setProperty("interests", 
profileInterests);
+                    modified = true;
+                }
+            }
+        } catch (UnsupportedOperationException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new UnsupportedOperationException(e);
+        }
+
+        return modified ? EventService.PROFILE_UPDATED : 
EventService.NO_CHANGE;
+    }
+}

Reply via email to