diff --git a/build-dependencies.xml b/build-dependencies.xml
index fed1d510a..c71f35e73 100644
--- a/build-dependencies.xml
+++ b/build-dependencies.xml
@@ -79,8 +79,6 @@
-
-
-
-
- * This exception is thrown in update / delete method if given entity is not found. - *
- * - *- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *
- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class EntityNotFoundException extends PersistenceException { - /** - *- * The serial version id. - *
- */ - private static final long serialVersionUID = 4314341295609435285L; - - /** - *
- * Constructs a new EntityNotFoundException instance.
- *
- * Constructs a new EntityNotFoundException instance with error message.
- *
- * Constructs a new EntityNotFoundException instance with inner cause.
- *
- * Constructs a new EntityNotFoundException instance with error message and inner cause.
- *
- * This exception indicates error with notification sending. - *
- *- * Thread-Safety:It's not thread-safe because its base class is not thread-safe. - *
- * - * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public class NotificationException extends TaskManagementException { - - /** - *
- * Constructs a new NotificationException instance.
- *
- * Constructs a new NotificationException instance with error message.
- *
- * Constructs a new NotificationException instance with inner cause.
- *
- * Constructs a new NotificationException instance with error message and inner cause.
- *
- * This is the service contract for sending notifications. - *
- *- * Thread-Safety: - * Implementations should be thread-safe, but the use of the Spring IoC container to inject configurations - * will not be treated as a factor in thread-safety. Also, it can be assumed that method inputs will not be - * used concurrently. - *
- * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public interface NotificationService { - - /** - *- * Sends notification about task creation. - *
- * @param userId the id of user performing this action. - * @param task the created task. - * - * @throws IllegalArgumentException if task is null or task.getName() is null/empty or task.getStatus() is - * null or task.getPriority() is null. - * - * @throws NotificationException if any error occurs, for example failed to get the user email from the - * userService. - */ - public void notifyTaskCreation(long userId, Task task) throws NotificationException; - - /** - *- * Send notification about task status change. - *
- * - *- * When status changes, the email will sent to the corresponding assignees of the task, and the creator of - * this task. - *
- * - * @param userId the ID of user performing this action. - * @param oldTask the task status before status change. - * @param newTask the task after status change. - * @throws IllegalArgumentException if any of the tasks (oldTask or newTask) is null or have - * Task.getName() null/empty or Task.getStatus() null, or the Task.getCreatedBy is null or empty. - * - * @throws NotificationException if any error occurs, such as failed to get the user's email addresses. - */ - public void notifyTaskStatusChange(long userId, TaskStatus oldTask, Task newTask) throws NotificationException; -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PermissionException.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PermissionException.java deleted file mode 100644 index f7c64d6f9..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PermissionException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -/** - *- * This exception is thrown in modifiable methods if the user isn't permitted to access the task/task list. - *
- * - *- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *
- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class PermissionException extends TaskManagementException { - /** - *- * The serial version id. - *
- */ - private static final long serialVersionUID = 6378965077902743498L; - - /** - *
- * Constructs a new PermissionException instance.
- *
- * Constructs a new PermissionException instance with error message.
- *
- * Constructs a new PermissionException instance with inner cause.
- *
- * Constructs a new PermissionException instance with error message and inner cause.
- *
- * This exception is thrown for any error related to database persistence. - *
- * - *- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *
- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class PersistenceException extends TaskManagementException { - /** - *- * The serial version id. - *
- */ - private static final long serialVersionUID = -3439432135588510236L; - - /** - *
- * Constructs a new PersistenceException instance.
- *
- * Constructs a new PersistenceException instance with error message.
- *
- * Constructs a new PersistenceException instance with inner cause.
- *
- * Constructs a new PersistenceException instance with error message and inner cause.
- *
- * This is the service contract for managing task lists in Cockpit. - *
- *- * Thread-Safety:Implementations should be thread-safe, - * but the use of the Spring IoC container to inject configurations - * will not be treated as a factor in thread-safety. Also, it can be assumed that method inputs will not be - * used concurrently. - *
- * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public interface TaskListService { - - /** - *- * Adds a new TaskList, and return the added TaskList entity. - *
- * @param userId the ID of user performing this action. - * @param taskList the task list to add. - * @return the added task list. It will not be null. - * - * @throws IllegalArgumentException if taskList is null or has getName() null/empty. - * @throws PermissionException if specified user doesn't exist. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public TaskList addTaskList(long userId, TaskList taskList) - throws TaskManagementException; - - /** - *- * Updates an existing TaskList. - *
- * @param userId the operation user id. - * @param taskList the task list to update. - * @throws IllegalArgumentException if taskList is null or has getName() null/empty. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public void updateTaskList(long userId, TaskList taskList) - throws TaskManagementException; - - /** - *- * Retrieve an existing TaskList. - *
- * - * @param userId the ID of user performing this action. - * @param taskListId the ask list ID. - * - * @return the retrieved entity, or null if the task list is not found. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public TaskList getTaskList(long userId, long taskListId) - throws TaskManagementException; - - /** - *- * Retrieves the default TaskList for a project. - *
- * NOTE, this method will create a default task list if it does not exists. - * - * @param userId the ID of user performing this action. - * @param projectId the project ID. - * @return the default task list. Not null (default task list will be added if not exists yet). - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified project doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public TaskList getDefaultTaskList(long userId, long projectId) - throws TaskManagementException; - - /** - *- * Deletes an existing TaskList. - *
- * - * @param userId the ID of user performing this action. - * @param taskListId the task list ID. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTaskList(long userId, long taskListId) - throws TaskManagementException; - - /** - *- * Resolves a TaskList, by marking all Tasks in the list as "Completed" and setting the TaskList - * as inactive (i.e. archived). - *
- * @param userId the ID of user performing this action. - * @param taskListId the task list ID. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws NotificationException if failed to sent the notification emails. - * @throws TaskManagementException if any other error occurs. - */ - public void resolveTaskList(long userId, long taskListId) - throws TaskManagementException; - - /** - *- * Retrieves TaskList's according to a TaskFilter (without tasks in each taskList). - *
- * - *- * Note that only TaskList data will be returned, without Task's in TaskList's and only the task lists to - * which the specified user has access will be returned. - *
- * - * @param userId the ID of user performing this action. - * @param taskFilter the task filter. If null, all task lists will be returned (without filtering). - * @return retrieved entities. Empty if none found. Not null. - * - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the query. - * @throws TaskManagementException if any other error occurs. - */ - public List- * Retrieves TaskList's according to a TaskFilter (with tasks in each taskList). - *
- * - *- * Note that only TaskList data will be returned, without Task's in TaskList's and only the task lists to - * which the specified user has access will be returned. - *
- * - * @param userId the ID of user performing this action. - * @param taskFilter the task filter. If null, all task lists will be returned (without filtering). - * @return retrieved entities. Empty if none found. Not null. - * - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the query. - * @throws TaskManagementException if any other error occurs. - */ - public List- * This exception is thrown for any configuration error of this application. - *
- * - *- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *
- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class TaskManagementConfigurationException extends RuntimeException { - /** - *- * The serial version id. - *
- */ - private static final long serialVersionUID = -1777545754399960549L; - - /** - *
- * Constructs a new TaskManagementConfigurationException instance.
- *
- * Constructs a new TaskManagementConfigurationException instance with error message.
- *
- * Constructs a new TaskManagementConfigurationException instance with inner cause.
- *
- * Constructs a new TaskManagementConfigurationException instance with error message and inner cause.
- *
- * This is the base exception for checked exceptions of this application. - *
- * - *- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *
- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class TaskManagementException extends Exception { - /** - *- * The serial version id. - *
- */ - private static final long serialVersionUID = 7125152408644361137L; - - /** - *
- * Constructs a new TaskManagementException instance.
- *
- * Constructs a new TaskManagementException instance with error message.
- *
- * Constructs a new TaskManagementException instance with inner cause.
- *
- * Constructs a new TaskManagementException instance with error message and inner cause.
- *
- * This is the service contract for managing tasks in cockpit. - *
- *- * Thread-Safety:Implementations should be thread-safe, but the use of the Spring IoC container to - * inject configurations will not be treated as a factor in thread-safety. Also, it can be assumed that method - * inputs will not be used concurrently. - *
- * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public interface TaskService { - - /** - *- * Adds a new Task, and return the added Task entity. - *
- *- * Notifications will be sent to all assignees of the task. - *
- * @param userId the ID of user performing this action. - * @param task the task to add. - * @return the added task. It will never be null. - * @throws IllegalArgumentException if task is null or getName() null/empty or getStatus() null or - * getPriority() null. - * @throws EntityNotFoundException if task list referred by task.getTaskListId() doesn't exist in - * persistence. - * @throws PermissionException if specified user doesn't exist. - * @throws PersistenceException if any persistence related error occurs. - * @throws NotificationException if error occurs with sending notifications. - * @throws TaskManagementException if any other error occurs. - */ - public Task addTask(long userId, Task task) - throws TaskManagementException; - - /** - *- * Updates an existing Task. - *
- *- * If task status will be changed, then notifications will be sent to all assignees of the task as well as - * the creator of the task. - *
- * - * @param userId the ID of user performing this action. - * @param task the task to update. - * - * @throws IllegalArgumentException If task is null or getName() null/empty or getStatus() null or - * getPriority() null. - * @throws EntityNotFoundException If specified task or task list referred by task.getTaskListId() - * doesn't exist in persistence. - * @throws PermissionException If specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException If any persistence related error occurs. - * @throws NotificationException If error occurs with sending notifications. - * @throws TaskManagementException if any other error occurs. - */ - public void updateTask(long userId, Task task) - throws TaskManagementException; - - /** - *- * Retrieves an existing Task. - *
- * @param userId the ID of user performing this action. - * @param taskId the id of the task to retrieve. - * - * @return retrieved entity. It will return null if not found or the task list of the task does not exist. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public Task getTask(long userId, long taskId) - throws TaskManagementException; - - /** - *- * Deletes an existing Task. - *
- * @param userId the ID of user performing this action. - * @param taskId the Task ID. - * - * @throws PermissionException - If specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws EntityNotFoundException - If specified task doesn't exist in persistence. - * @throws PersistenceException - If any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTask(long userId, long taskId) - throws TaskManagementException; - - /** - *- * Add an attachment to a task, and return the added TaskAttachment entity. - *
- *- * The attachment content will be passed to the method as an InputStream. - *
- *- * This method will not close the passed in InputStream. - *
- * @param userId the ID of user performing this action. - * @param attachment the task attachment entity. - * @param inputStream the task attachment content. - * @return the added task attachment. Not null. - * @throws IllegalArgumentException - If any argument is null or attachment has getFileName() null/empty or - * getMimeType() null/empty. - * @throws EntityNotFoundException - If task (referred by attachment.getTaskId()) doesn't exist in - * persistence. - * @throws PermissionException - If specified user doesn't exist. - * @throws PersistenceException - If any persistence related error occurs (including file I/O error, - * because file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public TaskAttachment addTaskAttachment(long userId, TaskAttachment attachment, InputStream inputStream) - throws TaskManagementException; - - /** - *- * Deletes an existing TaskAttachment. - *
- * - * @param userId the ID of user performing this action. - * @param attachmentId the ask attachment ID to delete. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task attachment doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs (including file I/O error, because - * file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTaskAttachment(long userId, long attachmentId) - throws TaskManagementException; - - /** - *- * Returns the file content of a TaskAttachment as an InputStream. - *
- * @param userId the ID of user performing this action. - * @param attachmentId the task attachment ID. - * - * @return retrieved task attachment content. It will return null if not found. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws PersistenceException if any persistence related error occurs (including file I/O error, because - * file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public InputStream getTaskAttachmentContent(long userId, long attachmentId) - throws TaskManagementException; - - - /** - *- * Groups the Tasks of given TaskList's by task priority and return the result. - *
- * - * @param taskLists the Task lists to group by priority. - * - * @return the result of grouping. Map key is task priority value, map value is a list of tasks with - * corresponding task priority. It is not null, and contains no null keys/values nor empty values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getPriority() is null or its - * getCreatedDate is null. - */ - public SortedMap- * Groups the Tasks of given TaskList's by task assignee and return the result. - *
- * - * @param taskLists the task lists to group by assignees. - * - * @return result of grouping. Map key is task assignee, map value is a list of tasks with corresponding - * assignee. If will not be null, or contains no null keys/values nor empty values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getAssignees() is null or - * contains a null element, or the getCreatedDate in the task is null. - */ - public SortedMap- * Groups the Tasks of given TaskList's by task due date and return the result. - *
- * NOTE, the group by date is truncated to the day precision, i.e, - * 2013.08.08 08:08:08 -> 2013.08.08 - * @param taskLists the task lists to group by the due date. - * @return the result of grouping. Map key is task start date value, map value is a list of tasks - * with corresponding start date. It will not be null, and contains no null keys/values nor empty - * values. - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getDueDate() is null, or - * the getCreatedDate() is null. - */ - public SortedMap- * Groups the Tasks of given TaskList's by task start date and return the result. - *
- * NOTE, the group by date is truncated to the day precision, i.e, - * 2013.08.08 08:08:08 -> 2013.08.08 - * @param taskLists the task lists to group by the start date. - * @return the result of grouping. Map key is task start date value, map value is a list of tasks - * with corresponding start date. It will not be null, and contains no null keys/values nor empty - * values. - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getStartDate() is null, or - * the getCreatedDate() is null. - */ - public SortedMap- * Groups the Tasks of given TaskList's by task status and return the result. - *
- * @param taskLists the task lists to group by the status. - * @return the result of grouping. Map key is task status value, map value is a list of tasks with - * corresponding task status. It will not be null, and contains no null keys/values nor empty - * values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getStatus() is null, or its - * getCreatedDate() is null. - */ - public SortedMap- * Gets the number of completed tasks of a given project. - *
- * @param userId the ID of user performing this action. - * @param projectId the Project ID. - * - * @return the amount of completed tasks. It will not be negative. - * - * @throws EntityNotFoundException - If specified project doesn't exist in persistence. - * @throws PersistenceException - If any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the operation. - * @throws TaskManagementException if any other error occurs. - */ - public int getNumberOfCompletedTasks(long userId, long projectId) - throws TaskManagementException; - - /** - *- * Gets the number of all tasks of a given project. - *
- * - * @param userId the ID of user performing this action. - * @param projectId the project ID. - * - * @return the amount of tasks. Not negative. - * - * @throws EntityNotFoundException if specified project doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the operation. - * @throws TaskManagementException if any other error occurs. - */ - public int getNumberOfAllTasks(long userId, long projectId) - throws TaskManagementException; -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/BaseJPAService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/BaseJPAService.java deleted file mode 100644 index 168a5db01..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/BaseJPAService.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import javax.annotation.PostConstruct; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; - -/** - *- * Base class for the JPA based services of this component. - *
- *- * It holds common configuration parameters (provides variables, getters, setters and checkInitialization - * method). - *
- *- * Sample Configuration: (the log is not required) - *
- <property name="userService" ref="mockUserService"/> - <property name="notificationService" ref="notificationService"/> - *- * - *
- * Thread Safety:This class is mutable, but can be used thread safely under - * following conditions: setters should not be - * called after initialization and method arguments will not be used concurrently. - *
- * - * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public abstract class BaseJPAService { - - /** - *- * Represents the logger for performing logging. If null, logging will not be performed. - *
- *- * It is fully mutable, has protected getter and public setter. - *
- *- * It can be any value. - *
- */ - private Log log; - - - /** - *- * Represents the service for managing users. - *
- *- * It is fully mutable, has protected getter and public setter. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *
- */ - private UserService userService; - - /** - *- * Represents the JPA entity manager for accessing persistence. - *
- *- * It is fully mutable, has protected getter and public setter. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *
- */ - @PersistenceContext(unitName = "taskPersistenceUnit") - private EntityManager entityManager; - - /** - *- * Represents the service for sending notifications. - *
- *- * It is fully mutable, has protected getter and public setter. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *
- */ - private NotificationService notificationService; - - - - /** - *- * Creates the instance of BaseJPAService (since this class is an abstract class, it is actually called by - * its concrete subclass). - *
- *- * This is the default constructor of BaseJPAService. - *
- */ - protected BaseJPAService() { - // does nothing - } - - /** - *- * Validates configuration parameters. - *
- *- * NOTE, in this class the required fields are: - * userService, entityManager, notificationService. - * The log is optional. - *
- * - * @throws TaskManagementConfigurationException if any configuration parameter has invalid value. - */ - @PostConstruct - public void checkInitialization() { - ServiceHelper.checkState(userService == null, - "The userService is not properly injected."); - ServiceHelper.checkState(entityManager == null, - "The entityManager is not properly injected."); - ServiceHelper.checkState(notificationService == null, - "The notificationService is not properly injected."); - - } - - /** - *- * Gets the logger for performing logging. - *
- * @return the logger for performing logging. It may be null. - */ - protected Log getLog() { - return log; - } - - /** - *- * Sets the logger for performing logging. - *
- * @param log the logger for performing logging. If null, logging will not be performed. - */ - public void setLog(Log log) { - this.log = log; - } - - - /** - *- * Gets the service for managing users. - *
- * @return the service for managing users. - */ - protected UserService getUserService() { - return userService; - } - - /** - *- * Sets the service for managing users. - *
- * @param userService the service for managing users. - */ - public void setUserService(UserService userService) { - this.userService = userService; - } - - /** - *- * Gets the JPA entity manager for accessing persistence. - *
- * @return the JPA entity manager for accessing persistence. - */ - protected EntityManager getEntityManager() { -/* Query query = entityManager.createNativeQuery("set lock mode to wait"); - query.executeUpdate();*/ - return entityManager; - } - - /** - *- * Sets the JPA entity manager for accessing persistence. - *
- * @param entityManager the JPA entity manager for accessing persistence. - */ - public void setEntityManager(EntityManager entityManager) { - this.entityManager = entityManager; - } - - /** - *- * Gets the service for sending notifications. - *
- * @return the service for sending notifications. - */ - protected NotificationService getNotificationService() { - return notificationService; - } - - /** - *- * Sets the service for sending notifications. - *
- * @param notificationService the service for sending notifications. - */ - public void setNotificationService(NotificationService notificationService) { - this.notificationService = notificationService; - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationService.java deleted file mode 100644 index 2fe90067d..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationService.java +++ /dev/null @@ -1,673 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; - -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.message.email.AddressException; -import com.topcoder.message.email.EmailEngine; -import com.topcoder.message.email.SendingException; -import com.topcoder.message.email.TCSEmailMessage; -import com.topcoder.service.user.UserService; -import com.topcoder.service.user.UserServiceException; -import com.topcoder.util.config.ConfigManagerException; -import com.topcoder.util.file.DocumentGenerator; -import com.topcoder.util.file.Template; -import com.topcoder.util.file.TemplateDataFormatException; -import com.topcoder.util.file.TemplateFormatException; -import com.topcoder.util.file.fieldconfig.NodeList; -import com.topcoder.util.file.fieldconfig.NodeListUtility; -import com.topcoder.util.file.fieldconfig.TemplateFields; -import com.topcoder.util.file.templatesource.FileTemplateSource; -import com.topcoder.util.file.templatesource.TemplateSourceException; -import com.topcoder.util.log.Log; - -/** - *- * This is the Email Engine (TC catalog component) based implementation of service for sending notifications. - *
- *- * It uses TC catalog components Email Engine and Document Generator to send template based email - * notifications. - *
- *- * Sample Configuration: - * - *
- * <bean id="notificationService" - * class="com.topcoder.direct.services.project.task.impl.EmailEngineNotificationService"> - * <property name="userService" ref="mockUserService"/> - * <property name="emailSender" value="donotreply@topcoder.com"/> - * <property name="taskCreationEmailSubjectTemplateText" - * value="Task "%TASK_NAME%" has been creation."/> - * <property name="taskCreationEmailBodyTemplatePath" - * value="test_files/create_body_template.txt"/> - * <property name="taskStatusChangeEmailSubjectTemplateText" - * value="Task "%TASK_NAME%" status has been changed."/> - * <property name="taskStatusChangeEmailBodyTemplatePath" - * value="test_files/status_body_template.txt"/> - * </bean> - *- * - * - *
- * Sample API Usage: - *
- * NotificationService notificationService = (NotificationService) ctx.getBean("notificationService");
- * notificatoinService.notifyTaskCreation(123, task);
- * notivicationService.notifyTaskStatusChange(123, TaskStatus.IN_PROGRESS, newTask);
- *
- *
- * - * Thread-Safety: This class is mutable, but can be used thread safely under following conditions: - * setters should not be called after initialization and method arguments will not be used concurrently. - *
- * - *- * Version 1.1 (Module Assembly TC - Cockpit Tasks Management Services Setup and Quick Add Task) - *
- * Represents the name of the class for logging. - *
- */ - private static final String CLASS_NAME = EmailEngineNotificationService.class.getName(); - - /** - *- * Represents the service for managing users. - *
- *- * It is used by all public business methods to obtain the user handle. - *
- *- * It is mutable, has setter for injection. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *
- */ - private UserService userService; - - /** - *- * Represents the logger for performing logging. If null, logging will not be performed. - *
- *- * It is used by all public business methods for logging. - *
- *- * It is mutable, has setter for injection. - *
- *- * It can be any value. - *
- */ - private Log log; - - /** - *- * Represents the email address of notification sender. - *
- *- * It is used by all public business methods to retrieve the sender. - *
- *- * It is mutable, has setter for injection. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *
- */ - private String emailSender; - - /** - *- * Represents the email subject template text to be used for constructing messages about task creation. - *
- *- * It is used by all public business methods. - *
- *- * It is mutable, has setter for injection. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *
- */ - private String taskCreationEmailSubjectTemplateText; - - /** - *- * Represents the email body template text to be used for constructing messages about task creation. - *
- *- * It is used by all public business methods. - *
- *- * It is mutable, has setter for injection. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *
- */ - private String taskCreationEmailBodyTemplatePath; - - /** - *- * Represents the email subject template text to be used for constructing messages about task status - * change. - *
- *- * It is used by all public business methods. - *
- *- * It is mutable, has setter for injection. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *
- */ - private String taskStatusChangeEmailSubjectTemplateText; - - /** - *- * Represents the email body template text to be used for constructing messages about task status change. - *
- *- * It is used by all public business methods. - *
- *- * It is mutable, has setter for injection. - *
- *- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *
- */ - private String taskStatusChangeEmailBodyTemplatePath; - - /** - *- * Creates the instance of EmailEngineNotificationService. - *
- *- * This is the default constructor of EmailEngineNotificationService. - *
- */ - public EmailEngineNotificationService() { - // does nothing - } - - /** - *- * Validates the configuration parameters. - *
- * In this class, the required fields are: - *- * userService, - * emailSender not null or empty, - * taskCreationEmailSubjectTemplateText not null or empty, - * taskCreationEmailBodyTemplatePath not null or empty, - * taskStatusChangeEmailSubjectTemplateText not null or empty, - * taskStatusChangeEmailBodyTemplatePath not null or empty, - *- * - * Refer to the class document for the demo configuration. - * - * @throws TaskManagementConfigurationException if any configuration parameter has invalid value. - */ - @PostConstruct - public void checkInitialization() { - ServiceHelper.checkState(userService == null, "The userService is not properly injected."); - ServiceHelper.checkState(emailSender == null || emailSender.trim().length() == 0, - "The emailSender cannot be null or empty."); - ServiceHelper.checkState(taskCreationEmailSubjectTemplateText == null - || taskCreationEmailSubjectTemplateText.trim().length() == 0, - "The taskCreationEmailSubjectTemplateText cannot be null or empty."); - ServiceHelper.checkState(taskCreationEmailBodyTemplatePath == null - || taskCreationEmailBodyTemplatePath.trim().length() == 0, - "The taskCreationEmailBodyTemplatePath cannot be null or empty."); - ServiceHelper.checkState(taskStatusChangeEmailSubjectTemplateText == null - || taskStatusChangeEmailSubjectTemplateText.trim().length() == 0, - "The taskStatusChangeEmailSubjectTemplateText cannot be null or empty."); - ServiceHelper.checkState(taskStatusChangeEmailBodyTemplatePath == null - || taskStatusChangeEmailBodyTemplatePath.trim().length() == 0, - "The taskStatusChangeEmailBodyTemplatePath cannot be null or empty."); - - } - - /** - *
- * Sends notification about task creation. - *
- * @param userId the id of user performing this action. - * @param task the created task. - * - * @throws IllegalArgumentException if task is null or task.getName() is null/empty or task.getStatus() is - * null or task.getPriority() is null. - * - * @throws NotificationException if any error occurs, for example failed to get the user email from the - * userService. - */ - public void notifyTaskCreation(long userId, Task task) throws NotificationException { - // prepare for logging - final String methodName = CLASS_NAME + "#notifyTaskCreation(long userId, Task task)"; - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "task"}, new Object[] {userId, task}); - - // validate the parameters - ServiceHelper.checkNull(log, methodName, task, "task"); - ServiceHelper.checkNullOrEmpty(log, methodName, task.getName(), "name in task"); - ServiceHelper.checkNull(log, methodName, task.getStatus(), "status in task"); - ServiceHelper.checkNull(log, methodName, task.getPriority(), "priority in task"); - - // prepare for the email parameter values - String taskName = task.getName(); - String taskNotes = task.getNotes() == null ? "" : task.getNotes(); - DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); - Date taskStartDate = task.getStartDate(); - Date taskDueDate = task.getDueDate(); - String taskStatus = convertTaskStatus(methodName, task.getStatus()); - String taskPriority = convertPriority(methodName, task.getPriority()); - - List