use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectSourceProvider method getCurrentState.
/**
* @see org.eclipse.ui.ISourceProvider#getCurrentState()
*/
@Override
public Map<String, Object> getCurrentState() {
final Map<String, Object> result = new HashMap<String, Object>();
final HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
result.put(LOGIN_STATUS, hcs.isLoggedIn());
return result;
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectUIPlugin method start.
/**
* @see AbstractUIPlugin#start(BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
try {
HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
boolean useDefaults;
if (!HaleConnectUIPlugin.getDefault().getPreferenceStore().contains(PreferenceConstants.HALE_CONNECT_BASEPATH_USE_DEFAULTS)) {
useDefaults = true;
HaleConnectUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.HALE_CONNECT_BASEPATH_USE_DEFAULTS, true);
} else {
useDefaults = HaleConnectUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.HALE_CONNECT_BASEPATH_USE_DEFAULTS);
}
if (useDefaults) {
// Force default values
hcs.getBasePathManager().setBasePath(HaleConnectServices.USER_SERVICE, PreferenceInitializer.HALE_CONNECT_BASEPATH_USERS_DEFAULT);
hcs.getBasePathManager().setBasePath(HaleConnectServices.BUCKET_SERVICE, PreferenceInitializer.HALE_CONNECT_BASEPATH_DATA_DEFAULT);
hcs.getBasePathManager().setBasePath(HaleConnectServices.PROJECT_STORE, PreferenceInitializer.HALE_CONNECT_BASEPATH_PROJECTS_DEFAULT);
hcs.getBasePathManager().setBasePath(HaleConnectServices.WEB_CLIENT, PreferenceInitializer.HALE_CONNECT_BASEPATH_CLIENT_DEFAULT);
} else {
hcs.getBasePathManager().setBasePath(HaleConnectServices.USER_SERVICE, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_USERS));
hcs.getBasePathManager().setBasePath(HaleConnectServices.BUCKET_SERVICE, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_DATA));
hcs.getBasePathManager().setBasePath(HaleConnectServices.PROJECT_STORE, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_PROJECTS));
hcs.getBasePathManager().setBasePath(HaleConnectServices.WEB_CLIENT, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_CLIENT));
}
} catch (Throwable t) {
log.error("Error initializing HaleConnectService", t);
}
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectTarget method updateLoginStatus.
private void updateLoginStatus() {
HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
boolean loggedIn = hcs.isLoggedIn();
ownershipGroup.setEnabled(loggedIn);
enableVersioning.setEnabled(loggedIn);
publicAccess.setEnabled(loggedIn);
ownerUser.setEnabled(loggedIn);
includeWebResources.setEnabled(loggedIn);
excludeData.setEnabled(loggedIn);
excludeCachedResources.setEnabled(loggedIn);
selectProjectButton.setEnabled(loggedIn);
newProject.setEnabled(loggedIn);
updateProject.setEnabled(loggedIn);
if (loggedIn) {
loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN));
loginStatusLabel.setText(MessageFormat.format("Logged in as {0}", hcs.getSession().getUsername()));
boolean orgAllowed;
if (hcs.getSession().getOrganisationIds().isEmpty()) {
orgAllowed = false;
} else {
try {
orgAllowed = hcs.testUserPermission(RESOURCE_TRANSFORMATION_PROJECT, hcs.getSession().getOrganisationIds().iterator().next(), PERMISSION_CREATE);
} catch (Throwable t) {
log.userError("A problem occurred while contacting hale connect. Functionality may be limited.", t);
orgAllowed = false;
}
}
ownerOrg.setEnabled(false);
orgSelector.getCombo().setEnabled(false);
if (orgAllowed) {
final SettableFuture<List<HaleConnectOrganisationInfo>> orgsFuture = SettableFuture.create();
Futures.addCallback(orgsFuture, new FutureCallback<List<HaleConnectOrganisationInfo>>() {
@Override
public void onSuccess(List<HaleConnectOrganisationInfo> result) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
ownerOrg.setEnabled(true);
orgSelector.getCombo().setEnabled(true);
orgSelector.setInput(result);
if (!result.isEmpty()) {
orgSelector.setSelection(new StructuredSelection(result.get(0)));
}
}
});
}
@Override
public void onFailure(Throwable t) {
log.userError("A problem occurred while contacting hale connect. Functionality may be limited.", t);
}
});
Thread fetchOrgInfoThread = new Thread(new Runnable() {
@Override
public void run() {
boolean hadException = false;
List<HaleConnectOrganisationInfo> organisations = new ArrayList<>();
List<HaleConnectException> exceptions = new ArrayList<>();
for (String orgId : hcs.getSession().getOrganisationIds()) {
try {
HaleConnectOrganisationInfo orgInfo = hcs.getOrganisationInfo(orgId);
if (orgInfo != null) {
organisations.add(orgInfo);
}
} catch (HaleConnectException e) {
hadException = true;
log.error("Error fetching organization details from hale connect.", e);
exceptions.add(e);
// As a fallback, display dummy value that
// contains the
// orgId
organisations.add(new HaleConnectOrganisationInfo(orgId, MessageFormat.format("<Organisation {0}>", orgId)));
}
}
orgsFuture.set(organisations);
if (hadException) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
log.userError("A problem occurred while contacting hale connect. Functionality may be limited.");
}
});
}
}
});
fetchOrgInfoThread.start();
}
boolean userAllowed;
try {
userAllowed = hcs.testUserPermission(RESOURCE_TRANSFORMATION_PROJECT, OwnerType.USER.getJsonValue(), PERMISSION_CREATE);
} catch (Throwable t) {
log.userError("A problem occurred while contacting hale connect. Functionality may be limited.", t);
userAllowed = false;
}
ownerUser.setEnabled(userAllowed);
ownerUser.setSelection(userAllowed);
if (!userAllowed || !orgAllowed) {
ownerOrg.setSelection(orgAllowed);
}
if (!userAllowed && !orgAllowed) {
loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
loginStatusLabel.setText("You do not have sufficient permissions to upload transformation projects to hale connect.");
}
} else {
loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
loginStatusLabel.setText("You are not logged in to hale connect. Please login before sharing a project.");
ownerOrg.setEnabled(false);
}
}
Aggregations