use of edu.stanford.bmir.protege.web.shared.pagination.Page 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.Page 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.Page in project webprotege by protegeproject.
the class ProjectChangesManager method getProjectChangesForRevision.
private void getProjectChangesForRevision(Revision revision, Optional<OWLEntity> subject, ImmutableList.Builder<ProjectChange> changesBuilder) {
if (subject.isPresent() && !entitiesByRevisionCache.containsEntity(revision, subject.get())) {
return;
}
Map<Optional<IRI>, List<OWLOntologyChangeRecord>> recordsBySubject = getChangeRecordsBySubject(revision);
List<OWLOntologyChangeRecord> limitedRecords = new ArrayList<>();
final int totalChanges;
if (subject.isPresent()) {
List<OWLOntologyChangeRecord> records = recordsBySubject.get(subject.map(OWLEntity::getIRI));
if (records == null) {
// Nothing in this revision that changes the subject
return;
}
totalChanges = records.size();
limitedRecords.addAll(records);
} else {
totalChanges = revision.getSize();
for (Map.Entry<Optional<IRI>, List<OWLOntologyChangeRecord>> entry : recordsBySubject.entrySet()) {
limitedRecords.addAll(entry.getValue());
if (limitedRecords.size() >= DEFAULT_CHANGE_LIMIT) {
break;
}
}
}
Revision2DiffElementsTranslator translator = new Revision2DiffElementsTranslator(ontologyIRIShortFormProvider);
List<DiffElement<String, OWLOntologyChangeRecord>> axiomDiffElements = translator.getDiffElementsFromRevision(limitedRecords);
sortDiff(axiomDiffElements);
List<DiffElement<String, SafeHtml>> renderedDiffElements = renderDiffElements(axiomDiffElements);
int pageElements = renderedDiffElements.size();
int pageCount;
if (pageElements == 0) {
pageCount = 1;
} else {
pageCount = totalChanges / pageElements + (totalChanges % pageElements);
}
Page<DiffElement<String, SafeHtml>> page = new Page<>(1, pageCount, renderedDiffElements, totalChanges);
ProjectChange projectChange = new ProjectChange(revision.getRevisionNumber(), revision.getUserId(), revision.getTimestamp(), revision.getHighLevelDescription(), totalChanges, page);
changesBuilder.add(projectChange);
}
use of edu.stanford.bmir.protege.web.shared.pagination.Page 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