use of org.apache.syncope.core.provisioning.api.notification.RecipientsProvider in project syncope by apache.
the class NotificationManagerImpl method getNotificationTask.
/**
* Create a notification task.
*
* @param notification notification to take as model
* @param any the any object this task is about
* @param jexlVars JEXL variables
* @return notification task, fully populated
*/
private NotificationTask getNotificationTask(final Notification notification, final Any<?> any, final Map<String, Object> jexlVars) {
if (any != null) {
virAttrHander.getValues(any);
}
List<User> recipients = new ArrayList<>();
if (notification.getRecipientsFIQL() != null) {
recipients.addAll(searchDAO.<User>search(SearchCondConverter.convert(notification.getRecipientsFIQL()), Collections.<OrderByClause>emptyList(), AnyTypeKind.USER));
}
if (notification.isSelfAsRecipient() && any instanceof User) {
recipients.add((User) any);
}
Set<String> recipientEmails = new HashSet<>();
List<UserTO> recipientTOs = new ArrayList<>(recipients.size());
recipients.forEach(recipient -> {
virAttrHander.getValues(recipient);
String email = getRecipientEmail(notification.getRecipientAttrName(), recipient);
if (email == null) {
LOG.warn("{} cannot be notified: {} not found", recipient, notification.getRecipientAttrName());
} else {
recipientEmails.add(email);
recipientTOs.add(userDataBinder.getUserTO(recipient, true));
}
});
if (notification.getStaticRecipients() != null) {
recipientEmails.addAll(notification.getStaticRecipients());
}
if (notification.getRecipientsProvider() != null) {
try {
RecipientsProvider recipientsProvider = ImplementationManager.build(notification.getRecipientsProvider());
recipientEmails.addAll(recipientsProvider.provideRecipients(notification));
} catch (Exception e) {
LOG.error("While building {}", notification.getRecipientsProvider(), e);
}
}
jexlVars.put("recipients", recipientTOs);
jexlVars.put("syncopeConf", this.findAllSyncopeConfs());
jexlVars.put("events", notification.getEvents());
NotificationTask task = entityFactory.newEntity(NotificationTask.class);
task.setNotification(notification);
if (any != null) {
task.setEntityKey(any.getKey());
task.setAnyTypeKind(any.getType().getKind());
}
task.setTraceLevel(notification.getTraceLevel());
task.getRecipients().addAll(recipientEmails);
task.setSender(notification.getSender());
task.setSubject(notification.getSubject());
if (StringUtils.isNotBlank(notification.getTemplate().getTextTemplate())) {
task.setTextBody(evaluate(notification.getTemplate().getTextTemplate(), jexlVars));
}
if (StringUtils.isNotBlank(notification.getTemplate().getHTMLTemplate())) {
task.setHtmlBody(evaluate(notification.getTemplate().getHTMLTemplate(), jexlVars));
}
return task;
}
Aggregations