2525
2626import com .microsoft .azure .management .Azure ;
2727import com .microsoft .azure .management .appservice .DeploymentSlot ;
28- import com .microsoft .azure .management .appservice .LogLevel ;
2928import com .microsoft .azure .management .appservice .PricingTier ;
3029import com .microsoft .azure .management .appservice .WebApp ;
3130import com .microsoft .azure .management .appservice .WebAppDiagnosticLogs ;
3635import com .microsoft .azuretools .authmanage .AuthMethodManager ;
3736import com .microsoft .azuretools .authmanage .models .SubscriptionDetail ;
3837import com .microsoft .azuretools .sdkmanage .AzureManager ;
39-
4038import com .microsoft .azuretools .utils .AzureModel ;
4139import com .microsoft .azuretools .utils .AzureModelController ;
4240import com .microsoft .azuretools .utils .CanceledByUserException ;
41+ import org .apache .commons .lang3 .StringUtils ;
42+ import rx .Observable ;
43+ import rx .schedulers .Schedulers ;
44+
4345import java .io .IOException ;
44- import java .io .InputStream ;
45- import java .io .OutputStream ;
4646import java .lang .reflect .Field ;
4747import java .lang .reflect .Modifier ;
4848import java .util .ArrayList ;
49+ import java .util .Collections ;
50+ import java .util .Comparator ;
4951import java .util .List ;
5052import java .util .Map ;
53+ import java .util .function .Function ;
5154import java .util .stream .Collectors ;
52- import rx .Observable ;
53- import rx .functions .Func1 ;
54- import rx .schedulers .Schedulers ;
5555
5656public class AzureMvpModel {
5757
@@ -112,6 +112,7 @@ public List<Subscription> getSelectedSubscriptions() {
112112 } catch (IOException e ) {
113113 e .printStackTrace ();
114114 }
115+ Collections .sort (ret , getComparator (Subscription ::displayName ));
115116 return ret ;
116117 }
117118
@@ -134,6 +135,8 @@ public List<ResourceEx<ResourceGroup>> getResourceGroups(boolean forceUpdate) th
134135 resourceGroups .addAll (srgMap .get (sd ).stream ().map (
135136 resourceGroup -> new ResourceEx <>(resourceGroup , sd .getSubscriptionId ())).collect (Collectors .toList ()));
136137 }
138+ Collections .sort (resourceGroups , getComparator ((ResourceEx <ResourceGroup > resourceGroupResourceEx ) ->
139+ resourceGroupResourceEx .getResource ().name ()));
137140 return resourceGroups ;
138141 }
139142
@@ -163,6 +166,7 @@ public List<ResourceGroup> getResourceGroupsBySubscriptionId(String sid) {
163166 } catch (IOException e ) {
164167 e .printStackTrace ();
165168 }
169+ Collections .sort (ret , getComparator (ResourceGroup ::name ));
166170 return ret ;
167171 }
168172
@@ -197,12 +201,15 @@ public List<Deployment> listAllDeployments() {
197201 }
198202 subscriber .onCompleted ();
199203 }).subscribeOn (Schedulers .io ()), subs .size ()).subscribeOn (Schedulers .io ()).toBlocking ().subscribe ();
204+ Collections .sort (deployments , getComparator (Deployment ::name ));
200205 return deployments ;
201206 }
202207
203208 public List <Deployment > listDeploymentsBySid (String sid ) throws IOException {
204209 Azure azure = AuthMethodManager .getInstance ().getAzureClient (sid );
205- return azure .deployments ().list ();
210+ List <Deployment > deployments = azure .deployments ().list ();
211+ Collections .sort (deployments , getComparator (Deployment ::name ));
212+ return deployments ;
206213 }
207214
208215 /**
@@ -215,6 +222,8 @@ public List<ResourceEx<Deployment>> getDeploymentByRgName(String sid, String rgN
215222 Azure azure = AuthMethodManager .getInstance ().getAzureClient (sid );
216223 res .addAll (azure .deployments ().listByResourceGroup (rgName ).stream ().
217224 map (deployment -> new ResourceEx <>(deployment , sid )).collect (Collectors .toList ()));
225+ Collections .sort (res ,
226+ getComparator ((ResourceEx <Deployment > deploymentResourceEx ) -> deploymentResourceEx .getResource ().name ()));
218227 return res ;
219228 }
220229
@@ -287,6 +296,7 @@ public List<Location> listLocationsBySubscriptionId(String sid) {
287296 } catch (Exception e ) {
288297 e .printStackTrace ();
289298 }
299+ Collections .sort (locations , getComparator (Location ::name ));
290300 return locations ;
291301 }
292302
@@ -304,9 +314,15 @@ public List<PricingTier> listPricingTier() throws IllegalAccessException {
304314 ret .add (pt );
305315 }
306316 }
317+ Collections .sort (ret , getComparator (PricingTier ::toString ));
307318 return correctPricingTiers (ret );
308319 }
309320
321+ private static <T > Comparator <T > getComparator (Function <T , String > toStringMethod ) {
322+ return (first , second ) ->
323+ StringUtils .compareIgnoreCase (toStringMethod .apply (first ), toStringMethod .apply (second ));
324+ }
325+
310326 // workaround for SDK not updated the PREMIUM pricing tiers to latest ones
311327 // https://github.com/Azure/azure-libraries-for-java/issues/660
312328 private List <PricingTier > correctPricingTiers (final List <PricingTier > pricingTiers ) {
0 commit comments