use of org.jboss.pnc.dto.notification.BuildConfigurationCreation in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method createBuildConfigurationWithRepository.
public void createBuildConfigurationWithRepository(String taskId, int scmRepositoryId, BuildConfiguration configuration) {
RepositoryConfiguration repositoryConfiguration = repositoryConfigurationRepository.queryById(scmRepositoryId);
final boolean sendMessage = taskId != null;
if (repositoryConfiguration == null) {
String errorMessage = "Repository Configuration was not found in database.";
logger.error(errorMessage);
if (sendMessage) {
sendErrorMessage(SCMRepository.builder().id(Integer.toString(scmRepositoryId)).build(), null, errorMessage, taskId);
return;
}
throw new RepositoryViolationException("Repository Configuration was not found in database.");
}
org.jboss.pnc.model.BuildConfiguration buildConfiguration = mapper.toEntity(configuration);
buildConfiguration.setRepositoryConfiguration(repositoryConfiguration);
org.jboss.pnc.model.BuildConfiguration buildConfigurationSaved = repository.save(buildConfiguration);
Set<Integer> bcSetIds;
if (configuration.getGroupConfigs() == null) {
bcSetIds = Collections.emptySet();
} else {
bcSetIds = configuration.getGroupConfigs().keySet().stream().map(Integer::valueOf).collect(Collectors.toSet());
}
SCMRepository scmRepository = scmRepositoryMapper.toDTO(repositoryConfiguration);
BuildConfiguration buildConfig = mapper.toDTO(buildConfigurationSaved);
try {
addBuildConfigurationToSet(buildConfigurationSaved, bcSetIds);
} catch (Exception e) {
logger.error(e.getMessage());
if (sendMessage) {
sendErrorMessage(scmRepository, buildConfig, e.getMessage(), taskId);
return;
}
throw new RepositoryViolationException("Failed to add BuildConfig to BuildConfigSets.");
}
logger.info("Created Build Configuration with Repository: {}.", buildConfig);
if (sendMessage) {
BuildConfigurationCreation successMessage = BuildConfigurationCreation.success(scmRepository, buildConfig, taskId);
notifier.sendMessage(successMessage);
}
}
use of org.jboss.pnc.dto.notification.BuildConfigurationCreation in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method sendErrorMessage.
private void sendErrorMessage(SCMRepository scmRepository, BuildConfigurationRef buildConfig, String message, String taskId) {
BuildConfigurationCreation errorMessage = BuildConfigurationCreation.error(scmRepository, buildConfig, message, taskId);
notifier.sendMessage(errorMessage);
}
Aggregations