use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class RSQLPredicateProducerTest method testComparator.
@Test
public void testComparator() {
Comparator<BuildConfiguration> comparator = producer.getComparator("=desc=id");
BuildConfiguration foo = BuildConfiguration.builder().id("3").name("FooBC").build();
BuildConfiguration bar = BuildConfiguration.builder().id("5").name("BarBC").build();
BuildConfiguration baz = BuildConfiguration.builder().id("7").name("BazBC").build();
List<BuildConfiguration> sorted = Arrays.asList(foo, bar, baz).stream().sorted(comparator).collect(Collectors.toList());
assertEquals(3, sorted.size());
assertEquals("BazBC", sorted.get(0).getName());
assertEquals("BarBC", sorted.get(1).getName());
assertEquals("FooBC", sorted.get(2).getName());
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class SCMRepositoryProviderImpl method startRCreationTask.
/**
* @param externalURL
* @param preBuildSyncEnabled
* @param jobType
* @param consumer
* @param buildConfiguration required when repository is created as part of BC creation process
* @return
*/
private Integer startRCreationTask(String externalURL, String revision, boolean preBuildSyncEnabled, JobNotificationType jobType, Consumer<RepositoryCreated> consumer, Optional<BuildConfiguration> buildConfiguration) {
String userToken = userService.currentUserToken();
org.jboss.pnc.bpm.model.RepositoryConfiguration repositoryConfiguration = org.jboss.pnc.bpm.model.RepositoryConfiguration.builder().externalUrl(externalURL).preBuildSyncEnabled(preBuildSyncEnabled).build();
RepositoryCreationTask task;
if (bpmConfig.isNewBpmForced() || userService.hasLoggedInUserRole(WORK_WITH_TECH_PREVIEW)) {
RepositoryCreationProcess.RepositoryCreationProcessBuilder repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision);
buildConfiguration.ifPresent(bc -> repositoryCreationProcess.buildConfiguration(bc));
task = new RepositoryCreationTask(repositoryCreationProcess.build(), userToken);
task.setTaskId(bpmManager.getNextTaskId());
task.setGlobalConfig(globalConfig);
task.setJsonEncodedProcessParameters(false);
task.setJobType(jobType);
RestConnector restConnector = new RestConnector(bpmConfig);
try {
Map<String, Object> processParameters = task.getExtendedProcessParameters();
restConnector.startProcess(bpmConfig.getNewBcCreationProcessId(), processParameters, userToken);
} catch (CoreException e) {
throw new RuntimeException("Could not get process parameters: " + task, e);
} catch (ProcessManagerException e) {
throw new RuntimeException("Could not start BPM task using REST connector: " + task, e);
}
} else {
// deprecated
RepositoryCreationProcess repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision).build();
task = new RepositoryCreationTask(repositoryCreationProcess, userToken);
task.setJobType(jobType);
Consumer<RepositoryCloneSuccess> successListener = event -> onRepoCloneSuccess(event.getData().getInternalUrl(), task.getTaskId(), consumer, jobType, externalURL, preBuildSyncEnabled);
task.addListener(BpmEventType.RC_REPO_CLONE_SUCCESS, MDCWrappers.wrap(successListener));
addErrorListeners(jobType, task);
try {
bpmManager.startTask(task);
} catch (CoreException e) {
throw new RuntimeException("Could not start BPM task: " + task, e);
}
}
return task.getTaskId();
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationPatchTest method shouldReplaceCollection.
@Test
public void shouldReplaceCollection() throws PatchBuilderException, IOException, JsonPatchException {
BuildConfigurationRef dependency1 = BuildConfigurationRef.refBuilder().id("1").build();
BuildConfigurationRef dependency2 = BuildConfigurationRef.refBuilder().id("2").build();
BuildConfigurationRef dependency2a = BuildConfigurationRef.refBuilder().id("2").build();
BuildConfigurationRef dependency3 = BuildConfigurationRef.refBuilder().id("3").build();
BuildConfigurationRef dependency4 = BuildConfigurationRef.refBuilder().id("4").build();
Map<String, BuildConfigurationRef> dependencies = new HashMap<>();
dependencies.put(dependency1.getId(), dependency1);
dependencies.put(dependency2.getId(), dependency2);
BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").dependencies(dependencies).build();
Map<String, BuildConfigurationRef> newDependencies = new HashMap<>();
newDependencies.put(dependency2a.getId(), dependency2a);
newDependencies.put(dependency3.getId(), dependency3);
newDependencies.put(dependency4.getId(), dependency4);
String patchString = new BuildConfigurationPatchBuilder().replaceDependencies(newDependencies).getJsonPatch();
BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
Assertions.assertThat(updatedBuildConfiguration.getDependencies()).containsOnly(newDependencies.entrySet().toArray(new Map.Entry[3]));
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationPatchTest method shouldAddToMap.
@Test
public void shouldAddToMap() throws PatchBuilderException, IOException, JsonPatchException {
Map<String, String> genericParameters = new HashMap<>();
genericParameters.put("k", "v");
BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").parameters(genericParameters).build();
Map<String, String> addParameters = Collections.singletonMap("k2", "v2");
String patchString = new BuildConfigurationPatchBuilder().addParameters(addParameters).getJsonPatch();
BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
genericParameters.putAll(addParameters);
Assertions.assertThat(updatedBuildConfiguration.getParameters()).contains(genericParameters.entrySet().toArray(new Map.Entry[2]));
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationPatchTest method shouldAddToCollection.
@Test
public void shouldAddToCollection() throws PatchBuilderException, IOException, JsonPatchException {
Map<String, BuildConfigurationRef> dependencies = new HashMap<>();
BuildConfigurationRef dependency1 = BuildConfigurationRef.refBuilder().id("1").build();
dependencies.put(dependency1.getId(), dependency1);
BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").dependencies(dependencies).build();
Map<String, BuildConfigurationRef> addDependencies = new HashMap<>();
BuildConfigurationRef dependency2 = BuildConfigurationRef.refBuilder().id("2").build();
addDependencies.put(dependency2.getId(), dependency2);
String patchString = new BuildConfigurationPatchBuilder().addDependencies(addDependencies).getJsonPatch();
BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
dependencies.putAll(addDependencies);
Assertions.assertThat(updatedBuildConfiguration.getDependencies()).containsKeys(dependency1.getId(), dependency2.getId());
}
Aggregations