Search in sources :

Example 46 with BuildConfiguration

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

the class BuildConfigurationRepositoryImplTest method shouldNotCreateBuildConfigurationWithDuplicatedName.

@Test
public void shouldNotCreateBuildConfigurationWithDuplicatedName() {
    String name = randomAlphabetic(10);
    repository.save(producers.createValidBuildConfiguration(name));
    BuildConfiguration duplicatedConfiguration = producers.createValidBuildConfiguration(name);
    assertThrows(() -> repository.save(duplicatedConfiguration), org.hibernate.exception.ConstraintViolationException.class);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 47 with BuildConfiguration

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

the class BuildConfigurationSetRepositoryTest method shouldSaveBCSetWithBCs.

@Test
public void shouldSaveBCSetWithBCs() {
    // given
    BuildConfigurationFactory buildConfigurationFactory = new BuildConfigurationFactory();
    BuildConfiguration buildConfiguration1 = buildConfigurationFactory.createDetached("One");
    BuildConfiguration buildConfiguration2 = buildConfigurationFactory.createDetached("Two");
    BuildConfiguration buildConfiguration3 = buildConfigurationFactory.createDetached("Three");
    BuildConfigurationSet buildConfigurationSet = BuildConfigurationSet.Builder.newBuilder().name("Build Group").buildConfiguration(buildConfiguration1).build();
    // when
    BuildConfigurationSet buildConfigurationSetSaved = buildConfigurationSetRepository.save(buildConfigurationSet);
    // then
    List<BuildConfiguration> buildConfigurationsLoaded = buildConfigurationRepository.queryWithPredicates(withBuildConfigurationSetId(buildConfigurationSetSaved.getId()), isNotArchived());
    assertThat(buildConfigurationsLoaded).isNotEmpty();
    assertThat(buildConfigurationsLoaded.size()).isEqualTo(1);
    assertThat(buildConfiguration1.getDefaultAlignmentParams().contains("-DdependencySource=REST"));
    assertThat(buildConfiguration2.getDefaultAlignmentParams().contains("-DdependencySource=REST"));
    assertThat(buildConfiguration3.getDefaultAlignmentParams().contains("-DdependencySource=REST"));
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 48 with BuildConfiguration

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

the class BuildRecordRepositoryTest method initBuildRecordBuilder.

private BuildRecord.Builder initBuildRecordBuilder(String id) {
    if (user == null) {
        List<User> users = userRepository.queryWithPredicates(UserPredicates.withUserName("demo-user"));
        if (users.size() > 0) {
            user = users.get(0);
        }
        if (user == null) {
            this.user = userRepository.save(User.Builder.newBuilder().username("demo-user").firstName("Demo First Name").lastName("Demo Last Name").email("demo-user@pnc.com").build());
        }
    }
    BuildConfiguration buildConfiguration = producers.createValidBuildConfiguration("buildRecordTest-" + id);
    BuildConfiguration saved = buildConfigurationRepository.save(buildConfiguration);
    BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.findAllByIdOrderByRevDesc(saved.getId()).get(0);
    return BuildRecord.Builder.newBuilder().id(id).buildConfigurationAudited(buildConfigurationAudited).submitTime(new Date()).user(user).status(BuildStatus.SUCCESS);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) User(org.jboss.pnc.model.User) Date(java.util.Date)

Example 49 with BuildConfiguration

use of org.jboss.pnc.model.BuildConfiguration 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 50 with BuildConfiguration

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

Aggregations

BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)65 Test (org.junit.Test)23 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)11 HashSet (java.util.HashSet)10 BuildRecord (org.jboss.pnc.model.BuildRecord)9 Project (org.jboss.pnc.model.Project)9 BuildOptions (org.jboss.pnc.spi.BuildOptions)9 BuildResult (org.jboss.pnc.spi.BuildResult)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 List (java.util.List)8 Set (java.util.Set)8 Inject (javax.inject.Inject)8 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)8 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)8 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)8 IdRev (org.jboss.pnc.model.IdRev)7 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)7 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)7 Collectors (java.util.stream.Collectors)5