2424import com .microsoft .azure .toolkit .lib .Azure ;
2525import com .microsoft .azure .toolkit .lib .appservice .AppServiceAppBase ;
2626import com .microsoft .azure .toolkit .lib .appservice .function .AzureFunctions ;
27- import com .microsoft .azure .toolkit .lib .appservice .function .FunctionApp ;
28- import com .microsoft .azure .toolkit .lib .appservice .function .FunctionAppBase ;
2927import com .microsoft .azure .toolkit .lib .common .form .AzureFormInput ;
3028import com .microsoft .azure .toolkit .lib .common .form .AzureValidationInfo ;
3129import com .microsoft .azure .toolkit .lib .common .model .AbstractAzResource ;
3230import com .microsoft .azure .toolkit .lib .common .task .AzureTask ;
3331import com .microsoft .azure .toolkit .lib .common .task .AzureTaskManager ;
3432import org .apache .commons .collections .MapUtils ;
33+ import org .apache .commons .lang3 .ObjectUtils ;
3534import org .apache .commons .lang3 .StringUtils ;
3635import org .jetbrains .annotations .NotNull ;
3736import org .jetbrains .annotations .Nullable ;
3837import org .jetbrains .idea .maven .project .MavenProject ;
3938
4039import javax .annotation .Nonnull ;
4140import javax .swing .*;
42- import java .awt .event .ItemEvent ;
4341import java .nio .file .Paths ;
4442import java .util .Arrays ;
4543import java .util .Collections ;
4644import java .util .List ;
47- import java .util .Map ;
4845import java .util .Objects ;
4946import java .util .Optional ;
5047import java .util .UUID ;
@@ -85,7 +82,7 @@ public void customize(JList list, Module module, int i, boolean b, boolean b1) {
8582 }
8683 });
8784 functionAppComboBox .setRequired (true );
88- chkSlot .addItemListener (e -> onSelectSlot ());
85+ chkSlot .addItemListener (e -> onSlotCheckBoxChanged ());
8986
9087 lblModule .setLabelFor (cbFunctionModule );
9188 lblFunction .setLabelFor (functionAppComboBox );
@@ -202,24 +199,23 @@ private void onSelectFunctionApp(final FunctionAppConfig value) {
202199 return ;
203200 }
204201 // disable slot for draft function
202+ this .chkSlot .setEnabled (StringUtils .isNotEmpty (value .getResourceId ()));
205203 if (StringUtils .isEmpty (value .getResourceId ())) {
206204 this .chkSlot .setSelected (false );
207205 }
208- this .chkSlot .setEnabled (StringUtils .isNotEmpty (value .getResourceId ()));
209- this .toggleDeploymentSlot (chkSlot .isSelected ());
210206 this .cbDeploymentSlot .setAppService (value .getResourceId ());
211207 if (!this .chkSlot .isSelected ()) {
212208 loadAppSettings (getResourceId (value , null ));
213209 }
214210 }
215211
216- private void loadAppSettings (@ Nonnull final String resourceId ) {
212+ private void loadAppSettings (@ Nullable final String resourceId ) {
217213 if (StringUtils .equalsIgnoreCase (resourceId , this .appSettingsResourceId ) && MapUtils .isNotEmpty (this .appSettingsTable .getAppSettings ())) {
218214 return ;
219215 }
220216 this .appSettingsResourceId = resourceId ;
221217 this .appSettingsTable .loadAppSettings (() -> {
222- final AbstractAzResource <?, ?, ?> resource = Azure .az ().getById (resourceId );
218+ final AbstractAzResource <?, ?, ?> resource = StringUtils . isBlank ( resourceId ) ? null : Azure .az ().getById (resourceId );
223219 return resource instanceof AppServiceAppBase <?, ?, ?> ? ((AppServiceAppBase <?, ?, ?>) resource ).getAppSettings () : Collections .emptyMap ();
224220 });
225221 }
@@ -247,10 +243,14 @@ private void selectModule(final Module target) {
247243 }
248244 }
249245
250- private void onSelectSlot () {
246+ private void onSlotCheckBoxChanged () {
251247 toggleDeploymentSlot (chkSlot .isSelected ());
252- if (!chkSlot .isSelected () && functionAppComboBox .getValue () != null ) {
253- // reload app settings for function app
248+ final FunctionAppConfig function = functionAppComboBox .getValue ();
249+ final DeploymentSlotConfig slot = cbDeploymentSlot .getValue ();
250+ // reload app settings when switch slot configuration
251+ if (chkSlot .isSelected () && ObjectUtils .allNotNull (function , slot )) {
252+ loadAppSettings (getResourceId (functionAppComboBox .getValue (), slot ));
253+ } else if (!chkSlot .isSelected () && Objects .nonNull (function )) {
254254 loadAppSettings (getResourceId (functionAppComboBox .getValue (), null ));
255255 }
256256 }
@@ -269,12 +269,15 @@ public List<AzureValidationInfo> getAllValidationInfos(final boolean revalidateI
269269 .filter (Objects ::nonNull ).collect (Collectors .toList ());
270270 }
271271
272+ @ Nullable
272273 private String getResourceId (@ Nonnull FunctionAppConfig config , @ Nullable DeploymentSlotConfig slotConfig ) {
273274 if (Objects .isNull (slotConfig )) {
274275 return StringUtils .isNoneBlank (config .getResourceId ()) ? config .getResourceId () :
275276 Azure .az (AzureFunctions .class ).functionApps (config .getSubscriptionId ()).getOrTemp (config .getName (), config .getResourceGroupName ()).getId ();
276277 } else {
277- return Azure .az (AzureFunctions .class ).functionApp (config .getResourceId ()).slots ().getOrTemp (slotConfig .getName (), null ).getId ();
278+ return Optional .ofNullable (Azure .az (AzureFunctions .class ).functionApp (config .getResourceId ()))
279+ .map (func -> func .slots ().getOrTemp (slotConfig .getName (), null ).getId ())
280+ .orElse (null );
278281 }
279282 }
280283
0 commit comments