Search in sources :

Example 1 with CommentedEntityData

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()));
}
Also used : HasGetRendering(edu.stanford.bmir.protege.web.server.mansyntax.render.HasGetRendering) CommentedEntityData.byLastModified(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byLastModified) edu.stanford.bmir.protege.web.shared.issues(edu.stanford.bmir.protege.web.shared.issues) RootOntology(edu.stanford.bmir.protege.web.server.inject.project.RootOntology) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Pager(edu.stanford.bmir.protege.web.server.pagination.Pager) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CommentedEntityData.byEntity(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byEntity) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) Map(java.util.Map) CommentedEntityData(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Comparator.comparing(java.util.Comparator.comparing) Nonnull(javax.annotation.Nonnull) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ArrayList(java.util.ArrayList) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CommentedEntityData(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData) Nonnull(javax.annotation.Nonnull)

Aggregations

AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)1 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)1 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)1 RootOntology (edu.stanford.bmir.protege.web.server.inject.project.RootOntology)1 HasGetRendering (edu.stanford.bmir.protege.web.server.mansyntax.render.HasGetRendering)1 Pager (edu.stanford.bmir.protege.web.server.pagination.Pager)1 CommentedEntityData (edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData)1 CommentedEntityData.byEntity (edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byEntity)1 CommentedEntityData.byLastModified (edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byLastModified)1 edu.stanford.bmir.protege.web.shared.issues (edu.stanford.bmir.protege.web.shared.issues)1 PageRequest (edu.stanford.bmir.protege.web.shared.pagination.PageRequest)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 ArrayList (java.util.ArrayList)1 Comparator.comparing (java.util.Comparator.comparing)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 Collectors.toList (java.util.stream.Collectors.toList)1 Nonnull (javax.annotation.Nonnull)1 Inject (javax.inject.Inject)1