use of edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData in project webprotege by protegeproject.
the class GetCommentedEntitiesActionHandler method execute.
@Nonnull
@Override
public GetCommentedEntitiesResult execute(@Nonnull GetCommentedEntitiesAction action, @Nonnull ExecutionContext executionContext) {
PageRequest request = action.getPageRequest();
List<EntityDiscussionThread> allThreads = repository.getThreadsInProject(action.getProjectId());
Map<OWLEntity, List<EntityDiscussionThread>> commentsByEntity = allThreads.stream().collect(groupingBy(EntityDiscussionThread::getEntity));
List<CommentedEntityData> result = new ArrayList<>();
commentsByEntity.forEach((entity, threads) -> {
if (rootOntology.containsEntityInSignature(entity)) {
int totalThreadCount = threads.size();
int openThreadCount = (int) threads.stream().filter(thread -> thread.getStatus().isOpen()).count();
List<Comment> entityComments = threads.stream().flatMap(thread -> thread.getComments().stream()).collect(toList());
Comment lastComment = entityComments.stream().max(comparing(c -> c.getUpdatedAt().orElse(c.getCreatedAt()))).get();
List<UserId> participants = entityComments.stream().map(Comment::getCreatedBy).collect(toList());
result.add(new CommentedEntityData(renderer.getRendering(entity), totalThreadCount, openThreadCount, entityComments.size(), lastComment.getUpdatedAt().orElse(lastComment.getCreatedAt()), lastComment.getCreatedBy(), participants));
}
});
if (action.getSortingKey() == SortingKey.SORT_BY_ENTITY) {
result.sort(byEntity);
} else {
result.sort(byLastModified);
}
Pager<CommentedEntityData> pager = Pager.getPagerForPageSize(result, request.getPageSize());
return new GetCommentedEntitiesResult(action.getProjectId(), pager.getPage(request.getPageNumber()));
}
Aggregations