Search in sources :

Example 11 with ApiException

use of com.haleconnect.api.projectstore.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);
}
Also used : UsersApi(com.haleconnect.api.user.v1.api.UsersApi) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) ApiException(com.haleconnect.api.user.v1.ApiException)

Example 12 with ApiException

use of com.haleconnect.api.projectstore.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;
}
Also used : HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) StringUtils(org.apache.commons.lang.StringUtils) Credentials(com.haleconnect.api.user.v1.model.Credentials) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ALogger(de.fhg.igd.slf4jplus.ALogger) Feedback(com.haleconnect.api.projectstore.v1.model.Feedback) SettableFuture(com.google.common.util.concurrent.SettableFuture) HaleConnectOrganisationInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ApiException(com.haleconnect.api.user.v1.ApiException) BucketIdent(com.haleconnect.api.projectstore.v1.model.BucketIdent) SharingOptions(eu.esdihumboldt.hale.io.haleconnect.project.SharingOptions) BucketDetail(com.haleconnect.api.projectstore.v1.model.BucketDetail) NewBucket(com.haleconnect.api.projectstore.v1.model.NewBucket) FilesApi(com.haleconnect.api.projectstore.v1.api.FilesApi) LocatableInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.LocatableInputSupplier) UsersApi(com.haleconnect.api.user.v1.api.UsersApi) Map(java.util.Map) Owner(eu.esdihumboldt.hale.io.haleconnect.Owner) PermissionsApi(com.haleconnect.api.projectstore.v1.api.PermissionsApi) URI(java.net.URI) OrganisationInfo(com.haleconnect.api.user.v1.model.OrganisationInfo) OrganisationsApi(com.haleconnect.api.user.v1.api.OrganisationsApi) ProgressIndicator(eu.esdihumboldt.hale.common.core.io.ProgressIndicator) ApiCallback(com.haleconnect.api.projectstore.v1.ApiCallback) HaleConnectSession(eu.esdihumboldt.hale.io.haleconnect.HaleConnectSession) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Token(com.haleconnect.api.user.v1.model.Token) ALoggerFactory(de.fhg.igd.slf4jplus.ALoggerFactory) HaleConnectProjectInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) File(java.io.File) HaleConnectInputSupplier(eu.esdihumboldt.hale.io.haleconnect.HaleConnectInputSupplier) HaleConnectUrnBuilder(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUrnBuilder) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) LoginApi(com.haleconnect.api.user.v1.api.LoginApi) List(java.util.List) HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) HaleConnectServiceListener(eu.esdihumboldt.hale.io.haleconnect.HaleConnectServiceListener) Optional(java.util.Optional) BasePathManager(eu.esdihumboldt.hale.io.haleconnect.BasePathManager) Collections(java.util.Collections) BucketsApi(com.haleconnect.api.projectstore.v1.api.BucketsApi) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ApiException(com.haleconnect.api.user.v1.ApiException)

Example 13 with ApiException

use of com.haleconnect.api.projectstore.v1.ApiException 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;
}
Also used : Call(com.squareup.okhttp.Call) OkHttpClient(com.squareup.okhttp.OkHttpClient) HashMap(java.util.HashMap) Request(com.squareup.okhttp.Request) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) ApiClient(com.haleconnect.api.projectstore.v1.ApiClient) Feedback(com.haleconnect.api.projectstore.v1.model.Feedback) TypeToken(com.google.gson.reflect.TypeToken) RequestBody(com.squareup.okhttp.RequestBody)

Aggregations

HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)11 Feedback (com.haleconnect.api.projectstore.v1.model.Feedback)5 ApiException (com.haleconnect.api.user.v1.ApiException)5 BucketsApi (com.haleconnect.api.projectstore.v1.api.BucketsApi)4 FilesApi (com.haleconnect.api.projectstore.v1.api.FilesApi)4 UsersApi (com.haleconnect.api.user.v1.api.UsersApi)3 UserInfo (com.haleconnect.api.user.v1.model.UserInfo)3 HaleConnectUserInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo)3 ApiCallback (com.haleconnect.api.projectstore.v1.ApiCallback)2 ApiException (com.haleconnect.api.projectstore.v1.ApiException)2 PermissionsApi (com.haleconnect.api.projectstore.v1.api.PermissionsApi)2 BucketDetail (com.haleconnect.api.projectstore.v1.model.BucketDetail)2 BucketIdent (com.haleconnect.api.projectstore.v1.model.BucketIdent)2 NewBucket (com.haleconnect.api.projectstore.v1.model.NewBucket)2 LoginApi (com.haleconnect.api.user.v1.api.LoginApi)2 OrganisationsApi (com.haleconnect.api.user.v1.api.OrganisationsApi)2 Credentials (com.haleconnect.api.user.v1.model.Credentials)2 OrganisationInfo (com.haleconnect.api.user.v1.model.OrganisationInfo)2 Token (com.haleconnect.api.user.v1.model.Token)2 HaleConnectOrganisationInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo)2