Search in sources :

Example 11 with Page

use of org.jboss.pnc.dto.response.Page in project pnc by project-ncl.

the class ArtifactProviderImpl method getAllFiltered.

@Override
public Page<ArtifactInfo> getAllFiltered(int pageIndex, int pageSize, Optional<String> identifierPattern, Set<ArtifactQuality> qualities, Optional<RepositoryType> repoType, Set<BuildCategory> buildCategories) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Tuple> query = artifactInfoQuery(cb, identifierPattern, qualities, repoType, buildCategories);
    int offset = pageIndex * pageSize;
    List<ArtifactInfo> artifacts = em.createQuery(query).setMaxResults(pageSize).setFirstResult(offset).getResultList().stream().map(this::mapTupleToArtifactInfo).collect(Collectors.toList());
    Predicate<Artifact>[] predicates = getPredicates(identifierPattern, qualities, repoType, buildCategories);
    int totalHits = repository.count(predicates);
    int totalPages = (totalHits + pageSize - 1) / pageSize;
    return new Page<>(pageIndex, pageSize, totalPages, totalHits, artifacts);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) Page(org.jboss.pnc.dto.response.Page) Tuple(javax.persistence.Tuple) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate)

Aggregations

Page (org.jboss.pnc.dto.response.Page)11 Date (java.util.Date)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)4 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)4 Test (org.junit.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 BuildRecord (org.jboss.pnc.model.BuildRecord)3 Instant (java.time.Instant)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 EntityManager (javax.persistence.EntityManager)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Condition (org.assertj.core.api.Condition)2