use of edu.stanford.bmir.protege.web.shared.project.ProjectId 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