Search in sources :

Example 11 with Event

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

the class DefaultMessageStream method postMessageToGroup.

@Override
public void postMessageToGroup(String message, DocumentReference group) throws IllegalAccessError {
    if (!this.bridge.exists(group)) {
        throw new IllegalArgumentException("Target group does not exist");
    }
    Event e = createMessageEvent(message, "groupMessage");
    e.setRelatedEntity(new ObjectReference("XWiki.XWikiGroups", group));
    e.setStream(this.serializer.serialize(group));
    e.setImportance(Importance.MAJOR);
    this.stream.addEvent(e);
}
Also used : ObjectReference(org.xwiki.model.reference.ObjectReference) Event(org.xwiki.eventstream.Event)

Example 12 with Event

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

the class DefaultMessageStream method getRecentPersonalMessages.

@Override
public List<Event> getRecentPersonalMessages(DocumentReference author, int limit, int offset) {
    List<Event> result = new ArrayList<Event>();
    try {
        Query q = this.qm.createQuery("where event.application = 'MessageStream' and event.type = 'personalMessage'" + " and event.user = :user order by event.date desc", Query.XWQL);
        q.bindValue("user", this.serializer.serialize(author));
        q.setLimit(limit > 0 ? limit : 30).setOffset(offset >= 0 ? offset : 0);
        result = this.stream.searchEvents(q);
    } catch (QueryException ex) {
        LOG.warn("Failed to search personal messages: {}", ex.getMessage());
    }
    return result;
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) ArrayList(java.util.ArrayList) Event(org.xwiki.eventstream.Event)

Example 13 with Event

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

the class DefaultMessageStream method deleteMessage.

@Override
public void deleteMessage(String id) {
    Query q;
    try {
        q = this.qm.createQuery("where event.id = :id", Query.XWQL);
        q.bindValue("id", id);
        List<Event> events = this.stream.searchEvents(q);
        if (events == null || events.isEmpty()) {
            throw new IllegalArgumentException("This message does not exist");
        } else if (events.get(0).getUser().equals(this.bridge.getCurrentUserReference())) {
            this.stream.deleteEvent(events.get(0));
        } else {
            throw new IllegalArgumentException("You are not authorized to delete this message");
        }
    } catch (QueryException ex) {
        LOG.warn("Failed to delete message: {}", ex.getMessage());
    }
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) Event(org.xwiki.eventstream.Event)

Example 14 with Event

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

the class DefaultMessageStream method postPublicMessage.

@Override
public void postPublicMessage(String message) {
    Event e = createMessageEvent(message, "publicMessage");
    DocumentReference userDoc = this.bridge.getCurrentUserReference();
    e.setRelatedEntity(userDoc);
    e.setImportance(Importance.MINOR);
    e.setStream(this.serializer.serialize(userDoc));
    this.stream.addEvent(e);
}
Also used : Event(org.xwiki.eventstream.Event) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 15 with Event

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

the class DefaultMessageStream method createMessageEvent.

/**
 * Creates an {@link Event} object with the common fields filled in: event ID, target document, application, user...
 * It also fills in the provided message body and type.
 *
 * @param message the message to store in the event; at most 2000 characters are stored, longer messages are
 *        automatically trimmed
 * @param messageType the type of message
 * @return the initialized event object
 */
protected Event createMessageEvent(String message, String messageType) {
    Event e = this.factory.createEvent();
    e.setApplication("MessageStream");
    e.setDocument(new DocumentReference(this.context.getCurrentEntityReference().getRoot().getName(), "XWiki", e.getId()));
    e.setBody(StringUtils.left(message, 2000));
    e.setType(messageType);
    return e;
}
Also used : Event(org.xwiki.eventstream.Event) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

Event (org.xwiki.eventstream.Event)60 Test (org.junit.Test)31 DocumentReference (org.xwiki.model.reference.DocumentReference)21 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)20 CompositeEvent (org.xwiki.notifications.CompositeEvent)17 ArrayList (java.util.ArrayList)7 Query (org.xwiki.query.Query)7 Date (java.util.Date)6 Expectations (org.jmock.Expectations)6 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)5 QueryException (org.xwiki.query.QueryException)5 ObjectReference (org.xwiki.model.reference.ObjectReference)4 HashMap (java.util.HashMap)3 WikiReference (org.xwiki.model.reference.WikiReference)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)2 EventStatus (org.xwiki.eventstream.EventStatus)2 EventStream (org.xwiki.eventstream.EventStream)2 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2