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);
}
Aggregations