Search in sources :

Example 6 with AzureValidationInfo

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;
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) ManagementException(com.azure.core.management.exception.ManagementException) CheckNameAvailabilityResultEntity(com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity) Nonnull(javax.annotation.Nonnull)

Example 7 with AzureValidationInfo

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;
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 8 with AzureValidationInfo

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;
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Nonnull(javax.annotation.Nonnull)

Aggregations

AzureValidationInfo (com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo)8 ManagementException (com.azure.core.management.exception.ManagementException)2 AzurePasswordFieldInput (com.microsoft.azure.toolkit.intellij.common.component.AzurePasswordFieldInput)2 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)2 Nonnull (javax.annotation.Nonnull)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 CloudException (com.microsoft.azure.CloudException)1 CheckNameAvailabilityResultEntity (com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity)1 AzureSqlServer (com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer)1