use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.
the class AccountService method getToken.
public String getToken(IResource t) {
String token = null;
ICluster cluster = getModel().getClusters().get(0);
List<IAccount> identities = cluster.getAccounts();
if (identities.isEmpty()) {
token = performLogin(cluster, null);
} else {
IAccount account = identities.get(0);
AccountStatus status = getStatus(account);
switch(status) {
case VALID:
token = account.getAccessToken();
break;
case NEEDS_REFRESH:
token = performRefresh(account);
break;
case NEEDS_LOGIN:
token = performLogin(cluster, account);
break;
}
}
return token;
}
use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.
the class MainPreferencePage method performOk.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#performOk()
*/
@Override
public boolean performOk() {
if (removed) {
ICluster cluster = AccountService.getDefault().getModel().getClusters().get(0);
if (!cluster.getAccounts().isEmpty()) {
IAccount account = cluster.getAccounts().get(0);
cluster.removeAccount(account);
cluster.save();
}
}
return true;
}
use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.
the class AccountModel method save.
@Override
public void save() {
clusters.forEach(ICluster::save);
Preferences accountRoot = getAccountsPreferences();
ISecurePreferences accountSecureRoot = getSecureAccountsPreferences();
removed.forEach(id -> {
removeAccount(id, accountRoot, accountSecureRoot);
});
removed.clear();
}
use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.
the class AccountModelTest method testAddRemoveAccount.
@Test
public void testAddRemoveAccount() {
IAccountModel m = AccountService.getDefault().getModel();
assertNotNull(m);
final Boolean[] checkAdded = new Boolean[] { false };
final Boolean[] checkRemoved = new Boolean[] { false };
IAccountModelListener listener = new AccountModelAdapter() {
@Override
public void accountAdded(IAccountModel source, IAccount account) {
checkAdded[0] = true;
}
@Override
public void accountRemoved(IAccountModel source, IAccount account) {
checkRemoved[0] = true;
}
};
m.addListener(listener);
try {
ICluster cluster = m.createCluster("id1");
m.addCluster(cluster);
List<ICluster> clusters = m.getClusters();
assertEquals(2, clusters.size());
assertEquals(0, cluster.getAccounts().size());
IAccount account = cluster.createAccount("id2");
cluster.addAccount(account);
assertEquals(1, cluster.getAccounts().size());
cluster.removeAccount(account);
assertEquals(0, cluster.getAccounts().size());
m.removeCluster(cluster);
clusters = m.getClusters();
assertEquals(1, clusters.size());
assertTrue(checkAdded[0]);
assertTrue(checkRemoved[0]);
} finally {
m.removeListener(listener);
}
}
use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.
the class AccountModelTest method testAddRemoveCluster.
@Test
public void testAddRemoveCluster() {
IAccountModel m = AccountService.getDefault().getModel();
assertNotNull(m);
final Boolean[] checkAdded = new Boolean[] { false };
final Boolean[] checkRemoved = new Boolean[] { false };
IAccountModelListener listener = new AccountModelAdapter() {
@Override
public void clusterAdded(IAccountModel source, ICluster cluster) {
checkAdded[0] = true;
}
@Override
public void clusterRemoved(IAccountModel source, ICluster cluster) {
checkRemoved[0] = true;
}
};
m.addListener(listener);
try {
ICluster cluster = m.createCluster("id1");
m.addCluster(cluster);
List<ICluster> clusters = m.getClusters();
assertEquals(2, clusters.size());
m.removeCluster(cluster);
clusters = m.getClusters();
assertEquals(1, clusters.size());
assertTrue(checkAdded[0]);
assertTrue(checkRemoved[0]);
} finally {
m.removeListener(listener);
}
}
Aggregations