Search in sources :

Example 6 with Notification

use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.

the class NotificationTest method issueSYNCOPE446.

@Test
public void issueSYNCOPE446() {
    Notification notification = entityFactory.newEntity(Notification.class);
    notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
    AnyAbout about = entityFactory.newEntity(AnyAbout.class);
    about.setNotification(notification);
    notification.add(about);
    about.setAnyType(anyTypeDAO.findUser());
    about.set("fake search condition");
    notification.setRecipientAttrName("email");
    notification.getStaticRecipients().add("syncope446@syncope.apache.org");
    notification.setSender("syncope@syncope.apache.org");
    notification.setSubject("Test notification");
    notification.setTemplate(mailTemplateDAO.find("test"));
    Notification actual = notificationDAO.save(notification);
    assertNotNull(actual);
    assertNotNull(actual.getKey());
    assertNotNull(actual.getStaticRecipients());
    assertFalse(actual.getStaticRecipients().isEmpty());
}
Also used : AnyAbout(org.apache.syncope.core.persistence.api.entity.AnyAbout) Notification(org.apache.syncope.core.persistence.api.entity.Notification) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 7 with Notification

use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.

the class NotificationTest method save.

@Test
public void save() {
    Notification notification = entityFactory.newEntity(Notification.class);
    notification.getEvents().add("save");
    AnyAbout about = entityFactory.newEntity(AnyAbout.class);
    about.setNotification(notification);
    notification.add(about);
    about.setAnyType(anyTypeDAO.findUser());
    about.set("fake search condition");
    notification.setRecipientsFIQL("fake recipients");
    notification.setRecipientAttrName("email");
    notification.setSender("syncope@syncope.apache.org");
    notification.setSubject("Test notification");
    notification.setTemplate(mailTemplateDAO.find("test"));
    Notification actual = notificationDAO.save(notification);
    assertNotNull(actual);
    assertNotNull(actual.getKey());
}
Also used : AnyAbout(org.apache.syncope.core.persistence.api.entity.AnyAbout) Notification(org.apache.syncope.core.persistence.api.entity.Notification) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 8 with Notification

use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.

the class NotificationDataBinderImpl method update.

@Override
public void update(final Notification notification, final NotificationTO notificationTO) {
    BeanUtils.copyProperties(notificationTO, notification, IGNORE_PROPERTIES);
    SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
    MailTemplate template = mailTemplateDAO.find(notificationTO.getTemplate());
    if (template == null) {
        sce.getElements().add("template");
    }
    notification.setTemplate(template);
    if (notification.getEvents().isEmpty()) {
        sce.getElements().add("events");
    }
    if (!notification.getStaticRecipients().isEmpty()) {
        notification.getStaticRecipients().forEach(mail -> {
            Matcher matcher = SyncopeConstants.EMAIL_PATTERN.matcher(mail);
            if (!matcher.matches()) {
                LOG.error("Invalid mail address: {}", mail);
                sce.getElements().add("staticRecipients: " + mail);
            }
        });
    }
    if (!sce.isEmpty()) {
        throw sce;
    }
    // 1. add or update all (valid) abouts from TO
    notificationTO.getAbouts().entrySet().stream().filter(entry -> StringUtils.isNotBlank(entry.getValue())).forEachOrdered((entry) -> {
        AnyType anyType = anyTypeDAO.find(entry.getKey());
        if (anyType == null) {
            LOG.debug("Invalid AnyType {} specified, ignoring...", entry.getKey());
        } else {
            AnyAbout about = notification.getAbout(anyType).orElse(null);
            if (about == null) {
                about = entityFactory.newEntity(AnyAbout.class);
                about.setAnyType(anyType);
                about.setNotification(notification);
                notification.add(about);
            }
            about.set(entry.getValue());
        }
    });
    // 2. remove all abouts not contained in the TO
    notification.getAbouts().removeIf(anyAbout -> !notificationTO.getAbouts().containsKey(anyAbout.getAnyType().getKey()));
    // 3. verify recipientAttrName
    try {
        intAttrNameParser.parse(notification.getRecipientAttrName(), AnyTypeKind.USER);
    } catch (ParseException e) {
        SyncopeClientException invalidRequest = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        invalidRequest.getElements().add(e.getMessage());
        throw invalidRequest;
    }
    if (notificationTO.getRecipientsProvider() == null) {
        notification.setRecipientsProvider(null);
    } else {
        Implementation recipientsProvider = implementationDAO.find(notificationTO.getRecipientsProvider());
        if (recipientsProvider == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", notificationTO.getRecipientsProvider());
        } else {
            notification.setRecipientsProvider(recipientsProvider);
        }
    }
}
Also used : SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Logger(org.slf4j.Logger) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Autowired(org.springframework.beans.factory.annotation.Autowired) BeanUtils(org.apache.syncope.core.spring.BeanUtils) StringUtils(org.apache.commons.lang3.StringUtils) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Notification(org.apache.syncope.core.persistence.api.entity.Notification) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) Component(org.springframework.stereotype.Component) Matcher(java.util.regex.Matcher) NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) AnyAbout(org.apache.syncope.core.persistence.api.entity.AnyAbout) MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) MailTemplateDAO(org.apache.syncope.core.persistence.api.dao.MailTemplateDAO) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) ParseException(java.text.ParseException) NotificationDataBinder(org.apache.syncope.core.provisioning.api.data.NotificationDataBinder) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) Matcher(java.util.regex.Matcher) AnyAbout(org.apache.syncope.core.persistence.api.entity.AnyAbout) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) ParseException(java.text.ParseException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 9 with Notification

use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.

the class MailTemplateLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_DELETE + "')")
public MailTemplateTO delete(final String key) {
    MailTemplate mailTemplate = mailTemplateDAO.find(key);
    if (mailTemplate == null) {
        LOG.error("Could not find mail template '" + key + "'");
        throw new NotFoundException(key);
    }
    List<Notification> notifications = notificationDAO.findByTemplate(mailTemplate);
    if (!notifications.isEmpty()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
        sce.getElements().addAll(notifications.stream().map(Entity::getKey).collect(Collectors.toList()));
        throw sce;
    }
    MailTemplateTO deleted = getMailTemplateTO(key);
    mailTemplateDAO.delete(key);
    return deleted;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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 10 with Notification

use of org.apache.syncope.core.persistence.api.entity.Notification in project syncope by apache.

the class NotificationTest method find.

@Test
public void find() {
    Notification notification = notificationDAO.find("9e2b911c-25de-4c77-bcea-b86ed9451050");
    assertNotNull(notification);
    assertNotNull(notification.getEvents());
    assertFalse(notification.getEvents().isEmpty());
    assertNotNull(notification.getAbout(anyTypeDAO.findUser()));
    assertNotNull(notification.getRecipientsFIQL());
}
Also used : Notification(org.apache.syncope.core.persistence.api.entity.Notification) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

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