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();
}
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;
}
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);
}
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;
}
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);
}
Aggregations