Search in sources :

Example 1 with FilesApi

use of com.haleconnect.api.projectstore.v1.api.FilesApi 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 2 with FilesApi

use of com.haleconnect.api.projectstore.v1.api.FilesApi 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 3 with FilesApi

use of com.haleconnect.api.projectstore.v1.api.FilesApi 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)

Aggregations

FilesApi (com.haleconnect.api.projectstore.v1.api.FilesApi)3 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)2 ApiException (com.haleconnect.api.projectstore.v1.ApiException)1 Feedback (com.haleconnect.api.projectstore.v1.model.Feedback)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1