Search in sources :

Example 6 with ApiException

use of com.haleconnect.api.projectstore.v1.ApiException in project hale by halestudio.

the class HaleConnectServiceImpl method setProjectSharingOptions.

@Override
public boolean setProjectSharingOptions(String projectId, Owner owner, SharingOptions options) throws HaleConnectException {
    BucketsApi bucketsApi = ProjectStoreHelper.getBucketsApi(this, this.getSession().getToken());
    Feedback feedback;
    try {
        feedback = bucketsApi.setBucketProperty(owner.getType().getJsonValue(), owner.getId(), projectId, "sharingOptions", options);
    } catch (com.haleconnect.api.projectstore.v1.ApiException e) {
        throw new HaleConnectException(e.getMessage(), e);
    }
    if (feedback.getError()) {
        log.error(MessageFormat.format("Error setting sharing options for hale connect project {0}", projectId));
        return false;
    }
    return true;
}
Also used : Feedback(com.haleconnect.api.projectstore.v1.model.Feedback) BucketsApi(com.haleconnect.api.projectstore.v1.api.BucketsApi) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)

Example 7 with ApiException

use of com.haleconnect.api.projectstore.v1.ApiException in project hale by halestudio.

the class HaleConnectInputSupplier method getInput.

@Override
public InputStream getInput() throws IOException {
    Owner owner = HaleConnectUrnBuilder.extractProjectOwner(getLocation());
    String projectId = HaleConnectUrnBuilder.extractProjectId(getLocation());
    FilesApi api = ProjectStoreHelper.getFilesApi(basePathResolver, apiKey);
    final ApiResponse<File> response;
    try {
        response = api.getProjectFilesAsZipWithHttpInfo(owner.getType().getJsonValue(), owner.getId(), projectId);
    } catch (com.haleconnect.api.projectstore.v1.ApiException e) {
        throw new IOException(e.getMessage(), e);
    }
    // Cache lastModified timestamp at the time of import
    getLastModified();
    return new BufferedInputStream(new FileInputStream(response.getData()));
}
Also used : FilesApi(com.haleconnect.api.projectstore.v1.api.FilesApi) BufferedInputStream(java.io.BufferedInputStream) ApiException(com.haleconnect.api.projectstore.v1.ApiException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with ApiException

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

Example 9 with ApiException

use of com.haleconnect.api.projectstore.v1.ApiException 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);
    }
}
Also used : HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) FilesApi(com.haleconnect.api.projectstore.v1.api.FilesApi) Feedback(com.haleconnect.api.projectstore.v1.model.Feedback) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with ApiException

use of com.haleconnect.api.projectstore.v1.ApiException 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();
}
Also used : BucketIdent(com.haleconnect.api.projectstore.v1.model.BucketIdent) Owner(eu.esdihumboldt.hale.io.haleconnect.Owner) BucketsApi(com.haleconnect.api.projectstore.v1.api.BucketsApi) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) NewBucket(com.haleconnect.api.projectstore.v1.model.NewBucket)

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