public static void loadVsoContexts()

in plugin/src/com/microsoft/alm/plugin/idea/common/ui/common/LookupHelper.java [217:291]


    public static void loadVsoContexts(final LoginPageModel loginPageModel,
                                       final ServerContextLookupPageModel lookupPageModel,
                                       final AuthenticationProvider authenticationProvider,
                                       final ServerContextLookupListener lookupListener,
                                       final ServerContextLookupOperation.ContextScope scope) {
        String serverUri = getVsspsUrlFromDisplayName(loginPageModel.getServerName());

        if (!authenticationProvider.isAuthenticated(serverUri)) {
            loginPageModel.addError(ModelValidationInfo.createWithResource(TfPluginBundle.KEY_LOGIN_PAGE_ERRORS_VSO_SIGN_IN_FAILED));
            loginPageModel.signOut();
            return;
        }

        loginPageModel.setConnected(true);
        lookupPageModel.setLoading(true);
        loginPageModel.setUserName(authenticationProvider.getAuthenticationInfo(serverUri).getUserNameForDisplay());
        lookupPageModel.clearContexts();

        //If the server name is a valid VSO account URL, only query for repositories/projects in the specified account
        //user can get here by entering account URL on TFS tab
        if (isValidVsoURL(loginPageModel.getServerName())) {
            final ServerContext vsoAccountContext = new ServerContextBuilder()
                    .uri(UrlHelper.getHttpsUrlFromHttpUrl(loginPageModel.getServerName()))
                    .type(ServerContext.Type.VSO)
                    .authentication(authenticationProvider.getAuthenticationInfo(loginPageModel.getServerName())).build();
            final List<ServerContext> vsoContexts = new ArrayList<ServerContext>();
            vsoContexts.add(vsoAccountContext);
            lookupListener.loadContexts(vsoContexts, scope);
        } else {
            //lookup all accounts and query for repositories/projects in all the accounts
            final AccountLookupOperation accountLookupOperation = OperationFactory.createAccountLookupOperation();
            accountLookupOperation.addListener(new Operation.Listener() {
                @Override
                public void notifyLookupStarted() {
                    // nothing to do
                }

                @Override
                public void notifyLookupCompleted() {
                    // nothing to do here, we are still loading contexts
                }

                @Override
                public void notifyLookupResults(final Operation.Results results) {
                    final ModelValidationInfo validationInfo;
                    if (results.hasError()) {
                        validationInfo = ModelValidationInfo.createWithMessage(
                                LocalizationServiceImpl.getInstance().getExceptionMessage(results.getError()));
                    } else if (results.isCancelled()) {
                        validationInfo = ModelValidationInfo.createWithResource(TfPluginBundle.KEY_OPERATION_LOOKUP_CANCELED);
                    } else {
                        validationInfo = ModelValidationInfo.NO_ERRORS;
                        // Take the list of accounts and use them to query the team projects
                        lookupListener.loadContexts(
                                accountLookupOperation.castResults(results).getServerContexts(),
                                scope);
                    }

                    // If there was an error or cancellation message, send it back to the user
                    if (validationInfo != ModelValidationInfo.NO_ERRORS) {
                        // Push this event back onto the UI thread
                        IdeaHelper.runOnUIThread(new Runnable() {
                            @Override
                            public void run() {
                                loginPageModel.addError(validationInfo);
                                loginPageModel.signOut();
                            }
                        });
                    }
                }
            });
            // Start the operation
            accountLookupOperation.doWorkAsync(Operation.EMPTY_INPUTS);
        }
    }