use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class HaleConnectServiceImpl method getUserInfo.
/**
* @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#getUserInfo(java.lang.String)
*/
@Override
public HaleConnectUserInfo getUserInfo(String userId) throws HaleConnectException {
if (!this.isLoggedIn()) {
return null;
}
if (!userInfoCache.containsKey(userId)) {
UsersApi api = UserServiceHelper.getUsersApi(this, this.getSession().getToken());
try {
UserInfo info = api.getProfile(userId);
userInfoCache.put(info.getId(), new HaleConnectUserInfo(info.getId(), info.getScreenName(), info.getFullName()));
} catch (ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
}
return userInfoCache.get(userId);
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class HaleConnectServiceImpl method testUserPermission.
@SuppressWarnings("unchecked")
@Override
public boolean testUserPermission(String resourceType, String role, String permission) throws HaleConnectException {
com.haleconnect.api.user.v1.api.PermissionsApi api = UserServiceHelper.getPermissionsApi(this, this.getSession().getToken());
try {
Map<String, Object> permissions = (Map<String, Object>) api.getResourcePermissionInfo(resourceType, permission);
if ("user".equals(role)) {
Object userPermission = permissions.get("user");
return !"false".equals(userPermission.toString());
} else {
// Interpret role as orgId
Object orgPermission = permissions.get("organisations");
if (orgPermission instanceof Map) {
// keySet is set of organisation ids
Map<String, Object> orgPermissions = (Map<String, Object>) orgPermission;
Object conditions = Optional.ofNullable(orgPermissions.get(role)).orElse(Collections.EMPTY_LIST);
if ("false".equals(conditions.toString())) {
return false;
} else if (conditions instanceof List) {
return ((List<?>) conditions).stream().anyMatch(cond -> "organisation".equals(cond.toString()));
}
}
}
} catch (ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
return false;
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class HaleConnectServiceImpl method processBucketDetail.
@SuppressWarnings("unchecked")
private HaleConnectProjectInfo processBucketDetail(BucketDetail bucket) {
String author = null;
Long lastModified = bucket.getLastModified();
if (bucket.getProperties() instanceof Map<?, ?>) {
Map<Object, Object> properties = (Map<Object, Object>) bucket.getProperties();
if (properties.containsKey("author")) {
author = properties.get("author").toString();
}
}
HaleConnectUserInfo user = null;
HaleConnectOrganisationInfo org = null;
try {
if (!StringUtils.isEmpty(bucket.getId().getUserId())) {
user = this.getUserInfo(bucket.getId().getUserId());
}
if (!StringUtils.isEmpty(bucket.getId().getOrgId())) {
org = this.getOrganisationInfo(bucket.getId().getOrgId());
}
} catch (HaleConnectException e) {
log.error(e.getMessage(), e);
}
return new HaleConnectProjectInfo(bucket.getId().getTransformationproject(), user, org, bucket.getName(), author, lastModified);
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectException in project hale by halestudio.
the class ProjectStoreHelper method executePlainTextCallWithFeedback.
/**
* Execute a REST call with the content type <code>text/plain; charset=utf-8
* </code>
*
* @param method HTTP method (POST, PUT)
* @param path REST path (without base path)
* @param body The plain text bdoy
* @param basePath The REST base path
* @param apiKey The API key
* @return the feedback
* @throws HaleConnectException thrown on any API error
*/
public static Feedback executePlainTextCallWithFeedback(String method, String path, String body, BasePathResolver basePath, String apiKey) throws HaleConnectException {
ApiClient apiClient = ProjectStoreHelper.getApiClient(basePath, apiKey);
OkHttpClient httpClient = apiClient.getHttpClient();
String url = apiClient.buildUrl(path, null);
Request.Builder reqBuilder = new Request.Builder().url(url);
Map<String, String> headerParams = new HashMap<String, String>();
apiClient.updateParamsForAuth(new String[] { "bearer" }, null, headerParams);
apiClient.processHeaderParams(headerParams, reqBuilder);
RequestBody reqBody = RequestBody.create(MediaType.parse("text/plain; charset=utf-8"), body);
Request request = reqBuilder.method(method, reqBody).build();
Call call = httpClient.newCall(request);
Feedback feedback;
try {
ApiResponse<Feedback> resp = apiClient.execute(call, new TypeToken<Feedback>() {
}.getType());
feedback = resp.getData();
} catch (com.haleconnect.api.projectstore.v1.ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
return feedback;
}
Aggregations