use of org.jboss.pnc.dto.BuildConfigurationWithLatestBuild 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.BuildConfigurationWithLatestBuild in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method testGetAllWithLatest.
@Test
@InSequence(10)
public void testGetAllWithLatest() throws RemoteResourceException {
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asAnonymous());
RemoteCollection<BuildConfigurationWithLatestBuild> bcsWithLatest = client.getAllWithLatestBuild();
BuildsFilterParameters filter = new BuildsFilterParameters();
filter.setLatest(true);
// from DatabaseDataInitializer
assertThat(bcsWithLatest).hasSize(5);
for (BuildConfigurationWithLatestBuild bc : bcsWithLatest.getAll()) {
List<Build> associatedBuilds = new ArrayList<>(client.getBuilds(bc.getId(), filter).getAll());
if (bc.getLatestBuild() != null) {
assertThat(associatedBuilds).isNotEmpty();
assertThat(bc.getLatestBuild().getId()).isEqualTo(associatedBuilds.get(0).getId());
}
}
}
Aggregations