use of io.lumeer.api.model.UserNotification in project engine by Lumeer.
the class PusherFacade method removeUserNotification.
public void removeUserNotification(@Observes final RemoveUserNotification removeUserNotification) {
if (isEnabled()) {
try {
UserNotification notification = removeUserNotification.getUserNotification();
Event event = createEventForRemove(notification.getClass().getSimpleName(), new ResourceId(getAppId(), notification.getId()), notification.getUserId());
sendNotificationsBatch(Collections.singletonList(event));
} catch (Exception e) {
log.log(Level.WARNING, "Unable to send push notification: ", e);
}
}
}
use of io.lumeer.api.model.UserNotification in project engine by Lumeer.
the class PusherFacade method createUserNotification.
public void createUserNotification(@Observes final CreateOrUpdateUserNotification createOrUpdateUserNotification) {
if (isEnabled()) {
try {
UserNotification notification = createOrUpdateUserNotification.getUserNotification();
Event event = createEventForObject(notification, CREATE_EVENT_SUFFIX, notification.getUserId());
sendNotificationsBatch(Collections.singletonList(event));
} catch (Exception e) {
log.log(Level.WARNING, "Unable to send push notification: ", e);
}
}
}
use of io.lumeer.api.model.UserNotification in project engine by Lumeer.
the class DelayedActionProcessor method executeActions.
private void executeActions(final List<DelayedAction> actions) {
// org id -> users
final Map<String, List<User>> userCache = new HashMap<>();
clearCache();
aggregateActions(actions).forEach(action -> {
final String organizationId = action.getData().getString(DelayedAction.DATA_ORGANIZATION_ID);
final List<User> allUsers = userCache.computeIfAbsent(organizationId, orgId -> userDao.getAllUsers(orgId));
// mix in users from actions
allUsers.addAll(getUsersFromActions(actions, allUsers));
// id -> user
final Map<String, User> users = getUsers(allUsers);
final Map<String, Language> userLanguages = initializeLanguages(users.values());
// email -> id
final Map<String, String> userIds = getUserIds(users.values());
final Language lang = userLanguages.getOrDefault(action.getReceiver(), Language.EN);
final User receiverUser = userIds.containsKey(action.getReceiver()) ? users.get(userIds.get(action.getReceiver())) : null;
final Collection collection = checkActionResourceExistsAndFillData(action, receiverUser);
if (collection != null) {
// if we do not know anything about the user, make sure to send the notification; otherwise check the user settings
if (receiverUser == null || isNotificationEnabled(action, receiverUser)) {
if (action.getNotificationChannel() == NotificationChannel.Email) {
final User user = userIds.containsKey(action.getInitiator()) ? users.get(userIds.get(action.getInitiator())) : null;
final String sender = user != null ? emailSenderFacade.formatUserReference(user) : "";
final String from = user != null ? emailSenderFacade.formatFrom(user) : "";
final String recipient = action.getReceiver();
final Map<String, Object> additionalData = processData(action.getData(), lang, receiverUser);
emailSenderFacade.sendEmailFromTemplate(getEmailTemplate(action), lang, sender, from, recipient, getEmailSubjectPart(action, additionalData, lang), additionalData);
} else if (action.getNotificationChannel() == NotificationChannel.Internal && userIds.containsKey(action.getReceiver())) {
UserNotification notification = createUserNotification(users.get(userIds.get(action.getReceiver())), action, lang);
notification = userNotificationDao.createNotification(notification);
if (pusherClient != null) {
pusherClient.trigger(List.of(createUserNotificationEvent(notification, PusherFacade.CREATE_EVENT_SUFFIX, userIds.get(action.getReceiver()))));
}
}
}
// reschedule past due actions
if (!rescheduleDueDateAction(actions, action, receiverUser, collection)) {
markActionAsCompleted(actions, action);
}
} else {
markActionAsCompleted(actions, action);
}
});
}
Aggregations