in plugin/src/com/microsoft/alm/plugin/idea/common/ui/controls/WorkItemQueryDropDown.java [88:161]
private void addQueriesFromServer(final DefaultActionGroup group) {
final AtomicBoolean isContextFound = new AtomicBoolean(true);
final RepositoryContext repositoryContext = VcsHelper.getRepositoryContext(project);
WorkItemQueriesLookupOperation operation = new WorkItemQueriesLookupOperation(repositoryContext);
operation.addListener(new Operation.Listener() {
@Override
public void notifyLookupStarted() {
// nothing to do
logger.info("WorkItemQueriesLookupOperation started.");
}
@Override
public void notifyLookupCompleted() {
logger.info("WorkItemQueriesLookupOperation completed and context found: " + isContextFound.get());
// only remove loading when we have actually gotten a context and made a successful call to get the queries
if (isContextFound.get()) {
IdeaHelper.runOnUIThread(new Runnable() {
@Override
public void run() {
group.remove(loadingAction);
}
});
}
isLoading = false;
}
@Override
public void notifyLookupResults(final Operation.Results results) {
final WorkItemQueriesLookupOperation.QueryResults wiResults = (WorkItemQueriesLookupOperation.QueryResults) results;
if (wiResults.isCancelled()) {
// Do nothing
logger.info("WorkItemQueriesLookupOperation was cancelled");
} else {
final ServerContext newContext;
if (wiResults.hasError() && AuthHelper.isNotAuthorizedError(wiResults.getError())) {
isContextFound.set(false);
//401 or 403 - token is not valid, prompt user for credentials and retry
newContext = ServerContextManager.getInstance().createContextFromGitRemoteUrl(repositoryContext.getUrl(), false);
} else {
newContext = null;
}
// Update table model on UI thread
IdeaHelper.runOnUIThread(new Runnable() {
@Override
public void run() {
if (wiResults.hasError()) {
if (AuthHelper.isNotAuthorizedError(wiResults.getError())) {
logger.warn("WorkItemQueriesLookupOperation failed due to auth error");
if (newContext != null) {
isContextFound.set(true);
//retry loading workitems with new context and authentication info
addQueriesFromServer(group);
} else {
//user cancelled login, don't retry
logger.info("WorkItemQueriesLookupOperation was cancelled");
}
} else {
IdeaHelper.showErrorDialog(project, wiResults.getError());
}
}
// add results to the menu
for (final QueryHierarchyItem item : wiResults.getQueries()) {
//TODO check for folder items here and handle appropriately
group.add(new QueryAction(item.getName(), item.getWiql()));
}
}
});
}
}
});
operation.doWorkAsync(queryOperationInput);
}