Search in sources :

Example 1 with ActivityEventStatus

use of com.xpn.xwiki.plugin.activitystream.api.ActivityEventStatus 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 ActivityEventStatus

use of com.xpn.xwiki.plugin.activitystream.api.ActivityEventStatus in project xwiki-platform by xwiki.

the class DefaultEventStatusManager method saveEventStatus.

@Override
public void saveEventStatus(EventStatus eventStatus) throws Exception {
    ActivityEventStatus status = eventConverter.convertEventStatusToActivityStatus(eventStatus);
    if (configuration.useLocalStore()) {
        saveEventStatusInStore(status);
    }
    if (configuration.useMainStore()) {
        XWikiContext context = contextProvider.get();
        // store event in the main database
        String oriDatabase = context.getWikiId();
        context.setWikiId(context.getMainXWiki());
        try {
            saveEventStatusInStore(status);
        } finally {
            context.setWikiId(oriDatabase);
        }
    }
}
Also used : ActivityEventStatus(com.xpn.xwiki.plugin.activitystream.api.ActivityEventStatus) XWikiContext(com.xpn.xwiki.XWikiContext)

Aggregations

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