Search in sources :

Example 1 with Page

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()));
}
Also used : PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) GetDeprecatedEntitiesResult(edu.stanford.bmir.protege.web.shared.entity.GetDeprecatedEntitiesResult) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) Nonnull(javax.annotation.Nonnull)

Example 2 with Page

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);
}
Also used : EntityType(org.semanticweb.owlapi.model.EntityType) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) EntitySearchResult(edu.stanford.bmir.protege.web.shared.search.EntitySearchResult) PerformEntitySearchResult(edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchResult) PerformEntitySearchResult(edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchResult) Nonnull(javax.annotation.Nonnull)

Example 3 with 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);
}
Also used : DiffElement(edu.stanford.bmir.protege.web.shared.diff.DiffElement) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) ProjectChange(edu.stanford.bmir.protege.web.shared.change.ProjectChange) Revision2DiffElementsTranslator(edu.stanford.bmir.protege.web.server.diff.Revision2DiffElementsTranslator) OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) ImmutableList(com.google.common.collect.ImmutableList)

Example 4 with Page

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());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) RootOntology(edu.stanford.bmir.protege.web.server.inject.project.RootOntology) LoggerFactory(org.slf4j.LoggerFactory) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) Inject(javax.inject.Inject) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) RenderingManager(edu.stanford.bmir.protege.web.server.renderer.RenderingManager) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) Imports(org.semanticweb.owlapi.model.parameters.Imports) Logger(org.slf4j.Logger) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) VIEW_PROJECT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) Pager(edu.stanford.bmir.protege.web.server.pagination.Pager) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) GetIndividualsAction(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsAction) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) BROWSING(edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) Nonnull(javax.annotation.Nonnull)

Aggregations

Page (edu.stanford.bmir.protege.web.shared.pagination.Page)4 PageRequest (edu.stanford.bmir.protege.web.shared.pagination.PageRequest)3 Nonnull (javax.annotation.Nonnull)3 ImmutableList (com.google.common.collect.ImmutableList)1 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)1 Revision2DiffElementsTranslator (edu.stanford.bmir.protege.web.server.diff.Revision2DiffElementsTranslator)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 BROWSING (edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING)1 Pager (edu.stanford.bmir.protege.web.server.pagination.Pager)1 RenderingManager (edu.stanford.bmir.protege.web.server.renderer.RenderingManager)1 BuiltInAction (edu.stanford.bmir.protege.web.shared.access.BuiltInAction)1 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)1 ProjectChange (edu.stanford.bmir.protege.web.shared.change.ProjectChange)1 DiffElement (edu.stanford.bmir.protege.web.shared.diff.DiffElement)1 GetDeprecatedEntitiesResult (edu.stanford.bmir.protege.web.shared.entity.GetDeprecatedEntitiesResult)1 OWLClassData (edu.stanford.bmir.protege.web.shared.entity.OWLClassData)1 OWLNamedIndividualData (edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData)1 GetIndividualsAction (edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsAction)1