use of com.haleconnect.api.user.v1.ApiException 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 com.haleconnect.api.user.v1.ApiException 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;
}
Aggregations