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