18484: Makes a list request on collectionService.get().
authorLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 29 Nov 2021 23:10:37 +0000 (20:10 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 29 Nov 2021 23:10:37 +0000 (20:10 -0300)
To avoid getting a whole collection record with its manifest_text field,
we use the list request with a uuid filter.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/services/collection-service/collection-service.test.ts
src/services/collection-service/collection-service.ts
src/services/common-service/common-service.ts

index c0aa85f1d3ab3e8df9912b993c978ef67d8c5834..1b0130c72915bf3d132f8844a239f56960072bc5 100644 (file)
@@ -30,6 +30,24 @@ describe('collection-service', () => {
         collectionService.update = jest.fn();
     });
 
+    describe('get', () => {
+        it('should make a list request with uuid filtering', async () => {
+            serverApi.get = jest.fn(() => Promise.resolve(
+                { data: { items: [{}] } }
+            ));
+            const uuid = 'zzzzz-4zz18-0123456789abcde'
+            await collectionService.get(uuid);
+            expect(serverApi.get).toHaveBeenCalledWith(
+                '/collections', {
+                    params: {
+                        filters: `[["uuid","=","zzzzz-4zz18-0123456789abcde"]]`,
+                        order: undefined
+                    },
+                }
+            );
+        });
+    });
+
     describe('update', () => {
         it('should call put selecting updated fields + others', async () => {
             serverApi.put = jest.fn(() => Promise.resolve({ data: {} }));
index 48e797c500e8b7e3dade9fc15727773176805773..43041ccd91cc2e3103a54860ad0930e826a50e0b 100644 (file)
@@ -11,6 +11,7 @@ import { extractFilesData } from "./collection-service-files-response";
 import { TrashableResourceService } from "services/common-service/trashable-resource-service";
 import { ApiActions } from "services/api/api-actions";
 import { customEncodeURI } from "common/url";
+import { FilterBuilder } from "services/api/filter-builder";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
@@ -28,6 +29,14 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         ]);
     }
 
+    async get(uuid: string, showErrors?: boolean) {
+        super.validateUuid(uuid);
+        // We use a filtered list request to avoid getting the manifest text
+        const filters = new FilterBuilder().addEqual('uuid', uuid).getFilters();
+        const lst = await super.list({filters}, showErrors);
+        return lst.items[0];
+    }
+
     create(data?: Partial<CollectionResource>) {
         return super.create({ ...data, preserveVersion: true });
     }
index 82777342b3b9931412ecacdac8290d240cf7fdc4..b5dd1a08b2d726d3c294c7f6077e38f1443ffe86 100644 (file)
@@ -68,7 +68,7 @@ export class CommonService<T> {
             }
         }
 
-    private validateUuid(uuid: string) {
+    protected validateUuid(uuid: string) {
         if (uuid === "") {
             throw new Error('UUID cannot be empty string');
         }
@@ -124,7 +124,7 @@ export class CommonService<T> {
         );
     }
 
-    list(args: ListArguments = {}): Promise<ListResults<T>> {
+    list(args: ListArguments = {}, showErrors?: boolean): Promise<ListResults<T>> {
         const { filters, order, ...other } = args;
         const params = {
             ...CommonService.mapKeys(snakeCase)(other),
@@ -135,7 +135,8 @@ export class CommonService<T> {
         if (QueryString.stringify(params).length <= 1500) {
             return CommonService.defaultResponse(
                 this.serverApi.get(`/${this.resourceType}`, { params }),
-                this.actions
+                this.actions,
+                showErrors
             );
         } else {
             // Using the POST special case to avoid URI length 414 errors.
@@ -152,7 +153,8 @@ export class CommonService<T> {
                         _method: 'GET'
                     }
                 }),
-                this.actions
+                this.actions,
+                showErrors
             );
         }
     }