Search in sources :

Example 1 with AnyAbout

use of org.apache.syncope.core.persistence.api.entity.AnyAbout 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 2 with AnyAbout

use of org.apache.syncope.core.persistence.api.entity.AnyAbout 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 3 with AnyAbout

use of org.apache.syncope.core.persistence.api.entity.AnyAbout 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 4 with AnyAbout

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

the class NotificationTest method issueSYNCOPE445.

@Test
public void issueSYNCOPE445() {
    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 search condition");
    notification.setRecipientAttrName("email");
    notification.getStaticRecipients().add("syncope445@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)

Aggregations

AnyAbout (org.apache.syncope.core.persistence.api.entity.AnyAbout)4 Notification (org.apache.syncope.core.persistence.api.entity.Notification)4 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)3 Test (org.junit.jupiter.api.Test)3 ParseException (java.text.ParseException)1 Matcher (java.util.regex.Matcher)1 StringUtils (org.apache.commons.lang3.StringUtils)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)1 NotificationTO (org.apache.syncope.common.lib.to.NotificationTO)1 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)1 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)1 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)1 ImplementationDAO (org.apache.syncope.core.persistence.api.dao.ImplementationDAO)1 MailTemplateDAO (org.apache.syncope.core.persistence.api.dao.MailTemplateDAO)1 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)1 EntityFactory (org.apache.syncope.core.persistence.api.entity.EntityFactory)1 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)1 MailTemplate (org.apache.syncope.core.persistence.api.entity.MailTemplate)1 NotificationDataBinder (org.apache.syncope.core.provisioning.api.data.NotificationDataBinder)1