use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method createWithScm.
@Override
public BuildConfigCreationResponse createWithScm(BuildConfigWithSCMRequest request) {
ValidationBuilder.validateObject(request, WhenCreatingNew.class).validateNotEmptyArgument().validateAnnotations();
BuildConfiguration buildConfiguration = request.getBuildConfig();
validateBeforeSaving(buildConfiguration.toBuilder().scmRepository(FAKE_REPOSITORY).build());
Long buildConfigurationId = sequenceHandlerRepository.getNextID(org.jboss.pnc.model.BuildConfiguration.SEQUENCE_NAME);
MDCUtils.addProcessContext(buildConfigurationId.toString());
BuildConfiguration newBuildConfigurationWithId = buildConfiguration.toBuilder().id(buildConfigurationId.toString()).build();
RepositoryCreationResponse rcResponse = scmRepositoryProvider.createSCMRepository(request.getScmUrl(), request.getBuildConfig().getScmRevision(), request.getPreBuildSyncEnabled(), JobNotificationType.BUILD_CONFIG_CREATION, // consumer is deprecated with new stateless approach
MDCWrappers.wrap(event -> {
createBuildConfigurationWithRepository(event.getTaskId() == null ? null : event.getTaskId().toString(), event.getRepositoryId(), newBuildConfigurationWithId);
}), Optional.of(newBuildConfigurationWithId));
BuildConfigCreationResponse response;
if (rcResponse.getTaskId() == null) {
// scm is internal, not running a RepositoryCreationTask.
// onRCCreationSuccess already called with id = rcResponse.getRepository().getId()
org.jboss.pnc.model.BuildConfiguration buildConfigurationFromDB = repository.queryByPredicates(withName(newBuildConfigurationWithId.getName()), isNotArchived());
response = new BuildConfigCreationResponse(mapper.toDTO(buildConfigurationFromDB));
} else {
response = new BuildConfigCreationResponse(rcResponse.getTaskId().toString());
}
MDCUtils.removeProcessContext();
return response;
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method populateBuildConfigWithLatestBuild.
private BuildConfigurationWithLatestBuild populateBuildConfigWithLatestBuild(BuildConfiguration buildConfig, List<BuildRecord> latestBuilds, List<BuildTask> runningBuilds) {
Integer bcId = mapper.getIdMapper().toEntity(buildConfig.getId());
Optional<BuildTask> latestBuildTask = runningBuilds.stream().filter(Objects::nonNull).filter(bt -> bt.getBuildConfigurationAudited().getId().equals(bcId)).max(Comparator.comparing(BuildTask::getSubmitTime));
Optional<BuildRecord> latestBuildRecord = latestBuilds.stream().filter(br -> br.getBuildConfigurationId().equals(bcId)).findFirst();
BuildRef latestBuild = latestBuildTask.map((bt -> (BuildRef) buildMapper.fromBuildTask(bt))).orElse(latestBuildRecord.map(buildMapper::toRef).orElse(null));
String latestBuildUsername = latestBuildTask.map(bt -> bt.getUser().getUsername()).orElse(latestBuildRecord.map(br -> br.getUser().getUsername()).orElse(null));
return BuildConfigurationWithLatestBuild.builderWithLatestBuild().buildConfig(buildConfig).latestBuild(latestBuild).latestBuildUsername(latestBuildUsername).build();
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method restoreRevision.
@Override
public Optional<BuildConfiguration> restoreRevision(String id, int rev) {
IdRev idRev = new IdRev(Integer.valueOf(id), rev);
BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(idRev);
org.jboss.pnc.model.BuildConfiguration originalBC = repository.queryById(Integer.valueOf(id));
org.jboss.pnc.model.User user = userService.currentUser();
if (buildConfigurationAudited == null || originalBC == null) {
return Optional.empty();
}
originalBC.setName(buildConfigurationAudited.getName());
originalBC.setBuildScript(buildConfigurationAudited.getBuildScript());
originalBC.setRepositoryConfiguration(buildConfigurationAudited.getRepositoryConfiguration());
originalBC.setScmRevision(buildConfigurationAudited.getScmRevision());
originalBC.setBuildType(buildConfigurationAudited.getBuildType());
originalBC.setBuildEnvironment(buildConfigurationAudited.getBuildEnvironment());
originalBC.setGenericParameters(buildConfigurationAudited.getGenericParameters());
originalBC.setLastModificationUser(user);
org.jboss.pnc.model.BuildConfiguration newBc = repository.save(originalBC);
newBc.getBuildConfigurationSets().forEach(BuildConfigurationSet::getId);
newBc.getDependencies().forEach(org.jboss.pnc.model.BuildConfiguration::getId);
repository.flushAndRefresh(newBc);
return Optional.of(mapper.toDTO(newBc));
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationPatchTest method shouldReplaceSimpleValue.
@Test
public void shouldReplaceSimpleValue() throws PatchBuilderException, IOException, JsonPatchException {
BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").description("Hello Tom!").build();
String newDescription = "Hi Jerry";
String patchString = new BuildConfigurationPatchBuilder().replaceDescription(newDescription).getJsonPatch();
BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
Assert.assertEquals(newDescription, updatedBuildConfiguration.getDescription());
}
use of org.jboss.pnc.dto.BuildConfiguration 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());
}
Aggregations