use of edu.stanford.bmir.protege.web.shared.pagination.PageRequest in project webprotege by protegeproject.
the class GetCollectionItemsActionHandler method execute.
@Nonnull
@Override
public GetCollectionItemsResult execute(@Nonnull GetCollectionItemsAction action, @Nonnull ExecutionContext executionContext) {
PageRequest pageRequest = action.getPageRequest();
List<CollectionItem> elementIdList = repository.list(action.getCollectionId(), pageRequest.getSkip(), pageRequest.getPageSize());
long totalItemsCount = repository.count(action.getCollectionId());
int pageCount = (int) (totalItemsCount / pageRequest.getPageSize()) + 1;
return new GetCollectionItemsResult(new Page<>(pageRequest.getPageNumber(), pageCount, elementIdList, elementIdList.size()), pageRequest);
}
use of edu.stanford.bmir.protege.web.shared.pagination.PageRequest in project webprotege by protegeproject.
the class GetDeprecatedEntitiesActionHandler method execute.
@Nonnull
@Override
public GetDeprecatedEntitiesResult execute(@Nonnull GetDeprecatedEntitiesAction action, @Nonnull ExecutionContext executionContext) {
PageRequest pageRequest = action.getPageRequest();
Optional<Page<OWLEntityData>> page = entityStream(action.getEntityTypes(), rootOntology, Imports.INCLUDED).filter(deprecatedEntityChecker::isDeprecated).map(renderingManager::getRendering).sorted().collect(toPageNumber(pageRequest.getPageNumber()).forPageSize(pageRequest.getPageSize()));
return new GetDeprecatedEntitiesResult(page.orElse(Page.emptyPage()));
}
use of edu.stanford.bmir.protege.web.shared.pagination.PageRequest in project webprotege by protegeproject.
the class PerformEntitySearchActionHandler method execute.
@Nonnull
@Override
public PerformEntitySearchResult execute(@Nonnull PerformEntitySearchAction action, @Nonnull ExecutionContext executionContext) {
Set<EntityType<?>> entityTypes = action.getEntityTypes();
String searchString = action.getSearchString();
EntitySearcher entitySearcher = EntitySearcher.get(projectId, tagsManager, executionContext.getUserId(), () -> entityStream(entityTypes, rootOntology, Imports.INCLUDED), renderer, entityTypes, searchString);
PageRequest pageRequest = action.getPageRequest();
int pageSize = pageRequest.getPageSize();
entitySearcher.setLimit(pageSize);
int pageNumber = pageRequest.getPageNumber();
entitySearcher.setSkip((pageNumber - 1) * pageSize);
entitySearcher.invoke();
int totalSearchResults = entitySearcher.getSearchResultsCount();
List<EntitySearchResult> results = entitySearcher.getResults();
int pageCount = (totalSearchResults / pageSize) + 1;
Page<EntitySearchResult> page = new Page<>(pageNumber > pageCount ? 1 : pageNumber, pageCount, results, totalSearchResults);
return new PerformEntitySearchResult(totalSearchResults, page);
}
use of edu.stanford.bmir.protege.web.shared.pagination.PageRequest 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()));
}
use of edu.stanford.bmir.protege.web.shared.pagination.PageRequest in project webprotege by protegeproject.
the class GetIndividualsActionHandler method execute.
@Nonnull
@Override
public GetIndividualsResult execute(@Nonnull GetIndividualsAction action, @Nonnull ExecutionContext executionContext) {
Stream<OWLNamedIndividual> stream;
if (action.getType().isOWLThing()) {
stream = rootOntology.getIndividualsInSignature(Imports.INCLUDED).stream();
} else {
stream = rootOntology.getImportsClosure().stream().flatMap(o -> o.getClassAssertionAxioms(action.getType()).stream()).map(OWLClassAssertionAxiom::getIndividual).filter(OWLIndividual::isNamed).map(OWLIndividual::asOWLNamedIndividual);
}
Counter counter = new Counter();
List<OWLNamedIndividualData> individualsData = stream.peek(i -> counter.increment()).map(renderingManager::getRendering).filter(i -> {
String searchString = action.getFilterString();
return searchString.isEmpty() || StringUtils.containsIgnoreCase(i.getBrowserText(), searchString);
}).distinct().sorted().collect(toList());
PageRequest pageRequest = action.getPageRequest();
Pager<OWLNamedIndividualData> pager = Pager.getPagerForPageSize(individualsData, pageRequest.getPageSize());
Page<OWLNamedIndividualData> page = pager.getPage(pageRequest.getPageNumber());
OWLClassData type = renderingManager.getRendering(action.getType());
logger.info(BROWSING, "{} {} retrieved instances of {} ({})", projectId, executionContext.getUserId(), action.getType(), renderingManager.getRendering(action.getType()).getBrowserText());
return new GetIndividualsResult(type, page, counter.getCount(), individualsData.size());
}
Aggregations