Search in sources :

Example 1 with ActivityEvent

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);
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)

Example 2 with ActivityEvent

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) Event(org.xwiki.eventstream.Event) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) URL(java.net.URL)

Example 3 with ActivityEvent

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;
}
Also used : WatchListEvent(org.xwiki.watchlist.internal.api.WatchListEvent) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ActivityStream(com.xpn.xwiki.plugin.activitystream.api.ActivityStream) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 4 with ActivityEvent

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);
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ArrayList(java.util.ArrayList) WatchListEventConverter(org.xwiki.watchlist.internal.WatchListEventConverter) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 5 with ActivityEvent

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);
}
Also used : Query(org.xwiki.query.Query) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) Map(java.util.Map)

Aggregations

ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)9 ArrayList (java.util.ArrayList)3 ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)2 ActivityEventImpl (com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl)2 ActivityStreamPlugin (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)2 Date (java.util.Date)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 WikiReference (org.xwiki.model.reference.WikiReference)2 WatchListEvent (org.xwiki.watchlist.internal.api.WatchListEvent)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 ActivityStream (com.xpn.xwiki.plugin.activitystream.api.ActivityStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Map (java.util.Map)1 Test (org.junit.Test)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 Event (org.xwiki.eventstream.Event)1 Query (org.xwiki.query.Query)1 WatchListEventConverter (org.xwiki.watchlist.internal.WatchListEventConverter)1