use of org.jboss.pnc.dto.response.Page in project pnc by project-ncl.
the class ProductMilestoneProviderImpl method getMilestonesOfArtifact.
@Override
public Page<MilestoneInfo> getMilestonesOfArtifact(String artifactId, int pageIndex, int pageSize) {
CriteriaBuilder cb = em.getCriteriaBuilder();
Optional<Integer> builtIn = getMilestoneIdByBuildRecord(cb, artifactId);
List<Integer> dependencyOf = getDependentMilestoneIds(cb, artifactId);
Set<Integer> milestoneIds = new HashSet<>(dependencyOf);
builtIn.ifPresent(milestoneIds::add);
// some builds are not in a milestone and so it gives us null
milestoneIds.remove(null);
if (milestoneIds.isEmpty()) {
return new Page<>();
}
CriteriaQuery<Tuple> query = milestoneInfoQuery(cb, milestoneIds);
int offset = pageIndex * pageSize;
List<MilestoneInfo> milestones = em.createQuery(query).setMaxResults(pageSize).setFirstResult(offset).getResultList().stream().map(m -> mapTupleToMilestoneInfo(m, builtIn)).collect(Collectors.toList());
return new Page<>(pageIndex, pageSize, milestoneIds.size(), milestones);
}
use of org.jboss.pnc.dto.response.Page in project bacon by project-ncl.
the class ProductTest method shouldListProducts.
@Test
@Order(2)
void shouldListProducts() throws JsonProcessingException {
Assumptions.assumeTrue(productId != null);
Product response = Product.builder().id(productId).name(PRODUCT_NAME_PREFIX + "suffix").build();
Page<Product> responsePage = new Page<>(0, 50, 1, Collections.singleton(response));
wmock.list(PRODUCT, responsePage);
Product[] products = executeAndDeserialize(Product[].class, "pnc", "product", "list");
assertThat(products).extracting(Product::getId).contains(productId);
}
use of org.jboss.pnc.dto.response.Page in project pnc by project-ncl.
the class BuildProviderImplTest method testGetAll.
@Test
public void testGetAll() throws InterruptedException {
BuildRecord buildRecord1 = mockBuildRecord();
// make sure new start time is in the next millisecond
Thread.sleep(1L);
BuildRecord buildRecord2 = mockBuildRecord();
// make sure new start time is in the next millisecond
Thread.sleep(1L);
BuildRecord buildRecord3 = mockBuildRecord();
Page<Build> all = provider.getAll(0, 10, null, null);
assertThat(all.getContent()).hasSize(3).haveExactly(1, new Condition<>(b -> buildRecord1.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present")).haveExactly(1, new Condition<>(b -> buildRecord2.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present")).haveExactly(1, new Condition<>(b -> buildRecord3.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present"));
}
use of org.jboss.pnc.dto.response.Page in project pnc by project-ncl.
the class DeliverableAnalyzerOperationProviderImplTest method testGetAll.
@Test
public void testGetAll() throws InterruptedException {
DeliverableAnalyzerOperation operation1 = mockDeliverableAnalyzerOperation();
// make sure new start time is in the next millisecond
Thread.sleep(1L);
DeliverableAnalyzerOperation operation2 = mockDeliverableAnalyzerOperation();
// make sure new start time is in the next millisecond
Thread.sleep(1L);
DeliverableAnalyzerOperation operation3 = mockDeliverableAnalyzerOperation();
Page<org.jboss.pnc.dto.DeliverableAnalyzerOperation> all = provider.getAll(0, 10, null, null);
assertThat(all.getContent()).hasSize(3).haveExactly(1, new Condition<>(op -> operation1.getId().getId().equals(op.getId()), "Operation 1 present")).haveExactly(1, new Condition<>(op -> operation2.getId().getId().equals(op.getId()), "Operation 2 present")).haveExactly(1, new Condition<>(op -> operation3.getId().getId().equals(op.getId()), "Operation 3 present"));
}
use of org.jboss.pnc.dto.response.Page in project pnc by project-ncl.
the class AbstractProvider method queryForCollection.
@Override
public Page<DTO> queryForCollection(int pageIndex, int pageSize, String sortingRsql, String query, Predicate<DB>... predicates) {
Predicate<DB> rsqlPredicate = rsqlPredicateProducer.getCriteriaPredicate(type, query);
PageInfo pageInfo = pageInfoProducer.getPageInfo(pageIndex, pageSize);
SortInfo sortInfo = rsqlPredicateProducer.getSortInfo(type, sortingRsql);
List<DB> collection = repository.queryWithPredicates(pageInfo, sortInfo, ObjectArrays.concat(rsqlPredicate, predicates));
int totalHits = repository.count(ObjectArrays.concat(rsqlPredicate, predicates));
int totalPages = (totalHits + pageSize - 1) / pageSize;
List<DTO> content = nullableStreamOf(collection).map(mapper::toDTO).collect(Collectors.toList());
return new Page<>(pageIndex, pageSize, totalPages, totalHits, content);
}
Aggregations