use of edu.stanford.bmir.protege.web.shared.event.EventTag 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);
}
use of edu.stanford.bmir.protege.web.shared.event.EventTag in project webprotege by protegeproject.
the class CreateEntityDiscussionThreadHandler method execute.
@Nonnull
@Override
public CreateEntityDiscussionThreadResult execute(@Nonnull CreateEntityDiscussionThreadAction action, @Nonnull ExecutionContext executionContext) {
String rawComment = action.getComment();
CommentRenderer commentRenderer = new CommentRenderer();
String renderedComment = commentRenderer.renderComment(rawComment);
UserId commentingUser = executionContext.getUserId();
Comment comment = new Comment(CommentId.create(), commentingUser, System.currentTimeMillis(), Optional.empty(), rawComment, renderedComment);
OWLEntity entity = action.getEntity();
EntityDiscussionThread thread = new EntityDiscussionThread(ThreadId.create(), action.getProjectId(), entity, Status.OPEN, ImmutableList.of(comment));
repository.saveThread(thread);
EventTag startTag = eventManager.getCurrentTag();
eventManager.postEvent(new DiscussionThreadCreatedEvent(thread));
int commentCount = repository.getCommentsCount(projectId, entity);
int openCommentCount = repository.getOpenCommentsCount(projectId, entity);
Optional<OWLEntityData> rendering = Optional.of(renderer.getRendering(entity));
eventManager.postEvent(new CommentPostedEvent(projectId, thread.getId(), comment, rendering, commentCount, openCommentCount));
EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(startTag);
setOutNotifications(thread, comment);
List<EntityDiscussionThread> threads = repository.findThreads(projectId, entity);
return new CreateEntityDiscussionThreadResult(ImmutableList.copyOf(threads), eventList);
}
Aggregations