use of org.apache.syncope.common.lib.to.NotificationTO in project syncope by apache.
the class NotificationTaskITCase method issueSYNCOPE446.
@Test
public void issueSYNCOPE446() throws Exception {
// 1. Create notification
ImplementationTO recipientsProvider = new ImplementationTO();
recipientsProvider.setKey(TestNotificationRecipientsProvider.class.getSimpleName());
recipientsProvider.setEngine(ImplementationEngine.JAVA);
recipientsProvider.setType(ImplementationType.RECIPIENTS_PROVIDER);
recipientsProvider.setBody(TestNotificationRecipientsProvider.class.getName());
Response response = implementationService.create(recipientsProvider);
recipientsProvider = implementationService.read(recipientsProvider.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(recipientsProvider);
NotificationTO notification = new NotificationTO();
notification.setTraceLevel(TraceLevel.ALL);
notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
String groupName = "group" + getUUIDString();
notification.getAbouts().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
notification.setSelfAsRecipient(false);
notification.setRecipientAttrName("email");
notification.getStaticRecipients().add("notificationtest@syncope.apache.org");
notification.setRecipientsProvider(recipientsProvider.getKey());
String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
notification.setSender(sender);
String subject = "Test notification " + getUUIDString();
notification.setSubject(subject);
notification.setTemplate("optin");
notification.setActive(true);
response = notificationService.create(notification);
notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
assertNotNull(notification);
assertEquals(recipientsProvider.getKey(), notification.getRecipientsProvider());
// 2. create group
GroupTO groupTO = new GroupTO();
groupTO.setName(groupName);
groupTO.setRealm("/even/two");
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
// 3. verify
NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getRecipients().containsAll(new TestNotificationRecipientsProvider().provideRecipients(null)));
NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>search(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).getResult().get(0);
assertEquals(taskTO, foundViaList);
execNotificationTask(taskService, taskTO.getKey(), 50);
assertTrue(verifyMail(sender, subject, "notificationtest@syncope.apache.org"));
}
use of org.apache.syncope.common.lib.to.NotificationTO in project syncope by apache.
the class NotificationDataBinderImpl method getNotificationTO.
@Override
public NotificationTO getNotificationTO(final Notification notification) {
NotificationTO notificationTO = new NotificationTO();
notificationTO.setKey(notification.getKey());
notificationTO.setTemplate(notification.getTemplate().getKey());
BeanUtils.copyProperties(notification, notificationTO, IGNORE_PROPERTIES);
notification.getAbouts().forEach(about -> {
notificationTO.getAbouts().put(about.getAnyType().getKey(), about.get());
});
if (notification.getRecipientsProvider() != null) {
notificationTO.setRecipientsProvider(notification.getRecipientsProvider().getKey());
}
return notificationTO;
}
use of org.apache.syncope.common.lib.to.NotificationTO 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;
}
use of org.apache.syncope.common.lib.to.NotificationTO in project syncope by apache.
the class AbstractITCase method createNotificationTask.
protected Pair<String, String> createNotificationTask(final boolean active, final boolean includeAbout, final TraceLevel traceLevel, final String sender, final String subject, final String... staticRecipients) {
// 1. Create notification
NotificationTO notification = new NotificationTO();
notification.setTraceLevel(traceLevel);
notification.getEvents().add("[LOGIC]:[UserLogic]:[]:[create]:[SUCCESS]");
if (includeAbout) {
notification.getAbouts().put(AnyTypeKind.USER.name(), SyncopeClient.getUserSearchConditionBuilder().inGroups("bf825fe1-7320-4a54-bd64-143b5c18ab97").query());
}
notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
notification.setSelfAsRecipient(true);
notification.setRecipientAttrName("email");
if (staticRecipients != null) {
notification.getStaticRecipients().addAll(Arrays.asList(staticRecipients));
}
notification.setSender(sender);
notification.setSubject(subject);
notification.setTemplate("optin");
notification.setActive(active);
Response response = notificationService.create(notification);
notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
assertNotNull(notification);
// 2. create user
UserTO userTO = UserITCase.getUniqueSampleTO("notificationtest@syncope.apache.org");
userTO.getMemberships().add(new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
return Pair.of(notification.getKey(), userTO.getUsername());
}
use of org.apache.syncope.common.lib.to.NotificationTO 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);
}
}
}
Aggregations