Search in sources :

Example 1 with EventStatus

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

the class DefaultEventStatusManager method getEventStatus.

@Override
public List<EventStatus> getEventStatus(List<Event> events, List<String> entityIds) throws Exception {
    List<EventStatus> results = new ArrayList<>();
    // Don't perform any query if the list of events or entities is actually empty
    if (events.isEmpty() || entityIds.isEmpty()) {
        return results;
    }
    // Get the ActivityEventStatus from the database and convert them
    Query query = queryManager.createQuery("select eventStatus from ActivityEventStatusImpl eventStatus " + "where eventStatus.activityEvent.id in :eventIds and eventStatus.entityId in :entityIds", Query.HQL);
    query.bindValue("eventIds", getEventIds(events));
    query.bindValue("entityIds", entityIds);
    for (ActivityEventStatus activityEventStatus : query.<ActivityEventStatus>execute()) {
        results.add(new DefaultEventStatus(eventConverter.convertActivityToEvent(activityEventStatus.getActivityEvent()), activityEventStatus.getEntityId(), activityEventStatus.isRead()));
    }
    // For status that are not present in the database, we create objects with read = false
    for (Event event : events) {
        for (String entityId : entityIds) {
            if (!isPresent(event, entityId, results)) {
                results.add(new DefaultEventStatus(event, entityId, false));
            }
        }
    }
    // Sort statuses by date, in the descending order, like notifications, otherwise the order is lost
    Collections.sort(results, (status1, status2) -> status2.getEvent().getDate().compareTo(status1.getEvent().getDate()));
    return results;
}
Also used : ActivityEventStatus(com.xpn.xwiki.plugin.activitystream.api.ActivityEventStatus) Query(org.xwiki.query.Query) DefaultEventStatus(org.xwiki.eventstream.internal.DefaultEventStatus) DefaultEventStatus(org.xwiki.eventstream.internal.DefaultEventStatus) EventStatus(org.xwiki.eventstream.EventStatus) ActivityEventStatus(com.xpn.xwiki.plugin.activitystream.api.ActivityEventStatus) ArrayList(java.util.ArrayList) Event(org.xwiki.eventstream.Event)

Example 2 with EventStatus

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

the class DefaultCompositeEventStatusManager method getCompositeEventStatuses.

@Override
public List<CompositeEventStatus> getCompositeEventStatuses(List<CompositeEvent> compositeEvents, String entityId) throws Exception {
    // Creating a list of all events to avoid multiple calls to getEventStatuses() and so multiple calls to the
    // database.
    List<Event> allEvents = new ArrayList<>();
    // But maintain a mapping between eventId and their composite event status
    Map<String, CompositeEventStatus> map = new HashMap<>();
    for (CompositeEvent compositeEvent : compositeEvents) {
        CompositeEventStatus compositeEventStatus = new CompositeEventStatus(compositeEvent);
        for (Event event : compositeEvent.getEvents()) {
            map.put(event.getId(), compositeEventStatus);
        }
        allEvents.addAll(compositeEvent.getEvents());
    }
    // Put the event statuses into the composite events statuses
    for (EventStatus eventStatus : getEventStatuses(allEvents, entityId)) {
        map.get(eventStatus.getEvent().getId()).add(eventStatus);
    }
    List<CompositeEventStatus> results = new ArrayList<>();
    // Keep the same order than inputs
    for (CompositeEvent event : compositeEvents) {
        results.add(map.get(event.getEvents().get(0).getId()));
    }
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompositeEventStatus(org.xwiki.notifications.CompositeEventStatus) EventStatus(org.xwiki.eventstream.EventStatus) CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) CompositeEventStatus(org.xwiki.notifications.CompositeEventStatus)

Aggregations

ArrayList (java.util.ArrayList)2 Event (org.xwiki.eventstream.Event)2 EventStatus (org.xwiki.eventstream.EventStatus)2 ActivityEventStatus (com.xpn.xwiki.plugin.activitystream.api.ActivityEventStatus)1 HashMap (java.util.HashMap)1 DefaultEventStatus (org.xwiki.eventstream.internal.DefaultEventStatus)1 CompositeEvent (org.xwiki.notifications.CompositeEvent)1 CompositeEventStatus (org.xwiki.notifications.CompositeEventStatus)1 Query (org.xwiki.query.Query)1