use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.
the class JPANotificationDAO method delete.
@Override
public void delete(final String key) {
Notification notification = find(key);
if (notification == null) {
return;
}
taskDAO.findAll(TaskType.NOTIFICATION, null, notification, null, null, -1, -1, Collections.<OrderByClause>emptyList()).stream().map(Entity::getKey).forEach(task -> delete(task));
entityManager().remove(notification);
}
use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.
the class NotificationManagerImpl method createTasks.
@Override
public List<NotificationTask> createTasks(final AuditElements.EventCategoryType type, final String category, final String subcategory, final String event, final Result condition, final Object before, final Object output, final Object... input) {
Any<?> any = null;
if (before instanceof UserTO) {
any = userDAO.find(((UserTO) before).getKey());
} else if (output instanceof UserTO) {
any = userDAO.find(((UserTO) output).getKey());
} else if (output instanceof Pair && ((Pair) output).getRight() instanceof UserTO) {
any = userDAO.find(((UserTO) ((Pair) output).getRight()).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof UserTO) {
any = userDAO.find(((ProvisioningResult) output).getEntity().getKey());
} else if (before instanceof AnyObjectTO) {
any = anyObjectDAO.find(((AnyObjectTO) before).getKey());
} else if (output instanceof AnyObjectTO) {
any = anyObjectDAO.find(((AnyObjectTO) output).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof AnyObjectTO) {
any = anyObjectDAO.find(((ProvisioningResult) output).getEntity().getKey());
} else if (before instanceof GroupTO) {
any = groupDAO.find(((GroupTO) before).getKey());
} else if (output instanceof GroupTO) {
any = groupDAO.find(((GroupTO) output).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) {
any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
}
AnyType anyType = any == null ? null : any.getType();
LOG.debug("Search notification for [{}]{}", anyType, any);
List<NotificationTask> notifications = new ArrayList<>();
for (Notification notification : notificationDAO.findAll()) {
if (LOG.isDebugEnabled()) {
notification.getAbouts().forEach(about -> {
LOG.debug("Notification about {} defined: {}", about.getAnyType(), about.get());
});
}
if (notification.isActive()) {
String currentEvent = AuditLoggerName.buildEvent(type, category, subcategory, event, condition);
if (!notification.getEvents().contains(currentEvent)) {
LOG.debug("No events found about {}", any);
} else if (anyType == null || any == null || !notification.getAbout(anyType).isPresent() || searchDAO.matches(any, SearchCondConverter.convert(notification.getAbout(anyType).get().get()))) {
LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
final Map<String, Object> model = new HashMap<>();
model.put("type", type);
model.put("category", category);
model.put("subcategory", subcategory);
model.put("event", event);
model.put("condition", condition);
model.put("before", before);
model.put("output", output);
model.put("input", input);
if (any instanceof User) {
model.put("user", userDataBinder.getUserTO((User) any, true));
} else if (any instanceof Group) {
model.put("group", groupDataBinder.getGroupTO((Group) any, true));
} else if (any instanceof AnyObject) {
model.put("group", anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true));
}
NotificationTask notificationTask = getNotificationTask(notification, any, model);
notificationTask = taskDAO.save(notificationTask);
notifications.add(notificationTask);
}
} else {
LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
}
}
return notifications;
}
use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.
the class NotificationDataBinderImpl method create.
@Override
public Notification create(final NotificationTO notificationTO) {
Notification result = entityFactory.newEntity(Notification.class);
update(result, notificationTO);
return result;
}
use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.
the class NotificationLogic method update.
@PreAuthorize("hasRole('" + StandardEntitlement.NOTIFICATION_UPDATE + "')")
public NotificationTO update(final NotificationTO notificationTO) {
Notification notification = notificationDAO.find(notificationTO.getKey());
if (notification == null) {
LOG.error("Could not find notification '" + notificationTO.getKey() + "'");
throw new NotFoundException(String.valueOf(notificationTO.getKey()));
}
binder.update(notification, notificationTO);
notification = notificationDAO.save(notification);
return binder.getNotificationTO(notification);
}
use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.
the class NotificationLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.NOTIFICATION_DELETE + "')")
public NotificationTO delete(final String key) {
Notification notification = notificationDAO.find(key);
if (notification == null) {
LOG.error("Could not find notification '" + key + "'");
throw new NotFoundException(String.valueOf(key));
}
NotificationTO deleted = binder.getNotificationTO(notification);
notificationDAO.delete(key);
return deleted;
}
Aggregations