Search in sources :

Example 1 with ConflictException

use of com.thoughtworks.go.config.exceptions.ConflictException in project gocd by gocd.

the class ExtractTemplateFromPipelineEntityConfigUpdateCommand method canContinue.

@Override
public boolean canContinue(CruiseConfig cruiseConfig) {
    PipelineConfig pipelineConfig = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName));
    if (pipelineConfig == null) {
        throw new RecordNotFoundException(EntityType.Pipeline, pipelineName);
    }
    if (pipelineConfig.hasTemplate()) {
        throw new ConflictException(EntityType.Pipeline.alreadyUsesATemplate(pipelineName));
    }
    PipelineTemplateConfig templateByName = cruiseConfig.getTemplates().templateByName(this.newTemplate.name());
    if (templateByName != null) {
        throw new ConflictException(EntityType.Template.alreadyExists(this.newTemplate.name()));
    }
    if (new NameTypeValidator().isNameInvalid(this.newTemplate.name().toString())) {
        throw new BadRequestException(NameTypeValidator.errorMessage("template", this.newTemplate.name()));
    }
    return true;
}
Also used : NameTypeValidator(com.thoughtworks.go.config.validation.NameTypeValidator) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ConflictException(com.thoughtworks.go.config.exceptions.ConflictException) BadRequestException(com.thoughtworks.go.config.exceptions.BadRequestException)

Aggregations

BadRequestException (com.thoughtworks.go.config.exceptions.BadRequestException)1 ConflictException (com.thoughtworks.go.config.exceptions.ConflictException)1 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)1 NameTypeValidator (com.thoughtworks.go.config.validation.NameTypeValidator)1