Search in sources :

Example 1 with IdRev

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

the class DefaultBuildCoordinatorTest method shouldCreateNoRebuildRequiredRecords.

@Test
public void shouldCreateNoRebuildRequiredRecords() throws CoreException, TimeoutException, InterruptedException {
    when(datastore.requiresRebuild(any(BuildConfigurationAudited.class), any(Boolean.class), any(Boolean.class), nullable(AlignmentPreference.class), anySet())).thenReturn(false);
    BuildConfigurationAudited bca1 = new BuildConfigurationAudited();
    IdRev idRev1 = new IdRev(BC_1.getId(), BC_1.getId() * 1000 + 1);
    bca1.setIdRev(idRev1);
    bca1.setId(idRev1.getId());
    bca1.setRev(idRev1.getRev());
    bca1.setProject(PROJECT);
    when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_1.getId())).thenReturn(bca1);
    BuildConfigurationAudited bca3 = new BuildConfigurationAudited();
    IdRev idRev3 = new IdRev(BC_3.getId(), BC_3.getId() * 1000 + 1);
    bca3.setIdRev(idRev3);
    bca3.setId(idRev3.getId());
    bca3.setRev(idRev3.getRev());
    bca3.setProject(PROJECT);
    when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_3.getId())).thenReturn(bca3);
    Set<BuildConfiguration> buildConfigs = new HashSet<>();
    buildConfigs.add(BC_1);
    buildConfigs.add(BC_3);
    when(datastore.getBuildConfigurations(any())).thenReturn(buildConfigs);
    Set<BuildRecord> storedRecords = new HashSet<>();
    when(datastore.storeRecordForNoRebuild(any())).thenAnswer(new SaveRecordForNoRebuildAnswer(storedRecords));
    BuildSetTask bsTask = coordinator.build(BCS, USER, BUILD_OPTIONS);
    coordinator.start();
    assertThat(bsTask.getBuildConfigSetRecord().get().getStatus()).isEqualTo(BuildStatus.NO_REBUILD_REQUIRED);
    Wait.forCondition(() -> storedRecords.size() == 2, 3, ChronoUnit.SECONDS);
    assertThat(storedRecords.size()).isEqualTo(2);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) IdRev(org.jboss.pnc.model.IdRev) BuildRecord(org.jboss.pnc.model.BuildRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with IdRev

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

the class BuildConfigurationAuditedRepositoryMock method save.

public BuildConfigurationAudited save(BuildConfigurationAudited entity) {
    IdRev idRev = entity.getIdRev();
    if (idRev == null) {
        throw new IllegalStateException("auto-setting " + this.getClass().getSimpleName() + " entity id is not supported");
    }
    BuildConfiguration buildConfiguration = entity.getBuildConfiguration();
    Integer newRev = idSequence.getAndIncrement();
    BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, newRev);
    getOptionalById(idRev).ifPresent(data::remove);
    data.add(entity);
    return entity;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IdRev(org.jboss.pnc.model.IdRev)

Example 3 with IdRev

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

the class BuildRecordRepositoryImpl method fetchBuildConfigurationAudited.

private void fetchBuildConfigurationAudited(BuildRecord buildRecord) {
    Integer revision = buildRecord.getBuildConfigurationRev();
    BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(new IdRev(buildRecord.getBuildConfigurationId(), revision));
    buildRecord.setBuildConfigurationAudited(buildConfigurationAudited);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordPredicates.withBuildConfigurationIdRev(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigurationIdRev) IdRev(org.jboss.pnc.model.IdRev)

Example 4 with IdRev

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

the class BuildConfigurationAuditedRepositoryImpl method queryById.

@Override
public Map<IdRev, BuildConfigurationAudited> queryById(Set<IdRev> idRevs) {
    logger.trace("Querying for BuildConfigurationAudited.idRevs: {}.", idRevs);
    List<String> idRevConcatenated = idRevs.stream().map(idRev -> idRev.getId() + "-" + idRev.getRev()).collect(Collectors.toList());
    // WORKAROUND: as I cannot concatenate AuditEntity property to match
    // `AuditEntity.property("id")-AuditEntity.property("rev")` in idRevConcatenated list
    // I can query all BuildConfigurationAudited with the only id and later on filter id and rev
    List<Integer> bcaRevIds = idRevs.stream().map(IdRev::getRev).collect(Collectors.toList());
    // Getting all revisions of BuildConfiguration with specified list of IDs
    List<Object[]> result = AuditReaderFactory.get(entityManager).createQuery().forRevisionsOfEntity(BuildConfiguration.class, false, false).add(AuditEntity.revisionNumber().in(bcaRevIds)).addOrder(AuditEntity.revisionNumber().desc()).getResultList();
    return result.stream().filter(res -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) res[1];
        return idRevConcatenated.contains(buildConfiguration.getId() + "-" + revisionEntity.getId());
    }).peek(res -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
        // preload generic parameters
        buildConfiguration.getGenericParameters().forEach((k, v) -> k.equals(null));
    }).map(res -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) res[1];
        return BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, revisionEntity.getId());
    }).collect(Collectors.toMap(BuildConfigurationAudited::getIdRev, bca -> bca));
}
Also used : 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) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity)

Example 5 with IdRev

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

the class BuildConfigurationAuditedRepositoryImpl method getBuildRecords.

/**
 * @param idRev
 * @return List of BuildRecords where only id is fetched
 */
private List<BuildRecord> getBuildRecords(IdRev idRev) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Base32LongID> query = cb.createQuery(Base32LongID.class);
    Root<BuildRecord> root = query.from(BuildRecord.class);
    query.select(root.get(BuildRecord_.id));
    query.where(cb.and(cb.equal(root.get(BuildRecord_.buildConfigurationId), idRev.getId()), cb.equal(root.get(BuildRecord_.buildConfigurationRev), idRev.getRev())));
    List<Base32LongID> buildRecordIds = entityManager.createQuery(query).getResultList();
    return buildRecordIds.stream().map(id -> BuildRecord.Builder.newBuilder().id(id).build()).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) 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) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord)

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