Search in sources :

Example 6 with Page

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

the class ProductMilestoneProviderImpl method getMilestonesOfArtifact.

@Override
public Page<MilestoneInfo> getMilestonesOfArtifact(String artifactId, int pageIndex, int pageSize) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    Optional<Integer> builtIn = getMilestoneIdByBuildRecord(cb, artifactId);
    List<Integer> dependencyOf = getDependentMilestoneIds(cb, artifactId);
    Set<Integer> milestoneIds = new HashSet<>(dependencyOf);
    builtIn.ifPresent(milestoneIds::add);
    // some builds are not in a milestone and so it gives us null
    milestoneIds.remove(null);
    if (milestoneIds.isEmpty()) {
        return new Page<>();
    }
    CriteriaQuery<Tuple> query = milestoneInfoQuery(cb, milestoneIds);
    int offset = pageIndex * pageSize;
    List<MilestoneInfo> milestones = em.createQuery(query).setMaxResults(pageSize).setFirstResult(offset).getResultList().stream().map(m -> mapTupleToMilestoneInfo(m, builtIn)).collect(Collectors.toList());
    return new Page<>(pageIndex, pageSize, milestoneIds.size(), milestones);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProductRelease(org.jboss.pnc.model.ProductRelease) Join(javax.persistence.criteria.Join) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) SetJoin(javax.persistence.criteria.SetJoin) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) ProductMilestonePredicates.withProductVersionId(org.jboss.pnc.spi.datastore.predicates.ProductMilestonePredicates.withProductVersionId) MilestoneInfo(org.jboss.pnc.dto.response.MilestoneInfo) UserService(org.jboss.pnc.facade.util.UserService) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) ProductRelease_(org.jboss.pnc.model.ProductRelease_) ProductVersion(org.jboss.pnc.model.ProductVersion) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ProductVersion_(org.jboss.pnc.model.ProductVersion_) PermitAll(javax.annotation.security.PermitAll) Patterns(org.jboss.pnc.constants.Patterns) BuildRecord_(org.jboss.pnc.model.BuildRecord_) ProductMilestoneRef(org.jboss.pnc.dto.ProductMilestoneRef) Artifact(org.jboss.pnc.model.Artifact) ValidationBuilder(org.jboss.pnc.facade.validation.ValidationBuilder) ProductMilestone_(org.jboss.pnc.model.ProductMilestone_) Set(java.util.Set) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) Product(org.jboss.pnc.model.Product) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) ConflictedEntryValidator(org.jboss.pnc.facade.validation.ConflictedEntryValidator) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) DUPLICATION(org.jboss.pnc.enums.ValidationErrorType.DUPLICATION) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) FORMAT(org.jboss.pnc.enums.ValidationErrorType.FORMAT) Artifact_(org.jboss.pnc.model.Artifact_) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ProductMilestoneRepository(org.jboss.pnc.spi.datastore.repositories.ProductMilestoneRepository) ProductMilestonePredicates.withProductVersionIdAndVersion(org.jboss.pnc.spi.datastore.predicates.ProductMilestonePredicates.withProductVersionIdAndVersion) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) ProductMilestoneProvider(org.jboss.pnc.facade.providers.api.ProductMilestoneProvider) WORK_WITH_TECH_PREVIEW(org.jboss.pnc.facade.providers.api.UserRoles.WORK_WITH_TECH_PREVIEW) WhenUpdating(org.jboss.pnc.dto.validation.groups.WhenUpdating) Root(javax.persistence.criteria.Root) Tuple(javax.persistence.Tuple) ProductMilestoneMapper(org.jboss.pnc.mapper.api.ProductMilestoneMapper) Logger(org.slf4j.Logger) ProductMilestoneReleaseManager(org.jboss.pnc.bpm.causeway.ProductMilestoneReleaseManager) ValidationResponse(org.jboss.pnc.dto.response.ValidationResponse) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Page(org.jboss.pnc.dto.response.Page) Product_(org.jboss.pnc.model.Product_) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) ProductMilestoneCloseResultMapper(org.jboss.pnc.mapper.api.ProductMilestoneCloseResultMapper) BpmModuleConfig(org.jboss.pnc.common.json.moduleconfig.BpmModuleConfig) Sequence(org.jboss.pnc.common.concurrent.Sequence) Collections(java.util.Collections) MilestoneInfo(org.jboss.pnc.dto.response.MilestoneInfo) Page(org.jboss.pnc.dto.response.Page) Tuple(javax.persistence.Tuple) HashSet(java.util.HashSet)

Example 7 with Page

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

the class ProductTest method shouldListProducts.

@Test
@Order(2)
void shouldListProducts() throws JsonProcessingException {
    Assumptions.assumeTrue(productId != null);
    Product response = Product.builder().id(productId).name(PRODUCT_NAME_PREFIX + "suffix").build();
    Page<Product> responsePage = new Page<>(0, 50, 1, Collections.singleton(response));
    wmock.list(PRODUCT, responsePage);
    Product[] products = executeAndDeserialize(Product[].class, "pnc", "product", "list");
    assertThat(products).extracting(Product::getId).contains(productId);
}
Also used : Product(org.jboss.pnc.dto.Product) Page(org.jboss.pnc.dto.response.Page) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) AbstractTest(org.jboss.pnc.bacon.test.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 8 with Page

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

the class BuildProviderImplTest method testGetAll.

@Test
public void testGetAll() throws InterruptedException {
    BuildRecord buildRecord1 = mockBuildRecord();
    // make sure new start time is in the next millisecond
    Thread.sleep(1L);
    BuildRecord buildRecord2 = mockBuildRecord();
    // make sure new start time is in the next millisecond
    Thread.sleep(1L);
    BuildRecord buildRecord3 = mockBuildRecord();
    Page<Build> all = provider.getAll(0, 10, null, null);
    assertThat(all.getContent()).hasSize(3).haveExactly(1, new Condition<>(b -> buildRecord1.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present")).haveExactly(1, new Condition<>(b -> buildRecord2.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present")).haveExactly(1, new Condition<>(b -> buildRecord3.getSubmitTime().toInstant().equals(b.getSubmitTime()), "Build present"));
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) Repository(org.jboss.pnc.spi.datastore.repositories.api.Repository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) UserService(org.jboss.pnc.facade.util.UserService) Graph(org.jboss.pnc.dto.response.Graph) Assert.fail(org.junit.Assert.fail) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) User(org.jboss.pnc.model.User) SortInfoProducer(org.jboss.pnc.spi.datastore.repositories.SortInfoProducer) ResultStatus(org.jboss.pnc.enums.ResultStatus) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Result(org.jboss.pnc.spi.coordinator.Result) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) WireMock.matchingJsonPath(com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath) Base32LongID(org.jboss.pnc.model.Base32LongID) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) HashSet(java.util.HashSet) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Edge(org.jboss.pnc.dto.response.Edge) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) CorruptedDataException(org.jboss.pnc.facade.validation.CorruptedDataException) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Logger(org.slf4j.Logger) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) Test(org.junit.Test) BuildRecord(org.jboss.pnc.model.BuildRecord) Mockito.when(org.mockito.Mockito.when) TemporaryBuildsCleanerAsyncInvoker(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleanerAsyncInvoker) Page(org.jboss.pnc.dto.response.Page) Vertex(org.jboss.pnc.dto.response.Vertex) Consumer(java.util.function.Consumer) Build(org.jboss.pnc.dto.Build) Condition(org.assertj.core.api.Condition) RandomUtils.randInt(org.jboss.pnc.common.util.RandomUtils.randInt) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Condition(org.assertj.core.api.Condition) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 9 with Page

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

the class DeliverableAnalyzerOperationProviderImplTest method testGetAll.

@Test
public void testGetAll() throws InterruptedException {
    DeliverableAnalyzerOperation operation1 = mockDeliverableAnalyzerOperation();
    // make sure new start time is in the next millisecond
    Thread.sleep(1L);
    DeliverableAnalyzerOperation operation2 = mockDeliverableAnalyzerOperation();
    // make sure new start time is in the next millisecond
    Thread.sleep(1L);
    DeliverableAnalyzerOperation operation3 = mockDeliverableAnalyzerOperation();
    Page<org.jboss.pnc.dto.DeliverableAnalyzerOperation> all = provider.getAll(0, 10, null, null);
    assertThat(all.getContent()).hasSize(3).haveExactly(1, new Condition<>(op -> operation1.getId().getId().equals(op.getId()), "Operation 1 present")).haveExactly(1, new Condition<>(op -> operation2.getId().getId().equals(op.getId()), "Operation 2 present")).haveExactly(1, new Condition<>(op -> operation3.getId().getId().equals(op.getId()), "Operation 3 present"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DeliverableAnalyzerOperationRepository(org.jboss.pnc.spi.datastore.repositories.DeliverableAnalyzerOperationRepository) Date(java.util.Date) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Repository(org.jboss.pnc.spi.datastore.repositories.api.Repository) ProgressStatus(org.jboss.pnc.api.enums.ProgressStatus) ProductMilestoneRepository(org.jboss.pnc.spi.datastore.repositories.ProductMilestoneRepository) DeliverableAnalyzerOperation(org.jboss.pnc.model.DeliverableAnalyzerOperation) UserService(org.jboss.pnc.facade.util.UserService) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) User(org.jboss.pnc.model.User) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Logger(org.slf4j.Logger) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) GenericEntity(org.jboss.pnc.model.GenericEntity) DeliverableAnalyzerOperationMapper(org.jboss.pnc.mapper.api.DeliverableAnalyzerOperationMapper) Page(org.jboss.pnc.dto.response.Page) Serializable(java.io.Serializable) Condition(org.assertj.core.api.Condition) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) Base32LongID(org.jboss.pnc.model.Base32LongID) Condition(org.assertj.core.api.Condition) DeliverableAnalyzerOperation(org.jboss.pnc.model.DeliverableAnalyzerOperation) Test(org.junit.Test)

Example 10 with Page

use of org.jboss.pnc.dto.response.Page 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)

Aggregations

Page (org.jboss.pnc.dto.response.Page)11 Date (java.util.Date)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)4 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)4 Test (org.junit.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 BuildRecord (org.jboss.pnc.model.BuildRecord)3 Instant (java.time.Instant)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 EntityManager (javax.persistence.EntityManager)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Condition (org.assertj.core.api.Condition)2