Search in sources :

Example 16 with SortInfo

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);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 17 with SortInfo

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo)

Example 18 with SortInfo

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);
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) Page(org.jboss.pnc.dto.response.Page) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo)

Example 19 with SortInfo

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();
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo)

Example 20 with SortInfo

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));
}
Also used : Node(cz.jirutka.rsql.parser.ast.Node) EmptySortInfo(org.jboss.pnc.datastore.limits.rsql.EmptySortInfo) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) EmptySortInfo(org.jboss.pnc.datastore.limits.rsql.EmptySortInfo)

Aggregations

SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)20 BuildRecord (org.jboss.pnc.model.BuildRecord)9 Test (org.junit.Test)9 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)8 DefaultPageInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo)7 DefaultSortInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)5 ArrayList (java.util.ArrayList)3 Build (org.jboss.pnc.dto.Build)3 Page (org.jboss.pnc.dto.response.Page)3 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)2 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)2 Node (cz.jirutka.rsql.parser.ast.Node)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EmptySortInfo (org.jboss.pnc.datastore.limits.rsql.EmptySortInfo)1 MergeIterator (org.jboss.pnc.facade.util.MergeIterator)1 BuildRecordPredicates.temporaryBuild (org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild)1 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)1