use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.
the class BuildIteratorTest method testBuildIterator.
@Test
public void testBuildIterator() {
SortInfo sortInfo = mock(SortInfo.class);
Predicate<BuildRecord> predicate = mock(Predicate.class);
mockRepository(sortInfo, predicate);
BuildProviderImpl.BuildIterator bit;
List<Integer> ret;
bit = provider.new BuildIterator(1, 10, 1, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
Build next = bit.next();
System.out.println("next: " + next);
ret.add(Integer.valueOf(next.getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 10, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(7, 12, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(7, 8, 9, 10, 11, 12), ret);
}
use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.
the class BuildProviderImplTest method testBuildIterator.
public void testBuildIterator() {
SortInfo sortInfo = mock(SortInfo.class);
Predicate<BuildRecord> predicate = mock(Predicate.class);
mockRepository(sortInfo, predicate);
BuildProviderImpl.BuildIterator bit;
List<Integer> ret;
bit = provider.new BuildIterator(1, 10, 1, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
Build next = bit.next();
System.out.println("next: " + next);
ret.add(Integer.valueOf(next.getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 10, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(7, 12, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(7, 8, 9, 10, 11, 12), ret);
}
use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo 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);
}
use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.
the class BuildProviderImpl method readLatestFinishedBuild.
private Optional<Build> readLatestFinishedBuild(Predicate<BuildRecord> predicate) {
PageInfo pageInfo = this.pageInfoProducer.getPageInfo(0, 1);
SortInfo sortInfo = this.sortInfoProducer.getSortInfo(SortInfo.SortingDirection.DESC, "submitTime");
List<BuildRecord> buildRecords = repository.queryWithPredicates(pageInfo, sortInfo, predicate);
return buildRecords.stream().map(mapper::toDTO).findFirst();
}
use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.
the class RSQLProducerImpl method getSortInfo.
@Override
public <DB extends GenericEntity<?>> SortInfo getSortInfo(Class<DB> type, String rsql) {
if (rsql == null || rsql.isEmpty()) {
return new EmptySortInfo();
}
if (!rsql.startsWith(FIXED_START_OF_SORTING_EXPRESSION)) {
rsql = FIXED_START_OF_SORTING_EXPRESSION + rsql;
}
Node rootNode = sortParser.parse(preprocessRSQL(rsql));
Function<RSQLSelectorPath, String> toPath = (RSQLSelectorPath selector) -> mapper.toPath(type, selector);
return (SortInfo) rootNode.accept(new SortRSQLNodeTraveller(toPath));
}
Aggregations