Object result = null;
try {
final AuditTrail auditTrail = (AuditTrail) properties.get("auditTrail");
final PluginManager pluginManager = (PluginManager) properties.get("pluginManager");
final WorkflowManager workflowManager = (WorkflowManager) pluginManager.getBean("workflowManager");
final WorkflowUserManager workflowUserManager = (WorkflowUserManager) pluginManager.getBean("workflowUserManager");
final DirectoryManager directoryManager = (DirectoryManager) pluginManager.getBean("directoryManager");
final String base = (String) properties.get("base");
final String smtpHost = (String) properties.get("host");
final String smtpPort = (String) properties.get("port");
final String smtpUsername = (String) properties.get("username");
final String smtpPassword = (String) properties.get("password");
final String security = (String) properties.get("security");
final String from = (String) properties.get("from");
final String cc = (String) properties.get("cc");
final String subject = (String) properties.get("subject");
final String emailMessage = (String) properties.get("emailMessage");
final String url = (String) properties.get("url");
final String urlName = (String) properties.get("urlName");
final String parameterName = (String) properties.get("parameterName");
final String passoverMethod = (String) properties.get("passoverMethod");
final String exclusion = (String) properties.get("exclusion");
final String isHtml = (String) properties.get("isHtml");
Map<String, String> replaceMap = null;
if ("true".equalsIgnoreCase(isHtml)) {
replaceMap = new HashMap<String, String>();
replaceMap.put("\\n", "<br/>");
}
final Map<String, String> replace = replaceMap;
String appId = auditTrail.getAppId();
String appVersion = auditTrail.getAppVersion();
AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
final AppDefinition appDef = appService.getAppDefinition(appId, appVersion);
if (smtpHost == null || smtpHost.trim().length() == 0) {
return null;
}
if (auditTrail != null && (auditTrail.getMethod().equals("createAssignments") || auditTrail.getMethod().equals("getDefaultAssignments") || auditTrail.getMethod().equals("assignmentReassign") || auditTrail.getMethod().equals("assignmentForceComplete"))) {
final String profile = DynamicDataSourceManager.getCurrentProfile();
new Thread(new Runnable() {
public void run() {
ThreadSessionUtil.initSession();
try {
HostManager.setCurrentProfile(profile);
List<String> userList = new ArrayList<String>();
String activityInstanceId = auditTrail.getMessage();
int maxAttempt = 5;
int numOfAttempt = 0;
WorkflowActivity wfActivity = null;
while (userList != null && userList.isEmpty() && numOfAttempt < maxAttempt) {
//LogUtil.info(getClass().getName(), "Attempting to get resource ids....");
Thread.sleep(4000);
wfActivity = workflowManager.getActivityById(activityInstanceId);
userList = workflowManager.getAssignmentResourceIds(wfActivity.getProcessDefId(), wfActivity.getProcessId(), activityInstanceId);
numOfAttempt++;
}
Collection<String> exclusionIds = new ArrayList<String>();
if (exclusion != null && !exclusion.isEmpty()) {
exclusionIds.addAll(Arrays.asList(exclusion.split(";")));
}
if (!exclusionIds.contains(WorkflowUtil.getProcessDefIdWithoutVersion(wfActivity.getProcessDefId()) + "-" + wfActivity.getActivityDefId())) {
LogUtil.info(UserNotificationAuditTrail.class.getName(), "Users to notify: " + userList);
if (userList != null) {
for (String username : userList) {
workflowUserManager.setCurrentThreadUser(username);
WorkflowAssignment wfAssignment = workflowManager.getAssignment(activityInstanceId);
Collection<String> addresses = AppUtil.getEmailList(null, username, null, null);
if (addresses != null && addresses.size() > 0) {