Search in sources :

Example 1 with ProjectRef

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

the class DeserializerTest method testDTOAsRefDeserialization3.

@Test
public void testDTOAsRefDeserialization3() throws IOException {
    String json = "{" + "         \"id\":122," + "         \"name\":\"mtest180719\"," + "         \"description\":null," + "         \"issueTrackerUrl\":null," + "         \"projectUrl\":null," + "         \"buildConfigs\":[" + "            {" + "               \"id\":134," + "               \"name\":\"mtest1907252\"," + "               \"description\":null," + "               \"buildScript\":\"mvn clean deploy\"," + "               \"scmRevision\":\"master\"," + "               \"creationTime\":\"2019-07-25T09:32:44.206Z\"," + "               \"modificationTime\":\"2019-08-14T11:37:51.355Z\"," + "               \"archived\":false," + "               \"buildType\":\"MVN\"" + "            }" + "         ]" + "      }";
    ObjectMapper mapper = provider.getContext(null);
    ProjectRef obj = mapper.readValue(json, ProjectRef.class);
}
Also used : ProjectRef(org.jboss.pnc.dto.ProjectRef) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with ProjectRef

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

the class RemoteBuildTest method getOrCreateBuildConfiguration.

private BuildConfiguration getOrCreateBuildConfiguration(String buildConfigurationName, String buildScript, String scmRevision, Map<String, String> genericParameters, String projectId, String repositoryConfigurationId, String buildEnvironmentId) throws RemoteResourceException {
    RemoteCollection<BuildConfiguration> existing = buildConfigurationRestClient.getAll(Optional.empty(), Optional.of("name==" + buildConfigurationName));
    Iterator<BuildConfiguration> it = existing.iterator();
    if (!it.hasNext()) {
        ProjectRef project = ProjectRef.refBuilder().id(projectId).build();
        SCMRepository repository = SCMRepository.builder().id(repositoryConfigurationId).build();
        Environment environment = Environment.builder().id(buildEnvironmentId).build();
        BuildConfiguration buildConfiguration = BuildConfiguration.builder().name(buildConfigurationName).project(project).scmRepository(repository).scmRevision(scmRevision).environment(environment).buildScript(buildScript).parameters(genericParameters).build();
        BuildConfiguration created = buildConfigurationRestClient.createNew(buildConfiguration);
        return created;
    } else {
        return it.next();
    }
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Environment(org.jboss.pnc.dto.Environment) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Example 3 with ProjectRef

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

the class BuildBCRevisionFetcher method mapFromAuditedBuildConfig.

@BeforeMapping
public void mapFromAuditedBuildConfig(BuildRecord build, @MappingTarget Build.Builder dtoBuilder) {
    Integer id = build.getBuildConfigurationId();
    Integer revision = build.getBuildConfigurationRev();
    // If somebody before us already set the BCA we don't need to query it from DB again
    BuildConfigurationAudited bca = build.getBuildConfigurationAudited();
    if (bca == null) {
        bca = bcAuditedRepository.queryById(new IdRev(id, revision));
    }
    BuildConfigurationRevisionRef bcRevision = bcRevisionMapper.toRef(bca);
    ProjectRef project = projectMapper.toRef(bca.getProject());
    Environment environment = environmentMapper.toRef(bca.getBuildEnvironment());
    SCMRepository scmRepository = scmRepositoryMapper.toRef(bca.getRepositoryConfiguration());
    dtoBuilder.buildConfigRevision(bcRevision);
    dtoBuilder.project(project);
    dtoBuilder.environment(environment);
    dtoBuilder.scmRepository(scmRepository);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Environment(org.jboss.pnc.dto.Environment) IdRev(org.jboss.pnc.model.IdRev) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository) BeforeMapping(org.mapstruct.BeforeMapping)

Example 4 with ProjectRef

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

the class BuildConfigurationPatchTest method shouldReplaceRef.

@Test
public void shouldReplaceRef() throws PatchBuilderException, IOException, JsonPatchException {
    ProjectRef project = ProjectRef.refBuilder().id("1").name("Project 1").build();
    ProjectRef newProject = ProjectRef.refBuilder().id("2").name("Project 2").build();
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").name("BC 1").project(project).build();
    String patchString = new BuildConfigurationPatchBuilder().replaceProject(newProject).replaceName("Build Configuration 1").getJsonPatch();
    BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
    Assert.assertEquals(newProject, updatedBuildConfiguration.getProject());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) ProjectRef(org.jboss.pnc.dto.ProjectRef) Test(org.junit.Test)

Example 5 with ProjectRef

use of org.jboss.pnc.dto.ProjectRef in project bacon by project-ncl.

the class PncEntitiesImporter method generatePncBuildConfig.

/**
 * @param buildConfig PiG buildconfig to generate
 * @param existing if present, we'll use it as the buildconfig to modify if null: we'll use a fresh buildconfig
 *        object
 *
 * @return BuildConfiguration generated
 */
private BuildConfiguration generatePncBuildConfig(BuildConfig buildConfig, BuildConfiguration existing) {
    ProjectRef project = getOrGenerateProject(buildConfig.getProject());
    SCMRepository repository = getOrGenerateRepository(buildConfig);
    Environment environment = Environment.builder().id(buildConfig.getEnvironmentId()).build();
    BuildConfiguration.Builder builder = BuildConfiguration.builder();
    if (existing != null) {
        builder = existing.toBuilder();
    }
    return builder.productVersion(version).parameters(buildConfig.getGenericParameters(null, false)).name(buildConfig.getName()).project(project).environment(environment).scmRepository(repository).scmRevision(buildConfig.getScmRevision()).buildScript(buildConfig.getBuildScript()).buildType(BuildType.valueOf(buildConfig.getBuildType())).brewPullActive(buildConfig.getBrewPullActive()).build();
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Environment(org.jboss.pnc.dto.Environment) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Aggregations

ProjectRef (org.jboss.pnc.dto.ProjectRef)6 Environment (org.jboss.pnc.dto.Environment)4 SCMRepository (org.jboss.pnc.dto.SCMRepository)4 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)3 BuildConfigurationRevisionRef (org.jboss.pnc.dto.BuildConfigurationRevisionRef)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 User (org.jboss.pnc.dto.User)1 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)1 IdRev (org.jboss.pnc.model.IdRev)1 BeforeMapping (org.mapstruct.BeforeMapping)1