use of org.jboss.pnc.mapper.api.BuildMapper in project pnc by project-ncl.
the class BuildProviderImpl method getSpecific.
@Override
public Build getSpecific(String buildId) {
List<BuildTask> runningBuilds = buildCoordinator.getSubmittedBuildTasks();
Build build = runningBuilds.stream().filter(buildTask -> buildId.equals(buildTask.getId())).findAny().map(buildMapper::fromBuildTask).orElse(null);
// if build not in runningBuilds, check the database
if (build == null) {
// use findByIdFetchProperties instead of super.getSpecific to get 'BuildConfigurationAudited' object
build = mapper.toDTO(buildRecordRepository.findByIdFetchProperties(parseId(buildId)));
}
return build;
}
use of org.jboss.pnc.mapper.api.BuildMapper 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();
}
Aggregations