use of com.haleconnect.api.projectstore.v1.ApiException in project hale by halestudio.
the class HaleConnectInputSupplier method getLastModified.
/**
* @return details on the hale connect project
*/
public Long getLastModified() {
if (lastModified == null) {
Owner owner = HaleConnectUrnBuilder.extractProjectOwner(getLocation());
String projectId = HaleConnectUrnBuilder.extractProjectId(getLocation());
final BucketsApi api = ProjectStoreHelper.getBucketsApi(basePathResolver, apiKey);
final ApiResponse<BucketDetail> response;
try {
response = api.getBucketInfoWithHttpInfo(owner.getType().getJsonValue(), owner.getId(), projectId);
lastModified = response.getData().getLastModified();
} catch (ApiException e) {
// Not fatal
}
}
return lastModified;
}
use of com.haleconnect.api.projectstore.v1.ApiException in project hale by halestudio.
the class HaleConnectServiceImpl method testProjectPermission.
@Override
public boolean testProjectPermission(String permission, Owner owner, String projectId) throws HaleConnectException {
PermissionsApi api = ProjectStoreHelper.getPermissionsApi(this, this.getSession().getToken());
String combinedBucketId = MessageFormat.format("{0}.{1}.{2}", owner.getType().getJsonValue(), owner.getId(), projectId);
try {
api.testBucketPermission(permission, combinedBucketId);
} catch (com.haleconnect.api.projectstore.v1.ApiException e) {
if (e.getCode() == 403) {
// not allowed
return false;
}
// other codes indicate client error or server-side exception
throw new HaleConnectException(e.getMessage(), e);
}
return true;
}
use of com.haleconnect.api.projectstore.v1.ApiException in project hale by halestudio.
the class HaleConnectServiceImpl method createUploadFileCallback.
private ApiCallback<Feedback> createUploadFileCallback(final SettableFuture<Boolean> future, final ProgressIndicator progress, final File file, final int totalWork) {
return new ApiCallback<Feedback>() {
AtomicLong chunkWritten = new AtomicLong(0);
AtomicLong bytesReported = new AtomicLong(0);
@Override
public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {
// not required
}
@Override
public void onFailure(com.haleconnect.api.projectstore.v1.ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
progress.end();
future.setException(new HaleConnectException(e.getMessage(), e, statusCode, responseHeaders));
}
@Override
public void onSuccess(Feedback result, int statusCode, Map<String, List<String>> responseHeaders) {
if (result.getError()) {
log.error(MessageFormat.format("Error uploading project file \"{0}\": {1}", file.getAbsolutePath(), result.getMessage()));
future.set(false);
} else {
future.set(true);
}
progress.end();
}
@Override
public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {
// bytesWritten contains the accumulated amount of bytes written
if (totalWork != ProgressIndicator.UNKNOWN) {
// Wait until at least 1 KiB was written
long chunk = chunkWritten.get();
chunk += bytesWritten - bytesReported.get();
if (chunk >= 1024) {
long workToReport = chunk >> 10;
// cannot overflow, total size in KiB
// is guaranteed to be < Integer.MAX_VALUE
progress.advance(Math.toIntExact(workToReport));
chunk -= workToReport << 10;
// chunkWritten now always < 1024
}
chunkWritten.set(chunk);
bytesReported.set(bytesWritten);
}
}
};
}
use of com.haleconnect.api.projectstore.v1.ApiException in project hale by halestudio.
the class HaleConnectServiceImpl method getOrganisationInfo.
/**
* @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#getOrganisationInfo(java.lang.String)
*/
@Override
public HaleConnectOrganisationInfo getOrganisationInfo(String orgId) throws HaleConnectException {
if (!this.isLoggedIn()) {
return null;
}
if (!orgInfoCache.containsKey(orgId)) {
OrganisationsApi api = UserServiceHelper.getOrganisationsApi(this, this.getSession().getToken());
try {
OrganisationInfo org = api.getOrganisation(orgId);
orgInfoCache.put(org.getId(), new HaleConnectOrganisationInfo(org.getId(), org.getName()));
} catch (ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
}
return orgInfoCache.get(orgId);
}
use of com.haleconnect.api.projectstore.v1.ApiException in project hale by halestudio.
the class HaleConnectServiceImpl method login.
/**
* @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#login(java.lang.String,
* java.lang.String)
*/
@Override
public boolean login(String username, String password) throws HaleConnectException {
LoginApi loginApi = UserServiceHelper.getLoginApi(this);
Credentials credentials = UserServiceHelper.buildCredentials(username, password);
try {
Token token = loginApi.login(credentials);
if (token != null) {
UsersApi usersApi = UserServiceHelper.getUsersApi(this, token.getToken());
// First get the current user's profile to obtain the user ID
// required to fetch the extended profile (including the user's
// roles/organisations) in the next step
UserInfo shortProfile = usersApi.getProfileOfCurrentUser();
session = new HaleConnectSessionImpl(username, token.getToken(), usersApi.getProfile(shortProfile.getId()));
notifyLoginStateChanged();
} else {
clearSession();
}
} catch (ApiException e) {
if (e.getCode() == 401) {
clearSession();
} else {
throw new HaleConnectException(e.getMessage(), e);
}
}
return isLoggedIn();
}
Aggregations