+
+
+
+ +
null
if the operation was successful; error message if it failed
- * @throws InvalidParameterException
- */
- protected abstract String send(Long userId, String subject, String message, boolean isHtmlFormat) throws InvalidParameterException;
+ /**
+ * Sends the message to the user.
+ *
+ * @param toUserId
+ * ID of the user
+ * @param subject
+ * subject of the message
+ * @param message
+ * text of the message
+ * @param isHtmlFormat
+ * whether the message is of HTML content-type or plain text
+ * @return null
if the operation was successful; error message if it failed
+ * @throws InvalidParameterException
+ */
+ protected abstract String send(Integer fromUserId, Integer toUserId, String subject, String message,
+ boolean isHtmlFormat) throws InvalidParameterException;
- public String getSignature() {
- return signature;
- }
+ public String getSignature() {
+ return signature;
+ }
- public String getDescription() {
- return description;
- }
+ public String getDescription() {
+ return description;
+ }
- @Override
- public boolean equals(Object o) {
- return o instanceof AbstractDeliveryMethod && ((AbstractDeliveryMethod) o).signature.equalsIgnoreCase(signature);
- }
+ @Override
+ public boolean equals(Object o) {
+ return (o instanceof AbstractDeliveryMethod)
+ && ((AbstractDeliveryMethod) o).signature.equalsIgnoreCase(signature);
+ }
- public short getId() {
- return id;
- }
+ public short getId() {
+ return id;
+ }
- public long getSendTimeout() {
- return sendTimeout;
- }
+ public long getSendTimeout() {
+ return sendTimeout;
+ }
- public void setSendTimeout(long sendTimeout) {
- this.sendTimeout = sendTimeout;
- }
+ public void setSendTimeout(long sendTimeout) {
+ this.sendTimeout = sendTimeout;
+ }
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java
===================================================================
diff -u -r84151d175a3fce3cd3ff1bd4eeccfd7cbef01802 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java (.../DeliveryMethodMail.java) (revision 84151d175a3fce3cd3ff1bd4eeccfd7cbef01802)
+++ lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java (.../DeliveryMethodMail.java) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -2,13 +2,17 @@
import java.io.UnsupportedEncodingException;
import java.security.InvalidParameterException;
+import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.validator.EmailValidator;
+import org.apache.log4j.Logger;
import org.lamsfoundation.lams.usermanagement.User;
import org.lamsfoundation.lams.util.Configuration;
+import org.lamsfoundation.lams.util.ConfigurationKeys;
import org.lamsfoundation.lams.util.Emailer;
/**
@@ -20,27 +24,45 @@
public class DeliveryMethodMail extends AbstractDeliveryMethod {
private static DeliveryMethodMail instance;
+ protected static final EmailValidator emailValidator = EmailValidator.getInstance();
+ private static final Logger log = Logger.getLogger(DeliveryMethodMail.class);
protected DeliveryMethodMail() {
super((short) 1, "MAIL", "Messages will be send by Mail");
}
@Override
- public String send(Long userId, String subject, String message, boolean isHtmlFormat) throws InvalidParameterException {
- if (userId == null) {
- return "User ID should not be null.";
+ 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 user = (User) EventNotificationService.getInstance().getUserManagementService().findById(User.class,
- userId.intValue());
- if (user == null) {
- return "User with the provided ID was not found.";
+ User toUser = (User) EventNotificationService.getInstance().getUserManagementService()
+ .findById(User.class, toUserId);
+ if (toUser == null) {
+ log.error("Target user with ID " + toUserId + " was not found.");
}
- String email = user.getEmail();
- if (StringUtils.isBlank(email)) {
- return "User's e-mail address is blank.";
+ String toEmail = toUser.getEmail();
+ if (!DeliveryMethodMail.emailValidator.isValid(toEmail)) {
+ return "Target user's e-mail address is invalid.";
}
- sendFromSupportEmail(subject, email, message, isHtmlFormat);
+
+ if (fromUserId == null) {
+ Emailer.sendFromSupportEmail(subject, toEmail, message, isHtmlFormat);
+ } else {
+ User fromUser = (User) EventNotificationService.getInstance().getUserManagementService()
+ .findById(User.class, toUserId);
+ if (fromUser == null) {
+ log.error("Source user with ID " + toUserId + " 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());
+ }
return null;
} catch (Exception e) {
return e.toString();
@@ -55,27 +77,6 @@
}
/**
- * Sends an email sourced from admin. Copied from Emailer class.
- *
- * @param subject
- * subject of the message
- * @param to
- * address to send
- * @param body
- * text of the message
- * @param isHtmlFormat
- * whether the message is of HTML content-type or plain text
- * @throws AddressException
- * if address was incorrect
- * @throws MessagingException
- * if the operation failed
- */
- public void sendFromSupportEmail(String subject, String to, String body, boolean isHtmlFormat) throws AddressException,
- MessagingException, UnsupportedEncodingException {
- Emailer.sendFromSupportEmail(subject, to, body, isHtmlFormat);
- }
-
- /**
* Sends an email to the address provided by the admin.
*
* @param subject
@@ -85,16 +86,20 @@
*
* @param isHtmlFormat
* whether the message is of HTML content-type or plain text
+ * @throws UnsupportedEncodingException
* @throws AddressException
* if address was incorrect
* @throws MessagingException
* if the operation failed
*/
void notifyAdmin(String subject, String body, boolean isHtmlFormat) throws AddressException,
- MessagingException, UnsupportedEncodingException {
- String adminEmail = Configuration.get("LamsSupportEmail");
- if (!StringUtils.isEmpty(adminEmail)) {
- sendFromSupportEmail(subject, adminEmail, body, isHtmlFormat);
+ 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);
+ } else {
+ Emailer.sendFromSupportEmail(subject, adminEmail, body, isHtmlFormat);
}
}
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/Event.java
===================================================================
diff -u -r84151d175a3fce3cd3ff1bd4eeccfd7cbef01802 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_common/src/java/org/lamsfoundation/lams/events/Event.java (.../Event.java) (revision 84151d175a3fce3cd3ff1bd4eeccfd7cbef01802)
+++ lams_common/src/java/org/lamsfoundation/lams/events/Event.java (.../Event.java) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -14,481 +14,489 @@
*
* @hibernate.class table="lams_events"
* @author Marcin Cieslak
- *
+ *
*/
public class Event {
- //--------- persistent fields -------------
- /**
- * Unique ID for Hibernate needs.
- */
- private Long uid;
+ // --------- persistent fields -------------
+ /**
+ * Unique ID for Hibernate needs.
+ */
+ private Long uid;
- /**
- * Name of the event.
- */
- protected String name;
+ /**
+ * Name of the event.
+ */
+ protected 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;
+ /**
+ * 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;
- /**
- * 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;
+ /**
+ * 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;
- /**
- * Was the event triggered (did it happen).
- */
- protected Boolean triggered = false;
+ /**
+ * 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 Setnull
or name is blank
- */
- public Event(String scope, String name, Long sessionId, String defaultSubject, String defaultMessage,
- boolean isHtmlContentType)
- throws InvalidParameterException {
- if (scope == null) {
- throw new InvalidParameterException("Event scope can not be null.");
- }
- if (StringUtils.isEmpty(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.htmlFormat = isHtmlContentType;
- fullSignature = 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);
+ /**
+ * Standard constructor used by EventNotificationService.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param defaultSubject
+ * subject of the message to send
+ * @param defaultMessage
+ * body of the message to send
+ * @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 {
+ if (scope == null) {
+ throw new InvalidParameterException("Event scope can not be null.");
}
-
- @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;
+ if (StringUtils.isEmpty(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.htmlFormat = isHtmlContentType;
+ fullSignature = Event.createFullSignature(scope, name, sessionId);
+ }
- /**
- * Full signature is compared.
- */
- @Override
- public boolean equals(Object o) {
- return o instanceof Event && ((Event) o).getFullSignature().equalsIgnoreCase(getFullSignature())
- || o instanceof CharSequence && ((CharSequence) o).toString().equalsIgnoreCase(getFullSignature());
+ /**
+ * 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.");
}
-
- @Override
- public int hashCode() {
- return getFullSignature().hashCode();
+ if (StringUtils.isEmpty(name)) {
+ throw new InvalidParameterException("Name should not be blank.");
}
+ return scope + '_' + name + (sessionId == null ? "" : "_" + sessionId);
+ }
- /**
- * @hibernate.property column="default_message"
- * @return
- */
- protected String getDefaultMessage() {
- return defaultMessage;
+ @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;
+ }
- /**
- * @hibernate.property column="default_subject"
- * @return
- */
- protected String getDefaultSubject() {
- return defaultSubject;
- }
+ /**
+ * Full signature is compared.
+ */
+ @Override
+ public boolean equals(Object o) {
+ return ((o instanceof Event) && ((Event) o).getFullSignature().equalsIgnoreCase(getFullSignature()))
+ || ((o instanceof CharSequence) && ((CharSequence) o).toString().equalsIgnoreCase(getFullSignature()));
+ }
- protected String getFullSignature() {
- if (fullSignature == null) {
- fullSignature = createFullSignature(getScope(), getName(), getEventSessionId());
- }
- return fullSignature;
- }
+ @Override
+ public int hashCode() {
+ return getFullSignature().hashCode();
+ }
- /**
- * @hibernate.property column="name" length="128"
- * @return
- */
- protected String getName() {
- return name;
- }
+ /**
+ * @hibernate.property column="default_message"
+ * @return
+ */
+ protected String getDefaultMessage() {
+ return defaultMessage;
+ }
- /**
- * @hibernate.property column="scope" length="128"
- * @return
- */
- protected String getScope() {
- return scope;
- }
+ /**
+ * @hibernate.property column="default_subject"
+ * @return
+ */
+ protected String getDefaultSubject() {
+ return defaultSubject;
+ }
- /**
- * @hibernate.property column="event_session_id"
- * @return
- */
- protected Long getEventSessionId() {
- return eventSessionId;
+ protected String getFullSignature() {
+ if (fullSignature == null) {
+ fullSignature = Event.createFullSignature(getScope(), getName(), getEventSessionId());
}
+ return fullSignature;
+ }
- /**
- *
- * @hibernate.set cascade="all-delete-orphan" order-by="last_operation_time desc" outer-join="true"
- * @hibernate.collection-key column="event_uid"
- * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.events.Subscription"
- *
- * @return
- */
- protected Settrue
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);
- }
+ /**
+ * 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,
+ @Override
+ public boolean 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;
- }
- event = new Event(scope, name, eventSessionId, defaultSubject, defaultMessage, isHtmlFormat);
- event.referenceCounter++;
- saveEvent(event);
- return true;
+ Event event = getEvent(scope, name, eventSessionId);
+ if (event != null) {
+ saveEvent(event);
+ return false;
}
+ 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 deleteEvent(String scope, String name, Long eventSessionId) throws InvalidParameterException {
+ if (scope == null) {
+ throw new InvalidParameterException("Scope should not be null.");
}
-
- @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)) {
- throw new InvalidParameterException("Name should not be blank.");
- }
- Event event = getEvent(scope, name, eventSessionId);
- if (event == null) {
- return false;
- }
- else {
- saveEvent(event);
- return true;
- }
+ if (StringUtils.isEmpty(name)) {
+ throw new InvalidParameterException("Name should not be blank.");
}
-
- @Override
- public Setnull
if it does not exist
- */
- protected Event getEvent(String scope, String name, Long eventSessionId) {
- String fullSignature = Event.createFullSignature(scope, name, eventSessionId);
+ /**
+ * 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;
- }
+ for (Event event : EventNotificationService.eventPool) {
+ if (event.equals(fullSignature)) {
+ if (event.deleted) {
+ return null;
}
-
- Event result = getEventDAO().getEvent(scope, name, eventSessionId);
- if (result == null) {
- return null;
- }
- result.referenceCounter++;
- EventNotificationService.eventPool.add(result);
- return result;
+ event.referenceCounter++;
+ return event;
+ }
}
- protected IUserManagementService getUserManagementService() {
- return userManagementService;
+ 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
- */
- protected void saveEvent(Event event) {
- event.referenceCounter--;
- if (event.referenceCounter <= 0) {
- EventNotificationService.eventPool.remove(event);
- if (event.deleted) {
- getEventDAO().deleteEvent(event);
- }
- else {
- getEventDAO().saveEvent(event);
- }
- }
- }
+ protected IUserManagementService getUserManagementService() {
+ return userManagementService;
+ }
- private Scheduler getScheduler() {
- return scheduler;
+ /**
+ * Saves the event into the database
+ *
+ * @param event
+ * event to be saved
+ */
+ protected 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 void setMessageService(MessageService messageService) {
- this.messageService = messageService;
- }
+ private Scheduler getScheduler() {
+ return scheduler;
+ }
- protected MessageService getMessageService() {
- return messageService;
- }
+ public void setMessageService(MessageService messageService) {
+ this.messageService = messageService;
+ }
+
+ protected MessageService getMessageService() {
+ return messageService;
+ }
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/events/IEventNotificationService.java
===================================================================
diff -u -r84151d175a3fce3cd3ff1bd4eeccfd7cbef01802 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_common/src/java/org/lamsfoundation/lams/events/IEventNotificationService.java (.../IEventNotificationService.java) (revision 84151d175a3fce3cd3ff1bd4eeccfd7cbef01802)
+++ lams_common/src/java/org/lamsfoundation/lams/events/IEventNotificationService.java (.../IEventNotificationService.java) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -5,224 +5,345 @@
/**
* Provides tools for managing events and notifing users.
+ *
* @author Marcin Cieslak
- *
+ *
*/
public interface IEventNotificationService {
- /**
- * Scope for the events that are common for the whole LAMS environment.
- */
- public static final String CORE_EVENTS_SCOPE = "CORE";
+ /**
+ * Scope for the events that are common for the whole LAMS environment.
+ */
+ public static final String CORE_EVENTS_SCOPE = "CORE";
- /**
- * User should be notified only once. Used when subscribing a user to an event.
- */
- public static final long PERIODICITY_SINGLE = 0;
+ /**
+ * Scope for events that were created after {@link #sendMessage(Long, AbstractDeliveryMethod, String, String)}
+ * failed.
+ */
+ public static final String SINGLE_MESSAGE_SCOPE = "SINGLE_MESSAGE";
- /**
- * User should be notified daily. Used when subscribing a user to an event.
- */
- public static final long PERIODICITY_DAILY = 24 * 60 * 60;
+ /**
+ * User should be notified only once. Used when subscribing a user to an event.
+ */
+ public static final long PERIODICITY_SINGLE = 0;
- /**
- * User should be notified weekly. Used when subscribing a user to an event.
- */
- public static final long PERIODICITY_WEEKLY = IEventNotificationService.PERIODICITY_DAILY * 7;
+ /**
+ * User should be notified daily. Used when subscribing a user to an event.
+ */
+ public static final long PERIODICITY_DAILY = 24 * 60 * 60;
- /**
- * User should be notified monthly. Used when subscribing a user to an event.
- */
- public static final long PERIODICITY_MONTHLY = IEventNotificationService.PERIODICITY_WEEKLY * 4;
+ /**
+ * User should be notified weekly. Used when subscribing a user to an event.
+ */
+ public static final long PERIODICITY_WEEKLY = IEventNotificationService.PERIODICITY_DAILY * 7;
- /**
- * Allows sending mail to users using the configured SMTP server.
- * Currently it is the only delivery method available.
- */
- public static final AbstractDeliveryMethod DELIVERY_METHOD_MAIL = DeliveryMethodMail.getInstance();
+ /**
+ * User should be notified monthly. Used when subscribing a user to an event.
+ */
+ public static final long PERIODICITY_MONTHLY = IEventNotificationService.PERIODICITY_WEEKLY * 4;
- /**
- * Creates an event and saves it into the database.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param defaultSubject subject of the message send to users; it can be altered when triggering the event
- * @param defaultMessage body of the message send to users; it can be altered when triggering the event
- * @param isHtmlFormat whether the message is of HTML content-type or plain text
- * @return true
if the event did not exist and was correctly created
- * @throws InvalidParameterException if scope was null
or name was blank
- */
- public abstract boolean createEvent(String scope, String name, Long eventSessionId, String defaultSubject,
- String defaultMessage, boolean isHtmlFormat) throws InvalidParameterException;
+ /**
+ * Allows sending mail to users using the configured SMTP server. Currently it is the only delivery method
+ * available.
+ */
+ public static final AbstractDeliveryMethod DELIVERY_METHOD_MAIL = DeliveryMethodMail.getInstance();
- /**
- * 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
- */
- public abstract boolean deleteEvent(String scope, String name, Long eventSessionId) throws InvalidParameterException;;
+ /**
+ * Creates an event and saves it into the database.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param defaultSubject
+ * subject of the message send to users; it can be altered when triggering the event
+ * @param defaultMessage
+ * body of the message send to users; it can be altered when triggering the event
+ * @param isHtmlFormat
+ * whether the message is of HTML content-type or plain text
+ * @return true
if the event did not exist and was correctly created
+ * @throws InvalidParameterException
+ * if scope was null
or name was blank
+ */
+ public abstract boolean createEvent(String scope, String name, Long eventSessionId, String defaultSubject,
+ String defaultMessage, boolean isHtmlFormat) throws InvalidParameterException;
- /**
- * Checks if event with the given parameters exists in the database.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @return true
if the event exists
- * @throws InvalidParameterException if scope was null
or name was blank
- */
- public abstract boolean eventExists(String scope, String name, Long eventSessionId) throws InvalidParameterException;
+ /**
+ * 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
+ */
+ public abstract boolean deleteEvent(String scope, String name, Long eventSessionId)
+ throws InvalidParameterException;;
- /**
- * 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
- */
- public abstract Settrue
if the event exists
+ * @throws InvalidParameterException
+ * if scope was null
or name was blank
+ */
+ public abstract boolean eventExists(String scope, String name, Long eventSessionId)
+ throws InvalidParameterException;
- /**
- * Checks if an user is subscribed to the given event.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param userId ID of the user
- * @return true
if the event exists and the user is subscribed (with at least one delivery method) to the event
- * @throws InvalidParameterException if scope or user ID were null
, name was blank or event does not exist
- */
- public abstract boolean isSubscribed(String scope, String name, Long eventSessionId, Long userId)
- throws InvalidParameterException;
+ /**
+ * 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
+ */
+ public abstract Settrue
if the message was succefully send to the user
- * @throws InvalidParameterException if userId or delivery method are null
- */
- public abstract boolean sendMessage(Long userId, AbstractDeliveryMethod deliveryMethod, String subject, String message, boolean isHtmlFormat)
- throws InvalidParameterException;
+ /**
+ * Checks if an user is subscribed to the given event.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param userId
+ * ID of the user
+ * @return true
if the event exists and the user is subscribed (with at least one delivery method) to
+ * the event
+ * @throws InvalidParameterException
+ * if scope or user ID were null
, name was blank or event does not exist
+ */
+ public abstract boolean isSubscribed(String scope, String name, Long eventSessionId, Long userId)
+ throws InvalidParameterException;
- /**
- *
- * Sends a single message to the given user. If it fails, an event is created for the needs of the resending mechanism.
- * @param userId IDs of users to send the message to
- * @param deliveryMethod method of messaged delivery to use
- * @param subject subject of the message to send
- * @param message body of the message to send
- * @param isHtmlFormat whether the message is of HTML content-type or plain text
- * @return true
if the message was succefully send to all the users; as in the current implementation a separate thread is used for sending messages, this method always returns true
- * @throws InvalidParameterException if userId array or delivery method are null
- */
- public abstract boolean sendMessage(Long[] userId, AbstractDeliveryMethod deliveryMethod, String subject, String message, boolean isHtmlFormat)
- throws InvalidParameterException;
+ /**
+ * Sends a single message to the given users.If it fails, an event is created for the needs of the resending
+ * mechanism.
+ *
+ * @param toUserId
+ * ID of users to send the message to
+ * @param deliveryMethod
+ * method of messaged delivery to use
+ * @param subject
+ * subject of the message to send
+ * @param message
+ * body of the message to send
+ * @param isHtmlFormat
+ * whether the message is of HTML content-type or plain text
+ * @return true
if the message was succefully send to the user
+ * @throws InvalidParameterException
+ * if userId or delivery method are null
+ */
+ public abstract boolean sendMessage(Integer fromUserId, Integer toUserId, 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 already exists,
- * only periodicity is updated.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param userId ID of the user
- * @param deliveryMethod method of messaged delivery to use
- * @param periodicity how often the user should be notified (in seconds)
- * @throws InvalidParameterException if scope, userId or delivery method are null
, or name is blank
- */
- public abstract boolean subscribe(String scope, String name, Long eventSessionId, Long userId,
- AbstractDeliveryMethod deliveryMethod, Long periodicity) throws InvalidParameterException;
+ /**
+ *
+ * Sends a single message to the given user. If it fails, an event is created for the needs of the resending
+ * mechanism.
+ *
+ * @param toUserIds
+ * IDs of users to send the message to
+ * @param deliveryMethod
+ * method of messaged delivery to use
+ * @param subject
+ * subject of the message to send
+ * @param message
+ * body of the message to send
+ * @param isHtmlFormat
+ * whether the message is of HTML content-type or plain text
+ * @return true
if the message was succefully send to all the users; as in the current implementation a
+ * separate thread is used for sending messages, this method always returns true
+ * @throws InvalidParameterException
+ * if userId array or delivery method are null
+ */
+ public abstract boolean sendMessage(Integer fromUserId, Integer[] toUserIds, AbstractDeliveryMethod deliveryMethod,
+ String subject, String message, boolean isHtmlFormat) throws InvalidParameterException;
- /**
- * Triggers the event with the default (or previously set) subject and message. Each subscribed user is notified.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @throws InvalidParameterException if scope is null
or name is blank
- */
- public abstract boolean trigger(String scope, String name, Long eventSessionId) throws InvalidParameterException;
+ /**
+ * Registeres an user for notification of the event. If a subscription with given user ID and delivery method
+ * already exists, only periodicity is updated.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param userId
+ * ID of the user
+ * @param deliveryMethod
+ * method of messaged delivery to use
+ * @param periodicity
+ * how often the user should be notified (in seconds)
+ * @throws InvalidParameterException
+ * if scope, userId or delivery method are null
, or name is blank
+ */
+ public abstract boolean subscribe(String scope, String name, Long eventSessionId, Integer userId,
+ AbstractDeliveryMethod deliveryMethod, Long periodicity) throws InvalidParameterException;
- /**
- * Triggers the event with the default subject and message, modifying placeholders ({0}, {1}, {2}
...) in the message body with the parameterValues
. Each subscribed user is notified.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param parameterValues values that should replace placeholders in the message body; for each object its text representation is acquired by toString()
method; then, the first string replaces {0}
tag, second one the {1}
tag and so on.
- * @throws InvalidParameterException if scope is null
or name is blank
- */
- public abstract boolean trigger(String scope, String name, Long eventSessionId, Object[] parameterValues)
- throws InvalidParameterException;
+ /**
+ * Triggers the event with the default (or previously set) subject and message. Each subscribed user is notified.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @throws InvalidParameterException
+ * if scope is null
or name is blank
+ */
+ public abstract boolean trigger(String scope, String name, Long eventSessionId) throws InvalidParameterException;
- /**
- * Triggers the event with given subject and message. Each subscribed user is notified. Default message and subject are overridden.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param subject subject of the message to send
- * @param message body of the message to send
- * @throws InvalidParameterException if scope is null
or name is blank
- */
- public abstract boolean trigger(String scope, String name, Long eventSessionId, String subject, String message)
- throws InvalidParameterException;
+ /**
+ * Triggers the event with the default subject and message, modifying placeholders ({0}, {1}, {2}
...)
+ * in the message body with the parameterValues
. Each subscribed user is notified.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param parameterValues
+ * values that should replace placeholders in the message body; for each object its text representation
+ * is acquired by toString()
method; then, the first string replaces {0}
tag,
+ * second one the {1}
tag and so on.
+ * @throws InvalidParameterException
+ * if scope is null
or name is blank
+ */
+ public abstract boolean trigger(String scope, String name, Long eventSessionId, Object[] parameterValues)
+ throws InvalidParameterException;
- /**
- * Notifies only a single user of the event using the default subject and message. Does not set the event as "triggered".
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param userId ID of the user
- * @throws InvalidParameterException if scope or userId are null
or name is blank
- */
- public abstract boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Long userId)
- throws InvalidParameterException;
+ /**
+ * Triggers the event with given subject and message. Each subscribed user is notified. Default message and subject
+ * are overridden.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param subject
+ * subject of the message to send
+ * @param message
+ * body of the message to send
+ * @throws InvalidParameterException
+ * if scope is null
or name is blank
+ */
+ public abstract boolean trigger(String scope, String name, Long eventSessionId, String subject, String message)
+ throws InvalidParameterException;
- /**
- * Notifies only a single user of the event using the default subject and message, modifying placeholders ({0}, {1}, {2}
...) in the message body with the parameterValues
. Does not set the event as "triggered".
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param userId ID of the user
- * @param parameterValues values that should replace placeholders in the message body; for each object its text representation is acquired by toString()
method; then, the first string replaces {0}
tag, second one the {1}
tag and so on.
- * @throws InvalidParameterException if scope or userId are null
or name is blank
- */
- public boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Long userId, Object[] parameterValues)
- throws InvalidParameterException;
+ /**
+ * Notifies only a single user of the event using the default subject and message. Does not set the event as
+ * "triggered".
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param userId
+ * ID of the user
+ * @throws InvalidParameterException
+ * if scope or userId are null
or name is blank
+ */
+ public abstract boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId)
+ throws InvalidParameterException;
- /**
- * Notifies only a single user of the event using the given subject and message. Does not set the event as "triggered". Default subject and message are NOT overridden.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param userId ID of the user
- * @param subject subject of the message to send
- * @param message body of the message to send
- * @throws InvalidParameterException if scope or userId are null
or name is blank
- */
- public abstract boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Long userId, String subject,
- String message) throws InvalidParameterException;
+ /**
+ * Notifies only a single user of the event using the default subject and message, modifying placeholders (
+ * {0}, {1}, {2}
...) in the message body with the parameterValues
. Does not set the event
+ * as "triggered".
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param userId
+ * ID of the user
+ * @param parameterValues
+ * values that should replace placeholders in the message body; for each object its text representation
+ * is acquired by toString()
method; then, the first string replaces {0}
tag,
+ * second one the {1}
tag and so on.
+ * @throws InvalidParameterException
+ * if scope or userId are null
or name is blank
+ */
+ public boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId,
+ Object[] parameterValues) throws InvalidParameterException;
- /**
- * Unregister an user from notification of the event.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param userId ID of the user
- * @throws InvalidParameterException if scope or userId are null
or name is blank
- */
- public abstract boolean unsubscribe(String scope, String name, Long eventSessionId, Long userId)
- throws InvalidParameterException;
+ /**
+ * Notifies only a single user of the event using the given subject and message. Does not set the event as
+ * "triggered". Default subject and message are NOT overridden.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param userId
+ * ID of the user
+ * @param subject
+ * subject of the message to send
+ * @param message
+ * body of the message to send
+ * @throws InvalidParameterException
+ * if scope or userId are null
or name is blank
+ */
+ public abstract boolean triggerForSingleUser(String scope, String name, Long eventSessionId, Integer userId,
+ String subject, String message) throws InvalidParameterException;
- /**
- * Unregister delivery method of the user from notification of the event.
- * @param scope scope of the event
- * @param name name of the event
- * @param eventSessionId session ID of the event
- * @param userId ID of the user
- * @param deliveryMethod delivery method which should be unregistered
- * @throws InvalidParameterException if scope, userId or delivery method are null
or name is blank
- */
- public abstract boolean unsubscribe(String scope, String name, Long eventSessionId, Long userId,
- AbstractDeliveryMethod deliveryMethod) throws InvalidParameterException;
+ /**
+ * Unregister an user from notification of the event.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param userId
+ * ID of the user
+ * @throws InvalidParameterException
+ * if scope or userId are null
or name is blank
+ */
+ public abstract boolean unsubscribe(String scope, String name, Long eventSessionId, Integer userId)
+ throws InvalidParameterException;
+
+ /**
+ * Unregister delivery method of the user from notification of the event.
+ *
+ * @param scope
+ * scope of the event
+ * @param name
+ * name of the event
+ * @param eventSessionId
+ * session ID of the event
+ * @param userId
+ * ID of the user
+ * @param deliveryMethod
+ * delivery method which should be unregistered
+ * @throws InvalidParameterException
+ * if scope, userId or delivery method are null
or name is blank
+ */
+ public abstract boolean 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
===================================================================
diff -u -r84151d175a3fce3cd3ff1bd4eeccfd7cbef01802 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_common/src/java/org/lamsfoundation/lams/events/ResendMessagesJob.java (.../ResendMessagesJob.java) (revision 84151d175a3fce3cd3ff1bd4eeccfd7cbef01802)
+++ lams_common/src/java/org/lamsfoundation/lams/events/ResendMessagesJob.java (.../ResendMessagesJob.java) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -9,66 +9,67 @@
import org.springframework.scheduling.quartz.QuartzJobBean;
/**
- * Quartz job for resending messages.
- * This job is scheduled from the start-up and periodically attempts to resend failed and marked for resending messages.
+ * 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
- *
+ *
*/
public class ResendMessagesJob extends QuartzJobBean {
- /**
- * 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;
+ /**
+ * 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;
- private static final EventNotificationService notificationService = EventNotificationService.getInstance();
+ private static final EventNotificationService notificationService = EventNotificationService.getInstance();
- private static final MessageService messageService = ResendMessagesJob.notificationService.getMessageService();
+ private static final MessageService messageService = ResendMessagesJob.notificationService.getMessageService();
- @Override
- protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
- try {
- EventNotificationService.log.debug("Event notification service is running a resend messages thread...");
- Listnull
if not applicable
- * @param message message to send
- * @param 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
- */
- protected void notifyUser(String subject, String message, boolean isHtmlFormat) {
- lastOperationTime = new Date();
- lastOperationMessage = deliveryMethod.send(userId, subject, message, isHtmlFormat);
- }
+ */
+ protected void notifyUser(String subject, String message, boolean isHtmlFormat) {
+ lastOperationTime = new Date();
+ lastOperationMessage = deliveryMethod.send(null, userId, subject, message, isHtmlFormat);
+ }
- protected void setPeriodicity(Long periodicity) {
- this.periodicity = periodicity == null ? IEventNotificationService.PERIODICITY_SINGLE : periodicity;
- }
+ protected void setPeriodicity(Long periodicity) {
+ this.periodicity = periodicity == null ? IEventNotificationService.PERIODICITY_SINGLE : periodicity;
+ }
- /**
- * @hibernate.property column="delivery_method_id"
- * @return
- */
- protected Short getDeliveryMethodId() {
- return deliveryMethodId;
- }
+ /**
+ * @hibernate.property column="delivery_method_id"
+ * @return
+ */
+ protected Short getDeliveryMethodId() {
+ return deliveryMethodId;
+ }
- /**
- * @hibernate.property column="last_operation_time"
- * @return
- */
- protected Date getLastOperationTime() {
- return lastOperationTime;
- }
+ /**
+ * @hibernate.property column="last_operation_time"
+ * @return
+ */
+ protected Date getLastOperationTime() {
+ return lastOperationTime;
+ }
- protected void setDeliveryMethodId(Short deliveryMethodId) {
- this.deliveryMethodId = deliveryMethodId;
- }
+ protected void setDeliveryMethodId(Short deliveryMethodId) {
+ this.deliveryMethodId = deliveryMethodId;
+ }
- protected void setLastOperationTime(Date lastOperationTime) {
- this.lastOperationTime = lastOperationTime;
- }
+ protected void setLastOperationTime(Date lastOperationTime) {
+ this.lastOperationTime = lastOperationTime;
+ }
- protected void setUserId(Long userId) {
- this.userId = userId;
- }
+ protected void setUserId(Integer userId) {
+ this.userId = userId;
+ }
- /**
- * @hibernate.id column="uid" generator-class="native"
- */
- private Long getUid() {
- return uid;
- }
+ /**
+ * @hibernate.id column="uid" generator-class="native"
+ */
+ private Long getUid() {
+ return uid;
+ }
- private void setUid(Long uid) {
- this.uid = uid;
- }
+ private void setUid(Long uid) {
+ this.uid = uid;
+ }
- @Override
- public Object clone() {
- return new Subscription(userId, deliveryMethod, periodicity);
- }
+ @Override
+ public Object clone() {
+ return new Subscription(userId, deliveryMethod, periodicity);
+ }
- protected void setLastOperationMessage(String lastOperationMessage) {
- this.lastOperationMessage = lastOperationMessage;
- }
+ protected void setLastOperationMessage(String lastOperationMessage) {
+ this.lastOperationMessage = lastOperationMessage;
+ }
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java
===================================================================
diff -u -r84151d175a3fce3cd3ff1bd4eeccfd7cbef01802 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java (.../Emailer.java) (revision 84151d175a3fce3cd3ff1bd4eeccfd7cbef01802)
+++ lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java (.../Emailer.java) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -3,17 +3,14 @@
import java.io.UnsupportedEncodingException;
import java.util.Properties;
-import javax.mail.Authenticator;
+import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
-import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
-import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
-import org.apache.log4j.Logger;
import org.masukomi.aspirin.core.MailQue;
/**
@@ -22,10 +19,6 @@
* @author lfoxton
*/
public class Emailer {
-
- public Emailer() {
- }
-
/**
* Sends an email sourced from support email
*
@@ -42,7 +35,7 @@
throws AddressException, MessagingException, UnsupportedEncodingException {
String supportEmail = Configuration.get(ConfigurationKeys.LAMS_ADMIN_EMAIL);
Properties properties = new Properties();
- send(subject, to, supportEmail, body, isHtmlFormat, properties);
+ Emailer.send(subject, to, supportEmail, body, isHtmlFormat, properties);
}
/**
@@ -91,7 +84,7 @@
public static void send(String subject, String to, String from, String body, boolean isHtmlFormat,
Properties mailServerConfig) throws AddressException, MessagingException, UnsupportedEncodingException {
- send(subject, to, "", from, "", body, isHtmlFormat, mailServerConfig);
+ Emailer.send(subject, to, "", from, "", body, isHtmlFormat, mailServerConfig);
}
@@ -117,7 +110,7 @@
boolean isHtmlFormat, Properties mailServerConfig) throws AddressException, MessagingException,
UnsupportedEncodingException {
- Session session = getMailSession(mailServerConfig);
+ Session session = Emailer.getMailSession(mailServerConfig);
boolean useInternalSMTPServer = Boolean.parseBoolean(Configuration
.get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER));
@@ -126,7 +119,7 @@
message.addRecipient(RecipientType.TO, new InternetAddress(to, toPerson));
message.setSubject(subject, "UTF-8");
message.setText(body, "UTF-8");
- String contentType = (isHtmlFormat) ? "text/html; charset=UTF-8" : "text/plain; charset=UTF-8";
+ String contentType = (isHtmlFormat) ? "text/html;charset=UTF-8" : "text/plain;charset=UTF-8";
message.addHeader("Content-Type", contentType);
if (useInternalSMTPServer) {
@@ -136,7 +129,5 @@
} else {
Transport.send(message);
}
-
}
-
-}
+}
\ No newline at end of file
Index: lams_monitoring/conf/language/lams/ApplicationResources.properties
===================================================================
diff -u -r1b117caf4135f53248542cbc97d71aac448f3de9 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_monitoring/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 1b117caf4135f53248542cbc97d71aac448f3de9)
+++ lams_monitoring/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -219,6 +219,7 @@
learner.group.sort.button =Sort
button.force.complete =Force complete
button.view.learner =View learner
+button.email =Email
button.close =Close
button.help =Help
button.help.tooltip =Open page with help on this tab
@@ -233,8 +234,8 @@
lesson.learners =Learners:
lesson.class =Class:
lesson.manage =Manage Lesson
-button.view.learners =View Learners
-button.view.learners.tooltip =Shows all the learners assigned to this lesson
+button.view.learners =View/Email Learners
+button.view.learners.tooltip =Shows all learners assigned to this lesson and allows to email them
button.edit.class =Edit Class
button.edit.class.tooltip =Edit the list of learners and monitors assigned to this lesson
button.open.im =Open IM
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/EmailScheduleMessageJob.java
===================================================================
diff -u -r84151d175a3fce3cd3ff1bd4eeccfd7cbef01802 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/EmailScheduleMessageJob.java (.../EmailScheduleMessageJob.java) (revision 84151d175a3fce3cd3ff1bd4eeccfd7cbef01802)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/quartz/job/EmailScheduleMessageJob.java (.../EmailScheduleMessageJob.java) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -18,16 +18,15 @@
*
* http://www.gnu.org/licenses/gpl.txt
* ****************************************************************
- */
-
-/* $Id$ */
+ */
+
+/* $Id$ */
package org.lamsfoundation.lams.monitoring.quartz.job;
import java.util.Collection;
import java.util.Map;
import org.apache.log4j.Logger;
-import org.lamsfoundation.lams.events.DeliveryMethodMail;
import org.lamsfoundation.lams.events.IEventNotificationService;
import org.lamsfoundation.lams.monitoring.service.IMonitoringService;
import org.lamsfoundation.lams.usermanagement.User;
@@ -57,7 +56,7 @@
Map properties = context.getJobDetail().getJobDataMap();
String emailBody = (String) properties.get("emailBody");
- //get users to whom send emails
+ // get users to whom send emails
int searchType = (Integer) properties.get("searchType");
Long lessonId = (Long) properties.get(AttributeNames.PARAM_LESSON_ID);
Integer orgId = (Integer) properties.get(AttributeNames.PARAM_ORGANISATION_ID);
@@ -69,19 +68,22 @@
for (User user : users) {
boolean isHtmlFormat = false;
- long userId = user.getUserId();
+ int userId = user.getUserId();
log.debug("Sending scheduled email to user [" + userId + "].");
- eventNotificationService.sendMessage(userId, DeliveryMethodMail.getInstance(), monitoringService
- .getMessageService().getMessage("event.emailnotifications.email.subject", new Object[] {}),
- emailBody, isHtmlFormat);
+ eventNotificationService.sendMessage(
+ null,
+ userId,
+ IEventNotificationService.DELIVERY_METHOD_MAIL,
+ monitoringService.getMessageService().getMessage("event.emailnotifications.email.subject",
+ new Object[] {}), emailBody, isHtmlFormat);
}
}
private IEventNotificationService getEventNotificationService(JobExecutionContext context)
throws JobExecutionException {
try {
final String CONTEXT_NAME = "context.central";
-
+
SchedulerContext sc = context.getScheduler().getContext();
ApplicationContext cxt = (ApplicationContext) sc.get(CONTEXT_NAME);
return (IEventNotificationService) cxt.getBean("eventNotificationService");
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/EmailNotificationsAction.java
===================================================================
diff -u -r84151d175a3fce3cd3ff1bd4eeccfd7cbef01802 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/EmailNotificationsAction.java (.../EmailNotificationsAction.java) (revision 84151d175a3fce3cd3ff1bd4eeccfd7cbef01802)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/EmailNotificationsAction.java (.../EmailNotificationsAction.java) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -231,11 +231,11 @@
boolean isSuccessfullySent = true;
String[] userIdStrs = request.getParameterValues("userId");
for (String userIdStr : userIdStrs) {
- long userId = Long.parseLong(userIdStr);
+ int userId = Integer.parseInt(userIdStr);
boolean isHtmlFormat = false;
- isSuccessfullySent &= eventNotificationService.sendMessage(
+ isSuccessfullySent &= eventNotificationService.sendMessage(null,
userId,
- DeliveryMethodMail.getInstance(),
+ IEventNotificationService.DELIVERY_METHOD_MAIL,
monitoringService.getMessageService().getMessage("event.emailnotifications.email.subject",
new Object[] {}), emailBody, isHtmlFormat);
}
Index: lams_monitoring/web/css/monitorLesson.css
===================================================================
diff -u -r1b117caf4135f53248542cbc97d71aac448f3de9 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_monitoring/web/css/monitorLesson.css (.../monitorLesson.css) (revision 1b117caf4135f53248542cbc97d71aac448f3de9)
+++ lams_monitoring/web/css/monitorLesson.css (.../monitorLesson.css) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -39,10 +39,16 @@
border: none;
}
-div.dialogContainer {
+.dialogContainer {
display: none;
}
+.dialogContainer iframe {
+ width: 100%;
+ height: 100%;
+ border: none;
+}
+
.dialogList {
overflow: auto;
border: thin solid black;
@@ -151,6 +157,10 @@
border: none;
}
+#emailDialog {
+ width: 100%;
+}
+
/********** SEQUENCE TAB STYLES **********/
div#sequenceCanvas {
text-align: center;
Index: lams_monitoring/web/includes/javascript/monitorLesson.js
===================================================================
diff -u -r02163efabf3b7e31a55e3b7b348ed55dafa6afe6 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_monitoring/web/includes/javascript/monitorLesson.js (.../monitorLesson.js) (revision 02163efabf3b7e31a55e3b7b348ed55dafa6afe6)
+++ lams_monitoring/web/includes/javascript/monitorLesson.js (.../monitorLesson.js) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -163,7 +163,23 @@
});
$('#classMonitorSortButton').click(function(){
sortDialogList('classMonitor');
- });
+ });
+
+ // sets up dialog for emailing learners
+ $('#emailDialog').dialog({
+ 'autoOpen' : false,
+ 'height' : 530,
+ 'width' : 700,
+ 'modal' : true,
+ 'resizable' : false,
+ 'show' : 'fold',
+ 'hide' : 'fold',
+ 'open' : function(){
+ $('#emailFrame').attr('src', LAMS_URL + 'emailUser.do?method=composeMail&lessonID='
+ + lessonId
+ + '&userID=' + $(this).dialog('option', 'userId'));
+ }
+ });
}
@@ -182,7 +198,7 @@
'classOnly' : true
},
success : function(response) {
- showLearnerGroupDialog(null, LESSON_GROUP_DIALOG_CLASS_LABEL, response);
+ showLearnerGroupDialog(null, LESSON_GROUP_DIALOG_CLASS_LABEL, response, false, false, true);
}
});
}
@@ -391,6 +407,10 @@
}
+function closeEmailDialog(){
+ $('#emailFrame').attr('src', null);
+ $('#emailDialog').dialog('close');
+}
//********** SEQUENCE TAB FUNCTIONS **********
@@ -455,6 +475,21 @@
}
},
{
+ 'text' : EMAIL_BUTTON_LABEL,
+ 'id' : 'learnerGroupDialogEmailButton',
+ 'class' : 'learnerGroupDialogSelectableButton',
+ 'click' : function() {
+ var selectedLearner = $('#learnerGroupList div.dialogListItemSelected');
+ if (selectedLearner.length == 1) {
+ $('#emailDialog').dialog('option',{
+ 'title' : 'Email user',
+ 'userId' : selectedLearner.attr('userId')
+ })
+ .dialog('open');
+ }
+ }
+ },
+ {
'text' : CLOSE_BUTTON_LABEL,
'id' : 'learnerGroupDialogCloseButton',
'click' : function() {
@@ -1251,7 +1286,7 @@
/**
* Show a dialog with user list and optional Force Complete and View Learner buttons.
*/
-function showLearnerGroupDialog(activityId, dialogTitle, learners, allowForceComplete, allowView) {
+function showLearnerGroupDialog(activityId, dialogTitle, learners, allowForceComplete, allowView, allowEmail) {
var learnerGroupList = $('#learnerGroupList').empty();
var learnerGroupDialog = $('#learnerGroupDialog');
@@ -1265,7 +1300,7 @@
.text(getLearnerDisplayName(learner))
.appendTo(learnerGroupList);
- if (allowForceComplete || allowView) {
+ if (allowForceComplete || allowView || allowEmail) {
learnerDiv.click(function(){
// select a learner
$(this).addClass('dialogListItemSelected')
@@ -1290,6 +1325,8 @@
.css('display', allowForceComplete ? 'inline' : 'none');
$('button#learnerGroupDialogViewButton')
.css('display', allowView ? 'inline' : 'none');
+ $('button#learnerGroupDialogEmailButton')
+ .css('display', allowEmail ? 'inline' : 'none');
learnerGroupDialog
.dialog('option',
Index: lams_monitoring/web/monitor.jsp
===================================================================
diff -u -r02163efabf3b7e31a55e3b7b348ed55dafa6afe6 -r1edbb81f16cedfcc1326e4eca6e520b5b48cbddc
--- lams_monitoring/web/monitor.jsp (.../monitor.jsp) (revision 02163efabf3b7e31a55e3b7b348ed55dafa6afe6)
+++ lams_monitoring/web/monitor.jsp (.../monitor.jsp) (revision 1edbb81f16cedfcc1326e4eca6e520b5b48cbddc)
@@ -39,6 +39,7 @@
var LEARNER_GROUP_SHOW_LABEL = 'updateTopic
method. So topic can keep this attachment if user choose "Cancel" edit
- * topic.
+ * happen in updateTopic
method. So topic can keep this attachment if user choose "Cancel" edit topic.
*
* @param mapping
* @param form
@@ -862,7 +861,7 @@
// check if the user has permission to hide posts.
// ForumToolSession toolSession = forumService
// .getSessionBySessionId(sessionId);
- //
+ //
// Forum forum = toolSession.getForum();
// ForumUser currentUser = getCurrentUser(request,sessionId);
// ForumUser forumCreatedBy = forum.getCreatedBy();
@@ -880,12 +879,12 @@
List msgDtoList = forumService.getTopicThread(rootTopicId);
updateMesssageFlag(msgDtoList);
request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList);
- request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, WebUtil.readStrParam(request,
- ForumConstants.ATTR_SESSION_MAP_ID));
+ request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID,
+ WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID));
return mapping.findForward("success");
}
-
+
/**
* Rates postings submitted by other learners.
*
@@ -945,8 +944,8 @@
if (numOfPostsInTopic < forum.getMinimumReply()) {
// create error
ActionMessages errors = new ActionMessages();
- errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.less.mini.post", forum
- .getMinimumReply()));
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("error.less.mini.post", forum.getMinimumReply()));
saveErrors(request, errors);
// get all root topic to display on init page
@@ -962,8 +961,8 @@
}
/**
- * This method will set flag in message DTO:
- *