use of io.lumeer.engine.api.event.DocumentEvent 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