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);
}
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;
}
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());
}
}
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);
}
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;
}
Aggregations