UNOMI-94 New action : add a profile to a list Signed-off-by: Serge Huber <shu...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/97581032 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/97581032 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/97581032 Branch: refs/heads/feature-UNOMI-5-KARAF4 Commit: 97581032c38efc4aa384a01a0266f84cd013f863 Parents: 7e81374 Author: Serge Huber <shu...@apache.org> Authored: Sat May 6 23:18:11 2017 +0200 Committer: Serge Huber <shu...@apache.org> Committed: Sat May 6 23:18:11 2017 +0200 ---------------------------------------------------------------------- extensions/lists-extension/actions/pom.xml | 68 ++++++++++++++++++++ .../unomi/lists/actions/AddToListsAction.java | 58 +++++++++++++++++ .../META-INF/cxs/actions/addToLists.json | 19 ++++++ .../resources/OSGI-INF/blueprint/blueprint.xml | 37 +++++++++++ extensions/lists-extension/pom.xml | 1 + kar/pom.xml | 5 ++ 6 files changed, 188 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/97581032/extensions/lists-extension/actions/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/lists-extension/actions/pom.xml b/extensions/lists-extension/actions/pom.xml new file mode 100644 index 0000000..91c0e8e --- /dev/null +++ b/extensions/lists-extension/actions/pom.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>cxs-lists-extension</artifactId> + <groupId>org.apache.unomi</groupId> + <version>1.2.0-incubating-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>cxs-lists-extension-actions</artifactId> + <name>Apache Unomi :: Extensions :: Lists :: Actions</name> + <description>List extension rule actions for the Apache Unomi Context Server</description> + + <version>1.2.0-incubating-SNAPSHOT</version> + <packaging>bundle</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-api</artifactId> + <version>1.2.0-incubating-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.unomi</groupId> + <artifactId>cxs-lists-extension-services</artifactId> + <version>1.2.0-incubating-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> + <Import-Package> + sun.misc;resolution:=optional, + * + </Import-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/97581032/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java ---------------------------------------------------------------------- diff --git a/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java b/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java new file mode 100644 index 0000000..3ec1407 --- /dev/null +++ b/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.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.lists.actions; + +import org.apache.unomi.api.Event; +import org.apache.unomi.api.Profile; +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.Date; +import java.util.List; + +/** + * A rule action that can add a profile to a list + */ +public class AddToListsAction implements ActionExecutor { + + ProfileService profileService; + EventService eventService; + + public void setProfileService(ProfileService profileService) { + this.profileService = profileService; + } + + public void setEventService(EventService eventService) { + this.eventService = eventService; + } + + @Override + public int execute(Action action, Event event) { + List<String> listIdentifiers = (List<String>) action.getParameterValues().get("listIdentifiers"); + Profile profile = event.getProfile(); + + profile.getSystemProperties().put("lists", listIdentifiers); + Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date()); + profileUpdated.setPersistent(false); + eventService.send(profileUpdated); + profileService.save(profile); + + return EventService.PROFILE_UPDATED; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/97581032/extensions/lists-extension/actions/src/main/resources/META-INF/cxs/actions/addToLists.json ---------------------------------------------------------------------- diff --git a/extensions/lists-extension/actions/src/main/resources/META-INF/cxs/actions/addToLists.json b/extensions/lists-extension/actions/src/main/resources/META-INF/cxs/actions/addToLists.json new file mode 100644 index 0000000..8875fa9 --- /dev/null +++ b/extensions/lists-extension/actions/src/main/resources/META-INF/cxs/actions/addToLists.json @@ -0,0 +1,19 @@ +{ + "metadata": { + "id": "addToListsAction", + "name": "addToListsAction", + "description": "", + "tags": [ + "demographic" + ], + "readOnly": true + }, + "actionExecutor": "addToLists", + "parameters": [ + { + "id": "listIdentifiers", + "type": "string", + "multivalued": true + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/97581032/extensions/lists-extension/actions/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/extensions/lists-extension/actions/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/lists-extension/actions/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..386fbe0 --- /dev/null +++ b/extensions/lists-extension/actions/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <reference id="profileService" interface="org.apache.unomi.api.services.ProfileService"/> + <reference id="eventService" interface="org.apache.unomi.api.services.EventService"/> + + <!-- Action executors --> + + <service auto-export="interfaces"> + <service-properties> + <entry key="actionExecutorId" value="addToLists"/> + </service-properties> + <bean class="org.apache.unomi.lists.actions.AddToListsAction"> + <property name="profileService" ref="profileService"/> + <property name="eventService" ref="eventService"/> + </bean> + </service> + +</blueprint> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/97581032/extensions/lists-extension/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/lists-extension/pom.xml b/extensions/lists-extension/pom.xml index d348ad9..6542575 100644 --- a/extensions/lists-extension/pom.xml +++ b/extensions/lists-extension/pom.xml @@ -22,6 +22,7 @@ <modules> <module>services</module> <module>rest</module> + <module>actions</module> </modules> <parent> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/97581032/kar/pom.xml ---------------------------------------------------------------------- diff --git a/kar/pom.xml b/kar/pom.xml index 623d362..20d4257 100644 --- a/kar/pom.xml +++ b/kar/pom.xml @@ -83,6 +83,11 @@ </dependency> <dependency> <groupId>org.apache.unomi</groupId> + <artifactId>cxs-lists-extension-actions</artifactId> + <version>1.2.0-incubating-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.unomi</groupId> <artifactId>cxs-geonames-services</artifactId> <version>1.2.0-incubating-SNAPSHOT</version> </dependency>