Search in sources :

Example 1 with NameTypeValidator

use of com.thoughtworks.go.config.validation.NameTypeValidator in project gocd by gocd.

the class PipelineConfig method validateTemplate.

public void validateTemplate(PipelineTemplateConfig templateConfig) {
    if (hasTemplate()) {
        if (new NameTypeValidator().isNameInvalid(templateName.toString())) {
            errors().add(TEMPLATE_NAME, NameTypeValidator.errorMessage("template", templateName));
        }
        if (hasStages() && !hasTemplateApplied()) {
            addError("stages", format("Cannot add stages to pipeline '%s' which already references template '%s'", this.name(), this.getTemplateName()));
            addError("template", format("Cannot set template '%s' on pipeline '%s' because it already has stages defined", this.getTemplateName(), this.name()));
        }
        if (templateConfig == null) {
            addError("pipeline", format("Pipeline '%s' refers to non-existent template '%s'.", name(), templateName));
        }
    }
}
Also used : NameTypeValidator(com.thoughtworks.go.config.validation.NameTypeValidator)

Example 2 with NameTypeValidator

use of com.thoughtworks.go.config.validation.NameTypeValidator in project gocd by gocd.

the class Role method validate.

@Override
default void validate(ValidationContext validationContext) {
    if (isBlank(getName()) || !new NameTypeValidator().isNameValid(getName())) {
        addError("name", NameTypeValidator.errorMessage("role name", getName()));
    }
    RolesConfig roles = validationContext.getServerSecurityConfig().getRoles();
    if (!isBlank(getName()) && !roles.isUniqueRoleName(getName())) {
        addError("name", "Role names should be unique. Role with the same name exists.");
    }
    Set<RoleUser> roleUsers = new HashSet<>();
    for (RoleUser user : getUsers()) {
        if (roleUsers.contains(user)) {
            new ErrorMarkingDuplicateHandler(this).invoke(user);
        } else {
            roleUsers.add(user);
        }
    }
}
Also used : NameTypeValidator(com.thoughtworks.go.config.validation.NameTypeValidator)

Example 3 with NameTypeValidator

use of com.thoughtworks.go.config.validation.NameTypeValidator in project gocd by gocd.

the class ElasticProfile method validate.

@Override
public void validate(ValidationContext validationContext) {
    validateUniqueness(getObjectDescription() + " " + (isBlank(id) ? "(noname)" : "'" + id + "'"));
    if (isBlank(id)) {
        errors().add(ID, getObjectDescription() + " cannot have a blank id.");
    }
    if (new NameTypeValidator().isNameInvalid(id)) {
        errors().add(ID, String.format("Invalid id '%s'. %s", id, NameTypeValidator.ERROR_MESSAGE));
    }
    if (errors().isEmpty() && !super.hasErrors()) {
        ClusterProfiles clusterProfiles = validationContext.getClusterProfiles();
        ClusterProfile associatedClusterProfile = clusterProfiles.find(this.clusterProfileId);
        if (associatedClusterProfile == null) {
            errors().add("clusterProfileId", String.format("No Cluster Profile exists with the specified cluster_profile_id '%s'.", this.clusterProfileId));
        }
    }
}
Also used : NameTypeValidator(com.thoughtworks.go.config.validation.NameTypeValidator)

Example 4 with NameTypeValidator

use of com.thoughtworks.go.config.validation.NameTypeValidator 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

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