use of io.lumeer.api.model.NotificationChannel in project engine by Lumeer.
the class NotificationSettingCodec method convertFromDocument.
public static NotificationSetting convertFromDocument(final Document bson) {
final String notificationTypeString = bson.getString(NotificationSetting.NOTIFICATION_TYPE);
final NotificationType notificationType = notificationTypeString != null ? NotificationType.valueOf(notificationTypeString) : null;
final String notificationChannelString = bson.getString(NotificationSetting.NOTIFICATION_CHANNEL);
final NotificationChannel notificationChannel = notificationChannelString != null ? NotificationChannel.valueOf(notificationChannelString) : null;
final String notificationFrequencyString = bson.getString(NotificationSetting.NOTIFICATION_FREQUENCY);
final NotificationFrequency notificationFrequency = notificationFrequencyString != null ? NotificationFrequency.valueOf(notificationFrequencyString) : null;
return new NotificationSetting(notificationType, notificationChannel, notificationFrequency);
}
use of io.lumeer.api.model.NotificationChannel in project engine by Lumeer.
the class DelayedActionProcessor method aggregateActions.
private List<DelayedAction> aggregateActions(final List<DelayedAction> actions) {
var actionsByIds = actions.stream().collect(Collectors.toMap(DelayedAction::getId, Function.identity()));
final List<DelayedAction> newActions = new ArrayList<>();
for (final NotificationChannel channel : NotificationChannel.values()) {
var actionsByUserAndTask = getActionsByTask(actions, channel);
actionsByUserAndTask.forEach((k, v) -> {
// for all chunks where there are more notifications than 1 for the same user
if (v.size() > 1) {
// check that we have the receiver and task id
if (v.stream().allMatch(a -> a.getReceiver() != null && a.getData().getString(DelayedAction.DATA_DOCUMENT_ID) != null)) {
// sort the actions from oldest to newest to merge them together in the right order
v.sort(Comparator.comparing(DelayedAction::getCheckAfter));
// merge the actions
DelayedAction action = v.get(0);
boolean wasAssignee = action.getNotificationType() == NotificationType.TASK_ASSIGNED;
final Set<NotificationType> originalTypes = new HashSet<>();
final List<String> originalIds = new ArrayList<>();
originalTypes.add(action.getNotificationType());
originalIds.add(action.getId());
actionsByIds.remove(action.getId());
for (int i = 1; i < v.size(); i++) {
final DelayedAction other = v.get(i);
action = action.merge(other);
wasAssignee = wasAssignee || (other.getNotificationType() == NotificationType.TASK_ASSIGNED);
originalTypes.add(other.getNotificationType());
originalIds.add(other.getId());
actionsByIds.remove(other.getId());
}
// set the correct type of the new aggregated action
if (wasAssignee) {
action.setNotificationType(NotificationType.TASK_ASSIGNED);
} else {
action.setNotificationType(NotificationType.TASK_CHANGED);
}
action.getData().append(DelayedAction.DATA_ORIGINAL_ACTION_TYPES, new ArrayList(originalTypes)).append(DelayedAction.DATA_ORIGINAL_ACTION_IDS, originalIds);
newActions.add(action);
}
}
});
}
newActions.addAll(actionsByIds.values());
return newActions;
}
use of io.lumeer.api.model.NotificationChannel in project engine by Lumeer.
the class AbstractPurposeChangeDetector method getDelayedActions.
protected List<DelayedAction> getDelayedActions(final DocumentEvent documentEvent, final Collection collection, final NotificationType notificationType, final ZonedDateTime when, final Set<Assignee> assignees) {
final List<DelayedAction> actions = new ArrayList<>();
if (assignees != null) {
assignees.stream().map(Assignee::getEmail).collect(Collectors.toSet()).stream().filter(// collect to set to have each value just once
assignee -> (notificationType == NotificationType.DUE_DATE_SOON || notificationType == NotificationType.PAST_DUE_DATE || !assignee.equals(currentUser.getEmail().toLowerCase()) && StringUtils.isNotEmpty(assignee))).forEach(assignee -> {
ZonedDateTime timeZonedWhen = when;
// but only when just date is visible
if ((notificationType == NotificationType.DUE_DATE_SOON || notificationType == NotificationType.PAST_DUE_DATE) && CollectionUtil.isDueDateInUTC(collection) && !CollectionUtil.hasDueDateFormatTimeOptions(collection)) {
final Optional<String> userTimeZone = assignees.stream().filter(a -> a.getEmail().equals(assignee) && StringUtils.isNotEmpty(a.getTimeZone())).map(Assignee::getTimeZone).findFirst();
if (userTimeZone.isPresent()) {
final TimeZone tz = TimeZone.getTimeZone(userTimeZone.get());
timeZonedWhen = when.withZoneSameLocal(tz.toZoneId());
}
}
// in the future, this can be removed and checked in DelayedActionProcessor
timeZonedWhen = roundTime(timeZonedWhen, NotificationFrequency.Immediately);
final String resourcePath = getResourcePath(documentEvent);
final String correlationId = requestDataKeeper.getAppId() != null ? requestDataKeeper.getAppId().getValue() : requestDataKeeper.getCorrelationId();
final DataDocument data = getData(documentEvent, collection, assignee, assignees);
for (NotificationChannel channel : NotificationChannel.values()) {
final DelayedAction action = new DelayedAction();
action.setInitiator(currentUser.getEmail());
action.setReceiver(assignee);
action.setResourcePath(resourcePath);
action.setNotificationType(notificationType);
action.setCheckAfter(timeZonedWhen);
action.setNotificationChannel(channel);
action.setCorrelationId(correlationId);
action.setData(data);
actions.add(action);
}
});
}
return actions;
}
Aggregations