You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by ql...@apache.org on 2016/08/04 17:04:30 UTC
[4/6] incubator-unomi git commit: UNOMI-47 : Once per profile handled
in the mailing action, because event updatedProfile is not persisted
UNOMI-47 : Once per profile handled in the mailing action, because event updatedProfile is not persisted
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/2d58c953
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/2d58c953
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/2d58c953
Branch: refs/heads/master
Commit: 2d58c953bfd1c494afd32f0e366588e05696daa9
Parents: 3e094f1
Author: Abdelkader Midani <am...@jahia.com>
Authored: Wed Aug 3 12:40:40 2016 +0200
Committer: Quentin Lamerand <ql...@jahia.com>
Committed: Thu Aug 4 19:02:06 2016 +0200
----------------------------------------------------------------------
plugins/mail/pom.xml | 6 ++++
.../plugins/mail/actions/SendMailAction.java | 31 ++++++++++++++++++++
.../META-INF/cxs/actions/sendMailAction.json | 16 ++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 4 +++
4 files changed, 57 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2d58c953/plugins/mail/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/mail/pom.xml b/plugins/mail/pom.xml
index fcc431e..7bb2eca 100644
--- a/plugins/mail/pom.xml
+++ b/plugins/mail/pom.xml
@@ -31,6 +31,12 @@
<dependencies>
<dependency>
+ <groupId>org.apache.unomi</groupId>
+ <artifactId>unomi-persistence-spi</artifactId>
+ <version>1.1.0-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2d58c953/plugins/mail/src/main/java/org/apache/unomi/plugins/mail/actions/SendMailAction.java
----------------------------------------------------------------------
diff --git a/plugins/mail/src/main/java/org/apache/unomi/plugins/mail/actions/SendMailAction.java b/plugins/mail/src/main/java/org/apache/unomi/plugins/mail/actions/SendMailAction.java
index af22211..278418d 100644
--- a/plugins/mail/src/main/java/org/apache/unomi/plugins/mail/actions/SendMailAction.java
+++ b/plugins/mail/src/main/java/org/apache/unomi/plugins/mail/actions/SendMailAction.java
@@ -22,25 +22,35 @@ import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.ImageHtmlEmail;
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.persistence.spi.PersistenceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stringtemplate.v4.ST;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
public class SendMailAction implements ActionExecutor {
private static final Logger logger = LoggerFactory.getLogger(SendMailAction.class.getName());
+ private PersistenceService persistenceService;
+
private String mailServerHostName;
private int mailServerPort;
private String mailServerUsername;
private String mailServerPassword;
private boolean mailServerSSLOnConnect = true;
+ public void setPersistenceService(PersistenceService persistenceService) {
+ this.persistenceService = persistenceService;
+ }
+
public void setMailServerHostName(String mailServerHostName) {
this.mailServerHostName = mailServerHostName;
}
@@ -62,6 +72,9 @@ public class SendMailAction implements ActionExecutor {
}
public int execute(Action action, Event event) {
+ String notifType = (String) action.getParameterValues().get("notificationType");
+ String notifTypeId = (String) action.getParameterValues().get("notificationTypeId");
+ Boolean notifyOnce = (Boolean) action.getParameterValues().get("notifyOncePerProfile");
String from = (String) action.getParameterValues().get("from");
String to = (String) action.getParameterValues().get("to");
String cc = (String) action.getParameterValues().get("cc");
@@ -69,6 +82,24 @@ public class SendMailAction implements ActionExecutor {
String subject = (String) action.getParameterValues().get("subject");
String template = (String) action.getParameterValues().get("template");
+ Map profileNotif = (HashMap) event.getProfile().getSystemProperties().get("notificationAck");
+ if (profileNotif != null && profileNotif.get(notifType) != null && ((HashMap) profileNotif.get(notifType)).get(notifTypeId) != null) {
+ Integer notifTypeAck = (Integer) ((HashMap) profileNotif.get(notifType) ).get(notifTypeId);
+ if(notifyOnce.booleanValue() && notifTypeAck > 0){
+ logger.info("Notification "+notifType+" already sent for the profile "+event.getProfileId());
+ return EventService.NO_CHANGE;
+ }
+ } else {
+ Map notification = profileNotif!=null?profileNotif:new HashMap();
+ notification.put(notifType, notification.get(notifType)!=null?notification.get(notifType):new HashMap());
+ Integer notifTypeAck = (Integer) ((HashMap) notification.get(notifType) ).get(notifTypeId);
+ if(notifTypeAck == null){
+ ((HashMap) notification.get(notifType) ).put(notifTypeId, 1);
+ }
+ event.getProfile().getSystemProperties().put("notificationAck", notification);
+ persistenceService.update(event.getProfile().getItemId(), null, Profile.class, "systemProperties", event.getProfile().getSystemProperties());
+ }
+
ST stringTemplate = new ST(template);
stringTemplate.add("profile", event.getProfile());
stringTemplate.add("event", event);
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2d58c953/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
----------------------------------------------------------------------
diff --git a/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json b/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
index c2c9152..cfd1679 100644
--- a/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
+++ b/plugins/mail/src/main/resources/META-INF/cxs/actions/sendMailAction.json
@@ -11,6 +11,22 @@
"actionExecutor": "sendMail",
"parameters": [
{
+ "id": "notificationType",
+ "type": "string",
+ "multivalued": false
+ },
+ {
+ "id": "notificationTypeId",
+ "type": "string",
+ "multivalued": false
+ },
+ {
+ "id": "notifyOncePerProfile",
+ "type": "boolean",
+ "multivalued": false,
+ "defaultValue": false
+ },
+ {
"id": "from",
"type": "string",
"multivalued": false
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2d58c953/plugins/mail/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/plugins/mail/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/plugins/mail/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 0cbde8d..e8e1849 100644
--- a/plugins/mail/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/plugins/mail/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -35,6 +35,7 @@
<!-- Action executors -->
<bean id="sendMailActionImpl" class="org.apache.unomi.plugins.mail.actions.SendMailAction">
+ <property name="persistenceService" ref="persistenceService"/>
<property name="mailServerHostName" value="${mail.server.hostname}"/>
<property name="mailServerPort" value="${mail.server.port}"/>
<property name="mailServerUsername" value="${mail.server.username}"/>
@@ -47,4 +48,7 @@
</service-properties>
</service>
+ <reference id="persistenceService"
+ interface="org.apache.unomi.persistence.spi.PersistenceService"/>
+
</blueprint>