Search in sources :

Example 1 with NotificationType

use of io.lumeer.api.model.NotificationType 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);
}
Also used : NotificationChannel(io.lumeer.api.model.NotificationChannel) NotificationFrequency(io.lumeer.api.model.NotificationFrequency) NotificationType(io.lumeer.api.model.NotificationType) NotificationSetting(io.lumeer.api.model.NotificationSetting)

Example 2 with NotificationType

use of io.lumeer.api.model.NotificationType 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;
}
Also used : NotificationChannel(io.lumeer.api.model.NotificationChannel) NotificationType(io.lumeer.api.model.NotificationType) ArrayList(java.util.ArrayList) DelayedAction(io.lumeer.api.model.DelayedAction) HashSet(java.util.HashSet)

Example 3 with NotificationType

use of io.lumeer.api.model.NotificationType 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)

Example 4 with NotificationType

use of io.lumeer.api.model.NotificationType in project engine by Lumeer.

the class UserNotificationCodec method decode.

@Override
public UserNotification decode(final BsonReader reader, final DecoderContext decoderContext) {
    final Document bson = documentCodec.decode(reader, decoderContext);
    final String id = bson.getObjectId(ID).toHexString();
    final String userId = bson.getString(USER_ID);
    final boolean read = bson.getBoolean(READ);
    final NotificationType type = NotificationType.values()[bson.getInteger(TYPE)];
    final org.bson.Document data = bson.get(DATA, org.bson.Document.class);
    ZonedDateTime createdAt = null;
    if (bson.getDate(CREATED_AT) != null) {
        createdAt = ZonedDateTime.ofInstant(bson.getDate(CREATED_AT).toInstant(), ZoneOffset.UTC);
    }
    ZonedDateTime firstReadAt = null;
    if (bson.getDate(FIRST_READ_AT) != null) {
        firstReadAt = ZonedDateTime.ofInstant(bson.getDate(FIRST_READ_AT).toInstant(), ZoneOffset.UTC);
    }
    final UserNotification notification = new UserNotification(userId, createdAt, read, firstReadAt, type, new DataDocument(data != null ? data : new org.bson.Document()));
    notification.setId(id);
    return notification;
}
Also used : Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ZonedDateTime(java.time.ZonedDateTime) NotificationType(io.lumeer.api.model.NotificationType) UserNotification(io.lumeer.api.model.UserNotification) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument)

Aggregations

NotificationType (io.lumeer.api.model.NotificationType)4 NotificationChannel (io.lumeer.api.model.NotificationChannel)3 DelayedAction (io.lumeer.api.model.DelayedAction)2 NotificationFrequency (io.lumeer.api.model.NotificationFrequency)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 ZonedDateTime (java.time.ZonedDateTime)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 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 Document (io.lumeer.api.model.Document)1 Group (io.lumeer.api.model.Group)1 NotificationSetting (io.lumeer.api.model.NotificationSetting)1 Organization (io.lumeer.api.model.Organization)1 Project (io.lumeer.api.model.Project)1 User (io.lumeer.api.model.User)1 UserNotification (io.lumeer.api.model.UserNotification)1