Search in sources :

Example 1 with Notification

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);
}
Also used : OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) JPANotification(org.apache.syncope.core.persistence.jpa.entity.JPANotification) Notification(org.apache.syncope.core.persistence.api.entity.Notification)

Example 2 with 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;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) User(org.apache.syncope.core.persistence.api.entity.user.User) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ArrayList(java.util.ArrayList) Notification(org.apache.syncope.core.persistence.api.entity.Notification) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with Notification

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;
}
Also used : Notification(org.apache.syncope.core.persistence.api.entity.Notification)

Example 4 with Notification

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);
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Notification(org.apache.syncope.core.persistence.api.entity.Notification) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with 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;
}
Also used : NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Notification(org.apache.syncope.core.persistence.api.entity.Notification) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Notification (org.apache.syncope.core.persistence.api.entity.Notification)11 AnyAbout (org.apache.syncope.core.persistence.api.entity.AnyAbout)4 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)4 Test (org.junit.jupiter.api.Test)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 NotificationTO (org.apache.syncope.common.lib.to.NotificationTO)2 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)2 MailTemplate (org.apache.syncope.core.persistence.api.entity.MailTemplate)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)1 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)1 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1