Search in sources :

Example 1 with BuildConfigurationCreation

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);
    }
}
Also used : BuildConfigurationCreation(org.jboss.pnc.dto.notification.BuildConfigurationCreation) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Example 2 with BuildConfigurationCreation

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);
}
Also used : BuildConfigurationCreation(org.jboss.pnc.dto.notification.BuildConfigurationCreation)

Aggregations

BuildConfigurationCreation (org.jboss.pnc.dto.notification.BuildConfigurationCreation)2 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)1 SCMRepository (org.jboss.pnc.dto.SCMRepository)1 ConflictedEntryException (org.jboss.pnc.facade.validation.ConflictedEntryException)1 DTOValidationException (org.jboss.pnc.facade.validation.DTOValidationException)1 EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)1 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)1 RepositoryViolationException (org.jboss.pnc.facade.validation.RepositoryViolationException)1 RepositoryConfiguration (org.jboss.pnc.model.RepositoryConfiguration)1