Index: 3rdParty_sources/versions.txt
===================================================================
RCS file: /usr/local/cvsroot/3rdParty_sources/versions.txt,v
diff -u -r1.11.2.16 -r1.11.2.17
--- 3rdParty_sources/versions.txt 22 Jan 2016 10:50:57 -0000 1.11.2.16
+++ 3rdParty_sources/versions.txt 16 Feb 2016 16:03:47 -0000 1.11.2.17
@@ -5,8 +5,6 @@
This project contains following versions:
-aspirin 0.8.03.201003071132
-
batik 1.7.0
CKEditor Java 2.6
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/core/MailHeaders.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/core/MailImpl.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/core/MimeMessageInputStreamSource.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/core/MimeMessageSource.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/core/MimeMessageWrapper.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/util/Base64.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/util/InternetPrintWriter.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/util/RFC2822Headers.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/util/RFC822Date.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/util/RFC822DateFormat.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/util/SimplifiedDateFormat.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/james/util/SynchronizedDateFormat.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/mailet/Mail.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/apache/mailet/MailAddress.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/Bouncer.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/Configuration.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationChangeListener.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationMBean.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/GenericPoolableRemoteDeliveryFactory.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/MXLookup.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailQue.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailWatcher.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/QueManager.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/QuedItem.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/RemoteDelivery.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMailWatcherImpl.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMimeMessageGenerator.java'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_admin/web/config/editconfig.jsp
===================================================================
RCS file: /usr/local/cvsroot/lams_admin/web/config/editconfig.jsp,v
diff -u -r1.14.2.1 -r1.14.2.2
--- lams_admin/web/config/editconfig.jsp 7 Oct 2014 20:10:35 -0000 1.14.2.1
+++ lams_admin/web/config/editconfig.jsp 16 Feb 2016 16:03:18 -0000 1.14.2.2
@@ -1,54 +1,38 @@
-<%@ page import="org.lamsfoundation.lams.util.Configuration" %>
-<%@ page import="org.lamsfoundation.lams.config.ConfigurationItem" %>
+<%@ page import="org.lamsfoundation.lams.util.Configuration"%>
+<%@ page import="org.lamsfoundation.lams.config.ConfigurationItem"%>
<%@ include file="/taglibs.jsp"%>
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
Index: lams_build/3rdParty.userlibraries
===================================================================
RCS file: /usr/local/cvsroot/lams_build/3rdParty.userlibraries,v
diff -u -r1.71.2.20 -r1.71.2.21
--- lams_build/3rdParty.userlibraries 10 Dec 2015 10:43:20 -0000 1.71.2.20
+++ lams_build/3rdParty.userlibraries 16 Feb 2016 16:03:35 -0000 1.71.2.21
@@ -5,7 +5,6 @@
-
Index: lams_build/build.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_build/build.xml,v
diff -u -r1.120.2.59 -r1.120.2.60
--- lams_build/build.xml 24 Sep 2015 16:36:05 -0000 1.120.2.59
+++ lams_build/build.xml 16 Feb 2016 16:03:35 -0000 1.120.2.60
@@ -433,24 +433,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: lams_build/liblist.txt
===================================================================
RCS file: /usr/local/cvsroot/lams_build/liblist.txt,v
diff -u -r1.25.2.27 -r1.25.2.28
--- lams_build/liblist.txt 10 Dec 2015 10:43:20 -0000 1.25.2.27
+++ lams_build/liblist.txt 16 Feb 2016 16:03:35 -0000 1.25.2.28
@@ -7,9 +7,6 @@
poi-ooxml-schemas-3.10-FINAL-20140208.jar
xmlbeans-2.4.0.jar 2.3.0
-aspirin aspirin.jar 0.8.03 Apache License 1.1 Apache embeddable send-only SMTP server
- dnsjava-2.0.6.jar 2.0.6 BSD Brian Wellington implementation of DNS in Java
-
autopatch autopatch-1.4.2-lams.jar 1.4.2-lams Apache License Tacit Knowledge automated Java patching system
discovery-1.0.5-lams.jar 1.0.5-lams
Index: lams_build/conf/j2ee/jboss-deployment-structure.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_build/conf/j2ee/Attic/jboss-deployment-structure.xml,v
diff -u -r1.1.2.43 -r1.1.2.44
--- lams_build/conf/j2ee/jboss-deployment-structure.xml 16 Dec 2015 17:53:17 -0000 1.1.2.43
+++ lams_build/conf/j2ee/jboss-deployment-structure.xml 16 Feb 2016 16:03:35 -0000 1.1.2.44
@@ -19,7 +19,6 @@
-
Fisheye: Tag 1.1.2.4 refers to a dead (removed) revision in file `lams_build/lib/aspirin/aspirin.module.xml'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1.1.2.2 refers to a dead (removed) revision in file `lams_build/lib/aspirin/dnsjava.module.xml'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_build/lib/lams/lams.jar
===================================================================
RCS file: /usr/local/cvsroot/lams_build/lib/lams/lams.jar,v
diff -u -r1.420.2.59 -r1.420.2.60
Binary files differ
Index: lams_central/src/java/org/lamsfoundation/lams/web/ForgotPasswordServlet.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/ForgotPasswordServlet.java,v
diff -u -r1.9.2.2 -r1.9.2.3
--- lams_central/src/java/org/lamsfoundation/lams/web/ForgotPasswordServlet.java 12 Jan 2016 13:14:22 -0000 1.9.2.2
+++ lams_central/src/java/org/lamsfoundation/lams/web/ForgotPasswordServlet.java 16 Feb 2016 16:03:23 -0000 1.9.2.3
@@ -22,7 +22,6 @@
import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
import org.lamsfoundation.lams.util.CentralConstants;
import org.lamsfoundation.lams.util.Configuration;
-import org.lamsfoundation.lams.util.ConfigurationKeys;
import org.lamsfoundation.lams.util.Emailer;
import org.lamsfoundation.lams.util.FileUtilException;
import org.lamsfoundation.lams.util.MessageService;
@@ -116,12 +115,9 @@
String SMPTServer = Configuration.get("SMTPServer");
String supportEmail = Configuration.get("LamsSupportEmail");
- boolean useInternalSMTPServer = Boolean
- .parseBoolean(Configuration.get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER));
User user = null;
- if ((!useInternalSMTPServer && ((SMPTServer == null) || SMPTServer.equals(""))) || (supportEmail == null)
- || supportEmail.equals("")) {
+ if ((SMPTServer == null) || SMPTServer.equals("") || (supportEmail == null) || supportEmail.equals("")) {
// Validate SMTP not set up
languageKey = ForgotPasswordServlet.SMTP_SERVER_NOT_SET;
} else {
Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/commonContext.xml,v
diff -u -r1.100.2.23 -r1.100.2.24
--- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml 9 Feb 2016 16:08:50 -0000 1.100.2.23
+++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml 16 Feb 2016 16:03:21 -0000 1.100.2.24
@@ -329,14 +329,14 @@
PROPAGATION_REQUIRED
- PROPAGATION_REQUIRED
+ PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
+ PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
- PROPAGATION_REQUIRED
- PROPAGATION_SUPPORTS
+ PROPAGATION_REQUIRED
Fisheye: Tag 1.1 refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch2040054.sql'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java,v
diff -u -r1.6.2.1 -r1.6.2.2
--- lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java 31 Jul 2015 07:05:45 -0000 1.6.2.1
+++ lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java 16 Feb 2016 16:03:21 -0000 1.6.2.2
@@ -2,7 +2,6 @@
import java.io.UnsupportedEncodingException;
import java.security.InvalidParameterException;
-import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
@@ -11,6 +10,7 @@
import org.apache.commons.validator.EmailValidator;
import org.apache.log4j.Logger;
import org.lamsfoundation.lams.usermanagement.User;
+import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
import org.lamsfoundation.lams.util.Configuration;
import org.lamsfoundation.lams.util.ConfigurationKeys;
import org.lamsfoundation.lams.util.Emailer;
@@ -22,26 +22,31 @@
*
*/
public class DeliveryMethodMail extends AbstractDeliveryMethod {
+ private static final Logger log = Logger.getLogger(DeliveryMethodMail.class);
private static DeliveryMethodMail instance;
- protected static final EmailValidator emailValidator = EmailValidator.getInstance();
- private static final Logger log = Logger.getLogger(DeliveryMethodMail.class);
+ private static final EmailValidator emailValidator = EmailValidator.getInstance();
- protected DeliveryMethodMail() {
- super((short) 1, "MAIL", "Messages will be send by Mail");
+ private IUserManagementService userManagementService = null;
+
+ public static DeliveryMethodMail getInstance() {
+ if (DeliveryMethodMail.instance == null) {
+ DeliveryMethodMail.instance = new DeliveryMethodMail();
+ }
+ return DeliveryMethodMail.instance;
}
+ private DeliveryMethodMail() {
+ super((short) 1, "MAIL", "Messages will be send by email");
+ }
+
@Override
public String send(Integer fromUserId, Integer toUserId, String subject, String message, boolean isHtmlFormat)
throws InvalidParameterException {
- if (toUserId == null) {
- log.error("Target user ID must not be null.");
- }
try {
- User toUser = (User) EventNotificationService.getInstance().getUserManagementService()
- .findById(User.class, toUserId);
+ User toUser = (User) userManagementService.findById(User.class, toUserId);
if (toUser == null) {
- log.error("Target user with ID " + toUserId + " was not found.");
+ return "Target user with ID " + toUserId + " was not found.";
}
String toEmail = toUser.getEmail();
if (!DeliveryMethodMail.emailValidator.isValid(toEmail)) {
@@ -51,29 +56,26 @@
if (fromUserId == null) {
Emailer.sendFromSupportEmail(subject, toEmail, message, isHtmlFormat);
} else {
- User fromUser = (User) EventNotificationService.getInstance().getUserManagementService()
- .findById(User.class, fromUserId);
+ User fromUser = (User) userManagementService.findById(User.class, fromUserId);
if (fromUser == null) {
- log.error("Source user with ID " + fromUserId + " was not found.");
+ return "Source user with ID " + fromUserId + " was not found.";
}
String fromEmail = fromUser.getEmail();
if (!DeliveryMethodMail.emailValidator.isValid(fromEmail)) {
return "Source user's e-mail address is invalid.";
}
- Emailer.send(subject, toEmail, fromEmail, message, isHtmlFormat, new Properties());
+ Emailer.send(subject, toEmail, "", fromEmail, "", message, isHtmlFormat);
}
return null;
} catch (Exception e) {
+ DeliveryMethodMail.log.error("Error while sending an email", e);
return e.toString();
}
}
- public static DeliveryMethodMail getInstance() {
- if (DeliveryMethodMail.instance == null) {
- DeliveryMethodMail.instance = new DeliveryMethodMail();
- }
- return DeliveryMethodMail.instance;
+ public void setUserManagementService(IUserManagementService userManagementService) {
+ this.userManagementService = userManagementService;
}
/**
@@ -92,12 +94,12 @@
* @throws MessagingException
* if the operation failed
*/
- void notifyAdmin(String subject, String body, boolean isHtmlFormat) throws AddressException,
- UnsupportedEncodingException, MessagingException {
+ void notifyAdmin(String subject, String body, boolean isHtmlFormat)
+ throws AddressException, UnsupportedEncodingException, MessagingException {
String adminEmail = Configuration.get(ConfigurationKeys.LAMS_ADMIN_EMAIL);
- if (StringUtils.isEmpty(adminEmail)) {
- DeliveryMethodMail.log.warn("Could not notify admin as his email is blank. The subject: " + subject
- + ". The message: " + body);
+ if (StringUtils.isBlank(adminEmail)) {
+ DeliveryMethodMail.log.warn(
+ "Could not notify admin as his email is blank. The subject: " + subject + ". The message: " + body);
} else {
Emailer.sendFromSupportEmail(subject, adminEmail, body, isHtmlFormat);
}
Index: lams_common/src/java/org/lamsfoundation/lams/events/Event.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/Event.java,v
diff -u -r1.5 -r1.5.2.1
--- lams_common/src/java/org/lamsfoundation/lams/events/Event.java 4 Jul 2013 11:35:26 -0000 1.5
+++ lams_common/src/java/org/lamsfoundation/lams/events/Event.java 16 Feb 2016 16:03:21 -0000 1.5.2.1
@@ -1,18 +1,16 @@
package org.lamsfoundation.lams.events;
import java.security.InvalidParameterException;
-import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
/**
* A event that users can subscribe to and at some point can be triggered, notifing the users.
*
- * @hibernate.class table="lams_events"
+ * @hibernate.class table="lams_notification_event"
* @author Marcin Cieslak
*
*/
@@ -27,85 +25,46 @@
/**
* Name of the event.
*/
- protected String name;
+ private String name;
/**
* Scope of the event. For events that are common for the whole LAMS environment,
* {@link EventNotificationService#CORE_EVENTS_SCOPE} should be used. For tools their signature should be used.
*/
- protected String scope;
+ private String scope;
/**
* Identifier for a session in which the event is valid. or events that are common for the whole LAMS environment
* null
can be used. For tools their content ID should be used.
*/
- protected Long eventSessionId;
+ private Long eventSessionId;
/**
- * Was the event triggered (did it happen).
- */
- protected Boolean triggered = false;
-
- /**
* Set of users that are subscribed to this event, along with the required data.
*/
- protected Set subscriptions = new HashSet();
+ private Set subscriptions = new HashSet();
/**
- * Default message that will be send when the event is triggered and no other message is or was provided.
- */
- protected String defaultMessage;
-
- /**
- * Default subject of the message that will be send when the event is triggered and no other message is or was
- * provided.
- */
- protected String defaultSubject;
-
- /**
* Message that will be send when the event is triggered.
*/
- protected String message;
+ private String message;
/**
* Subject of the message that will be send when the event is triggered.
*/
- protected String subject;
+ private String subject;
/**
* Boolean indicates whether the message should be sent as text/html content or regular text/plain one
*/
- protected boolean htmlFormat;
+ private boolean htmlFormat;
/**
* If sending notifications fails, this property holds the time of this failure.
*/
- protected Date failTime;
+ private Date failTime;
- // -------------- non-persistent fields --------------
- /**
- * Label that identifies the event.
- */
- protected String fullSignature;
-
- /**
- * Used for event instance management in EventNotificationService.
- */
- protected int referenceCounter;
-
- /**
- * Thread that notifies users of the event. Since sending messages to multiple users can take some time, another
- * thread is responsible for that, so the main one does not get blocked.
- */
- protected Thread notificationThread;
-
- /**
- * Should the event be deleted from the database.
- */
- protected boolean deleted;
-
public Event() {
-
}
/**
@@ -124,115 +83,73 @@
* @throws InvalidParameterException
* if scope is null
or name is blank
*/
- public Event(String scope, String name, Long sessionId, String defaultSubject, String defaultMessage,
- boolean isHtmlContentType) throws InvalidParameterException {
+ public Event(String scope, String name, Long sessionId, String subject, String message, boolean isHtmlContentType)
+ throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Event scope can not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Event name can not be blank.");
}
this.scope = scope;
this.name = name;
- eventSessionId = sessionId;
- this.defaultSubject = defaultSubject;
- this.defaultMessage = defaultMessage;
+ this.eventSessionId = sessionId;
+ this.subject = subject;
+ this.message = message;
this.htmlFormat = isHtmlContentType;
- fullSignature = Event.createFullSignature(scope, name, sessionId);
}
- /**
- * Build a string that identifies the event.
- *
- * @param scope
- * scope of the event
- * @param name
- * name of the event
- * @param eventSessionId
- * session ID of the event
- * @return event signature of the event
- * @throws InvalidParameterException
- * if scope is null
or name is blank
- */
- protected static String createFullSignature(String scope, String name, Long sessionId)
- throws InvalidParameterException {
- if (scope == null) {
- throw new InvalidParameterException("Scope should not be null.");
- }
- if (StringUtils.isEmpty(name)) {
- throw new InvalidParameterException("Name should not be blank.");
- }
- return scope + '_' + name + (sessionId == null ? "" : "_" + sessionId);
- }
-
@Override
public Object clone() {
- Event clone = new Event(scope, name, eventSessionId, defaultSubject, defaultMessage, htmlFormat);
- for (Subscription subscription : getSubscriptions()) {
- clone.getSubscriptions().add((Subscription) subscription.clone());
- }
- return clone;
+ return new Event(scope, name, eventSessionId, subject, message, htmlFormat);
}
/**
- * Full signature is compared.
+ * @hibernate.property column="event_session_id"
+ * @return
*/
- @Override
- public boolean equals(Object o) {
- return ((o instanceof Event) && ((Event) o).getFullSignature().equalsIgnoreCase(getFullSignature()))
- || ((o instanceof CharSequence) && ((CharSequence) o).toString().equalsIgnoreCase(getFullSignature()));
+ public Long getEventSessionId() {
+ return eventSessionId;
}
- @Override
- public int hashCode() {
- return getFullSignature().hashCode();
- }
-
/**
- * @hibernate.property column="default_message"
+ * @hibernate.property column="fail_time"
* @return
*/
- protected String getDefaultMessage() {
- return defaultMessage;
+ public Date getFailTime() {
+ return failTime;
}
/**
- * @hibernate.property column="default_subject"
+ * @hibernate.property column="message"
* @return
*/
- protected String getDefaultSubject() {
- return defaultSubject;
+ public String getMessage() {
+ return message;
}
- protected String getFullSignature() {
- if (fullSignature == null) {
- fullSignature = Event.createFullSignature(getScope(), getName(), getEventSessionId());
- }
- return fullSignature;
- }
-
/**
* @hibernate.property column="name" length="128"
* @return
*/
- protected String getName() {
+ public String getName() {
return name;
}
/**
* @hibernate.property column="scope" length="128"
* @return
*/
- protected String getScope() {
+ public String getScope() {
return scope;
}
/**
- * @hibernate.property column="event_session_id"
+ * @hibernate.property column="subject"
* @return
*/
- protected Long getEventSessionId() {
- return eventSessionId;
+ public String getSubject() {
+ return subject;
}
/**
@@ -243,260 +160,58 @@
*
* @return
*/
- protected Set getSubscriptions() {
+ public Set getSubscriptions() {
return subscriptions;
}
/**
* @hibernate.id column="uid" generator-class="native"
*/
- protected Long getUid() {
+ public Long getUid() {
return uid;
}
/**
- * @hibernate.property column="triggered"
+ * @hibernate.property column="html_format" length="1"
* @return
*/
- protected boolean isTriggered() {
- return triggered;
+ public boolean isHtmlFormat() {
+ return htmlFormat;
}
- /**
- * See {@link IEventNotificationService#triggerForSingleUser(String, String, Long, Long)}
- */
- protected boolean triggerForSingleUser(Integer userId, String subject, String message)
- throws InvalidParameterException {
- if (userId == null) {
- throw new InvalidParameterException("User ID can not be null.");
- }
+ public void setEventSessionId(Long sessionId) {
+ eventSessionId = sessionId;
+ }
- List subscriptionList = new ArrayList(getSubscriptions());
- for (int index = 0; index < subscriptionList.size(); index++) {
- Subscription subscription = subscriptionList.get(index);
- if (subscription.getUserId().equals(userId) && subscription.isEligibleForNotification()) {
- subscription.notifyUser(subject, message, this.isHtmlFormat());
- return subscription.getLastOperationSuccessful();
- }
- }
- return false;
+ public void setFailTime(Date failTime) {
+ this.failTime = failTime;
}
- protected void setDefaultMessage(String defaultMessage) {
- this.defaultMessage = defaultMessage;
+ public void setHtmlFormat(boolean isHtmlContentType) {
+ this.htmlFormat = isHtmlContentType;
}
- protected void setDefaultSubject(String defaultSubject) {
- this.defaultSubject = defaultSubject;
+ public void setMessage(String message) {
+ this.message = message;
}
- protected void setName(String name) {
+ public void setName(String name) {
this.name = name;
}
- protected void setScope(String scope) {
+ public void setScope(String scope) {
this.scope = scope;
}
- protected void setEventSessionId(Long sessionId) {
- eventSessionId = sessionId;
+ public void setSubject(String subject) {
+ this.subject = subject;
}
- protected void setSubscriptions(Set subscriptions) {
+ public void setSubscriptions(Set subscriptions) {
this.subscriptions = subscriptions;
}
- protected void setTriggered(boolean triggered) {
- this.triggered = triggered;
- }
-
- protected void setUid(Long uid) {
+ public void setUid(Long uid) {
this.uid = uid;
}
-
- /**
- * See {@link IEventNotificationService#subscribe(String, String, Long, Long, AbstractDeliveryMethod, Long)
- *
- */
- protected boolean subscribe(Integer userId, AbstractDeliveryMethod deliveryMethod, Long periodicity)
- throws InvalidParameterException {
- if (userId == null) {
- throw new InvalidParameterException("User ID can not be null.");
- }
- if (deliveryMethod == null) {
- throw new InvalidParameterException("Delivery method can not be null.");
- }
- boolean substriptionFound = false;
- Subscription toSubscribe = new Subscription(userId, deliveryMethod, periodicity);
- List subscriptionList = new ArrayList(getSubscriptions());
- for (int index = 0; index < subscriptionList.size(); index++) {
- Subscription subscription = subscriptionList.get(index);
- if (subscription.equals(toSubscribe)) {
- substriptionFound = true;
- if (!subscription.getPeriodicity().equals(periodicity)) {
- subscription.setPeriodicity(periodicity);
- }
- }
- }
- if (!substriptionFound) {
- getSubscriptions().add(new Subscription(userId, deliveryMethod, periodicity));
- return true;
- }
- return false;
-
- }
-
- /**
- * See {@link IEventNotificationService#trigger(String, String, Long, String, String)
- */
- protected void trigger(String subject, String message) {
- if ((notificationThread == null) || !notificationThread.isAlive()) {
- triggered = true;
-
- if ((subject != null) && subject.equals(getDefaultSubject())) {
- setSubject(null);
- } else {
- setSubject(subject);
- }
-
- if ((message != null) && message.equals(getDefaultMessage())) {
- setMessage(null);
- } else {
- setMessage(message);
- }
-
- final String subjectToSend = getSubject() == null ? getDefaultSubject() : getSubject();
- final String messageToSend = getMessage() == null ? getDefaultMessage() : getMessage();
- final boolean isHtmlContentType = isHtmlFormat();
- final Event finalRef = this;
- notificationThread = new Thread(new Runnable() {
- @Override
- public void run() {
- List subscriptionList = new ArrayList(getSubscriptions());
- Event eventFailCopy = null;
- for (int index = 0; index < subscriptionList.size(); index++) {
- Subscription subscription = subscriptionList.get(index);
- if ((getFailTime() != null) || subscription.isEligibleForNotification()) {
- subscription.notifyUser(subjectToSend, messageToSend, isHtmlContentType);
- if (subscription.getLastOperationSuccessful()) {
- if (getFailTime() != null) {
- getSubscriptions().remove(subscription);
- }
- } else if (getFailTime() == null) {
- if (eventFailCopy == null) {
- eventFailCopy = (Event) finalRef.clone();
- eventFailCopy.referenceCounter++;
- eventFailCopy.getSubscriptions().clear();
- }
- eventFailCopy.subscribe(subscription.getUserId(), subscription.getDeliveryMethod(),
- subscription.getPeriodicity());
- }
- }
- }
- EventNotificationService.getInstance().saveEvent(finalRef);
-
- /*
- * if any of the notifications failed,
- * a copy of the event is created in order to repeat the attempt later
- */
- if ((eventFailCopy != null) && !eventFailCopy.getSubscriptions().isEmpty()) {
- eventFailCopy.setFailTime(new Date());
- eventFailCopy.setDefaultSubject(subjectToSend);
- eventFailCopy.setDefaultMessage(messageToSend);
- eventFailCopy.setTriggered(true);
- EventNotificationService.getInstance().saveEvent(eventFailCopy);
- }
- }
- }, "LAMS_" + getFullSignature() + "_notification_thread");
- notificationThread.start();
- }
- }
-
- /**
- * See {@link IEventNotificationService#unsubscribe(String, String, Long, Long)
- */
- protected boolean unsubscribe(Integer userId) throws InvalidParameterException {
- if (userId == null) {
- throw new InvalidParameterException("User ID can not be null.");
- }
- List subscriptionList = new ArrayList(getSubscriptions());
- boolean subscriptionFound = false;
- for (int index = 0; index < subscriptionList.size(); index++) {
- Subscription subscription = subscriptionList.get(index);
- if (subscription.getUserId().equals(userId)) {
- getSubscriptions().remove(subscription);
- subscriptionFound = true;
- }
- }
- return subscriptionFound;
- }
-
- /**
- * See {@link IEventNotificationService#unsubscribe(String, String, Long, Long, AbstractDeliveryMethod)
- */
- protected boolean unsubscribe(Integer userId, AbstractDeliveryMethod deliveryMethod) throws InvalidParameterException {
- if (userId == null) {
- throw new InvalidParameterException("User ID can not be null.");
- }
- if (deliveryMethod == null) {
- throw new InvalidParameterException("Delivery method can not be null.");
- }
- List subscriptionList = new ArrayList(getSubscriptions());
- for (int index = 0; index < subscriptionList.size(); index++) {
- Subscription subscription = subscriptionList.get(index);
- if (subscription.getUserId().equals(userId) && subscription.getDeliveryMethod().equals(deliveryMethod)) {
- getSubscriptions().remove(subscription);
- return true;
- }
- }
- return false;
- }
-
- /**
- * @hibernate.property column="fail_time"
- * @return
- */
- protected Date getFailTime() {
- return failTime;
- }
-
- protected void setFailTime(Date failTime) {
- this.failTime = failTime;
- }
-
- /**
- * @hibernate.property column="message"
- * @return
- */
- protected String getMessage() {
- return message;
- }
-
- protected void setMessage(String message) {
- this.message = message;
- }
-
- /**
- * @hibernate.property column="subject"
- * @return
- */
- protected String getSubject() {
- return subject;
- }
-
- protected void setSubject(String subject) {
- this.subject = subject;
- }
-
- /**
- * @hibernate.property column="html_format" length="1"
- * @return
- */
- protected boolean isHtmlFormat() {
- return htmlFormat;
- }
-
- protected void setHtmlFormat(boolean isHtmlContentType) {
- this.htmlFormat = isHtmlContentType;
- }
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/EventNotificationService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/EventNotificationService.java,v
diff -u -r1.7.2.2 -r1.7.2.3
--- lams_common/src/java/org/lamsfoundation/lams/events/EventNotificationService.java 21 Oct 2014 21:25:09 -0000 1.7.2.2
+++ lams_common/src/java/org/lamsfoundation/lams/events/EventNotificationService.java 16 Feb 2016 16:03:21 -0000 1.7.2.3
@@ -1,8 +1,9 @@
package org.lamsfoundation.lams.events;
import java.security.InvalidParameterException;
+import java.util.ArrayList;
import java.util.Date;
-import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -26,123 +27,43 @@
* @author Marcin Cieslak
*
*/
-class EventNotificationService implements IEventNotificationService {
- /**
- * The only instance of this class, since it is a singleton.
- */
- private static EventNotificationService instance;
+public class EventNotificationService implements IEventNotificationService {
- /**
- * Contains message delivery methods that are available for programmers.
- */
- protected final static Set availableDeliveryMethods = new HashSet(2);
+ private static final Logger log = Logger.getLogger(EventNotificationService.class);
- /**
- * Contains events that are currently in use. Prevents multiple loading of an event from the database.
- */
- protected final static Set eventPool = new HashSet();
-
- protected static final Logger log = Logger.getLogger(EventNotificationService.class);
-
- /**
- * Interface to contact the database.
- */
- protected EventDAO eventDAO;
-
- /**
- * Interface to receive contact details of the users.
- */
- protected IUserManagementService userManagementService;
-
- protected MessageService messageService;
-
- protected ILessonService lessonService;
-
- protected ILamsToolService toolService;
-
- /**
- * Default constructor. Should be called only once, since this class in a singleton.
- */
- public EventNotificationService() {
- if (EventNotificationService.instance == null) {
- EventNotificationService.instance = this;
- EventNotificationService.availableDeliveryMethods.add(IEventNotificationService.DELIVERY_METHOD_MAIL);
+ static {
+ IEventNotificationService.availableDeliveryMethods.add(IEventNotificationService.DELIVERY_METHOD_MAIL);
}
- }
- /**
- * Gets the only existing instance of the class.
- *
- * @return instance of this class
- */
- public static EventNotificationService getInstance() {
- return EventNotificationService.instance;
- }
+ private EventDAO eventDAO = null;
+ private MessageService messageService = null;
+ private ILessonService lessonService = null;
+ private ILamsToolService toolService = null;
+ private IUserManagementService userManagementService = null;
- /**
- * Allows to plug-in a delivery method.
- *
- * @param deliveryMethod
- * delivery method to add
- * @return true
if the delivery method with the same ID did not exist and the given delivery method was
- * added successfuly
- */
- public boolean addDeliveryMethod(AbstractDeliveryMethod deliveryMethod) {
- return EventNotificationService.availableDeliveryMethods.add(deliveryMethod);
- }
-
@Override
- public boolean createEvent(String scope, String name, Long eventSessionId, String defaultSubject,
+ public void createEvent(String scope, String name, Long eventSessionId, String defaultSubject,
String defaultMessage, boolean isHtmlFormat) throws InvalidParameterException {
- Event event = getEvent(scope, name, eventSessionId);
- if (event != null) {
- saveEvent(event);
- return false;
+ if (!eventExists(scope, name, eventSessionId)) {
+ Event event = new Event(scope, name, eventSessionId, defaultSubject, defaultMessage, isHtmlFormat);
+ eventDAO.saveEvent(event);
}
- event = new Event(scope, name, eventSessionId, defaultSubject, defaultMessage, isHtmlFormat);
- event.referenceCounter++;
- saveEvent(event);
- return true;
}
@Override
- public boolean deleteEvent(String scope, String name, Long eventSessionId) throws InvalidParameterException {
- if (scope == null) {
- throw new InvalidParameterException("Scope should not be null.");
- }
- if (StringUtils.isEmpty(name)) {
- throw new InvalidParameterException("Name should not be blank.");
- }
- Event event = getEvent(scope, name, eventSessionId);
- if (event == null) {
- return false;
- } else {
- event.deleted = true;
- saveEvent(event);
- return true;
- }
- }
-
- @Override
public boolean eventExists(String scope, String name, Long eventSessionId) throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
- Event event = getEvent(scope, name, eventSessionId);
- if (event == null) {
- return false;
- } else {
- saveEvent(event);
- return true;
- }
+ return eventDAO.getEvent(scope, name, eventSessionId) != null;
}
@Override
public Set getAvailableDeliveryMethods() {
- return EventNotificationService.availableDeliveryMethods;
+ return IEventNotificationService.availableDeliveryMethods;
}
@Override
@@ -151,44 +72,118 @@
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
if (userId == null) {
throw new InvalidParameterException("User ID should not be null.");
}
- Event event = getEvent(scope, name, eventSessionId);
- boolean isSubscribed = false;
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event != null) {
for (Subscription subscription : event.getSubscriptions()) {
if (subscription.getUserId().equals(userId)) {
- isSubscribed = true;
- break;
+ return true;
}
}
- saveEvent(event);
}
- return isSubscribed;
+ return false;
}
@Override
+ public boolean notifyLessonMonitors(Long sessionId, String message, boolean isHtmlFormat) {
+ List monitoringUsers = lessonService.getMonitorsByToolSessionId(sessionId);
+ if (monitoringUsers.isEmpty()) {
+ return true;
+ }
+
+ Integer[] monitoringUsersIds = new Integer[monitoringUsers.size()];
+ for (int i = 0; i < monitoringUsersIds.length; i++) {
+ monitoringUsersIds[i] = monitoringUsers.get(i).getUserId();
+ }
+
+ ToolSession toolSession = toolService.getToolSession(sessionId);
+ Lesson lesson = toolSession.getLesson();
+ ToolActivity toolActivity = toolSession.getToolActivity();
+ String lessonName = lesson.getLessonName();
+ String activityTitle = toolActivity.getTitle();
+ String toolName = toolActivity.getTool().getToolDisplayName();
+ String emailSubject = new StringBuilder(toolName).append(" ")
+ .append(messageService.getMessage("email.notifications.tool")).append(": ").append(activityTitle)
+ .append(" ").append(messageService.getMessage("email.notifications.activity")).append(" - ")
+ .append(lessonName).append(" ").append(messageService.getMessage("email.notifications.lesson"))
+ .toString();
+
+ String courseName = lesson.getOrganisation().getName();
+ String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL).trim();
+ String emailBody = new StringBuilder(messageService.getMessage("email.notifications.course")).append(": ")
+ .append(courseName).append('\n').append(messageService.getMessage("email.notifications.lesson.caption"))
+ .append(": ").append(lessonName).append("\n\n").append(message).append("\n\n").append(serverUrl)
+ .toString();
+
+ return sendMessage(null, monitoringUsersIds, IEventNotificationService.DELIVERY_METHOD_MAIL, emailSubject,
+ emailBody, isHtmlFormat);
+ }
+
+ /**
+ * Sends the message to the user. Properties storing information of the last notification attempt are updated.
+ *
+ * @param subject
+ * subject of the message; null
if not applicable
+ * @param message
+ * message to send
+ * @param isHtmlFormat
+ * whether the message is of HTML content-type or plain text
+ */
+ public void notifyUser(Subscription subscription, String subject, String message, boolean isHtmlFormat) {
+ subscription.setLastOperationTime(new Date());
+ subscription.setLastOperationMessage(
+ subscription.getDeliveryMethod().send(null, subscription.getUserId(), subject, message, isHtmlFormat));
+ }
+
+ @Override
+ public void resendMessages() {
+ try {
+ EventNotificationService.log.debug("The resend messages thread is running..");
+ List events = eventDAO.getEventsToResend();
+ for (Event event : events) {
+ trigger(event, null, null);
+ if (event.getFailTime() != null) {
+ if (!event.getSubscriptions().isEmpty() && ((System.currentTimeMillis()
+ - event.getFailTime().getTime()) >= IEventNotificationService.RESEND_TIME_LIMIT)) {
+ StringBuilder body = new StringBuilder(messageService.getMessage("mail.resend.abandon.body1"))
+ .append(event.getMessage())
+ .append(messageService.getMessage("mail.resend.abandon.body2"));
+ for (Subscription subscription : event.getSubscriptions()) {
+ User user = (User) userManagementService.findById(User.class, subscription.getUserId());
+ body.append(user.getLogin()).append('\n');
+ }
+ IEventNotificationService.DELIVERY_METHOD_MAIL.notifyAdmin(
+ messageService.getMessage("mail.resend.abandon.subject"), body.toString(),
+ event.isHtmlFormat());
+ eventDAO.deleteEvent(event);
+ }
+ }
+ }
+ } catch (Exception e) {
+ EventNotificationService.log.error("Error while resending messages", e);
+ }
+ }
+
+ @Override
public boolean sendMessage(Integer fromUserId, Integer toUserId, AbstractDeliveryMethod deliveryMethod,
String subject, String message, boolean isHtmlFormat) throws InvalidParameterException {
- Event eventFailCopy = new Event(IEventNotificationService.SINGLE_MESSAGE_SCOPE, String.valueOf(System
- .currentTimeMillis()), null, subject, message, isHtmlFormat);
String result = deliveryMethod.send(fromUserId, toUserId, subject, message, isHtmlFormat);
- if (result != null) {
- EventNotificationService.log.warn("Error occured while sending message: " + result);
- eventFailCopy.subscribe(toUserId, deliveryMethod, null);
+ if (result == null) {
+ return true;
}
- if (!eventFailCopy.subscriptions.isEmpty()) {
- eventFailCopy.setFailTime(new Date());
- eventFailCopy.referenceCounter++;
- saveEvent(eventFailCopy);
- return false;
- }
- return true;
+ EventNotificationService.log.error("Error occured while sending message: " + result);
+ Event event = new Event(IEventNotificationService.SINGLE_MESSAGE_SCOPE,
+ String.valueOf(System.currentTimeMillis()), null, subject, message, isHtmlFormat);
+ subscribe(event, toUserId, deliveryMethod, null);
+ event.setFailTime(new Date());
+ eventDAO.saveEvent(event);
+ return false;
}
@Override
@@ -201,79 +196,86 @@
if (deliveryMethod == null) {
throw new InvalidParameterException("Delivery method must not be null.");
}
- if (toUserIds.length > 0) {
- if (toUserIds.length == 1) {
- return sendMessage(fromUserId, toUserIds[0], deliveryMethod, subject, message, isHtmlFormat);
- } else {
- final Event event = new Event(IEventNotificationService.SINGLE_MESSAGE_SCOPE, String.valueOf(System
- .currentTimeMillis()), null, subject, message, isHtmlFormat);
- event.referenceCounter++;
- event.notificationThread = new Thread(new Runnable() {
- @Override
- public void run() {
- for (Integer id : toUserIds) {
- String result = deliveryMethod.send(fromUserId, id, subject, message, isHtmlFormat);
- if (result != null) {
- EventNotificationService.log.warn("Error occured while sending message: " + result);
- event.subscribe(id, deliveryMethod, null);
- }
- }
- if (!event.subscriptions.isEmpty()) {
- event.setFailTime(new Date());
- event.setTriggered(true);
- saveEvent(event);
- }
- }
- }, "LAMS_single_message_send_thread");
- event.notificationThread.start();
-
+ boolean totalSendResult = true;
+ Event event = null;
+ for (Integer id : toUserIds) {
+ String result = deliveryMethod.send(fromUserId, id, subject, message, isHtmlFormat);
+ if (result != null) {
+ totalSendResult = false;
+ EventNotificationService.log.warn("Error occured while sending message: " + result);
+ event = new Event(IEventNotificationService.SINGLE_MESSAGE_SCOPE,
+ String.valueOf(System.currentTimeMillis()), null, subject, message, isHtmlFormat);
+ subscribe(event, id, deliveryMethod, null);
}
}
- return true;
+ if (event != null) {
+ event.setFailTime(new Date());
+ eventDAO.saveEvent(event);
+ }
+
+ return totalSendResult;
+
}
-
- @Override
- public boolean notifyLessonMonitors(Long sessionId, String message, boolean isHtmlFormat) {
- final String NEW_LINE_CHARACTER = "\r\n";
- List monitoringUsers = lessonService.getMonitorsByToolSessionId(sessionId);
- if (monitoringUsers == null || monitoringUsers.isEmpty()) {
- return true;
+ public void setEventDAO(EventDAO eventDAO) {
+ this.eventDAO = eventDAO;
+ }
+
+ public void setLessonService(ILessonService lessonService) {
+ this.lessonService = lessonService;
+ }
+
+ public void setMessageService(MessageService messageService) {
+ this.messageService = messageService;
+ }
+
+ public void setToolService(ILamsToolService toolService) {
+ this.toolService = toolService;
+ }
+
+ public void setUserManagementService(IUserManagementService userManagementService) {
+ this.userManagementService = userManagementService;
+ IEventNotificationService.DELIVERY_METHOD_MAIL.setUserManagementService(userManagementService);
+ }
+
+ /**
+ * See {@link IEventNotificationService#subscribe(String, String, Long, Long, AbstractDeliveryMethod, Long)
+ *
+ */
+ protected void subscribe(Event event, Integer userId, AbstractDeliveryMethod deliveryMethod, Long periodicity)
+ throws InvalidParameterException {
+ if (userId == null) {
+ throw new InvalidParameterException("User ID can not be null.");
}
-
- Integer[] monitoringUsersIds = new Integer[monitoringUsers.size()];
- for (int i = 0; i < monitoringUsersIds.length; i++) {
- monitoringUsersIds[i] = monitoringUsers.get(i).getUserId();
+ if (deliveryMethod == null) {
+ throw new InvalidParameterException("Delivery method can not be null.");
}
-
- ToolSession toolSession = toolService.getToolSession(sessionId);
- Lesson lesson = toolSession.getLesson();
- ToolActivity toolActivity = toolSession.getToolActivity();
- String lessonName = lesson.getLessonName();
- String activityTitle = toolActivity.getTitle();
- String toolName = toolActivity.getTool().getToolDisplayName();
- String emailSubject = toolName + " " + messageService.getMessage("email.notifications.tool") + ": " +
- activityTitle + " " + messageService.getMessage("email.notifications.activity") + " - " +
- lessonName + " " + messageService.getMessage("email.notifications.lesson");
-
- String courseName = lesson.getOrganisation().getName();
- String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL).trim();
- String emailBody = messageService.getMessage("email.notifications.course") + ": " + courseName + NEW_LINE_CHARACTER +
- messageService.getMessage("email.notifications.lesson.caption") + ": " + lessonName + NEW_LINE_CHARACTER + NEW_LINE_CHARACTER +
- message + NEW_LINE_CHARACTER + NEW_LINE_CHARACTER +
- serverUrl;
-
- return sendMessage(null, monitoringUsersIds, IEventNotificationService.DELIVERY_METHOD_MAIL, emailSubject,
- emailBody, isHtmlFormat);
+ boolean substriptionFound = false;
+ List subscriptionList = new ArrayList(event.getSubscriptions());
+ for (int index = 0; index < subscriptionList.size(); index++) {
+ Subscription subscription = subscriptionList.get(index);
+ if (subscription.getUserId().equals(userId)
+ && subscription.getDeliveryMethod().equals(deliveryMethod.getId())) {
+ substriptionFound = true;
+ if (!subscription.getPeriodicity().equals(periodicity)) {
+ subscription.setPeriodicity(periodicity);
+ }
+ break;
+ }
+ }
+ if (!substriptionFound) {
+ event.getSubscriptions().add(new Subscription(userId, deliveryMethod, periodicity));
+ }
+ eventDAO.saveEvent(event);
}
@Override
- public boolean subscribe(String scope, String name, Long eventSessionId, Integer userId,
+ public void subscribe(String scope, String name, Long eventSessionId, Integer userId,
AbstractDeliveryMethod deliveryMethod, Long periodicity) throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
if (userId == null) {
@@ -282,215 +284,267 @@
if (deliveryMethod == null) {
throw new InvalidParameterException("Delivery method should not be null.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- boolean newSubscription = true;
- try {
- newSubscription = event.subscribe(userId, deliveryMethod, periodicity);
- } catch (Exception e) {
- EventNotificationService.log.error(e);
+ subscribe(event, userId, deliveryMethod, periodicity);
+ }
+
+ /**
+ * See {@link IEventNotificationService#trigger(String, String, Long, String, String)
+ */
+ private void trigger(Event event, String subject, String message) {
+ String subjectToSend = subject == null ? event.getSubject() : subject;
+ String messageToSend = message == null ? event.getMessage() : message;
+
+ Event eventFailCopy = null;
+ Iterator subscriptionIterator = event.getSubscriptions().iterator();
+ while (subscriptionIterator.hasNext()) {
+ Subscription subscription = subscriptionIterator.next();
+ if ((event.getFailTime() != null) || subscription.isEligibleForNotification()) {
+ notifyUser(subscription, subjectToSend, messageToSend, event.isHtmlFormat());
+ if (subscription.getLastOperationSuccessful()) {
+ if (event.getFailTime() != null) {
+ subscriptionIterator.remove();
+ }
+ } else if (event.getFailTime() == null) {
+ if (eventFailCopy == null) {
+ eventFailCopy = (Event) event.clone();
+ }
+ subscribe(eventFailCopy, subscription.getUserId(), subscription.getDeliveryMethod(),
+ subscription.getPeriodicity());
+ }
+ }
}
- saveEvent(event);
- return newSubscription;
+ if (event.getSubscriptions().isEmpty()) {
+ eventDAO.deleteEvent(event);
+ } else {
+ eventDAO.saveEvent(event);
+ }
+ /*
+ * if any of the notifications failed,
+ * a copy of the event is created in order to repeat the attempt later
+ */
+ if (eventFailCopy != null) {
+ eventFailCopy.setFailTime(new Date());
+ eventFailCopy.setSubject(subjectToSend);
+ eventFailCopy.setMessage(messageToSend);
+ eventDAO.saveEvent(eventFailCopy);
+ }
}
@Override
- public boolean trigger(String scope, String name, Long eventSessionId) throws InvalidParameterException {
+ public void trigger(String scope, String name, Long eventSessionId) throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- try {
- event.trigger(event.getDefaultSubject(), event.getDefaultMessage());
- } catch (Exception e) {
- EventNotificationService.log.error(e.getMessage());
- }
- return true;
+ trigger(event, null, null);
}
@Override
- public boolean trigger(String scope, String name, Long eventSessionId, Object[] parameterValues)
+ public void trigger(String scope, String name, Long eventSessionId, Object[] parameterValues)
throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- String body = event.getDefaultMessage();
+ String message = event.getMessage();
if ((parameterValues != null) && (parameterValues.length > 0)) {
for (int index = 0; index < parameterValues.length; index++) {
Object value = parameterValues[index];
String replacement = value == null ? "" : value.toString();
- body = body.replace("{" + index + "}", replacement);
+ message = message.replace("{" + index + "}", replacement);
}
}
- try {
- event.trigger(event.getDefaultSubject(), body);
- } catch (Exception e) {
- EventNotificationService.log.error(e.getMessage());
- }
- return true;
+ trigger(event, null, message);
}
@Override
- public boolean trigger(String scope, String name, Long eventSessionId, String title, String message)
+ public void trigger(String scope, String name, Long eventSessionId, String title, String message)
throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- try {
- event.trigger(title, message);
- } catch (Exception e) {
- EventNotificationService.log.error(e.getMessage());
+ trigger(event, title, message);
+ }
+
+ /**
+ * See {@link IEventNotificationService#triggerForSingleUser(String, String, Long, Long)}
+ */
+ protected boolean triggerForSingleUser(Event event, Integer userId, String subject, String message)
+ throws InvalidParameterException {
+ if (userId == null) {
+ throw new InvalidParameterException("User ID can not be null.");
}
- return true;
+
+ for (Subscription subscription : event.getSubscriptions()) {
+ if (subscription.getUserId().equals(userId) && subscription.isEligibleForNotification()) {
+ notifyUser(subscription, subject, message, event.isHtmlFormat());
+ return subscription.getLastOperationSuccessful();
+ }
+ }
+ return false;
}
@Override
- public boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId)
+ public void triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId)
throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
if (userId == null) {
throw new InvalidParameterException("User ID should not be null.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- boolean notificationSuccessful = false;
- try {
- notificationSuccessful = event.triggerForSingleUser(userId, event.getDefaultSubject(),
- event.getDefaultMessage());
- } catch (Exception e) {
- EventNotificationService.log.error(e.getMessage());
- }
- saveEvent(event);
- return notificationSuccessful;
+ triggerForSingleUser(event, userId, null, null);
}
@Override
- public boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId,
+ public void triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId,
Object[] parameterValues) throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
if (userId == null) {
throw new InvalidParameterException("User ID should not be null.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- String body = event.getDefaultMessage();
+ String message = event.getMessage();
if ((parameterValues != null) && (parameterValues.length > 0)) {
for (int index = 0; index < parameterValues.length; index++) {
Object value = parameterValues[index];
String replacement = value == null ? "" : value.toString();
- body = body.replace("{" + index + "}", replacement);
+ message = message.replace("{" + index + "}", replacement);
}
}
- boolean notificationSuccessful = false;
- try {
- notificationSuccessful = event.triggerForSingleUser(userId, event.getDefaultSubject(), body);
- } catch (Exception e) {
- EventNotificationService.log.error(e.getMessage());
- }
- saveEvent(event);
- return notificationSuccessful;
+ triggerForSingleUser(event, userId, null, message);
}
@Override
- public boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId, String subject,
+ public void triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId, String subject,
String message) throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
if (userId == null) {
throw new InvalidParameterException("User ID should not be null.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- boolean notificationSuccessful = false;
- try {
- notificationSuccessful = event.triggerForSingleUser(userId, subject, message);
- } catch (Exception e) {
+ triggerForSingleUser(event, userId, subject, message);
+ }
- EventNotificationService.log.error(e.getMessage());
- } finally {
- saveEvent(event);
+ /**
+ * See {@link IEventNotificationService#unsubscribe(String, String, Long, Long)
+ */
+ protected void unsubscribe(Event event, Integer userId) throws InvalidParameterException {
+ if (userId == null) {
+ throw new InvalidParameterException("User ID can not be null.");
}
- return notificationSuccessful;
+ Iterator subscriptionIterator = event.getSubscriptions().iterator();
+ while (subscriptionIterator.hasNext()) {
+ Subscription subscription = subscriptionIterator.next();
+ if (subscription.getUserId().equals(userId)) {
+ subscriptionIterator.remove();
+ }
+ }
+ if (event.getSubscriptions().isEmpty()) {
+ eventDAO.deleteEvent(event);
+ } else {
+ eventDAO.saveEvent(event);
+ }
}
+ /**
+ * See {@link IEventNotificationService#unsubscribe(String, String, Long, Long, AbstractDeliveryMethod)
+ */
+ protected void unsubscribe(Event event, Integer userId, AbstractDeliveryMethod deliveryMethod)
+ throws InvalidParameterException {
+ if (userId == null) {
+ throw new InvalidParameterException("User ID can not be null.");
+ }
+ if (deliveryMethod == null) {
+ throw new InvalidParameterException("Delivery method can not be null.");
+ }
+ Iterator subscriptionIterator = event.getSubscriptions().iterator();
+ while (subscriptionIterator.hasNext()) {
+ Subscription subscription = subscriptionIterator.next();
+ if (subscription.getUserId().equals(userId) && subscription.getDeliveryMethod().equals(deliveryMethod)) {
+ subscriptionIterator.remove();
+ }
+ }
+ if (event.getSubscriptions().isEmpty()) {
+ eventDAO.deleteEvent(event);
+ } else {
+ eventDAO.saveEvent(event);
+ }
+ }
+
@Override
- public boolean unsubscribe(String scope, String name, Long eventSessionId, Integer userId)
+ public void unsubscribe(String scope, String name, Long eventSessionId, Integer userId)
throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
if (userId == null) {
throw new InvalidParameterException("User ID should not be null.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- boolean subscriptionFound = false;
- try {
- subscriptionFound = event.unsubscribe(userId);
- } catch (Exception e) {
-
- EventNotificationService.log.error(e.getMessage());
- } finally {
- saveEvent(event);
- }
- return subscriptionFound;
+ unsubscribe(event, userId);
}
@Override
- public boolean unsubscribe(String scope, String name, Long eventSessionId, Integer userId,
+ public void unsubscribe(String scope, String name, Long eventSessionId, Integer userId,
AbstractDeliveryMethod deliveryMethod) throws InvalidParameterException {
if (scope == null) {
throw new InvalidParameterException("Scope should not be null.");
}
- if (StringUtils.isEmpty(name)) {
+ if (StringUtils.isBlank(name)) {
throw new InvalidParameterException("Name should not be blank.");
}
if (userId == null) {
@@ -499,115 +553,10 @@
if (deliveryMethod == null) {
throw new InvalidParameterException("Delivery nethod should not be null.");
}
- Event event = getEvent(scope, name, eventSessionId);
+ Event event = eventDAO.getEvent(scope, name, eventSessionId);
if (event == null) {
throw new InvalidParameterException("An event with the given parameters does not exist.");
}
- boolean subscriptionFound = false;
- try {
- subscriptionFound = event.unsubscribe(userId, deliveryMethod);
- } catch (Exception e) {
-
- EventNotificationService.log.error(e.getMessage());
- } finally {
- saveEvent(event);
- }
- return subscriptionFound;
+ unsubscribe(event, userId, deliveryMethod);
}
-
- /**
- * Gets the event, either from the database or the event pool.
- *
- * @param scope
- * scope of the event
- * @param name
- * name of the event
- * @param eventSessionId
- * session ID of the event
- * @return event if it exists and it is not deleted; null
if it does not exist
- */
- protected Event getEvent(String scope, String name, Long eventSessionId) {
- String fullSignature = Event.createFullSignature(scope, name, eventSessionId);
-
- for (Event event : EventNotificationService.eventPool) {
- if (event.equals(fullSignature)) {
- if (event.deleted) {
- return null;
- }
- event.referenceCounter++;
- return event;
- }
- }
-
- Event result = getEventDAO().getEvent(scope, name, eventSessionId);
- if (result == null) {
- return null;
- }
- result.referenceCounter++;
- EventNotificationService.eventPool.add(result);
- return result;
- }
-
- /**
- * Saves the event into the database
- *
- * @param event
- * event to be saved
- */
- @Override
- public void saveEvent(Event event) {
- event.referenceCounter--;
- if (event.referenceCounter <= 0) {
- EventNotificationService.eventPool.remove(event);
- if (event.deleted) {
- getEventDAO().deleteEvent(event);
- } else {
- getEventDAO().saveEvent(event);
- }
- }
- }
-
- public EventDAO getEventDAO() {
- return eventDAO;
- }
-
- public void setEventDAO(EventDAO eventDAO) {
- this.eventDAO = eventDAO;
- }
-
- protected IUserManagementService getUserManagementService() {
- return userManagementService;
- }
-
- public void setUserManagementService(IUserManagementService userManagementService) {
- this.userManagementService = userManagementService;
- }
-
- public void setMessageService(MessageService messageService) {
- this.messageService = messageService;
- }
-
- protected MessageService getMessageService() {
- return messageService;
- }
-
- public void setLessonService(ILessonService lessonService) {
- this.lessonService = lessonService;
- }
-
- protected ILessonService getLessonService() {
- return lessonService;
- }
-
- public void setToolService(ILamsToolService toolService) {
- this.toolService = toolService;
- }
-
- protected ILamsToolService getToolService() {
- return toolService;
- }
-
- public List getEventsToResend() {
- return eventDAO.getEventsToResend();
- }
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/IEventNotificationService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/IEventNotificationService.java,v
diff -u -r1.4.2.1 -r1.4.2.2
--- lams_common/src/java/org/lamsfoundation/lams/events/IEventNotificationService.java 21 Oct 2014 21:25:09 -0000 1.4.2.1
+++ lams_common/src/java/org/lamsfoundation/lams/events/IEventNotificationService.java 16 Feb 2016 16:03:21 -0000 1.4.2.2
@@ -1,7 +1,7 @@
package org.lamsfoundation.lams.events;
import java.security.InvalidParameterException;
-import java.util.List;
+import java.util.HashSet;
import java.util.Set;
/**
@@ -44,11 +44,18 @@
static final long PERIODICITY_MONTHLY = IEventNotificationService.PERIODICITY_WEEKLY * 4;
/**
+ * Period after which the thread gives up on attempting to resend messages. Currently - 2 days.
+ */
+ static final long RESEND_TIME_LIMIT = 2 * 24 * 60 * 60 * 1000;
+
+ /**
* Allows sending mail to users using the configured SMTP server. Currently it is the only delivery method
* available.
*/
- static final AbstractDeliveryMethod DELIVERY_METHOD_MAIL = DeliveryMethodMail.getInstance();
+ static final DeliveryMethodMail DELIVERY_METHOD_MAIL = DeliveryMethodMail.getInstance();
+ static final Set availableDeliveryMethods = new HashSet(2);
+
/**
* Creates an event and saves it into the database.
*
@@ -68,32 +75,10 @@
* @throws InvalidParameterException
* if scope was null
or name was blank
*/
- abstract boolean createEvent(String scope, String name, Long eventSessionId, String defaultSubject,
- String defaultMessage, boolean isHtmlFormat) throws InvalidParameterException;
+ void createEvent(String scope, String name, Long eventSessionId, String defaultSubject, String defaultMessage,
+ boolean isHtmlFormat) throws InvalidParameterException;
/**
- * Saves an event into the database.
- */
- void saveEvent(Event event);
-
-
- /**
- * Deletes an event.
- *
- * @param scope
- * scope of the event
- * @param name
- * name of the event
- * @param eventSessionId
- * session ID of the event
- * @return true
if the event existed and was deleted
- * @throws InvalidParameterException
- * if scope was null
or name was blank
- */
- abstract boolean deleteEvent(String scope, String name, Long eventSessionId)
- throws InvalidParameterException;;
-
- /**
* Checks if event with the given parameters exists in the database.
*
* @param scope
@@ -106,23 +91,14 @@
* @throws InvalidParameterException
* if scope was null
or name was blank
*/
- abstract boolean eventExists(String scope, String name, Long eventSessionId)
- throws InvalidParameterException;
+ boolean eventExists(String scope, String name, Long eventSessionId) throws InvalidParameterException;
-
/**
- * Returns Event that are to be resend by QuartzJob
- * @return events to resend
- */
- List getEventsToResend();
-
-
- /**
* Gets the available delivery methods that can be used when subscribing an user to an event.
*
* @return set of available delivery methods in the system
*/
- abstract Set getAvailableDeliveryMethods();
+ Set getAvailableDeliveryMethods();
/**
* Checks if an user is subscribed to the given event.
@@ -140,10 +116,23 @@
* @throws InvalidParameterException
* if scope or user ID were null
, name was blank or event does not exist
*/
- abstract boolean isSubscribed(String scope, String name, Long eventSessionId, Long userId)
- throws InvalidParameterException;
+ boolean isSubscribed(String scope, String name, Long eventSessionId, Long userId) throws InvalidParameterException;
/**
+ * Notify lesson monitors with the specified message
+ *
+ * @param sessionId
+ * tool session to which monitors belong
+ * @param message
+ * message to be sent
+ * @isHtmlFormat whether email is required to of HTML format
+ * @return
+ */
+ boolean notifyLessonMonitors(Long sessionId, String message, boolean isHtmlFormat);
+
+ void resendMessages();
+
+ /**
* Sends a single message to the given users.If it fails, an event is created for the needs of the resending
* mechanism.
*
@@ -161,8 +150,8 @@
* @throws InvalidParameterException
* if userId or delivery method are null
*/
- abstract boolean sendMessage(Integer fromUserId, Integer toUserId, AbstractDeliveryMethod deliveryMethod,
- String subject, String message, boolean isHtmlFormat) throws InvalidParameterException;
+ boolean sendMessage(Integer fromUserId, Integer toUserId, AbstractDeliveryMethod deliveryMethod, String subject,
+ String message, boolean isHtmlFormat) throws InvalidParameterException;
/**
*
@@ -184,18 +173,8 @@
* @throws InvalidParameterException
* if userId array or delivery method are null
*/
- abstract boolean sendMessage(Integer fromUserId, Integer[] toUserIds, AbstractDeliveryMethod deliveryMethod,
- String subject, String message, boolean isHtmlFormat) throws InvalidParameterException;
-
- /**
- * Notify lesson monitors with the specified message
- *
- * @param sessionId tool session to which monitors belong
- * @param message message to be sent
- * @isHtmlFormat whether email is required to of HTML format
- * @return
- */
- boolean notifyLessonMonitors(Long sessionId, String message, boolean isHtmlFormat);
+ boolean sendMessage(Integer fromUserId, Integer[] toUserIds, AbstractDeliveryMethod deliveryMethod, String subject,
+ String message, boolean isHtmlFormat) throws InvalidParameterException;
/**
* Registeres an user for notification of the event. If a subscription with given user ID and delivery method
@@ -216,7 +195,7 @@
* @throws InvalidParameterException
* if scope, userId or delivery method are null
, or name is blank
*/
- abstract boolean subscribe(String scope, String name, Long eventSessionId, Integer userId,
+ void subscribe(String scope, String name, Long eventSessionId, Integer userId,
AbstractDeliveryMethod deliveryMethod, Long periodicity) throws InvalidParameterException;
/**
@@ -231,7 +210,7 @@
* @throws InvalidParameterException
* if scope is null
or name is blank
*/
- abstract boolean trigger(String scope, String name, Long eventSessionId) throws InvalidParameterException;
+ void trigger(String scope, String name, Long eventSessionId) throws InvalidParameterException;
/**
* Triggers the event with the default subject and message, modifying placeholders ({0}, {1}, {2}
...)
@@ -250,7 +229,7 @@
* @throws InvalidParameterException
* if scope is null
or name is blank
*/
- abstract boolean trigger(String scope, String name, Long eventSessionId, Object[] parameterValues)
+ void trigger(String scope, String name, Long eventSessionId, Object[] parameterValues)
throws InvalidParameterException;
/**
@@ -270,7 +249,7 @@
* @throws InvalidParameterException
* if scope is null
or name is blank
*/
- abstract boolean trigger(String scope, String name, Long eventSessionId, String subject, String message)
+ void trigger(String scope, String name, Long eventSessionId, String subject, String message)
throws InvalidParameterException;
/**
@@ -288,7 +267,7 @@
* @throws InvalidParameterException
* if scope or userId are null
or name is blank
*/
- abstract boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId)
+ void triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId)
throws InvalidParameterException;
/**
@@ -311,8 +290,8 @@
* @throws InvalidParameterException
* if scope or userId are null
or name is blank
*/
- boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId,
- Object[] parameterValues) throws InvalidParameterException;
+ void triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId, Object[] parameterValues)
+ throws InvalidParameterException;
/**
* Notifies only a single user of the event using the given subject and message. Does not set the event as
@@ -333,8 +312,8 @@
* @throws InvalidParameterException
* if scope or userId are null
or name is blank
*/
- abstract boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId,
- String subject, String message) throws InvalidParameterException;
+ void triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId, String subject,
+ String message) throws InvalidParameterException;
/**
* Unregister an user from notification of the event.
@@ -350,8 +329,7 @@
* @throws InvalidParameterException
* if scope or userId are null
or name is blank
*/
- abstract boolean unsubscribe(String scope, String name, Long eventSessionId, Integer userId)
- throws InvalidParameterException;
+ void unsubscribe(String scope, String name, Long eventSessionId, Integer userId) throws InvalidParameterException;
/**
* Unregister delivery method of the user from notification of the event.
@@ -369,7 +347,6 @@
* @throws InvalidParameterException
* if scope, userId or delivery method are null
or name is blank
*/
- abstract boolean unsubscribe(String scope, String name, Long eventSessionId, Integer userId,
+ void unsubscribe(String scope, String name, Long eventSessionId, Integer userId,
AbstractDeliveryMethod deliveryMethod) throws InvalidParameterException;
-
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/ResendMessagesJob.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/ResendMessagesJob.java,v
diff -u -r1.4.2.1 -r1.4.2.2
--- lams_common/src/java/org/lamsfoundation/lams/events/ResendMessagesJob.java 21 Oct 2014 21:25:09 -0000 1.4.2.1
+++ lams_common/src/java/org/lamsfoundation/lams/events/ResendMessagesJob.java 16 Feb 2016 16:03:21 -0000 1.4.2.2
@@ -1,11 +1,5 @@
package org.lamsfoundation.lams.events;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.lamsfoundation.lams.usermanagement.User;
-import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
-import org.lamsfoundation.lams.util.MessageService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,104 +10,24 @@
* Quartz job for resending messages. This job is scheduled from the start-up and periodically attempts to resend failed
* and marked for resending messages.
*
- * @author Administrator
+ * @author Marcin Cieslak
*
*/
public class ResendMessagesJob extends QuartzJobBean {
- protected static final Logger log = Logger.getLogger(ResendMessagesJob.class);
-
- /**
- * Period after which the thread gives up on attempting to resend messages.
- * Currently - 2 days.
- */
- private static final long RESEND_TIME_LIMIT = 2 * 24 * 60 * 60 * 1000;
+ @Autowired
+ private IEventNotificationService eventNotificationService;
- @Autowired
- private IEventNotificationService eventNotificationService;
+ public ResendMessagesJob() {
+ //First recover context of the job since it is created by Quartz, not Spring
+ SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
+ }
- @Autowired
- private MessageService commonMessageService;
-
- @Autowired
- private IUserManagementService userManagementService;
-
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
- //First recover context of the job since it is created by Quartz, not Spring
- SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
- resendMessages();
+ eventNotificationService.resendMessages();
}
- private void resendMessages() throws JobExecutionException {
- try {
- EventNotificationService.log.debug("Event notification service is running a resend messages thread...");
- List events = eventNotificationService.getEventsToResend();
- for (Event event : events) {
- event.referenceCounter++;
- if (event.getFailTime() != null) {
- event.trigger(event.getSubject(), event.getMessage());
- event.notificationThread.join();
- if (event.getSubscriptions().isEmpty()) {
- event.deleted = true;
- } else if (System.currentTimeMillis() - event.getFailTime().getTime() >= ResendMessagesJob.RESEND_TIME_LIMIT) {
- event.deleted = true;
- StringBuilder body = new StringBuilder(
- commonMessageService.getMessage("mail.resend.abandon.body1")).append(
- event.getDefaultMessage()).append(
- commonMessageService.getMessage("mail.resend.abandon.body2"));
- for (Subscription subscription : event.getSubscriptions()) {
- User user = (User) userManagementService.findById(User.class, subscription.getUserId());
- body.append(user.getLogin()).append('\n');
- }
- ((DeliveryMethodMail) IEventNotificationService.DELIVERY_METHOD_MAIL).notifyAdmin(
- commonMessageService.getMessage("mail.resend.abandon.subject"),
- body.toString(), event.isHtmlFormat());
- }
- } else {
- for (Subscription subscription : event.getSubscriptions()) {
- if ((subscription.getLastOperationTime() != null)
- && (System.currentTimeMillis() - subscription.getLastOperationTime().getTime() > subscription
- .getPeriodicity())) {
- String subject = event.getSubject() == null ? event.getDefaultSubject() : event
- .getSubject();
- String message = event.getMessage() == null ? event.getDefaultMessage() : event
- .getMessage();
- boolean isHtmlFormat = event.isHtmlFormat();
- subscription.notifyUser(subject, message, isHtmlFormat);
- }
- }
- }
- eventNotificationService.saveEvent(event);
- }
- } catch (Exception e) {
- log.error("Error while resending messages", e);
- throw new JobExecutionException("Error while resending messages");
- }
- }
-
- public IEventNotificationService getEventNotificationService() {
- return eventNotificationService;
- }
-
-
- public void setEventNotificationService(IEventNotificationService eventNotificationService) {
- this.eventNotificationService = eventNotificationService;
- }
-
- public MessageService getCommonMessageService() {
- return commonMessageService;
- }
-
- public void setCommonMessageService(MessageService commonMessageService) {
- this.commonMessageService = commonMessageService;
- }
-
- public IUserManagementService getUserManagementService() {
- return userManagementService;
- }
-
- public void setUserManagementService(IUserManagementService userManagementService) {
- this.userManagementService = userManagementService;
- }
-
+ public void setEventNotificationService(IEventNotificationService eventNotificationService) {
+ this.eventNotificationService = eventNotificationService;
+ }
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/Subscription.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/Subscription.java,v
diff -u -r1.5 -r1.5.2.1
--- lams_common/src/java/org/lamsfoundation/lams/events/Subscription.java 4 Jul 2013 11:35:26 -0000 1.5
+++ lams_common/src/java/org/lamsfoundation/lams/events/Subscription.java 16 Feb 2016 16:03:21 -0000 1.5.2.1
@@ -3,18 +3,15 @@
import java.security.InvalidParameterException;
import java.util.Date;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-
/**
* Subscription for an event notification. This class binds an user to an event and stores some information on the
* notification attempts.
*
- * @hibernate.class table="lams_event_subscriptions"
+ * @hibernate.class table="lams_notification_subscription"
* @author Marcin Cieslak
*
*/
-class Subscription {
- // ------ persistent fields -------
+public class Subscription {
/**
* Unique ID for Hibernate needs.
*/
@@ -23,41 +20,40 @@
/**
* ID of the subscribed user
*/
- protected Integer userId;
+ private Integer userId;
- protected Event event;
+ private Event event;
/**
* ID of the delivery method used to send a message for this subscription.
*/
- protected Short deliveryMethodId;
+ private Short deliveryMethodId;
/**
* How often should the message be resend
*/
- protected Long periodicity;
+ private Long periodicity;
/**
* Time of the notification attempt
*/
- protected Date lastOperationTime;
+ private Date lastOperationTime;
/**
* Message returned by a delivery methond during the last notification attempt
*/
- protected String lastOperationMessage;
+ private String lastOperationMessage;
// --------- non-persitent fields ----------
/**
* Delivery method used to send a message.
*/
- protected AbstractDeliveryMethod deliveryMethod;
+ private AbstractDeliveryMethod deliveryMethod;
/**
* For Hibernate usage.
*/
public Subscription() {
-
}
/**
@@ -67,7 +63,7 @@
* @param deliveryMethod
* @param periodicity
*/
- protected Subscription(Integer userId, AbstractDeliveryMethod deliveryMethod, Long periodicity) {
+ public Subscription(Integer userId, AbstractDeliveryMethod deliveryMethod, Long periodicity) {
if (deliveryMethod == null) {
throw new InvalidParameterException("Delivery method can not be null.");
}
@@ -77,21 +73,14 @@
deliveryMethodId = deliveryMethod.getId();
}
- /**
- * Only user ID and delivery method count.
- */
@Override
- public boolean equals(Object o) {
- if (!(o instanceof Subscription)) {
- return false;
- }
- Subscription other = (Subscription) o;
- return other.getUserId().equals(getUserId()) && other.getDeliveryMethod().equals(getDeliveryMethod());
+ public Object clone() {
+ return new Subscription(userId, deliveryMethod, periodicity);
}
- protected AbstractDeliveryMethod getDeliveryMethod() {
+ public AbstractDeliveryMethod getDeliveryMethod() {
if (deliveryMethod == null) {
- for (AbstractDeliveryMethod delivery : EventNotificationService.getInstance().getAvailableDeliveryMethods()) {
+ for (AbstractDeliveryMethod delivery : IEventNotificationService.availableDeliveryMethods) {
if (delivery.getId() == deliveryMethodId) {
deliveryMethod = delivery;
}
@@ -101,125 +90,100 @@
}
/**
- * @hibernate.property column="last_operation_message"
+ * @hibernate.property column="delivery_method_id"
* @return
*/
- protected String getLastOperationMessage() {
- return lastOperationMessage;
+ public Short getDeliveryMethodId() {
+ return deliveryMethodId;
}
- protected boolean getLastOperationSuccessful() {
- return lastOperationMessage == null;
- }
-
/**
- * @hibernate.property column="periodicity"
+ * @hibernate.many-to-one
+ * @hibernate.column name="event_uid"
* @return
*/
- protected Long getPeriodicity() {
- return periodicity;
+ public Event getEvent() {
+ return event;
}
/**
- * @hibernate.property column="user_id"
+ * @hibernate.property column="last_operation_message"
* @return
*/
- protected Integer getUserId() {
- return userId;
+ public String getLastOperationMessage() {
+ return lastOperationMessage;
}
+ public boolean getLastOperationSuccessful() {
+ return lastOperationMessage == null;
+ }
+
/**
- * @hibernate.many-to-one
- * @hibernate.column name="event_uid"
+ * @hibernate.property column="last_operation_time"
* @return
*/
- public Event getEvent() {
- return event;
+ public Date getLastOperationTime() {
+ return lastOperationTime;
}
- public void setEvent(Event event) {
- this.event = event;
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder().append(getUserId()).append(getDeliveryMethod()).toHashCode();
- }
-
/**
- * States if a message should be send to the user or rather this subscription should be skipped.
- *
- * @return if the message should be send
+ * @hibernate.property column="periodicity"
+ * @return
*/
- protected boolean isEligibleForNotification() {
- return !getLastOperationSuccessful() || lastOperationTime == null
- || System.currentTimeMillis() - lastOperationTime.getTime() > periodicity;
+ public Long getPeriodicity() {
+ return periodicity;
}
/**
- * Sends the message to the user. Properties storing information of the last notification attempt are updated.
- *
- * @param subject
- * subject of the message; null
if not applicable
- * @param message
- * message to send
- * @param isHtmlFormat
- * whether the message is of HTML content-type or plain text
+ * @hibernate.id column="uid" generator-class="native"
*/
- protected void notifyUser(String subject, String message, boolean isHtmlFormat) {
- lastOperationTime = new Date();
- lastOperationMessage = deliveryMethod.send(null, userId, subject, message, isHtmlFormat);
+ public Long getUid() {
+ return uid;
}
- protected void setPeriodicity(Long periodicity) {
- this.periodicity = periodicity == null ? IEventNotificationService.PERIODICITY_SINGLE : periodicity;
- }
-
/**
- * @hibernate.property column="delivery_method_id"
+ * @hibernate.property column="user_id"
* @return
*/
- protected Short getDeliveryMethodId() {
- return deliveryMethodId;
+ public Integer getUserId() {
+ return userId;
}
/**
- * @hibernate.property column="last_operation_time"
- * @return
+ * States if a message should be send to the user or rather this subscription should be skipped.
+ *
+ * @return if the message should be send
*/
- protected Date getLastOperationTime() {
- return lastOperationTime;
+ public boolean isEligibleForNotification() {
+ return !getLastOperationSuccessful() || (lastOperationTime == null)
+ || ((System.currentTimeMillis() - lastOperationTime.getTime()) > periodicity);
}
- protected void setDeliveryMethodId(Short deliveryMethodId) {
+ public void setDeliveryMethodId(Short deliveryMethodId) {
this.deliveryMethodId = deliveryMethodId;
}
- protected void setLastOperationTime(Date lastOperationTime) {
- this.lastOperationTime = lastOperationTime;
+ public void setEvent(Event event) {
+ this.event = event;
}
- protected void setUserId(Integer userId) {
- this.userId = userId;
+ public void setLastOperationMessage(String lastOperationMessage) {
+ this.lastOperationMessage = lastOperationMessage;
}
- /**
- * @hibernate.id column="uid" generator-class="native"
- */
- private Long getUid() {
- return uid;
+ public void setLastOperationTime(Date lastOperationTime) {
+ this.lastOperationTime = lastOperationTime;
}
- private void setUid(Long uid) {
- this.uid = uid;
+ public void setPeriodicity(Long periodicity) {
+ this.periodicity = periodicity == null ? IEventNotificationService.PERIODICITY_SINGLE : periodicity;
}
- @Override
- public Object clone() {
- return new Subscription(userId, deliveryMethod, periodicity);
+ public void setUid(Long uid) {
+ this.uid = uid;
}
- protected void setLastOperationMessage(String lastOperationMessage) {
- this.lastOperationMessage = lastOperationMessage;
+ public void setUserId(Integer userId) {
+ this.userId = userId;
}
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java,v
diff -u -r1.3.2.3 -r1.3.2.4
--- lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java 8 Dec 2014 21:50:14 -0000 1.3.2.3
+++ lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java 16 Feb 2016 16:03:21 -0000 1.3.2.4
@@ -11,13 +11,14 @@
@Repository
class EventDAOHibernate extends LAMSBaseDAO implements EventDAO {
- protected static final String GET_EVENT_QUERY = "FROM " + Event.class.getName()
+ private static final String GET_EVENT_QUERY = "FROM " + Event.class.getName()
+ " AS e WHERE e.scope=? AND e.name=? AND e.eventSessionId=? AND e.failTime IS NULL";
- protected static final String GET_EVENTS_TO_RESEND_QUERY = "SELECT DISTINCT e FROM " + Event.class.getName()
- + " AS e, Subscription AS s WHERE s.event = e AND (e.failTime IS NOT NULL OR "
- + "(s.periodicity > 0 AND (NOW()- s.lastOperationTime >= s.periodicity)))";
-
+ private static final String GET_EVENTS_TO_RESEND_QUERY = "SELECT DISTINCT e FROM " + Event.class.getName()
+ + " AS e INNER JOIN e.subscriptions AS subscription WHERE (e.failTime IS NOT NULL OR "
+ + "(subscription.periodicity > 0 AND subscription.lastOperationTime IS NOT NULL "
+ + "AND (NOW()- subscription.lastOperationTime >= subscription.periodicity)))";
+
@SuppressWarnings("unchecked")
public Event getEvent(String scope, String name, Long sessionId) throws InvalidParameterException {
List events = (List) doFind(EventDAOHibernate.GET_EVENT_QUERY,
Index: lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java,v
diff -u -r1.53.2.4 -r1.53.2.5
--- lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java 28 Oct 2015 08:36:19 -0000 1.53.2.4
+++ lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java 16 Feb 2016 16:03:21 -0000 1.53.2.5
@@ -48,8 +48,6 @@
public static String SMTP_SERVER = "SMTPServer";
- public static String USE_INTERNAL_SMTP_SERVER = "InternalSMTPServer";
-
public static String LAMS_ADMIN_EMAIL = "LamsSupportEmail";
/**
Index: lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java,v
diff -u -r1.6.2.2 -r1.6.2.3
--- lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java 10 Feb 2016 15:40:52 -0000 1.6.2.2
+++ lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java 16 Feb 2016 16:03:21 -0000 1.6.2.3
@@ -11,7 +11,7 @@
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
-import org.masukomi.aspirin.core.MailQue;
+import org.apache.commons.lang.StringUtils;
/**
* A class that handles emails
@@ -34,8 +34,7 @@
public static void sendFromSupportEmail(String subject, String to, String body, boolean isHtmlFormat)
throws AddressException, MessagingException, UnsupportedEncodingException {
String supportEmail = Configuration.get(ConfigurationKeys.LAMS_ADMIN_EMAIL);
- Properties properties = new Properties();
- Emailer.send(subject, to, supportEmail, body, isHtmlFormat, properties);
+ Emailer.send(subject, to, "", supportEmail, "", body, isHtmlFormat);
}
/**
@@ -45,24 +44,21 @@
* @param properties
* @return
*/
- public static Session getMailSession(Properties properties) {
- Session session;
- boolean useInternalSMTPServer = Boolean.parseBoolean(Configuration
- .get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER));
- if (!useInternalSMTPServer) {
- String smtpServer = Configuration.get(ConfigurationKeys.SMTP_SERVER);
- properties.put("mail.smtp.host", smtpServer);
- }
+ public static Session getMailSession() {
+ String smtpServer = Configuration.get(ConfigurationKeys.SMTP_SERVER);
+ Properties properties = new Properties();
+ properties.put("mail.smtp.host", smtpServer);
String smtpAuthUser = Configuration.get(ConfigurationKeys.SMTP_AUTH_USER);
String smtpAuthPass = Configuration.get(ConfigurationKeys.SMTP_AUTH_PASSWORD);
- if (!useInternalSMTPServer && (smtpAuthUser != null) && !smtpAuthUser.trim().equals("")) {
+ Session session = null;
+ if (StringUtils.isBlank(smtpAuthUser)) {
+ session = Session.getInstance(properties);
+ } else {
properties.setProperty("mail.smtp.submitter", smtpAuthUser);
properties.setProperty("mail.smtp.auth", "true");
SMTPAuthenticator auth = new SMTPAuthenticator(smtpAuthUser, smtpAuthPass);
session = Session.getInstance(properties, auth);
- } else {
- session = Session.getInstance(properties);
}
return session;
}
@@ -74,27 +70,6 @@
* the subject of the email
* @param to
* the email of the recipient
- * @param from
- * the email to source the email from
- * @param body
- * the body of the email
- * @param isHtmlFormat
- * whether the message is of HTML content-type or plain text
- */
- public static void send(String subject, String to, String from, String body, boolean isHtmlFormat,
- Properties mailServerConfig) throws AddressException, MessagingException, UnsupportedEncodingException {
-
- Emailer.send(subject, to, "", from, "", body, isHtmlFormat, mailServerConfig);
-
- }
-
- /**
- * Send email to recipients
- *
- * @param subject
- * the subject of the email
- * @param to
- * the email of the recipient
* @param toPerson
* receiver's name
* @param from
@@ -107,13 +82,9 @@
* whether the message is of HTML content-type or plain text
*/
public static void send(String subject, String to, String toPerson, String from, String fromPerson, String body,
- boolean isHtmlFormat, Properties mailServerConfig) throws AddressException, MessagingException,
- UnsupportedEncodingException {
+ boolean isHtmlFormat) throws AddressException, MessagingException, UnsupportedEncodingException {
+ Session session = Emailer.getMailSession();
- Session session = Emailer.getMailSession(mailServerConfig);
- boolean useInternalSMTPServer = Boolean.parseBoolean(Configuration
- .get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER));
-
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from, fromPerson));
message.addRecipient(RecipientType.TO, new InternetAddress(to, toPerson));
@@ -122,12 +93,6 @@
String contentType = (isHtmlFormat) ? "text/html;charset=UTF-8" : "text/plain;charset=UTF-8";
message.addHeader("Content-Type", contentType);
- if (useInternalSMTPServer) {
- MailQue myMailQue = new MailQue();
- myMailQue.queMail(message);
-
- } else {
- Transport.send(message);
- }
+ Transport.send(message);
}
}
\ No newline at end of file
Index: lams_tool_wiki/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/WikiPageAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_wiki/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/WikiPageAction.java,v
diff -u -r1.15 -r1.15.2.1
--- lams_tool_wiki/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/WikiPageAction.java 17 Jul 2013 08:45:12 -0000 1.15
+++ lams_tool_wiki/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/WikiPageAction.java 16 Feb 2016 16:03:17 -0000 1.15.2.1
@@ -24,14 +24,13 @@
package org.lamsfoundation.lams.tool.wiki.web.actions;
-import java.net.URLEncoder;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
@@ -73,6 +72,7 @@
/**
* Default method when no dispatch parameter is specified.
*/
+ @Override
protected abstract ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception;
@@ -116,7 +116,8 @@
WikiPage currentPage = wikiService.getWikiPageByUid(currentPageUid);
// Check if the content is different
- if (!currentPage.getCurrentWikiContent().getBody().equals(wikiForm.getWikiBody()) || !currentPage.getTitle().equals(wikiForm.getTitle())) {
+ if (!currentPage.getCurrentWikiContent().getBody().equals(wikiForm.getWikiBody())
+ || !currentPage.getTitle().equals(wikiForm.getTitle())) {
// Set up the wiki user if this is a tool session (learner)
// Also set the editable flag here
@@ -128,7 +129,7 @@
// Setting the editable flag based on call origin
ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE, true);
- if (mode == null || mode == ToolAccessMode.TEACHER) {
+ if ((mode == null) || (mode == ToolAccessMode.TEACHER)) {
// Author/Monitor/Live edit
// If no editable flag came in the form (as in learner), set
@@ -148,12 +149,12 @@
wikiService.updateWikiPage(wikiForm, currentPage, user);
// Send edit notifications
- if (toolSessionID != null && user != null) {
+ if ((toolSessionID != null) && (user != null)) {
notifyWikiChange(toolSessionID, "notify.pageEdited.subject", "notify.pageEdited.body", user, request);
}
}
-
+
// Make sure the current page is set correctly then return to the wiki
return returnToWiki(mapping, wikiForm, request, response, currentPageUid);
}
@@ -169,8 +170,8 @@
*/
public ActionForward revertPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
- Long revertPageContentVersion = new Long(WebUtil.readLongParam(request,
- WikiConstants.ATTR_HISTORY_PAGE_CONTENT_ID));
+ Long revertPageContentVersion = new Long(
+ WebUtil.readLongParam(request, WikiConstants.ATTR_HISTORY_PAGE_CONTENT_ID));
Long currentPageUid = WebUtil.readLongParam(request, WikiConstants.ATTR_CURRENT_WIKI);
// set up wikiService
@@ -200,9 +201,9 @@
// Updating the wikiPage, setting a null user which indicated this
// change was made in author
wikiService.updateWikiPage(wikiForm, currentPage, user);
-
+
// Send revert notifications
- if (toolSessionID != null && user != null) {
+ if ((toolSessionID != null) && (user != null)) {
notifyWikiChange(toolSessionID, "notify.pageEdited.subject", "notify.pageEdited.body", user, request);
}
@@ -220,8 +221,8 @@
*/
public ActionForward comparePage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
- Long revertPageContentVersion = new Long(WebUtil.readLongParam(request,
- WikiConstants.ATTR_HISTORY_PAGE_CONTENT_ID));
+ Long revertPageContentVersion = new Long(
+ WebUtil.readLongParam(request, WikiConstants.ATTR_HISTORY_PAGE_CONTENT_ID));
Long currentPageUid = WebUtil.readLongParam(request, WikiConstants.ATTR_CURRENT_WIKI);
// set up wikiService
@@ -239,8 +240,8 @@
// Do the compariason
String diff = wikiService.comparePages(compareContent.getBody(), currentContent.getBody());
- request.setAttribute(WikiConstants.ATTR_COMPARE_VERSIONS, compareContent.getVersion().toString() + "-"
- + currentContent.getVersion().toString());
+ request.setAttribute(WikiConstants.ATTR_COMPARE_VERSIONS,
+ compareContent.getVersion().toString() + "-" + currentContent.getVersion().toString());
request.setAttribute(WikiConstants.ATTR_COMPARE_TITLE, currentWikiPage.getTitle());
request.setAttribute(WikiConstants.ATTR_COMPARE_STRING, diff);
@@ -258,8 +259,8 @@
*/
public ActionForward viewPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
- Long revertPageContentVersion = new Long(WebUtil.readLongParam(request,
- WikiConstants.ATTR_HISTORY_PAGE_CONTENT_ID));
+ Long revertPageContentVersion = new Long(
+ WebUtil.readLongParam(request, WikiConstants.ATTR_HISTORY_PAGE_CONTENT_ID));
Long currentPageUid = WebUtil.readLongParam(request, WikiConstants.ATTR_CURRENT_WIKI);
// set up wikiService
@@ -374,7 +375,7 @@
// Setting the editable flag based on call origin
ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE, true);
- if (mode == null || mode == ToolAccessMode.TEACHER) {
+ if ((mode == null) || (mode == ToolAccessMode.TEACHER)) {
// Author/Monitor/Live edit
// If no editable flag came in the form (as in learner), set false
if (wikiForm.getNewPageIsEditable() == null) {
@@ -391,12 +392,12 @@
// inserting the wiki page, null user and session indicates that this
// page was saved in author
Long currentPageUid = wikiService.insertWikiPage(wikiForm, wiki, user, session);
-
+
// Send adding page notifications
- if (toolSessionID != null && user != null) {
+ if ((toolSessionID != null) && (user != null)) {
notifyWikiChange(toolSessionID, "notify.pageAdded.subject", "notify.pageAdded.body", user, request);
}
-
+
// go to the new wiki page
return returnToWiki(mapping, wikiForm, request, response, currentPageUid);
}
@@ -418,7 +419,7 @@
// Get the session information for notifications
Long toolSessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID, true);
WikiUser user = getCurrentUser(toolSessionID);
-
+
// set up wikiService
if (wikiService == null) {
wikiService = WikiServiceProxy.getWikiService(this.getServlet().getServletContext());
@@ -429,17 +430,17 @@
// Updating the wikiPage, setting a null user which indicated this
// change was made in author
wikiService.markWikiPageAsDeleted(wikiPage);
-
+
// Send removed page notifications
- if (toolSessionID != null && user != null) {
+ if ((toolSessionID != null) && (user != null)) {
notifyWikiChange(toolSessionID, "notify.pageRemoved.subject", "notify.pageRemoved.body", user, request);
}
// return to the same page with information about being removed displayed
return this.returnToWiki(mapping, form, request, response, currentPageUid);
}
-
+
/**
* Restore a page previously marked as removed.
*/
@@ -451,7 +452,7 @@
// Get the session information for notifications
Long toolSessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID, true);
WikiUser user = getCurrentUser(toolSessionID);
-
+
// set up wikiService
if (wikiService == null) {
wikiService = WikiServiceProxy.getWikiService(this.getServlet().getServletContext());
@@ -461,9 +462,9 @@
// Updating the wikiPage
wikiService.restoreWikiPage(wikiPage);
-
+
// Send removed page notifications
- if (toolSessionID != null && user != null) {
+ if ((toolSessionID != null) && (user != null)) {
notifyWikiChange(toolSessionID, "notify.pageRestored.subject", "notify.pageRestored.body", user, request);
}
@@ -497,15 +498,9 @@
}
IEventNotificationService notificationService = wikiService.getEventNotificationService();
+ notificationService.createEvent(WikiConstants.TOOL_SIGNATURE, WikiConstants.EVENT_NOTIFY_LEARNERS,
+ toolSessionID, null, null, false);
- // first check whether the event exists and create it if it doesnt
- if (!notificationService.eventExists(WikiConstants.TOOL_SIGNATURE, WikiConstants.EVENT_NOTIFY_LEARNERS,
- toolSessionID)) {
- boolean isHtmlFormat = false;
- notificationService.createEvent(WikiConstants.TOOL_SIGNATURE, WikiConstants.EVENT_NOTIFY_LEARNERS,
- toolSessionID, null, null, isHtmlFormat);
- }
-
// Get whether the user is subscribed
boolean subscribed = notificationService.isSubscribed(WikiConstants.TOOL_SIGNATURE,
WikiConstants.EVENT_NOTIFY_LEARNERS, toolSessionID, user.getUserID().longValue());
@@ -522,7 +517,7 @@
}
// return to the wiki page
- return returnToWiki(mapping, (WikiPageForm) form, request, response, currentPageUid);
+ return returnToWiki(mapping, form, request, response, currentPageUid);
}
@@ -538,10 +533,9 @@
IEventNotificationService notificationService = wikiService.getEventNotificationService();
- String subject = wikiService.getLocalisedMessage(subjectLangKey, new Object[] { wikiSession
- .getSessionName() });
+ String subject = wikiService.getLocalisedMessage(subjectLangKey, new Object[] { wikiSession.getSessionName() });
String fullName = wikiUser.getFirstName() + " " + wikiUser.getLastName();
-
+
// Notify all the monitors
if (wikiSession.getWiki().isNotifyUpdates()) {
boolean isHtmlFormat = false;
@@ -550,7 +544,7 @@
for (User monitor : monitors) {
Integer monitorUserId = monitor.getUserId();
String contentFolderId = wikiService.getLearnerContentFolder(toolSessionID, monitorUserId.longValue());
-
+
String relativePath = "/tool/" + WikiConstants.TOOL_SIGNATURE
+ "/monitoring.do?dispatch=showWiki&toolSessionID=" + toolSessionID.toString()
+ "&contentFolderID=" + contentFolderId;
@@ -563,8 +557,8 @@
String body = wikiService.getLocalisedMessage(bodyLangKey,
new Object[] { fullName, wikiSession.getSessionName(), link });
- notificationService.sendMessage(null, monitorUserId,
- IEventNotificationService.DELIVERY_METHOD_MAIL, subject, body, isHtmlFormat);
+ notificationService.sendMessage(null, monitorUserId, IEventNotificationService.DELIVERY_METHOD_MAIL,
+ subject, body, isHtmlFormat);
}
}
@@ -573,20 +567,19 @@
if (notificationService.eventExists(WikiConstants.TOOL_SIGNATURE, WikiConstants.EVENT_NOTIFY_LEARNERS,
toolSessionID)) {
- String relativePath = "/tool/" + WikiConstants.TOOL_SIGNATURE
- + "/learning.do?mode=learner&toolSessionID=" + toolSessionID.toString();
-
+ String relativePath = "/tool/" + WikiConstants.TOOL_SIGNATURE + "/learning.do?mode=learner&toolSessionID="
+ + toolSessionID.toString();
+
String hash = relativePath + "," + toolSessionID.toString() + ",l";
hash = new String(Base64.encodeBase64(hash.getBytes()));
-
- String link = Configuration.get(ConfigurationKeys.SERVER_URL) + "r.do?" +
- "h=" + hash;
-
- String body = wikiService.getLocalisedMessage(bodyLangKey, new Object[] { fullName,
- wikiSession.getSessionName(), link });
-
- notificationService.trigger(WikiConstants.TOOL_SIGNATURE, WikiConstants.EVENT_NOTIFY_LEARNERS, toolSessionID,
- subject, body);
+
+ String link = Configuration.get(ConfigurationKeys.SERVER_URL) + "r.do?" + "h=" + hash;
+
+ String body = wikiService.getLocalisedMessage(bodyLangKey,
+ new Object[] { fullName, wikiSession.getSessionName(), link });
+
+ notificationService.trigger(WikiConstants.TOOL_SIGNATURE, WikiConstants.EVENT_NOTIFY_LEARNERS,
+ toolSessionID, subject, body);
}
}
@@ -596,14 +589,14 @@
private void revertJavascriptTokenReplacement(WikiPageForm form) {
String encodedWikiBody = form.getNewPageWikiBody();
if (encodedWikiBody != null) {
- form.setNewPageWikiBody(encodedWikiBody.replace(WikiConstants.JAVASCRIPT_REPLACE_TOKEN,
- WikiConstants.JAVASCRIPT_TOKEN));
+ form.setNewPageWikiBody(
+ encodedWikiBody.replace(WikiConstants.JAVASCRIPT_REPLACE_TOKEN, WikiConstants.JAVASCRIPT_TOKEN));
}
encodedWikiBody = form.getWikiBody();
if (encodedWikiBody != null) {
- form.setWikiBody(encodedWikiBody.replace(WikiConstants.JAVASCRIPT_REPLACE_TOKEN,
- WikiConstants.JAVASCRIPT_TOKEN));
+ form.setWikiBody(
+ encodedWikiBody.replace(WikiConstants.JAVASCRIPT_REPLACE_TOKEN, WikiConstants.JAVASCRIPT_TOKEN));
}
}
}