use of io.gravitee.am.management.service.impl.notifications.ManagementUINotifierConfiguration in project gravitee-access-management by gravitee-io.
the class UserNotificationServiceImpl method send.
@Override
public CompletableFuture<Void> send(Notification notification, Map<String, Object> param) {
var future = new CompletableFuture<Void>();
final UserProperties audience = (UserProperties) param.get(NotificationDefinitionUtils.NOTIFIER_DATA_USER);
final DomainProperties domain = (DomainProperties) param.get(NotificationDefinitionUtils.NOTIFIER_DATA_DOMAIN);
if (audience == null || domain == null) {
logger.warn("Receive notification to store in database without user or domain, ignore it.");
future.complete(null);
} else {
try {
ManagementUINotifierConfiguration notifierConfiguration = mapper.readValue(notification.getConfiguration(), ManagementUINotifierConfiguration.class);
String content = uiTemplateProvider.getNotificationContent(notifierConfiguration.getTemplate(), param);
final Date now = new Date();
final UserNotification userNotif = new UserNotification();
userNotif.setMessage(content);
userNotif.setCreatedAt(now);
userNotif.setUpdatedAt(now);
userNotif.setStatus(UserNotificationStatus.UNREAD);
userNotif.setReferenceId(domain.getId());
userNotif.setReferenceType(ReferenceType.DOMAIN);
userNotif.setAudienceId(audience.getId());
logger.debug("Receive notification to store in database for user '{}'", audience.getId());
notificationRepository.create(userNotif).observeOn(Schedulers.io()).subscribe(createdNotif -> {
logger.debug("Notification stored: {}", createdNotif);
// CompletableStage use the Void type. So it requires null to be mapped properly in the NotificationTrigger
future.complete(null);
}, future::completeExceptionally);
} catch (Exception e) {
logger.warn("Unable to deserialize ManagementUI Notifier configuration : {}", e.getMessage());
future.completeExceptionally(e);
}
}
return future;
}
Aggregations