Search in sources :

Example 1 with ArtifactInfo

use of org.jboss.pnc.dto.response.ArtifactInfo in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsFilteredByIdentifier.

@Test
public void testGetAllArtifactsFilteredByIdentifier() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ArtifactInfo> result;
    result = client.getAllFiltered("*demo:*:jar:*", null, null);
    assertThat(result).allSatisfy(a -> assertThat(a.getIdentifier().contains("demo:") && a.getIdentifier().contains(":jar:")));
    result = client.getAllFiltered("demo:built-artifact11:pom:*", null, null);
    // from DatabaseDataInitializer
    assertThat(result).hasSize(1);
    result = client.getAllFiltered("demo:built-artifact22:jar:1.0", null, null);
    // from DatabaseDataInitializer
    assertThat(result).hasSize(1);
}
Also used : ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) ArtifactClient(org.jboss.pnc.client.ArtifactClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with ArtifactInfo

use of org.jboss.pnc.dto.response.ArtifactInfo in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsFilteredByQualitiesList.

@Test
public void testGetAllArtifactsFilteredByQualitiesList() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ArtifactInfo> result;
    result = client.getAllFiltered(null, new HashSet<>(Arrays.asList(ArtifactQuality.NEW)), null);
    assertThat(result).allSatisfy(a -> assertThat(a.getArtifactQuality().equals(ArtifactQuality.NEW)));
    result = client.getAllFiltered(null, new HashSet<>(Arrays.asList(ArtifactQuality.VERIFIED, ArtifactQuality.DELETED)), null);
    // from DatabaseDataInitializer
    assertThat(result).hasSize(2);
}
Also used : ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) ArtifactClient(org.jboss.pnc.client.ArtifactClient) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with ArtifactInfo

use of org.jboss.pnc.dto.response.ArtifactInfo in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsFilteredByBuildCategories.

@Test
public void testGetAllArtifactsFilteredByBuildCategories() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ArtifactInfo> result;
    result = client.getAllFiltered(null, null, null, new HashSet<>(Arrays.asList(BuildCategory.STANDARD)));
    assertThat(result).allSatisfy(a -> assertThat(a.getBuildCategory().equals(BuildCategory.STANDARD)));
    result = client.getAllFiltered(null, null, null, new HashSet<>(Arrays.asList(BuildCategory.SERVICE)));
    // from DatabaseDataInitializer
    assertThat(result).hasSize(2);
}
Also used : ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) ArtifactClient(org.jboss.pnc.client.ArtifactClient) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with ArtifactInfo

use of org.jboss.pnc.dto.response.ArtifactInfo in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsFilteredByRepoType.

@Test
public void testGetAllArtifactsFilteredByRepoType() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ArtifactInfo> result;
    RepositoryType type = RepositoryType.NPM;
    result = client.getAllFiltered(null, null, type);
    // from DatabaseDataInitializer
    assertThat(result).hasSize(2).allSatisfy(a -> assertThat(a.getRepositoryType().equals(type)));
}
Also used : ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) RepositoryType(org.jboss.pnc.enums.RepositoryType) ArtifactClient(org.jboss.pnc.client.ArtifactClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 5 with ArtifactInfo

use of org.jboss.pnc.dto.response.ArtifactInfo in project pnc by project-ncl.

the class ArtifactProviderImpl method getAllFiltered.

@Override
public Page<ArtifactInfo> getAllFiltered(int pageIndex, int pageSize, Optional<String> identifierPattern, Set<ArtifactQuality> qualities, Optional<RepositoryType> repoType, Set<BuildCategory> buildCategories) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Tuple> query = artifactInfoQuery(cb, identifierPattern, qualities, repoType, buildCategories);
    int offset = pageIndex * pageSize;
    List<ArtifactInfo> artifacts = em.createQuery(query).setMaxResults(pageSize).setFirstResult(offset).getResultList().stream().map(this::mapTupleToArtifactInfo).collect(Collectors.toList());
    Predicate<Artifact>[] predicates = getPredicates(identifierPattern, qualities, repoType, buildCategories);
    int totalHits = repository.count(predicates);
    int totalPages = (totalHits + pageSize - 1) / pageSize;
    return new Page<>(pageIndex, pageSize, totalPages, totalHits, artifacts);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) Page(org.jboss.pnc.dto.response.Page) Tuple(javax.persistence.Tuple) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate)

Aggregations

ArtifactInfo (org.jboss.pnc.dto.response.ArtifactInfo)5 ArtifactClient (org.jboss.pnc.client.ArtifactClient)4 ContainerTest (org.jboss.pnc.test.category.ContainerTest)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)2 Tuple (javax.persistence.Tuple)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Page (org.jboss.pnc.dto.response.Page)1 RepositoryType (org.jboss.pnc.enums.RepositoryType)1 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)1