001: /*
002: * Copyright (c) Mateusz Prokopowicz. All Rights Reserved.
003: */
004:
005: package com.technoetic.xplanner.mail;
006:
007: import java.util.Calendar;
008: import java.util.Collection;
009: import java.util.Date;
010: import java.util.HashMap;
011: import java.util.Iterator;
012: import java.util.Map;
013:
014: import org.apache.log4j.Logger;
015:
016: import com.technoetic.xplanner.db.TaskQueryHelper;
017: import com.technoetic.xplanner.domain.Person;
018: import com.technoetic.xplanner.domain.Project;
019: import com.technoetic.xplanner.domain.Task;
020: import com.technoetic.xplanner.domain.UserStory;
021: import com.technoetic.xplanner.util.TimeGenerator;
022:
023: /**
024: * User: Mateusz Prokopowicz
025: * Date: Apr 19, 2005
026: * Time: 1:34:22 PM
027: */
028: public class MissingTimeEntryNotifier implements
029: com.technoetic.xplanner.Command {
030: private static Logger log = Logger
031: .getLogger(MissingTimeEntryNotifier.class);
032:
033: public static final String EMAIL_TASK_HEADER = "iteration.metrics.tableheading.task";
034: public static final String EMAIL_STORY_HEADER = "iteration.metrics.tableheading.story";
035: public static final String SUBJECT_FOR_ACCEPTORS = "job.emailnotifier.subjectForAcceptors";
036: public static final String SUBJECT_FOR_PROJECT_LEADS = "job.emailnotifier.subjectForProjectLeeds";
037: public static final String EMAIL_BODY_HEADER_FOR_ACCEPTORS = "job.emailnotifier.bodyHeaderForAcceptors";
038: public static final String EMAIL_BODY_HEADER_FOR_PROJECT_LEADERS = "job.emailnotifier.bodyheaderForProjectLeeds";
039: public static final String EMAIL_BODY_FOOTER = "job.emailnotifier.bodyFooter";
040:
041: private TaskQueryHelper taskQueryHelper;
042: private EmailNotificationSupport emailNotificationSupport;
043: private TimeGenerator timeGenerator;
044:
045: public void setTimeGenerator(TimeGenerator timeGenerator) {
046: this .timeGenerator = timeGenerator;
047: }
048:
049: public MissingTimeEntryNotifier(TaskQueryHelper taskQueryHelper,
050: EmailNotificationSupport emailNotificationSupport) {
051: this .taskQueryHelper = taskQueryHelper;
052: this .emailNotificationSupport = emailNotificationSupport;
053: }
054:
055: public void sendMissingTimeEntryReportToLeads(Date endDate) {
056: Collection col;
057: HashMap notificationEmails = new HashMap();
058: col = taskQueryHelper.getProjectLeedsEmailNotification(endDate);
059: for (Iterator iterator = col.iterator(); iterator.hasNext();) {
060: Object[] objects = (Object[]) iterator.next();
061: Task task = (Task) objects[0];
062: UserStory story = (UserStory) objects[1];
063: Person receiver = (Person) objects[2];
064: Person acceptor = (Person) objects[3];
065:
066: emailNotificationSupport.compileEmail(notificationEmails,
067: receiver.getId(), acceptor, task, story);
068: }
069: emailNotificationSupport.sendNotifications(notificationEmails,
070: EMAIL_BODY_HEADER_FOR_PROJECT_LEADERS,
071: SUBJECT_FOR_PROJECT_LEADS);
072: log.debug("Notifications have been sent to project leads.");
073: }
074:
075: public void sendMissingTimeEntryReminderToAcceptors(Date endDate) {
076: Map projectsToBeNotified = new HashMap();
077: Map notificationEmails = new HashMap();
078: Collection col = taskQueryHelper
079: .getTaskAcceptorsEmailNotification(endDate);
080: for (Iterator it = col.iterator(); it.hasNext();) {
081: Object[] objects = (Object[]) it.next();
082: Task task = (Task) objects[0];
083: UserStory story = (UserStory) objects[1];
084: Project project = (Project) objects[2];
085: if (emailNotificationSupport.isProjectToBeNotified(
086: projectsToBeNotified, project)) {
087: emailNotificationSupport.compileEmail(
088: notificationEmails, task.getAcceptorId(), null,
089: task, story);
090: }
091: }
092: emailNotificationSupport.sendNotifications(notificationEmails,
093: EMAIL_BODY_HEADER_FOR_ACCEPTORS, SUBJECT_FOR_ACCEPTORS);
094: log.debug("Notifications have been sent to acceptors.");
095: }
096:
097: public void execute() {
098: //fixme the notifier should be configured with a time window to check for idle started tasks. Right now we hard code the previous day which may not be the right day if the job schedule is changed and if team is distributed
099: Date yesterdayMidnight = TimeGenerator.shiftDate(timeGenerator
100: .getTodaysMidnight(), Calendar.DATE, -1);
101: log
102: .debug("Send notification for tasks with no time entry after "
103: + yesterdayMidnight);
104: sendMissingTimeEntryReminderToAcceptors(yesterdayMidnight);
105: sendMissingTimeEntryReportToLeads(yesterdayMidnight);
106: }
107: }
|