Currently i am able to get group id by:
Set candidates = delegateTask.getCandidates();
Iterator iterator = candidates.iterator();
while (iterator.hasNext()) {
System.out.println("Task ID: "+iterator.next().getGroupId());
}
From there, how can get list of users in that group and their Email ID’s(Through Java Code)
String taskId = delegateTask.getId();
IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();
ArrayList<String> groupIDs = new ArrayList<String>();
for (IdentityLink link : delegateTask.getCandidates()) {
groupIDs.add(link.getGroupId());
LOGGER.log(Level.INFO, "Group iDs: " + link.getGroupId());
}
if (!groupIDs.isEmpty()) {
// create user list by querying via group ID
for (String groupID : groupIDs) {
List<User> userList = identityService.createUserQuery().memberOfGroup(groupID).list();
// mail to each user in the group
for (User userInGroup : userList) {
String assignee = userInGroup.getId();
String recipient = userInGroup.getEmail();
if (recipient != null && !recipient.isEmpty()) {
Email email = new SimpleEmail();
email.setCharset("utf-8");
email.setHostName(HOST);
email.setAuthentication(USER, PWD);
try {
email.setFrom("noreply@camunda.org");
email.setSubject("Task assigned: " + delegateTask.getName());
email.setMsg("Please complete: http://localhost:12306/camunda/app/tasklist/default/#/task/"
+ taskId);
email.addTo(recipient);
email.send();
LOGGER.info("Task Assignment Email successfully sent to user '" + assignee
+ "' with address '" + recipient + "'.");
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Could not send email to assignee", e);
}
} else {
LOGGER.warning("Not sending email to user " + assignee + "', user has no email address.");
}
}
}
}
When you create a Java TaskListener class you have to Override the notify function. This function has as an input the DelegateTask.
But remember: You got to have a user task in your bpmn, to have a TaskListener. An ExecutionListener has a DelegateExecution as an input variable in the notify function.