use of org.jboss.pnc.facade.providers.api.BuildPageInfo 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.facade.providers.api.BuildPageInfo in project pnc by project-ncl.
the class BuildProviderImplTest method testGetLatestBuild.
@Test
public void testGetLatestBuild() {
// Prepare
mockBuildTask();
mockBuildTask();
mockBuildRecord();
mockBuildTask();
BuildRecord latestBuild = mockBuildRecord();
logger.debug("Task id: {}", latestBuild.getId());
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", true, false, "");
Page<Build> builds = provider.getBuilds(pageInfo);
// Verify
assertEquals(1, builds.getTotalHits());
assertEquals(BuildMapper.idMapper.toDto(latestBuild.getId()), builds.getContent().iterator().next().getId());
}
use of org.jboss.pnc.facade.providers.api.BuildPageInfo in project pnc by project-ncl.
the class BuildProviderImplTest method testFailFilterLikeRunningBuildsByBuildConfigName.
@Test
public void testFailFilterLikeRunningBuildsByBuildConfigName() {
// Given
mockBuildRecord();
mockBuildTask();
String givenBcName = "VeryLongAndComplicatedBcName";
String givenBcNamePattern = "LongAndComplicated*";
BuildTask givenBT = mockBuildTask(givenBcName);
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 2, "", "", false, true, givenBcNamePattern);
Page<Build> builds = provider.getBuilds(pageInfo);
// Then
assertEquals(0, builds.getTotalHits());
}
use of org.jboss.pnc.facade.providers.api.BuildPageInfo in project pnc by project-ncl.
the class BuildProviderImplTest method testGetLatestRunningBuild.
@Test
public void testGetLatestRunningBuild() {
// Prepare
mockBuildTask();
mockBuildTask();
mockBuildRecord();
BuildTask latestRunning = mockBuildTask();
mockBuildRecord();
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", true, true, "");
Page<Build> builds = provider.getBuilds(pageInfo);
// Verify
assertEquals(1, builds.getTotalHits());
assertEquals(latestRunning.getId(), builds.getContent().iterator().next().getId());
}
use of org.jboss.pnc.facade.providers.api.BuildPageInfo in project pnc by project-ncl.
the class BuildProviderImplTest method testPage.
private void testPage(int idx, int size, Base32LongID... ids) {
BuildPageInfo pageInfo = new BuildPageInfo(idx, size, "", "", false, false, "");
Page<Build> builds = provider.getBuilds(pageInfo);
Iterator<Build> it = builds.getContent().iterator();
for (Base32LongID id : ids) {
assertEquals(BuildMapper.idMapper.toDto(id), it.next().getId());
}
assertFalse(it.hasNext());
}
Aggregations