Skip to content

Commit 804905f

Browse files
committed
Add name validation for slot creation dialog, AB#1993990
1 parent 0819c27 commit 804905f

File tree

1 file changed

+25
-0
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/ui/components

1 file changed

+25
-0
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/ui/components/DeploymentSlotCreationDialog.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.microsoft.azure.toolkit.intellij.common.AzureTextInput;
1212
import com.microsoft.azure.toolkit.lib.common.form.AzureForm;
1313
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;
14+
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
1415
import org.apache.commons.lang3.StringUtils;
1516
import org.jetbrains.annotations.Nullable;
1617

@@ -20,23 +21,29 @@
2021
import java.util.List;
2122
import java.util.stream.Collectors;
2223

24+
import static com.microsoft.azure.toolkit.intellij.common.AzureBundle.message;
25+
import static com.microsoft.intellij.util.ValidationUtils.isValidAppServiceName;
26+
2327
public class DeploymentSlotCreationDialog extends AzureDialog<DeploymentSlotConfig> implements AzureForm<DeploymentSlotConfig> {
2428
private static final String DO_NOT_CLONE_SETTINGS = "Do not clone settings";
2529
private static final String PARENT = "parent";
2630

2731
private AzureTextInput txtName;
2832
private AzureComboBox<String> cbConfigurationSource;
2933
private JPanel pnlRoot;
34+
private final List<DeploymentSlotConfig> existingSlots;
3035

3136
public DeploymentSlotCreationDialog(@Nullable Project project, @Nonnull List<DeploymentSlotConfig> existingSlots) {
3237
super(project);
38+
this.existingSlots = existingSlots;
3339
$$$setupUI$$$();
3440
this.cbConfigurationSource.setItemsLoader(() -> {
3541
final List<String> collect = existingSlots.stream().map(DeploymentSlotConfig::getName).collect(Collectors.toList());
3642
collect.add(0, PARENT);
3743
collect.add(DO_NOT_CLONE_SETTINGS);
3844
return collect;
3945
});
46+
this.txtName.addValidator(this::validateDeploymentSlotName);
4047
super.init();
4148
}
4249

@@ -76,6 +83,24 @@ public List<AzureFormInput<?>> getInputs() {
7683
return Arrays.asList(txtName, cbConfigurationSource);
7784
}
7885

86+
private AzureValidationInfo validateDeploymentSlotName() {
87+
final String value = txtName.getValue();
88+
if (StringUtils.isEmpty(value)) {
89+
return AzureValidationInfo.error(message("appService.name.validate.empty"), txtName);
90+
}
91+
if (value.length() < 2 || value.length() > 60) {
92+
return AzureValidationInfo.error(message("appService.name.validate.length"), txtName);
93+
}
94+
if (!isValidAppServiceName(value)) {
95+
return AzureValidationInfo.error(message("appService.name.validate.invalidName"), txtName);
96+
}
97+
final DeploymentSlotConfig existingSlot = existingSlots.stream()
98+
.filter(slot -> StringUtils.equalsIgnoreCase(slot.getName(), value))
99+
.findFirst().orElse(null);
100+
return existingSlot == null ? AzureValidationInfo.success(txtName) :
101+
AzureValidationInfo.error(String.format("Slot with name (%s) already exists", value), txtName);
102+
}
103+
79104
void $$$setupUI$$$() {
80105
}
81106
}

0 commit comments

Comments
 (0)