use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent in project xwiki-platform by xwiki.
the class ActivityStreamImpl method addActivityEvent.
@Override
public void addActivityEvent(String streamName, String type, String title, List<String> params, XWikiContext context) throws ActivityStreamException {
ActivityEvent event = newActivityEvent();
event.setStream(streamName);
event.setType(type);
event.setTitle(title);
event.setBody(title);
event.setParams(params);
addActivityEvent(event, context);
}
use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent in project xwiki-platform by xwiki.
the class EventConverter method convertActivityToEvent.
/**
* Convert an old {@link ActivityEvent} to the new {@link Event}.
*
* @param e the activity event to transform
* @return the equivalent event
*/
public Event convertActivityToEvent(ActivityEvent e) {
Event result = this.eventFactory.createRawEvent();
result.setApplication(e.getApplication());
result.setBody(e.getBody());
result.setDate(e.getDate());
result.setDocument(new DocumentReference(this.resolver.resolve(e.getPage(), EntityType.DOCUMENT, new WikiReference(e.getWiki()))));
result.setId(e.getEventId());
result.setDocumentTitle(e.getParam1());
if (StringUtils.isNotEmpty(e.getParam2())) {
if (StringUtils.endsWith(e.getType(), "Attachment")) {
result.setRelatedEntity(this.explicitResolver.resolve(e.getParam2(), EntityType.ATTACHMENT, result.getDocument()));
} else if (StringUtils.endsWith(e.getType(), "Comment") || StringUtils.endsWith(e.getType(), "Annotation")) {
result.setRelatedEntity(this.explicitResolver.resolve(e.getParam2(), EntityType.OBJECT, result.getDocument()));
}
}
result.setImportance(Event.Importance.MEDIUM);
if (e.getPriority() > 0) {
int priority = e.getPriority() / 10 - 1;
if (priority >= 0 && priority < Event.Importance.values().length) {
result.setImportance(Event.Importance.values()[priority]);
}
}
result.setGroupId(e.getRequestId());
result.setStream(e.getStream());
result.setTitle(e.getTitle());
result.setType(e.getType());
if (StringUtils.isNotBlank(e.getUrl())) {
try {
result.setUrl(new URL(e.getUrl()));
} catch (MalformedURLException ex) {
// Should not happen
}
}
result.setUser(new DocumentReference(this.resolver.resolve(e.getUser(), EntityType.DOCUMENT)));
result.setDocumentVersion(e.getVersion());
result.setParameters(e.getParameters());
result.setTarget(e.getTarget());
return result;
}
use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent in project xwiki-platform by xwiki.
the class DefaultWatchListEventMatcher method getEventsSince.
@Override
public List<WatchListEvent> getEventsSince(Date start) {
List<WatchListEvent> events = new ArrayList<>();
XWikiContext context = getXWikiContext();
ActivityStream actStream = ((ActivityStreamPlugin) context.getWiki().getPlugin(ActivityStreamPlugin.PLUGIN_NAME, context)).getActivityStream();
List<Object> parameters = new ArrayList<Object>();
parameters.add(start);
try {
// FIXME: Watch out for memory usage here, since the list of events could be huge in some cases.
List<ActivityEvent> rawEvents = actStream.searchEvents("act.date > ? and act.type in ('" + StringUtils.join(MATCHING_EVENT_TYPES, "','") + "')", false, true, 0, 0, parameters, context);
// WatchListEvent#equals(WatchListEvent).
for (ActivityEvent rawEvent : rawEvents) {
WatchListEvent event = this.eventConverter.convert(rawEvent);
int existingIndex = events.indexOf(event);
if (existingIndex == -1) {
// An event on a new document, add the new event.
events.add(event);
} else {
// An event on an existing document, add to the events of that document.
WatchListEvent existingCompositeEvent = events.get(existingIndex);
existingCompositeEvent.addEvent(event);
}
}
} catch (Exception e) {
logger.error("Failed to retrieve updated documents from activity stream since [{}]", start, e);
}
return events;
}
use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent in project xwiki-platform by xwiki.
the class WatchListNotifier method sendEmailNotification.
/**
* Sends the email notifying the subscriber that the updatedDocuments have been changed.
*
* @param subscriber user to notify
* @param events list of events
* @param emailTemplate email template to use
* @param previousFireTime last time the notification was fired
* @param context the XWiki context
* @throws XWikiException if mail sending fails
*/
public void sendEmailNotification(String subscriber, List<WatchListEvent> events, String emailTemplate, Date previousFireTime, XWikiContext context) throws XWikiException {
// Convert the parameters.
List<org.xwiki.watchlist.internal.api.WatchListEvent> watchListEvents = new ArrayList<>();
WatchListEventConverter<ActivityEvent> eventConverter = Utils.getComponent(new DefaultParameterizedType(null, WatchListEventConverter.class, ActivityEvent.class));
for (WatchListEvent event : events) {
List<ActivityEvent> activityEvents = event.getData();
// Get the main event.
org.xwiki.watchlist.internal.api.WatchListEvent watchListEvent = eventConverter.convert(activityEvents.get(0));
// Possibly composite event.
for (int i = 1; i < activityEvents.size(); i++) {
org.xwiki.watchlist.internal.api.WatchListEvent associatedEvent = eventConverter.convert(activityEvents.get(i));
watchListEvent.addEvent(associatedEvent);
}
// Add the converted event to the list.
watchListEvents.add(watchListEvent);
}
// Delegate to the component.
org.xwiki.watchlist.internal.api.WatchListNotifier notifier = Utils.getComponent(org.xwiki.watchlist.internal.api.WatchListNotifier.class);
notifier.sendNotification(subscriber, watchListEvents, emailTemplate, previousFireTime);
}
use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent in project xwiki-platform by xwiki.
the class BridgeEventStream method searchEvents.
@Override
public List<Event> searchEvents(Query query) throws QueryException {
Query q = this.qm.createQuery("select event from ActivityEventImpl event " + query.getStatement(), query.getLanguage());
for (Map.Entry<String, Object> entry : query.getNamedParameters().entrySet()) {
q.bindValue(entry.getKey(), entry.getValue());
}
for (Map.Entry<Integer, Object> entry : query.getPositionalParameters().entrySet()) {
q.bindValue(entry.getKey(), entry.getValue());
}
q.setLimit(query.getLimit());
q.setOffset(query.getOffset());
List<ActivityEvent> events = q.execute();
return convertActivitiesToEvents(events);
}
Aggregations