Search in sources :

Example 11 with IdRev

use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.

the class BuildConfigurationAuditedRepositoryImpl method searchIdRevForBuildConfigurationName.

@Override
public List<IdRev> searchIdRevForBuildConfigurationName(String buildConfigurationName) {
    buildConfigurationName = buildConfigurationName.replaceAll("\\*", "%");
    List<Object[]> result = AuditReaderFactory.get(entityManager).createQuery().forRevisionsOfEntity(BuildConfiguration.class, false, false).add(AuditEntity.property("name").like(buildConfigurationName)).addOrder(AuditEntity.revisionNumber().desc()).getResultList();
    return result.stream().map(o -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) o[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) o[1];
        return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
    }).collect(Collectors.toList());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) Project(org.jboss.pnc.model.Project) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Logger(org.slf4j.Logger) BuildRecord_(org.jboss.pnc.model.BuildRecord_) Set(java.util.Set) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) AuditReaderFactory(org.hibernate.envers.AuditReaderFactory) AuditEntity(org.hibernate.envers.query.AuditEntity) Base32LongID(org.jboss.pnc.model.Base32LongID) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) IdRev(org.jboss.pnc.model.IdRev)

Example 12 with IdRev

use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.

the class BuildConfigurationAuditedRepositoryImpl method searchIdRevForBuildConfigurationNameOrProjectName.

@Override
public List<IdRev> searchIdRevForBuildConfigurationNameOrProjectName(List<Project> projectsMatchingName, String name) {
    AuditDisjunction disjunction = AuditEntity.disjunction();
    projectsMatchingName.forEach(project -> disjunction.add(AuditEntity.relatedId("project").eq(project.getId())));
    disjunction.add(AuditEntity.property("name").like(name));
    List<Object[]> result = AuditReaderFactory.get(entityManager).createQuery().forRevisionsOfEntity(BuildConfiguration.class, false, false).add(disjunction).addOrder(AuditEntity.revisionNumber().desc()).getResultList();
    return result.stream().map(o -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) o[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) o[1];
        return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
    }).collect(Collectors.toList());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) Project(org.jboss.pnc.model.Project) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Logger(org.slf4j.Logger) BuildRecord_(org.jboss.pnc.model.BuildRecord_) Set(java.util.Set) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) AuditReaderFactory(org.hibernate.envers.AuditReaderFactory) AuditEntity(org.hibernate.envers.query.AuditEntity) Base32LongID(org.jboss.pnc.model.Base32LongID) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) IdRev(org.jboss.pnc.model.IdRev)

Example 13 with IdRev

use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.

the class DefaultDatastore method requiresRebuild.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public boolean requiresRebuild(BuildConfigurationAudited buildConfigurationAudited, boolean checkImplicitDependencies, boolean temporaryBuild, AlignmentPreference alignmentPreference, Set<Integer> processedDependenciesCache, Consumer<BuildRecord> nonRebuildCauseSetter) {
    IdRev idRev = buildConfigurationAudited.getIdRev();
    // Step 1 - Check the existence of a build with the same revision
    BuildRecord latestSuccessfulBuildRecord = buildRecordRepository.getAnyLatestSuccessfulBuildRecordWithRevision(idRev, temporaryBuild);
    if (latestSuccessfulBuildRecord == null) {
        logger.debug("Rebuild of buildConfiguration.idRev: {} required as there is no successful BuildRecord.", idRev);
        return true;
    }
    // Step 2 - Check the existence of more recent builds with different revision
    if (!isLatestSuccessBRFromThisBCA(buildConfigurationAudited, temporaryBuild)) {
        return true;
    }
    // Step 3 - check implicit dependencies
    if (checkImplicitDependencies) {
        logger.debug("Checking if BCA: {} has implicit dependencies that need rebuild", idRev);
        boolean rebuild = hasARebuiltImplicitDependency(latestSuccessfulBuildRecord, temporaryBuild, alignmentPreference, processedDependenciesCache);
        logger.debug("Implicit dependency check for rebuild of buildConfiguration.idRev: {} required: {}.", idRev, rebuild);
        if (rebuild) {
            return true;
        }
    }
    // Step 4 - check explicit dependencies
    Set<BuildConfiguration> dependencies = buildConfigurationAudited.getBuildConfiguration().getDependencies();
    boolean rebuild = hasARebuiltExplicitDependency(latestSuccessfulBuildRecord, dependencies, temporaryBuild, alignmentPreference);
    logger.debug("Explicit dependency check for rebuild of buildConfiguration.idRev: {} required: {}.", idRev, rebuild);
    if (!rebuild) {
        nonRebuildCauseSetter.accept(latestSuccessfulBuildRecord);
    }
    return rebuild;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) IdRev(org.jboss.pnc.model.IdRev) BuildRecord(org.jboss.pnc.model.BuildRecord) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 14 with IdRev

use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.

the class BuildConfigProviderTest method testGetRevision.

@Test
public void testGetRevision() {
    // With
    final Integer revision = 1;
    BuildConfigurationAudited bca = BuildConfigurationAudited.fromBuildConfiguration(bc, revision);
    when(buildConfigurationAuditedRepository.queryById(new IdRev(bc.getId(), revision))).thenReturn(bca);
    // When
    BuildConfigurationRevision bcr = provider.getRevision(bc.getId().toString(), revision);
    // Then
    assertThat(bcr).isNotNull();
    assertThat(bcr.getId()).isEqualTo(bc.getId().toString());
    assertThat(bcr.getRev()).isEqualTo(revision);
    assertThat(bcr.getName()).isEqualTo(bc.getName());
    assertThat(bcr.getProject().getId()).isEqualTo(bc.getProject().getId().toString());
    assertThat(bcr.getCreationTime()).isEqualTo(bc.getCreationTime().toInstant());
    assertThat(bcr.getBuildType()).isEqualTo(bc.getBuildType());
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) IdRev(org.jboss.pnc.model.IdRev) Test(org.junit.Test)

Example 15 with IdRev

use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.

the class ArtifactProviderTest method testGetRevision.

@Test
public void testGetRevision() {
    // With
    final Integer revision = 1;
    ArtifactAudited aa = ArtifactAudited.fromArtifact(artifact1, revision);
    when(artifactAuditedRepository.queryById(new IdRev(artifact1.getId(), revision))).thenReturn(aa);
    // When
    ArtifactRevision ar = provider.getRevision(artifact1.getId().toString(), revision);
    // Then
    assertThat(ar).isNotNull();
    assertThat(ar.getId()).isEqualTo(artifact1.getId().toString());
    assertThat(ar.getRev()).isEqualTo(revision);
}
Also used : IdRev(org.jboss.pnc.model.IdRev) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) Test(org.junit.Test)

Aggregations

IdRev (org.jboss.pnc.model.IdRev)18 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)14 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)9 BuildRecord (org.jboss.pnc.model.BuildRecord)7 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 Stateless (javax.ejb.Stateless)5 Inject (javax.inject.Inject)5 Base32LongID (org.jboss.pnc.model.Base32LongID)5 BuildConfigurationAuditedRepository (org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 Root (javax.persistence.criteria.Root)4 AuditReaderFactory (org.hibernate.envers.AuditReaderFactory)4 DefaultRevisionEntity (org.hibernate.envers.DefaultRevisionEntity)4