use of org.xwiki.eventstream.internal.DefaultEventStatus in project xwiki-platform by xwiki.
the class NotificationScriptEventHelper method saveEventStatus.
/**
* Save a status for the current user.
* See {@link NotificationScriptService#saveEventStatus(String, boolean)} for more details.
*
* @param eventId id of the event
* @param isRead either or not the current user has read the given event
* @throws Exception if an error occurs
*/
public void saveEventStatus(String eventId, boolean isRead) throws Exception {
DefaultEvent event = new DefaultEvent();
event.setId(eventId);
String userId = entityReferenceSerializer.serialize(documentAccessBridge.getCurrentUserReference());
eventStatusManager.saveEventStatus(new DefaultEventStatus(event, userId, isRead));
}
use of org.xwiki.eventstream.internal.DefaultEventStatus 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;
}
Aggregations