use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class AccountNameTextField method doValidateValue.
@Override
@Nonnull
public AzureValidationInfo doValidateValue() {
if (StringUtils.isBlank(subscriptionId)) {
return AzureValidationInfo.UNINITIALIZED;
}
final AzureValidationInfo info = super.doValidateValue();
if (!AzureValidationInfo.OK.equals(info)) {
return info;
}
final String value = this.getValue();
// validate length
if (StringUtils.length(value) < minLength || StringUtils.length(value) > maxLength) {
return AzureValidationInfo.builder().input(this).message(String.format("Server name must be at least %s characters and at most %s characters.", minLength, maxLength)).type(AzureValidationInfo.Type.ERROR).build();
}
// validate special character
if (!PATTERN.matcher(value).matches()) {
return AzureValidationInfo.builder().input(this).message("The field can contain only lowercase letters and numbers. Name must be between 3 and 24 characters.").type(AzureValidationInfo.Type.ERROR).build();
}
// validate availability
CheckNameAvailabilityResultEntity resultEntity;
try {
resultEntity = Azure.az(AzureStorageAccount.class).checkNameAvailability(subscriptionId, this.getValue());
} catch (ManagementException e) {
return AzureValidationInfo.builder().input(this).message(e.getMessage()).type(AzureValidationInfo.Type.ERROR).build();
}
if (!resultEntity.isAvailable()) {
String message = resultEntity.getUnavailabilityReason();
if ("AlreadyExists".equalsIgnoreCase(resultEntity.getUnavailabilityReason())) {
message = "The specified storage account name is already taken.";
}
return AzureValidationInfo.builder().input(this).message(message).type(AzureValidationInfo.Type.ERROR).build();
}
return AzureValidationInfo.OK;
}
use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class ServerNameTextField method doValidateValue.
@Override
@NotNull
public AzureValidationInfo doValidateValue() {
if (StringUtils.isBlank(subscriptionId)) {
return AzureValidationInfo.UNINITIALIZED;
}
final AzureValidationInfo info = super.doValidateValue();
if (!AzureValidationInfo.OK.equals(info)) {
return info;
}
final String value = this.getValue();
// validate length
if (StringUtils.length(value) < minLength || StringUtils.length(value) > maxLength) {
return AzureValidationInfo.builder().input(this).message(String.format("Server name must be at least %s characters and at most %s characters.", minLength, maxLength)).type(AzureValidationInfo.Type.ERROR).build();
}
// validate special character
if (!PATTERN.matcher(value).matches()) {
return AzureValidationInfo.builder().input(this).message("Your server name can contain only lowercase letters, numbers, and '-', but can't start or end with '-'.").type(AzureValidationInfo.Type.ERROR).build();
}
// validate availability
if (Objects.nonNull(validateFunction)) {
return validateFunction.apply(this);
}
return AzureValidationInfo.OK;
}
use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class AzureArtifactComboBox method doValidate.
@Nonnull
@Override
public AzureValidationInfo doValidate() {
final AzureValidationInfo info = super.doValidate();
final AzureArtifact artifact = this.getValue();
if (info == AzureValidationInfo.OK && Objects.nonNull(artifact) && artifact.getType() == AzureArtifactType.File) {
final VirtualFile referencedObject = (VirtualFile) artifact.getReferencedObject();
if (Objects.nonNull(this.fileFilter) && !this.fileFilter.value(referencedObject)) {
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
return builder.input(this).message(AzureMessageBundle.message("common.artifact.artifactNotSupport").toString()).type(AzureValidationInfo.Type.ERROR).build();
}
}
return info;
}
Aggregations