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());
}
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());
}
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);
}
}
}
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());
}
Aggregations