Search in sources :

Example 1 with CreateOrUpdateUserNotification

use of io.lumeer.engine.api.event.CreateOrUpdateUserNotification in project engine by Lumeer.

the class MongoUserNotificationDao method updateNotifications.

@Override
public void updateNotifications(final String searchField, final String searchId, final Map<String, String> updates) {
    final List<Bson> sets = updates.entrySet().stream().map(e -> Updates.set(e.getKey(), e.getValue())).collect(Collectors.toList());
    final UpdateResult result = databaseCollection().updateMany(Filters.eq(searchField, searchId), Updates.combine(sets));
    if (result.getModifiedCount() > 0 && createOrUpdateUserNotificationEvent != null) {
        final List<UserNotification> updatedNotifications = databaseCollection().find(Filters.eq(searchField, searchId)).into(new ArrayList<>());
        updatedNotifications.forEach(notification -> createOrUpdateUserNotificationEvent.fire(new CreateOrUpdateUserNotification(notification)));
    }
}
Also used : Document(org.bson.Document) MongoCollection(com.mongodb.client.MongoCollection) UserNotification(io.lumeer.api.model.UserNotification) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Filters(com.mongodb.client.model.Filters) Bson(org.bson.conversions.Bson) Inject(javax.inject.Inject) UpdateResult(com.mongodb.client.result.UpdateResult) Map(java.util.Map) Event(javax.enterprise.event.Event) UserNotificationCodec(io.lumeer.storage.mongodb.codecs.UserNotificationCodec) MongoException(com.mongodb.MongoException) ReturnDocument(com.mongodb.client.model.ReturnDocument) Updates(com.mongodb.client.model.Updates) Set(java.util.Set) IndexOptions(com.mongodb.client.model.IndexOptions) Collectors(java.util.stream.Collectors) CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) Indexes(com.mongodb.client.model.Indexes) StorageException(io.lumeer.storage.api.exception.StorageException) List(java.util.List) MongoFilters.idFilter(io.lumeer.storage.mongodb.util.MongoFilters.idFilter) Sorts(com.mongodb.client.model.Sorts) RemoveUserNotification(io.lumeer.engine.api.event.RemoveUserNotification) UserNotificationDao(io.lumeer.storage.api.dao.UserNotificationDao) PostConstruct(javax.annotation.PostConstruct) DeleteResult(com.mongodb.client.result.DeleteResult) ObjectId(org.bson.types.ObjectId) FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UserNotification(io.lumeer.api.model.UserNotification) CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) RemoveUserNotification(io.lumeer.engine.api.event.RemoveUserNotification) CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) UpdateResult(com.mongodb.client.result.UpdateResult) Bson(org.bson.conversions.Bson)

Example 2 with CreateOrUpdateUserNotification

use of io.lumeer.engine.api.event.CreateOrUpdateUserNotification 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);
        }
    }
}
Also used : CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) RemoveUserNotification(io.lumeer.engine.api.event.RemoveUserNotification) UserNotification(io.lumeer.api.model.UserNotification) OrganizationUserEvent(io.lumeer.engine.api.event.OrganizationUserEvent) ResourceVariableEvent(io.lumeer.engine.api.event.ResourceVariableEvent) SelectionListEvent(io.lumeer.engine.api.event.SelectionListEvent) Event(org.marvec.pusher.data.Event)

Aggregations

UserNotification (io.lumeer.api.model.UserNotification)2 CreateOrUpdateUserNotification (io.lumeer.engine.api.event.CreateOrUpdateUserNotification)2 RemoveUserNotification (io.lumeer.engine.api.event.RemoveUserNotification)2 MongoException (com.mongodb.MongoException)1 MongoCollection (com.mongodb.client.MongoCollection)1 Filters (com.mongodb.client.model.Filters)1 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)1 IndexOptions (com.mongodb.client.model.IndexOptions)1 Indexes (com.mongodb.client.model.Indexes)1 ReturnDocument (com.mongodb.client.model.ReturnDocument)1 Sorts (com.mongodb.client.model.Sorts)1 Updates (com.mongodb.client.model.Updates)1 DeleteResult (com.mongodb.client.result.DeleteResult)1 UpdateResult (com.mongodb.client.result.UpdateResult)1 OrganizationUserEvent (io.lumeer.engine.api.event.OrganizationUserEvent)1 ResourceVariableEvent (io.lumeer.engine.api.event.ResourceVariableEvent)1 SelectionListEvent (io.lumeer.engine.api.event.SelectionListEvent)1 UserNotificationDao (io.lumeer.storage.api.dao.UserNotificationDao)1 StorageException (io.lumeer.storage.api.exception.StorageException)1 UserNotificationCodec (io.lumeer.storage.mongodb.codecs.UserNotificationCodec)1