use of edu.stanford.bmir.protege.web.shared.event.EventList in project webprotege by protegeproject.
the class EventManager method getEventsFromTag.
/**
* Gets the live events posted to this manager which have a tag greater or equal to the specified tag. Events are coalesced
* where possible. That is, if event E1 is posted at time t1 and event E2 is posted at time t2 and E1 and E2 are
* equal then a list containing only E2 will be returned.
* @param fromTag The tag that denotes the point after which events will be retrieved. Not {@code null}.
* @return The list of live events that happened since the specified tag. Not {@code null}.
* @throws NullPointerException if {@code tag} is {@code null}.
*/
public EventList<E> getEventsFromTag(EventTag fromTag) {
checkNotNull(fromTag, "tag must not be null");
List<E> resultList = new ArrayList<>();
final EventTag curTag;
try {
readLock.lock();
curTag = currentTag;
for (EventBucket bucket : eventQueue) {
if (bucket.getTag().isGreaterOrEqualTo(fromTag)) {
resultList.addAll(bucket.getEvents());
}
}
} finally {
readLock.unlock();
}
final EventTag toTag = curTag.next();
if (resultList.isEmpty()) {
return new EventList<>(fromTag, toTag);
}
// Prune duplicates
LinkedHashSet<E> events = new LinkedHashSet<>(resultList);
return new EventList<>(fromTag, events, toTag);
}
use of edu.stanford.bmir.protege.web.shared.event.EventList in project webprotege by protegeproject.
the class SetDiscussionThreadStatusHandler method execute.
@Nonnull
@Override
public SetDiscussionThreadStatusResult execute(@Nonnull SetDiscussionThreadStatusAction action, @Nonnull ExecutionContext executionContext) {
EventTag fromTag = eventManager.getCurrentTag();
ThreadId threadId = action.getThreadId();
Status status = action.getStatus();
Optional<EntityDiscussionThread> thread = repository.setThreadStatus(threadId, status);
int openComments = thread.map(t -> repository.getOpenCommentsCount(projectId, t.getEntity())).orElse(-1);
eventManager.postEvent(new DiscussionThreadStatusChangedEvent(projectId, threadId, thread.map(EntityDiscussionThread::getEntity), openComments, status));
EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(fromTag);
return new SetDiscussionThreadStatusResult(threadId, status, eventList);
}
use of edu.stanford.bmir.protege.web.shared.event.EventList in project webprotege by protegeproject.
the class EditCommentActionHandler method execute.
@Nonnull
@Override
public EditCommentResult execute(@Nonnull EditCommentAction action, @Nonnull ExecutionContext executionContext) {
EventTag fromTag = eventManager.getCurrentTag();
Optional<EntityDiscussionThread> thread = repository.getThread(action.getThreadId());
if (!thread.isPresent()) {
throw new RuntimeException("Invalid comment thread");
}
EntityDiscussionThread t = thread.get();
String renderedComment = new CommentRenderer().renderComment(action.getBody());
Optional<Comment> updatedComment = t.getComments().stream().filter(c -> c.getId().equals(action.getCommentId())).limit(1).map(c -> new Comment(c.getId(), c.getCreatedBy(), c.getCreatedAt(), Optional.of(System.currentTimeMillis()), action.getBody(), renderedComment)).peek(c -> repository.updateComment(t.getId(), c)).findFirst();
updatedComment.ifPresent(comment -> eventManager.postEvent(new CommentUpdatedEvent(projectId, t.getId(), comment)));
EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(fromTag);
return new EditCommentResult(updatedComment, eventList);
}
Aggregations