use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo in project pnc by project-ncl.
the class BuildRecordRepositoryImpl method getAnyLatestSuccessfulBuildRecordWithBuildConfig.
@Override
public BuildRecord getAnyLatestSuccessfulBuildRecordWithBuildConfig(Integer configurationId, boolean temporaryBuild) {
PageInfo pageInfo = new DefaultPageInfo(0, 1);
SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationId(configurationId), withSuccess(), includeTemporary(temporaryBuild));
if (buildRecords.size() == 0) {
return null;
} else {
return buildRecords.get(0);
}
}
use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo in project pnc by project-ncl.
the class BuildRecordRepositoryImpl method getPreferredLatestSuccessfulBuildRecordWithRevision.
@Override
public BuildRecord getPreferredLatestSuccessfulBuildRecordWithRevision(IdRev idRev, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
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(idRev, temporaryBuild, alignmentPreference));
if (buildRecords.size() == 0) {
return null;
} else {
return buildRecords.get(0);
}
}
use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo in project pnc by project-ncl.
the class BuildRecordRepositoryImpl method getPreferredLatestSuccessfulBuildRecordWithBuildConfig.
@Override
public BuildRecord getPreferredLatestSuccessfulBuildRecordWithBuildConfig(Integer configurationId, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
PageInfo pageInfo = new DefaultPageInfo(0, 1);
SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationId(configurationId), withSuccess(), includeTemporary(configurationId, temporaryBuild, alignmentPreference));
if (buildRecords.size() == 0) {
return null;
} else {
return buildRecords.get(0);
}
}
use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo in project pnc by project-ncl.
the class BuildProviderImpl method getByAttribute.
public Page<Build> getByAttribute(BuildPageInfo buildPageInfo, Map<String, String> attributeConstraints) {
Set<Predicate<BuildRecord>> predicates = new HashSet<>();
for (Map.Entry<String, String> entry : attributeConstraints.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key.startsWith("!")) {
predicates.add(withoutAttribute(key.substring(1)));
} else {
predicates.add(withAttribute(key, value));
}
}
Predicate<BuildRecord> queryPredicate = rsqlPredicateProducer.getCriteriaPredicate(BuildRecord.class, buildPageInfo.getQ());
predicates.add(queryPredicate);
Predicate<BuildRecord>[] predicatesArray = predicates.toArray(new Predicate[predicates.size()]);
PageInfo pageInfo = toPageInfo(buildPageInfo);
SortInfo sortInfo = rsqlPredicateProducer.getSortInfo(type, buildPageInfo.getSort());
List<BuildRecord> resultList = ((BuildRecordRepository) BuildProviderImpl.this.repository).queryWithPredicatesUsingCursor(pageInfo, sortInfo, predicatesArray);
int hits = repository.count(predicatesArray);
return new Page<>(buildPageInfo.getPageIndex(), buildPageInfo.getPageSize(), hits, resultList.stream().map(b -> mapper.toDTO(b)).collect(Collectors.toList()));
}
use of org.jboss.pnc.spi.datastore.repositories.api.PageInfo in project pnc by project-ncl.
the class PageInfoTest method shouldReturnCustomLimits.
@Test
public void shouldReturnCustomLimits() throws Exception {
// given
int size = 12;
int offset = 13;
// when
PageInfo testedLimits = defaultPageInfoProducer.getPageInfo(offset, size);
// then
assertThat(testedLimits.getPageOffset()).isEqualTo(13);
assertThat(testedLimits.getPageSize()).isEqualTo(12);
}
Aggregations