Search in sources :

Example 1 with Base32LongID

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

the class ProductMilestoneReleaseManager method storeBuildRecordPush.

private void storeBuildRecordPush(BuildImportResultRest buildRest, ProductMilestoneRelease productMilestoneRelease) {
    Base32LongID recordId = BuildMapper.idMapper.toEntity(buildRest.getBuildRecordId());
    BuildRecord record = buildRecordRepository.queryById(recordId);
    if (record == null) {
        log.error("No record found for record id: {}, skipped saving info: {}", recordId, buildRest);
        return;
    }
    BuildPushStatus status;
    try {
        status = convertStatus(buildRest.getStatus());
    } catch (ProcessManagerException e) {
        log.error("Cannot convert status.", e);
        throw new RuntimeException("Cannot convert status.", e);
    }
    BuildRecordPushResult buildRecordPush = BuildRecordPushResult.newBuilder().id(Sequence.nextId()).buildRecord(record).status(status).brewBuildId(buildRest.getBrewBuildId()).brewBuildUrl(buildRest.getBrewBuildUrl()).tagPrefix(// TODO tag!
    "").productMilestoneRelease(productMilestoneRelease).build();
    buildRecordPushResultRepository.save(buildRecordPush);
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildPushStatus(org.jboss.pnc.enums.BuildPushStatus) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 2 with Base32LongID

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

the class BuildConfigurationAuditedRepositoryImpl method getBuildRecords.

/**
 * @param buildConfigurationId
 * @return List of BuildRecords where only id is fetched
 */
private List<BuildRecord> getBuildRecords(Integer buildConfigurationId) {
    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.equal(root.get(BuildRecord_.buildConfigurationId), buildConfigurationId));
    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)

Example 3 with Base32LongID

use of org.jboss.pnc.model.Base32LongID 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)

Example 4 with Base32LongID

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

the class BuildProviderImplTest method testFilterFinishedBuildsByBuildConfigName.

@Test
public void testFilterFinishedBuildsByBuildConfigName() {
    // Given
    Base32LongID givenIdAndBcName = new Base32LongID(85792L);
    mockBuildTask();
    mockBuildTask();
    BuildRecord givenBuild = mockBuildRecord(givenIdAndBcName, new Long[0], new Long[0]);
    when(buildConfigurationAuditedRepository.searchIdRevForBuildConfigurationName(givenIdAndBcName.toString())).thenReturn(Stream.of(givenBuild.getBuildConfigurationAuditedIdRev()).collect(Collectors.toList()));
    // When
    BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", false, false, givenIdAndBcName.toString());
    Page<Build> builds = provider.getBuilds(pageInfo);
    // Then
    assertEquals(1, builds.getTotalHits());
    Iterator<Build> it = builds.getContent().iterator();
    assertEquals(BuildMapper.idMapper.toDto(givenBuild.getId()), it.next().getId());
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 5 with Base32LongID

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

the class BuildProviderImplTest method testGetBuildsPages.

@Test
public void testGetBuildsPages() {
    // Prepare
    BuildRecord build8 = mockBuildRecord();
    BuildTask build7 = mockBuildTask();
    BuildRecord build6 = mockBuildRecord();
    BuildTask build5 = mockBuildTask();
    BuildRecord build4 = mockBuildRecord();
    BuildTask build3 = mockBuildTask();
    BuildRecord build2 = mockBuildRecord();
    BuildTask build1 = mockBuildTask();
    testPage(0, 2, new Base32LongID(build1.getId()), build2.getId());
    testPage(1, 2, new Base32LongID(build3.getId()), build4.getId());
    testPage(2, 2, new Base32LongID(build5.getId()), build6.getId());
    testPage(3, 2, new Base32LongID(build7.getId()), build8.getId());
    testPage(1, 3, build4.getId(), new Base32LongID(build5.getId()), build6.getId());
    testPage(2, 3, new Base32LongID(build7.getId()), build8.getId());
    testPage(2, 10);
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Aggregations

Base32LongID (org.jboss.pnc.model.Base32LongID)26 BuildRecord (org.jboss.pnc.model.BuildRecord)18 Test (org.junit.Test)7 Build (org.jboss.pnc.dto.Build)6 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)6 Date (java.util.Date)5 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)5 IdRev (org.jboss.pnc.model.IdRev)5 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)5 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)4 Collectors (java.util.stream.Collectors)3 Stateless (javax.ejb.Stateless)3 Inject (javax.inject.Inject)3 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)3 BuildConfigurationAuditedRepository (org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository)3 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)3 Logger (org.slf4j.Logger)3