use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class HaleConnectLoginHandler method performLogin.
/**
* Login to hale connect using the credentials entered in the given
* {@link HaleConnectLoginDialog}.
*
* @param loginDialog Login dialog with credentials
* @return true if successfully logged in
*/
public static boolean performLogin(HaleConnectLoginDialog loginDialog) {
HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
String username = loginDialog.getUsername();
String password = loginDialog.getPassword();
boolean saveCredentials = loginDialog.isSaveCredentials();
try {
if (hcs.login(username, password)) {
loginDialog.close();
if (saveCredentials) {
try {
HaleConnectUIPlugin.storeUsername(username);
HaleConnectUIPlugin.storePassword(password);
} catch (StorageException e) {
log.error("hale connect credentials could not be saved.", e);
}
}
log.userInfo("Login to hale connect successful.");
return true;
} else {
log.userWarn("Login to hale connect failed, please check the credentials.");
}
} catch (HaleConnectException e) {
log.userError("An error occurred while trying to login to hale connect", e);
}
return false;
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException 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);
}
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class HaleConnectServiceImpl method uploadProjectFileAsync.
@Override
public ListenableFuture<Boolean> uploadProjectFileAsync(String projectId, Owner owner, File file, ProgressIndicator progress) throws HaleConnectException {
if (!this.isLoggedIn()) {
throw new HaleConnectException("Not logged in");
}
String apiKey = this.getSession().getToken();
// PUT /buckets/{ownerType}/{ownerId}/{bucketID}/name
FilesApi filesApi = ProjectStoreHelper.getFilesApi(this, apiKey);
// refactor to reuse code in both sync and async methods
SettableFuture<Boolean> future = SettableFuture.create();
try {
// POST /raw
int totalWork = computeTotalWork(file);
progress.begin("Uploading project archive", totalWork);
filesApi.addFilesAsync(owner.getType().getJsonValue(), owner.getId(), projectId, file, createUploadFileCallback(future, progress, file, totalWork));
} catch (com.haleconnect.api.projectstore.v1.ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
return future;
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class HaleConnectServiceImpl method uploadProjectFile.
/**
* @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#uploadProjectFile(java.lang.String,
* eu.esdihumboldt.hale.io.haleconnect.Owner, java.io.File,
* eu.esdihumboldt.hale.common.core.io.ProgressIndicator)
*/
@Override
public boolean uploadProjectFile(String projectId, Owner owner, File file, ProgressIndicator progress) throws HaleConnectException {
if (!this.isLoggedIn()) {
throw new HaleConnectException("Not logged in");
}
String apiKey = this.getSession().getToken();
SettableFuture<Boolean> future = SettableFuture.create();
try {
FilesApi filesApi = ProjectStoreHelper.getFilesApi(this, apiKey);
// POST /raw
int totalWork = computeTotalWork(file);
ApiCallback<Feedback> apiCallback = createUploadFileCallback(future, progress, file, totalWork);
progress.begin("Uploading project archive", totalWork);
filesApi.addFilesAsync(owner.getType().getJsonValue(), owner.getId(), projectId, file, apiCallback);
return future.get();
} catch (com.haleconnect.api.projectstore.v1.ApiException e1) {
throw new HaleConnectException(e1.getMessage(), e1, e1.getCode(), e1.getResponseHeaders());
} catch (ExecutionException e2) {
Throwable t = e2.getCause();
if (t instanceof HaleConnectException) {
throw (HaleConnectException) t;
} else {
throw new HaleConnectException(t.getMessage(), t);
}
} catch (InterruptedException e3) {
throw new HaleConnectException(e3.getMessage(), e3);
}
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class HaleConnectServiceImpl method createProject.
/**
* @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#createProject(java.lang.String,
* java.lang.String, eu.esdihumboldt.hale.io.haleconnect.Owner,
* boolean)
*/
@Override
public String createProject(String name, String author, Owner owner, boolean versionControl) throws HaleConnectException {
if (!this.isLoggedIn()) {
throw new HaleConnectException("Not logged in");
}
String apiKey = this.getSession().getToken();
NewBucket newBucket = new NewBucket();
newBucket.setName(name);
newBucket.setVersionControl(versionControl);
final BucketIdent id;
try {
BucketsApi bucketsApi = ProjectStoreHelper.getBucketsApi(this, apiKey);
// POST /buckets
id = bucketsApi.createBucketWithOwner(owner.getType().getJsonValue(), owner.getId(), newBucket);
Owner bucketOwner = UserServiceHelper.toOwner(id.getUserId(), id.getOrgId());
// PUT /buckets/{ownerType}/{ownerId}/{bucketID}/p/author
bucketsApi.setBucketProperty(bucketOwner.getType().getJsonValue(), bucketOwner.getId(), id.getTransformationproject(), "author", author);
} catch (com.haleconnect.api.projectstore.v1.ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
return id.getTransformationproject();
}
Aggregations