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));
}
}
}
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);
}
}
}
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));
}
}
}
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;
}
Aggregations