Search in sources :

Example 6 with BuildPageInfo

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()));
}
Also used : Page(org.jboss.pnc.dto.response.Page) BuildRecord(org.jboss.pnc.model.BuildRecord) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) 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) Map(java.util.Map) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) HashSet(java.util.HashSet)

Example 7 with BuildPageInfo

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());
}
Also used : Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 8 with BuildPageInfo

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());
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) Test(org.junit.Test)

Example 9 with BuildPageInfo

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());
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) Test(org.junit.Test)

Example 10 with BuildPageInfo

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());
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo)

Aggregations

BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)10 Build (org.jboss.pnc.dto.Build)9 Test (org.junit.Test)8 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)6 BuildRecord (org.jboss.pnc.model.BuildRecord)4 Base32LongID (org.jboss.pnc.model.Base32LongID)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Page (org.jboss.pnc.dto.response.Page)1 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)1 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)1 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)1 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)1 DefaultPageInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo)1