Search in sources :

Example 11 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldCreateProperComparatorAndSortWithTwoDimensions.

@Test
public void shouldCreateProperComparatorAndSortWithTwoDimensions() throws Exception {
    // given
    String sorting = "=asc=(field1,field2)";
    List<SortTester> tester = new ArrayList<>();
    tester.add(new SortTester("a", "b"));
    tester.add(new SortTester("a", "a"));
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    List<String> sorted = tester.stream().sorted(testedSorting.getComparator()).map(SortTester::getField2).collect(Collectors.toList());
    // then
    assertThat(sorted).containsExactly("a", "b");
}
Also used : ArrayList(java.util.ArrayList) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 12 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldParseSimpleAscendingRSQL.

@Test
public void shouldParseSimpleAscendingRSQL() throws Exception {
    // given
    String sorting = "sort=asc=id";
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    // then
    assertThat(testedSorting.getFields()).containsExactly("id");
    assertThat(testedSorting.getDirection()).isEqualTo(SortInfo.SortingDirection.ASC);
}
Also used : SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 13 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldAllowSortingStringWithoutSortAtTheBeginning.

@Test
public void shouldAllowSortingStringWithoutSortAtTheBeginning() throws Exception {
    // given
    String sorting = "=asc=(id,name)";
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    // then
    assertThat(testedSorting.getFields()).containsExactly("id", "name");
    assertThat(testedSorting.getDirection()).isEqualTo(SortInfo.SortingDirection.ASC);
}
Also used : SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 14 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getAnyLatestSuccessfulBuildRecordWithRevision.

@Override
public BuildRecord getAnyLatestSuccessfulBuildRecordWithRevision(IdRev idRev, boolean temporaryBuild) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationIdRev(idRev), withSuccess(), includeTemporary(temporaryBuild));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Example 15 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getLatestSuccessfulBuildRecord.

@Override
public BuildRecord getLatestSuccessfulBuildRecord(IdRev idRev, boolean temporaryBuild) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.id.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationIdRev(idRev), withSuccess(), includeTemporary(idRev, temporaryBuild));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

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