Search in sources :

Example 1 with DocumentEvent

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;
}
Also used : SelectedWorkspace(io.lumeer.api.SelectedWorkspace) UserDao(io.lumeer.storage.api.dao.UserDao) NotificationType(io.lumeer.api.model.NotificationType) NotificationChannel(io.lumeer.api.model.NotificationChannel) CollectionUtil(io.lumeer.api.util.CollectionUtil) DocumentCommentedEvent(io.lumeer.engine.api.event.DocumentCommentedEvent) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) CollectionPurposeUtils(io.lumeer.core.util.CollectionPurposeUtils) StringUtils(org.apache.commons.lang3.StringUtils) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) DelayedAction(io.lumeer.api.model.DelayedAction) RequestDataKeeper(io.lumeer.core.auth.RequestDataKeeper) Organization(io.lumeer.api.model.Organization) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) DocumentEvent(io.lumeer.engine.api.event.DocumentEvent) DataDocument(io.lumeer.engine.api.data.DataDocument) TimeZone(java.util.TimeZone) Document(io.lumeer.api.model.Document) CreateDocument(io.lumeer.engine.api.event.CreateDocument) Set(java.util.Set) NotificationFrequency(io.lumeer.api.model.NotificationFrequency) Collectors(java.util.stream.Collectors) ResourceUtils.findAttribute(io.lumeer.api.util.ResourceUtils.findAttribute) DocumentUtils(io.lumeer.core.util.DocumentUtils) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) DelayedActionDao(io.lumeer.storage.api.dao.DelayedActionDao) Optional(java.util.Optional) Attribute(io.lumeer.api.model.Attribute) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) Utils(io.lumeer.core.util.Utils) Collection(io.lumeer.api.model.Collection) ConstraintType(io.lumeer.api.model.ConstraintType) NotificationChannel(io.lumeer.api.model.NotificationChannel) DataDocument(io.lumeer.engine.api.data.DataDocument) TimeZone(java.util.TimeZone) ZonedDateTime(java.time.ZonedDateTime) ArrayList(java.util.ArrayList) DelayedAction(io.lumeer.api.model.DelayedAction)

Aggregations

SelectedWorkspace (io.lumeer.api.SelectedWorkspace)1 Attribute (io.lumeer.api.model.Attribute)1 Collection (io.lumeer.api.model.Collection)1 CollectionPurpose (io.lumeer.api.model.CollectionPurpose)1 ConstraintType (io.lumeer.api.model.ConstraintType)1 DelayedAction (io.lumeer.api.model.DelayedAction)1 Document (io.lumeer.api.model.Document)1 Group (io.lumeer.api.model.Group)1 NotificationChannel (io.lumeer.api.model.NotificationChannel)1 NotificationFrequency (io.lumeer.api.model.NotificationFrequency)1 NotificationType (io.lumeer.api.model.NotificationType)1 Organization (io.lumeer.api.model.Organization)1 Project (io.lumeer.api.model.Project)1 User (io.lumeer.api.model.User)1 CollectionUtil (io.lumeer.api.util.CollectionUtil)1 ResourceUtils.findAttribute (io.lumeer.api.util.ResourceUtils.findAttribute)1 RequestDataKeeper (io.lumeer.core.auth.RequestDataKeeper)1 ConstraintManager (io.lumeer.core.constraint.ConstraintManager)1 DefaultConfigurationProducer (io.lumeer.core.facade.configuration.DefaultConfigurationProducer)1 CollectionPurposeUtils (io.lumeer.core.util.CollectionPurposeUtils)1