Search in sources :

Example 6 with PageInfo

use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo 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 7 with PageInfo

use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo 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)

Example 8 with PageInfo

use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo 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 9 with PageInfo

use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo 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)

Aggregations

PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)9 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)8 BuildRecord (org.jboss.pnc.model.BuildRecord)7 DefaultPageInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo)7 DefaultSortInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)5 Page (org.jboss.pnc.dto.response.Page)2 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)1 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)1 Test (org.junit.Test)1