1 18 19 package cowsultants.itracker.web.scheduler.tasks; 20 21 import java.util.*; 22 import java.rmi.*; 23 import javax.naming.*; 24 import javax.rmi.*; 25 26 import cowsultants.itracker.ejb.client.interfaces.*; 27 import cowsultants.itracker.ejb.client.models.*; 28 import cowsultants.itracker.ejb.client.util.*; 29 import cowsultants.itracker.web.scheduler.*; 30 31 36 public class ReminderNotification implements SchedulableTask { 37 public static final String DEFAULT_BASE_URL = "http://localhost:8080/itracker"; 38 public static final int DEFAULT_ISSUE_AGE = 30; 39 40 public ReminderNotification() { 41 } 42 43 62 public void performTask(String [] args) { 63 IssueModel[] issues; 64 String baseURL = DEFAULT_BASE_URL; 65 int issueAge = DEFAULT_ISSUE_AGE; 66 int projectId = -1; 67 int severity = -1; 68 69 if(args != null) { 71 if(args.length > 0 && args[0] != null) { 72 baseURL = args[0]; 73 } 74 if(args.length > 1) { 75 try { 76 issueAge = Integer.parseInt(args[1]); 77 } catch(NumberFormatException nfe) { 78 Logger.logDebug("Invalid issue age specified in ReminderNotification task."); 79 } 80 } 81 if(args.length > 2) { 82 try { 83 projectId = Integer.parseInt(args[2]); 84 } catch(NumberFormatException nfe) { 85 Logger.logDebug("Invalid projectId specified in ReminderNotification task."); 86 } 87 } 88 if(args.length > 3) { 89 try { 90 severity = Integer.parseInt(args[3]); 91 } catch(NumberFormatException nfe) { 92 Logger.logDebug("Invalid severity specified in ReminderNotification task."); 93 } 94 } 95 } 96 Logger.logDebug("Reminder Notifications being sent for project " + projectId + " with issues over " + issueAge + " days old with severity " + severity + ". Base URL = " + baseURL); 97 98 try { 99 InitialContext ic = new InitialContext(); 100 Object ihRef = ic.lookup("java:comp/env/" + IssueHandler.JNDI_NAME); 101 IssueHandlerHome ihHome = (IssueHandlerHome) PortableRemoteObject.narrow(ihRef, IssueHandlerHome.class); 102 IssueHandler ih = ihHome.create(); 103 104 GregorianCalendar cal = new GregorianCalendar(); 105 cal.add(Calendar.DAY_OF_MONTH, 0 - issueAge); 106 Date oldDate = cal.getTime(); 107 Date currentDate = new Date(); 108 109 if(projectId > 0) { 110 issues = ih.getIssuesByProjectId(new Integer (projectId), IssueUtilities.STATUS_RESOLVED); 111 } else { 112 issues = ih.getIssuesWithStatusLessThan(IssueUtilities.STATUS_RESOLVED); 113 } 114 if(issues != null && issues.length > 0) { 115 for(int i = 0; i < issues.length; i++) { 116 if(severity >= 0 && issues[i].getSeverity() != severity) { 117 continue; 118 } 119 if(issues[i].getLastModifiedDate() != null && issues[i].getLastModifiedDate().before(oldDate)) { 120 HashSet addresses = new HashSet(); 121 long numMillis = currentDate.getTime() - issues[i].getLastModifiedDate().getTime(); 122 int numDays = (int) (numMillis / (24 * 60 * 60 * 1000)); 123 124 NotificationModel[] notifications = ih.getPrimaryIssueNotifications(issues[i].getId()); 125 for(int j = 0; j < notifications.length; j++) { 126 if(notifications[j].getUserEmail() != null && notifications[j].getUserEmail().indexOf('@') >= 0) { 127 addresses.add(notifications[j].getUserEmail()); 128 } 129 } 130 Logger.logDebug("Sending reminder notification for issue " + issues[i].getId() + " to " + addresses.size() + " users."); 131 ih.sendNotification(issues[i].getId(), NotificationUtilities.TYPE_ISSUE_REMINDER, baseURL, addresses, new Integer (numDays)); 132 } 133 } 134 } 135 } catch(Exception e) { 136 Logger.logError("Error sending reminder notifications. Message: " + e.getMessage()); 137 } 138 } 139 } 140 | Popular Tags |