in core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/notification/DefaultNotificationManager.java [268:366]
public List<NotificationTask> createTasks(
final String who,
final OpEvent.CategoryType type,
final String category,
final String subcategory,
final String op,
final OpEvent.Outcome outcome,
final Object before,
final Object output,
final Object... input) {
Optional<? extends Any> any = Optional.empty();
if (before instanceof UserTO userTO) {
any = userDAO.findById(userTO.getKey());
} else if (output instanceof UserTO userTO) {
any = userDAO.findById(userTO.getKey());
} else if (output instanceof final Pair pair
&& pair.getRight() instanceof final UserTO userTO) {
any = userDAO.findById(userTO.getKey());
} else if (output instanceof final ProvisioningResult provisioningResult1
&& provisioningResult1.getEntity() instanceof UserTO) {
any = userDAO.findById(provisioningResult1.getEntity().getKey());
} else if (before instanceof AnyObjectTO anyObjectTO) {
any = anyObjectDAO.findById(anyObjectTO.getKey());
} else if (output instanceof AnyObjectTO anyObjectTO) {
any = anyObjectDAO.findById(anyObjectTO.getKey());
} else if (output instanceof final ProvisioningResult result
&& result.getEntity() instanceof AnyObjectTO) {
any = anyObjectDAO.findById(result.getEntity().getKey());
} else if (before instanceof GroupTO groupTO) {
any = groupDAO.findById(groupTO.getKey());
} else if (output instanceof GroupTO groupTO) {
any = groupDAO.findById(groupTO.getKey());
} else if (output instanceof final ProvisioningResult provisioningResult
&& provisioningResult.getEntity() instanceof GroupTO) {
any = groupDAO.findById(provisioningResult.getEntity().getKey());
}
AnyType anyType = any.map(Any::getType).orElse(null);
LOG.debug("Search notification for [{}]{}", anyType, any);
List<NotificationTask> notifications = new ArrayList<>();
for (Notification notification : notificationDAO.findAll()) {
if (LOG.isDebugEnabled()) {
notification.getAbouts().
forEach(a -> LOG.debug("Notification about {} defined: {}", a.getAnyType(), a.get()));
}
if (notification.isActive()) {
String currentEvent = OpEvent.toString(type, category, subcategory, op, outcome);
if (!notification.getEvents().contains(currentEvent)) {
LOG.debug("No events found about {}", any);
} else if (anyType == null || any.isEmpty()
|| notification.getAbout(anyType).isEmpty()
|| anyMatchDAO.matches(any.get(), SearchCondConverter.convert(
searchCondVisitor, notification.getAbout(anyType).get().get()))) {
LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
Map<String, Object> jexlVars = new HashMap<>();
jexlVars.put("who", who);
jexlVars.put("type", type);
jexlVars.put("category", category);
jexlVars.put("subcategory", subcategory);
jexlVars.put("event", op);
jexlVars.put("condition", outcome);
jexlVars.put("before", before);
jexlVars.put("output", output);
jexlVars.put("input", input);
any.ifPresent(a -> {
switch (a) {
case User user ->
jexlVars.put("user", userDataBinder.getUserTO(user, true));
case Group group ->
jexlVars.put("group", groupDataBinder.getGroupTO(group, true));
case AnyObject anyObject ->
jexlVars.put("anyObject", anyObjectDataBinder.getAnyObjectTO(anyObject, true));
default -> {
}
}
});
NotificationTask notificationTask = getNotificationTask(notification, any.orElse(null), jexlVars);
notificationTask = taskDAO.save(notificationTask);
notifications.add(notificationTask);
}
} else {
LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
}
}
return notifications;
}