| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.web.scheduler.tasks; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
import java.util.ArrayList; |
| 23 |
|
import java.util.Calendar; |
| 24 |
|
import java.util.Date; |
| 25 |
|
import java.util.GregorianCalendar; |
| 26 |
|
import java.util.HashSet; |
| 27 |
|
import java.util.List; |
| 28 |
|
|
| 29 |
|
import javax.mail.internet.InternetAddress; |
| 30 |
|
|
| 31 |
|
import org.apache.log4j.Logger; |
| 32 |
|
import org.itracker.model.Issue; |
| 33 |
|
import org.itracker.model.Notification; |
| 34 |
|
import org.itracker.model.Notification.Type; |
| 35 |
|
import org.itracker.services.ConfigurationService; |
| 36 |
|
import org.itracker.services.IssueService; |
| 37 |
|
import org.itracker.services.NotificationService; |
| 38 |
|
import org.itracker.services.util.IssueUtilities; |
| 39 |
|
import org.itracker.web.util.ServletContextUtils; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
@see |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 83 (83) |
Complexity: 25 |
Complexity Density: 0.47 |
|
| 46 |
|
public class ReminderNotification extends BaseJob { |
| 47 |
|
|
| 48 |
|
public static final String DEFAULT_BASE_URL = "http://localhost:8080/itracker"; |
| 49 |
|
public static final int DEFAULT_ISSUE_AGE = 30; |
| 50 |
|
|
| 51 |
|
private final Logger logger; |
| 52 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
0
|
public ReminderNotification() {... |
| 54 |
0
|
this.logger = Logger.getLogger(getClass()); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
@param |
| 74 |
|
@see |
| 75 |
|
|
|
|
|
| 0% |
Uncovered Elements: 80 (80) |
Complexity: 24 |
Complexity Density: 0.46 |
|
| 76 |
0
|
public void performTask(String[] args) {... |
| 77 |
0
|
List<Issue> issues; |
| 78 |
0
|
String baseURL = DEFAULT_BASE_URL; |
| 79 |
0
|
int issueAge = DEFAULT_ISSUE_AGE; |
| 80 |
0
|
int projectId = -1; |
| 81 |
0
|
int severity = -1; |
| 82 |
0
|
ConfigurationService configurationService = ServletContextUtils.getItrackerServices().getConfigurationService(); |
| 83 |
|
|
| 84 |
|
|
| 85 |
0
|
if(args != null) { |
| 86 |
0
|
if(args.length > 0 && args[0] != null) { |
| 87 |
0
|
baseURL = args[0]; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
0
|
if (null == baseURL) { |
| 91 |
0
|
baseURL = configurationService.getSystemBaseURL(); |
| 92 |
|
} |
| 93 |
0
|
if(args.length > 1) { |
| 94 |
0
|
try { |
| 95 |
0
|
issueAge = Integer.parseInt(args[1]); |
| 96 |
|
} catch(NumberFormatException nfe) { |
| 97 |
0
|
logger.debug("Invalid issue age specified in ReminderNotification task."); |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
0
|
if(args.length > 2) { |
| 101 |
0
|
try { |
| 102 |
0
|
projectId = Integer.parseInt(args[2]); |
| 103 |
|
} catch(NumberFormatException nfe) { |
| 104 |
0
|
logger.debug("Invalid projectId specified in ReminderNotification task."); |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
0
|
if(args.length > 3) { |
| 108 |
0
|
try { |
| 109 |
0
|
severity = Integer.parseInt(args[3]); |
| 110 |
|
} catch(NumberFormatException nfe) { |
| 111 |
0
|
logger.debug("Invalid severity specified in ReminderNotification task."); |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
} |
| 115 |
0
|
logger.debug("Reminder Notifications being sent for project " + projectId + " with issues over " + issueAge + " days old with severity " + severity + ". Base URL = " + baseURL); |
| 116 |
|
|
| 117 |
0
|
try { |
| 118 |
0
|
IssueService issueService = ServletContextUtils.getItrackerServices().getIssueService(); |
| 119 |
0
|
NotificationService notificationService = ServletContextUtils.getItrackerServices().getNotificationService(); |
| 120 |
0
|
GregorianCalendar cal = new GregorianCalendar(); |
| 121 |
0
|
cal.add(Calendar.DAY_OF_MONTH, 0 - issueAge); |
| 122 |
0
|
Date oldDate = cal.getTime(); |
| 123 |
0
|
Date currentDate = new Date(); |
| 124 |
|
|
| 125 |
0
|
if(projectId > 0) { |
| 126 |
0
|
issues = issueService.getIssuesByProjectId(projectId, IssueUtilities.STATUS_RESOLVED); |
| 127 |
|
} else { |
| 128 |
0
|
issues = issueService.getIssuesWithStatusLessThan(IssueUtilities.STATUS_RESOLVED); |
| 129 |
|
} |
| 130 |
0
|
if(issues != null && issues.size() > 0) { |
| 131 |
0
|
for(int i = 0; i < issues.size(); i++) { |
| 132 |
0
|
if(severity >= 0 && issues.get(i).getSeverity() != severity) { |
| 133 |
0
|
continue; |
| 134 |
|
} |
| 135 |
0
|
if(issues.get(i).getLastModifiedDate() != null && issues.get(i).getLastModifiedDate().before(oldDate)) { |
| 136 |
0
|
HashSet<InternetAddress> addresses = new HashSet<InternetAddress>(); |
| 137 |
0
|
long numMillis = currentDate.getTime() - issues.get(i).getLastModifiedDate().getTime(); |
| 138 |
0
|
int numDays = (int) (numMillis / (24 * 60 * 60 * 1000)); |
| 139 |
|
|
| 140 |
0
|
List<Notification> notifications = notificationService.getPrimaryIssueNotifications(issues.get(i)); |
| 141 |
0
|
for(int j = 0; j < notifications.size(); j++) { |
| 142 |
0
|
if(notifications.get(j).getUser().getEmail() != null |
| 143 |
|
&& notifications.get(j).getUser().getEmail().indexOf('@') >= 0) { |
| 144 |
0
|
addresses.add(notifications.get(j).getUser().getEmailAddress()); |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
0
|
InternetAddress[] addressesArray = new ArrayList<InternetAddress>(addresses).toArray(new InternetAddress[]{}); |
| 148 |
|
|
| 149 |
0
|
if (logger.isDebugEnabled()) { |
| 150 |
0
|
logger.debug("Sending reminder notification for issue " + issues.get(i).getId() + " to " + addressesArray.length + " users."); |
| 151 |
|
} |
| 152 |
0
|
notificationService.sendNotification(issues.get(i), Type.ISSUE_REMINDER, baseURL, addressesArray, numDays); |
| 153 |
|
|
| 154 |
|
} |
| 155 |
|
} |
| 156 |
|
} |
| 157 |
|
} catch(Exception e) { |
| 158 |
0
|
logger.error("Error sending reminder notifications. Message: ", e); |
| 159 |
0
|
throw new RuntimeException("failed to send reminder notifications.", e); |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
|
} |