Search in sources :

Example 31 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultLiveMimeMessageIterator method retrieveCompositeEventList.

/**
 * For the given user, we will have to check that the composite event that we have to send matches the user
 * preferences.
 *
 * If, for any reason, one of the events of the original composite event is not meant for the user, we clone
 * the original composite event and remove the incriminated event.
 */
@Override
protected List<CompositeEvent> retrieveCompositeEventList(DocumentReference user) throws NotificationException {
    CompositeEvent resultCompositeEvent = new CompositeEvent(this.compositeEvent);
    if (this.hasCorrespondingNotificationPreference(user, resultCompositeEvent)) {
        // Apply the filters that the user has defined in its notification preferences
        // If one of the events present in the composite event does not match a user filter, remove the event
        List<NotificationFilter> filters = new ArrayList<>(notificationFilterManager.getAllFilters(user));
        Collections.sort(filters);
        Iterator<Event> it = resultCompositeEvent.getEvents().iterator();
        while (it.hasNext()) {
            Event event = it.next();
            if (isEventFiltered(filters, event, user)) {
                it.remove();
            }
        }
        if (resultCompositeEvent.getEvents().size() == 0) {
            return Collections.emptyList();
        }
        return Collections.singletonList(resultCompositeEvent);
    }
    return Collections.emptyList();
}
Also used : ArrayList(java.util.ArrayList) CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter)

Example 32 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultEventFactory method createEvent.

@Override
public Event createEvent() {
    Event result = new DefaultEvent();
    result.setId(UUID.randomUUID().toString());
    result.setGroupId(getCurrentGroupId());
    result.setUser(new DocumentReference(this.resolver.resolve(this.bridge.getCurrentUser(), EntityType.DOCUMENT)));
    result.setDate(new Date());
    return result;
}
Also used : Event(org.xwiki.eventstream.Event) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date)

Example 33 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultMessageStream method postPersonalMessage.

@Override
public void postPersonalMessage(String message) {
    Event e = createMessageEvent(message, "personalMessage");
    DocumentReference userDoc = this.bridge.getCurrentUserReference();
    e.setRelatedEntity(userDoc);
    e.setStream(this.serializer.serialize(userDoc));
    this.stream.addEvent(e);
}
Also used : Event(org.xwiki.eventstream.Event) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 34 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultMessageStream method getRecentDirectMessages.

@Override
public List<Event> getRecentDirectMessages(int limit, int offset) {
    List<Event> result = new ArrayList<Event>();
    try {
        Query q = this.qm.createQuery("where event.application = 'MessageStream' and event.type = 'directMessage'" + " and event.stream = :targetUser order by event.date desc", Query.XWQL);
        q.bindValue("targetUser", this.serializer.serialize(this.bridge.getCurrentUserReference()));
        q.setLimit(limit > 0 ? limit : 30).setOffset(offset >= 0 ? offset : 0);
        result = this.stream.searchEvents(q);
    } catch (QueryException ex) {
        LOG.warn("Failed to search direct messages: {}", ex.getMessage());
    }
    return result;
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) ArrayList(java.util.ArrayList) Event(org.xwiki.eventstream.Event)

Example 35 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultMessageStream method postDirectMessageToUser.

@Override
public void postDirectMessageToUser(String message, DocumentReference user) {
    if (!this.bridge.exists(user)) {
        throw new IllegalArgumentException("Target user does not exist");
    }
    Event e = createMessageEvent(message, "directMessage");
    e.setRelatedEntity(new ObjectReference("XWiki.XWikiUsers", user));
    e.setStream(this.serializer.serialize(user));
    e.setImportance(Importance.CRITICAL);
    this.stream.addEvent(e);
}
Also used : ObjectReference(org.xwiki.model.reference.ObjectReference) Event(org.xwiki.eventstream.Event)

Aggregations

Event (org.xwiki.eventstream.Event)60 Test (org.junit.Test)31 DocumentReference (org.xwiki.model.reference.DocumentReference)21 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)20 CompositeEvent (org.xwiki.notifications.CompositeEvent)17 ArrayList (java.util.ArrayList)7 Query (org.xwiki.query.Query)7 Date (java.util.Date)6 Expectations (org.jmock.Expectations)6 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)5 QueryException (org.xwiki.query.QueryException)5 ObjectReference (org.xwiki.model.reference.ObjectReference)4 HashMap (java.util.HashMap)3 WikiReference (org.xwiki.model.reference.WikiReference)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)2 EventStatus (org.xwiki.eventstream.EventStatus)2 EventStream (org.xwiki.eventstream.EventStream)2 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2