Search in sources :

Example 1 with MilestoneInfo

use of org.jboss.pnc.dto.response.MilestoneInfo 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 2 with MilestoneInfo

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

the class ArtifactEndpointTest method shouldGetMilestonesInfo.

@Test
public void shouldGetMilestonesInfo() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<MilestoneInfo> milestonesInfo = client.getMilestonesInfo(artifactRest3.getId());
    assertThat(milestonesInfo).hasSize(1).first().extracting(MilestoneInfo::isBuilt).isEqualTo(false);
    RemoteCollection<MilestoneInfo> milestonesInfo2 = client.getMilestonesInfo(artifactRest1.getId());
    ObjectAssert<MilestoneInfo> milestone = assertThat(milestonesInfo2).hasSize(1).first();
    milestone.extracting(MilestoneInfo::isBuilt).isEqualTo(true);
    milestone.extracting(MilestoneInfo::getProductName).isEqualTo("Project Newcastle Demo Product");
    milestone.extracting(MilestoneInfo::getMilestoneVersion).isEqualTo("1.0.0.Build1");
}
Also used : MilestoneInfo(org.jboss.pnc.dto.response.MilestoneInfo) ArtifactClient(org.jboss.pnc.client.ArtifactClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

MilestoneInfo (org.jboss.pnc.dto.response.MilestoneInfo)2 Instant (java.time.Instant)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 PermitAll (javax.annotation.security.PermitAll)1 Stateless (javax.ejb.Stateless)1 Inject (javax.inject.Inject)1 EntityManager (javax.persistence.EntityManager)1 NoResultException (javax.persistence.NoResultException)1 Tuple (javax.persistence.Tuple)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Join (javax.persistence.criteria.Join)1 JoinType (javax.persistence.criteria.JoinType)1