[arvados] created: 2.1.0-2620-ga8bc8a013

git repository hosting git at public.arvados.org
Wed Jul 6 20:10:22 UTC 2022


        at  a8bc8a013598f16f70333656abff8be72fae803f (commit)


commit a8bc8a013598f16f70333656abff8be72fae803f
Author: Krzysztof Majewski <krzysztof.majewski.km1 at contractors.roche.com>
Date:   Tue Jun 28 10:23:25 2022 +0200

    Add new method to upload files via Keep Web API
    
    Arvados-DCO-1.1-Signed-off-by: Krzysztof Majewski majewski.kielce at gmail.com

diff --git a/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java b/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java
index 0145b0fc4..05d39e9e6 100644
--- a/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java
+++ b/sdk/java-v2/src/main/java/org/arvados/client/api/client/KeepWebApiClient.java
@@ -9,8 +9,11 @@ package org.arvados.client.api.client;
 
 import okhttp3.HttpUrl;
 import okhttp3.Request;
+import okhttp3.RequestBody;
 import org.arvados.client.config.ConfigProvider;
 
+import java.io.File;
+
 public class KeepWebApiClient extends BaseApiClient {
 
     public KeepWebApiClient(ConfigProvider config) {
@@ -35,6 +38,16 @@ public class KeepWebApiClient extends BaseApiClient {
         return newCall(request);
     }
 
+    public String upload(String collectionUuid, File file, ProgressListener progressListener) {
+        RequestBody requestBody = new CountingFileRequestBody(file, progressListener);
+
+        Request request = getRequestBuilder()
+                .url(getUrlBuilder(collectionUuid, file.getName()).build())
+                .put(requestBody)
+                .build();
+        return newCall(request);
+    }
+
     private HttpUrl.Builder getUrlBuilder(String collectionUuid, String filePathName) {
         return new HttpUrl.Builder()
                 .scheme(config.getApiProtocol())
diff --git a/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java b/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java
index 8563adcc7..596c9421a 100644
--- a/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java
+++ b/sdk/java-v2/src/main/java/org/arvados/client/api/client/ProgressListener.java
@@ -10,5 +10,5 @@ package org.arvados.client.api.client;
 @FunctionalInterface
 public interface ProgressListener {
 
-    void updateProgress(long num);
+    void updateProgress(long uploadedBytes);
 }
\ No newline at end of file
diff --git a/sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java b/sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java
new file mode 100644
index 000000000..07b7b2533
--- /dev/null
+++ b/sdk/java-v2/src/test/java/org/arvados/client/api/client/KeepWebApiClientTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) The Arvados Authors. All rights reserved.
+ *
+ * SPDX-License-Identifier: AGPL-3.0 OR Apache-2.0
+ *
+ */
+
+package org.arvados.client.api.client;
+
+import org.arvados.client.test.utils.ArvadosClientMockedWebServerTest;
+import org.junit.Test;
+
+import java.io.File;
+import java.nio.file.Files;
+
+import static org.arvados.client.test.utils.ApiClientTestUtils.getResponse;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class KeepWebApiClientTest extends ArvadosClientMockedWebServerTest {
+
+    private KeepWebApiClient client = new KeepWebApiClient(CONFIG);
+
+    @Test
+    public void uploadFile() throws Exception {
+        // given
+        String collectionUuid = "112ci-4zz18-p51w7z3fpopo6sm";
+        File file = Files.createTempFile("keep-upload-test", "txt").toFile();
+        Files.write(file.toPath(), "test data".getBytes());
+
+        server.enqueue(getResponse("keep-client-upload-response"));
+
+        // when
+        String uploadResponse = client.upload(collectionUuid, file, uploadedBytes -> System.out.printf("Uploaded bytes: %s/%s%n", uploadedBytes, file.length()));
+
+        // then
+        assertThat(uploadResponse).isEqualTo("Created");
+    }
+
+}
diff --git a/sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json b/sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json
new file mode 100644
index 000000000..5284f287d
--- /dev/null
+++ b/sdk/java-v2/src/test/resources/org/arvados/client/api/client/keep-client-upload-response.json
@@ -0,0 +1 @@
+Created
\ No newline at end of file

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list