use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CommentNotificationEventListener method collectOrgEntitiesByRole.
protected Set<OrganizationalEntity> collectOrgEntitiesByRole(List<String> mentionedRoles, CaseCommentEvent event, StringBuilder commentContent) {
Set<OrganizationalEntity> recipients = new HashSet<>();
CommentInstance comment = event.getComment();
for (String roleName : mentionedRoles) {
if (comment.getRestrictedTo() != null && !comment.getRestrictedTo().isEmpty() && !comment.getRestrictedTo().contains(roleName)) {
// mentioned role is not allowed to see this comment so remove it from the list
continue;
}
try {
Collection<OrganizationalEntity> assignments = ((CaseAssignment) event.getCaseFile()).getAssignments(roleName);
recipients.addAll(assignments);
String assignmnetsFlatten = assignments.stream().map(oe -> oe.getId()).collect(Collectors.joining(","));
String updatedCommentContent = commentContent.toString().replaceAll("@" + roleName, assignmnetsFlatten);
commentContent.setLength(0);
commentContent.append(updatedCommentContent);
} catch (IllegalArgumentException e) {
logger.debug("Role {} does not exist in case {}", roleName, event.getCaseId());
}
}
return recipients;
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseFileInstanceImpl method getAssignments.
@Override
public Collection<OrganizationalEntity> getAssignments(String roleName) {
String[] roleNames = roleName.split(separator);
Collection<OrganizationalEntity> foundAssignments = new ArrayList<>();
for (String role : roleNames) {
CaseRoleInstance caseRoleInstance = this.roles.get(role);
if (caseRoleInstance == null) {
throw new IllegalArgumentException("No role with name " + role + " was found");
}
foundAssignments.addAll(caseRoleInstance.getRoleAssignments());
}
return foundAssignments;
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseFileInstanceImpl method getRolesForOrgEntities.
public List<String> getRolesForOrgEntities(List<String> orgEntities) {
List<String> collected = new ArrayList<>();
if (roles == null || roles.isEmpty()) {
return collected;
}
List<CaseRoleInstance> roleInstances = new ArrayList<>();
for (Entry<String, CaseRoleInstance> entry : roles.entrySet()) {
roleInstances.add(entry.getValue());
}
for (CaseRoleInstance cri : roleInstances) {
if (cri.getRoleAssignments() == null || cri.getRoleAssignments().isEmpty()) {
continue;
}
for (OrganizationalEntity assignee : cri.getRoleAssignments()) {
if (orgEntities.contains(assignee.getId())) {
collected.add(cri.getRoleName());
}
}
}
return collected;
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class NotifyOwnerSLAViolationListener method afterSLAViolated.
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
CaseFileInstance caseFile = getCaseFile((KieSession) event.getKieRuntime());
if (caseFile != null) {
String caseId = ((WorkflowProcessInstanceImpl) event.getProcessInstance()).getCorrelationKey();
if (caseFile.getCaseId().equals(caseId)) {
try {
Collection<OrganizationalEntity> adminAssignments = ((CaseAssignment) caseFile).getAssignments("owner");
String recipients = adminAssignments.stream().map(oe -> userInfo.getEmailForEntity(oe)).collect(Collectors.joining(";"));
logger.debug("Case instance {} has SLA violation, notifying owner", caseId);
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
Map<String, Object> parameters = buildEmailParameters(recipients, caseId, event);
TaskSpecification taskSpec = caseService.newTaskSpec("Email", "SLA Violation for case " + caseId, parameters);
caseService.addDynamicTask(caseId, taskSpec);
} catch (IllegalArgumentException e) {
logger.debug("There is no owner role defined in case instance {}, unable to notify SLA violation", caseId);
}
}
}
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class EmailNotificationPublisherTest method testEmailNotificationWithoutTemplate.
@Test
public void testEmailNotificationWithoutTemplate() throws Exception {
EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo);
Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newUser("john")));
publisher.publish("admin@jbpm.org", "Test notification", recipients, "Test body");
assertEquals(1, wiser.getMessages().size());
MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
// Side effect of MIME encoding (I think.. ): \r\n..
String content = ((String) msg.getContent()).replace("\r\n", "");
assertEquals("Test body", content);
assertEquals("Test notification", msg.getSubject());
assertEquals("admin@jbpm.org", ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals("john@domain.com", ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
assertNull(msg.getRecipients(RecipientType.CC));
assertNull(msg.getRecipients(RecipientType.BCC));
}
Aggregations