From e885706c8a2a107d4fd473cacbeb720e0c5c5088 Mon Sep 17 00:00:00 2001 From: Anya Wallace Date: Thu, 19 Dec 2024 13:27:42 -0800 Subject: [PATCH] remove logic for getting metadata from MMS --- .../FileService/DatabaseFileService/index.ts | 26 ------ .../test/DatabaseFileService.test.ts | 33 ------- .../services/FileService/FileServiceNoop.ts | 6 +- .../FileService/HttpFileService/index.ts | 44 +--------- .../test/HttpFileService.test.ts | 87 ------------------- packages/core/services/FileService/index.ts | 4 - packages/core/state/interaction/logics.ts | 2 - 7 files changed, 2 insertions(+), 200 deletions(-) diff --git a/packages/core/services/FileService/DatabaseFileService/index.ts b/packages/core/services/FileService/DatabaseFileService/index.ts index 27011b99..b2fe55b5 100644 --- a/packages/core/services/FileService/DatabaseFileService/index.ts +++ b/packages/core/services/FileService/DatabaseFileService/index.ts @@ -202,30 +202,4 @@ export default class DatabaseFileService implements FileService { `; return this.databaseService.execute(sql); } - - public async getEditableFileMetadata( - fileIds: string[] - ): Promise<{ [fileId: string]: AnnotationNameToValuesMap }> { - const sql = new SQLBuilder() - .from(this.dataSourceNames) - .where(`${DatabaseService.HIDDEN_UID_ANNOTATION} IN (${fileIds.join(", ")})`) - .toSQL(); - - const rows = await this.databaseService.query(sql); - return rows - .map((row) => DatabaseFileService.convertDatabaseRowToFileDetail(row)) - .reduce( - (acc, file) => ({ - ...acc, - [file.uid]: file.annotations.reduce( - (annoAcc, annotation) => ({ - ...annoAcc, - [annotation.name]: annotation.values, - }), - {} as AnnotationNameToValuesMap - ), - }), - {} as { [fileId: string]: AnnotationNameToValuesMap } - ); - } } diff --git a/packages/core/services/FileService/DatabaseFileService/test/DatabaseFileService.test.ts b/packages/core/services/FileService/DatabaseFileService/test/DatabaseFileService.test.ts index 81d1b0c9..3269add3 100644 --- a/packages/core/services/FileService/DatabaseFileService/test/DatabaseFileService.test.ts +++ b/packages/core/services/FileService/DatabaseFileService/test/DatabaseFileService.test.ts @@ -65,39 +65,6 @@ describe("DatabaseFileService", () => { }); }); - describe("getEditableFileMetadata", () => { - it("converts response into a map of file uids to metadata", async () => { - // Arrange - const databaseFileService = new DatabaseFileService({ - dataSourceNames: ["mock source name", "another mock source name"], - databaseService, - downloadService: new FileDownloadServiceNoop(), - }); - - // Act - const response = await databaseFileService.getEditableFileMetadata([ - "abc123", - "def456", - ]); - - // Assert - expect(response).to.deep.equal({ - abc123: { - "File Name": ["file"], - "File Path": ["path/to/file"], - "File Size": ["432226"], - num_files: ["6"], - }, - def456: { - "File Name": ["file"], - "File Path": ["path/to/file"], - "File Size": ["432226"], - num_files: ["6"], - }, - }); - }); - }); - describe("getAggregateInformation", () => { it("issues request for aggregated information about given files", async () => { // Arrange diff --git a/packages/core/services/FileService/FileServiceNoop.ts b/packages/core/services/FileService/FileServiceNoop.ts index 569bd2d9..bf268427 100644 --- a/packages/core/services/FileService/FileServiceNoop.ts +++ b/packages/core/services/FileService/FileServiceNoop.ts @@ -1,4 +1,4 @@ -import FileService, { AnnotationNameToValuesMap, SelectionAggregationResult } from "."; +import FileService, { SelectionAggregationResult } from "."; import { DownloadResolution, DownloadResult } from "../FileDownloadService"; import FileDetail from "../../entity/FileDetail"; @@ -11,10 +11,6 @@ export default class FileServiceNoop implements FileService { return Promise.resolve({ count: 0, size: 0 }); } - public getEditableFileMetadata(): Promise<{ [fileId: string]: AnnotationNameToValuesMap }> { - return Promise.resolve({}); - } - public getFiles(): Promise { return Promise.resolve([]); } diff --git a/packages/core/services/FileService/HttpFileService/index.ts b/packages/core/services/FileService/HttpFileService/index.ts index 02acef16..f27dc349 100644 --- a/packages/core/services/FileService/HttpFileService/index.ts +++ b/packages/core/services/FileService/HttpFileService/index.ts @@ -23,20 +23,10 @@ interface Config extends ConnectionConfig { downloadService: FileDownloadService; } -// Used for the GET request to MMS for file metadata -interface EditableFileMetadata { - fileId: string; - annotations?: { - annotationId: number; - values: string[]; - }[]; - templateId?: number; -} - const FESBaseUrlToMMSBaseUrlMap = { [FileExplorerServiceBaseUrl.LOCALHOST]: "https://localhost:9060", [FileExplorerServiceBaseUrl.STAGING]: "https://stg-aics.corp.alleninstitute.org", - [FileExplorerServiceBaseUrl.PRODUCTION]: "https://stg-aics.corp.alleninstitute.org", // TO DO: unsure if using stg for prod was intentional + [FileExplorerServiceBaseUrl.PRODUCTION]: "https://aics.corp.alleninstitute.org", }; /** @@ -171,36 +161,4 @@ export default class HttpFileService extends HttpServiceBase implements FileServ const requestBody = JSON.stringify({ customMetadata: { annotations } }); await this.put(url, requestBody); } - - public async getEditableFileMetadata( - fileIds: string[], - annotationIdToAnnotationMap?: Record - ): Promise<{ [fileId: string]: AnnotationNameToValuesMap }> { - const mmsBaseUrl = FESBaseUrlToMMSBaseUrlMap[this.baseUrl as FileExplorerServiceBaseUrl]; - const url = `${mmsBaseUrl}/${HttpFileService.BASE_EDIT_FILES_URL}/${fileIds.join(",")}`; - const response = await this.get(url); - - // Group files by fileId - return response.data.reduce( - (fileAcc, file) => ({ - ...fileAcc, - // Group annotations by name - [file.fileId]: - file.annotations?.reduce((annoAcc, annotation) => { - const name = annotationIdToAnnotationMap?.[annotation.annotationId]?.name; - if (!name) { - throw new Error( - "Failure mapping editable metadata response. " + - `Failed to find annotation name for annotation id ${annotation.annotationId}` - ); - } - return { - ...annoAcc, - [name]: annotation.values, - }; - }, {} as AnnotationNameToValuesMap) || {}, - }), - {} as { [fileId: string]: AnnotationNameToValuesMap } - ); - } } diff --git a/packages/core/services/FileService/HttpFileService/test/HttpFileService.test.ts b/packages/core/services/FileService/HttpFileService/test/HttpFileService.test.ts index 78e28573..548ef40c 100644 --- a/packages/core/services/FileService/HttpFileService/test/HttpFileService.test.ts +++ b/packages/core/services/FileService/HttpFileService/test/HttpFileService.test.ts @@ -2,7 +2,6 @@ import { createMockHttpClient } from "@aics/redux-utils"; import { expect } from "chai"; import HttpFileService from ".."; -import Annotation from "../../../../entity/Annotation"; import FileSelection from "../../../../entity/FileSelection"; import FileSet from "../../../../entity/FileSet"; import NumericRange from "../../../../entity/NumericRange"; @@ -73,92 +72,6 @@ describe("HttpFileService", () => { }); }); - describe("getEditableFileMetadata", () => { - const colorAnnotation = "Color"; - const colorAnnotationId = 3; - const fileIdWithColorAnnotation = "abc123"; - const fileIdWithoutColorAnnotation = "def456"; - const httpClient = createMockHttpClient([ - { - when: (config) => - !!config.url?.includes(`filemetadata/${fileIdWithColorAnnotation}`), - respondWith: { - data: { - data: [ - { - fileId: "abc123", - annotations: [ - { - annotationId: colorAnnotationId, - values: ["red"], - }, - ], - }, - ], - }, - }, - }, - { - when: (config) => - !!config.url?.includes(`filemetadata/${fileIdWithoutColorAnnotation}`), - respondWith: { - data: { - data: [ - { - fileId: "abc123", - annotations: [ - { - annotationId: 4, - values: ["AICS-0"], - }, - ], - }, - ], - }, - }, - }, - ]); - - it("converts response into a map of file_id to metadata", async () => { - const httpFileService = new HttpFileService({ - baseUrl, - httpClient, - downloadService: new FileDownloadServiceNoop(), - }); - - // Act - const fileMetadata = await httpFileService.getEditableFileMetadata( - [fileIdWithColorAnnotation], - { [colorAnnotationId]: new Annotation({ annotationName: colorAnnotation } as any) } - ); - - // Assert - expect(fileMetadata).to.deep.equal({ - [fileIdWithColorAnnotation]: { - [colorAnnotation]: ["red"], - }, - }); - }); - - it("fails if unable to find id of annotation", async () => { - const httpFileService = new HttpFileService({ - baseUrl, - httpClient, - downloadService: new FileDownloadServiceNoop(), - }); - - // Act / Assert - try { - await httpFileService.getEditableFileMetadata([fileIdWithoutColorAnnotation]); - expect(false, "Expected to throw").to.be.true; - } catch (e) { - expect((e as Error).message).to.equal( - "Failure mapping editable metadata response. Failed to find annotation name for annotation id 4" - ); - } - }); - }); - describe("getAggregateInformation", () => { const totalFileSize = 12424114; const totalFileCount = 7; diff --git a/packages/core/services/FileService/index.ts b/packages/core/services/FileService/index.ts index 2b2b110f..c95b969d 100644 --- a/packages/core/services/FileService/index.ts +++ b/packages/core/services/FileService/index.ts @@ -58,9 +58,5 @@ export default interface FileService { ): Promise; getAggregateInformation(fileSelection: FileSelection): Promise; getCountOfMatchingFiles(fileSet: FileSet): Promise; - getEditableFileMetadata( - fileIds: string[], - annotationIdToAnnotationMap?: Record - ): Promise<{ [fileId: string]: AnnotationNameToValuesMap }>; getFiles(request: GetFilesRequest): Promise; } diff --git a/packages/core/state/interaction/logics.ts b/packages/core/state/interaction/logics.ts index affe73f6..32d34059 100644 --- a/packages/core/state/interaction/logics.ts +++ b/packages/core/state/interaction/logics.ts @@ -541,8 +541,6 @@ const editFilesLogic = createLogic({ // Dispatch an event to alert the user of the start of the process const editRequestId = uniqueId(); const editProcessMsg = "Editing files in progress."; - // TODO: Lyndsay's design did not include a progress bar for editing files - // nor a way to cancel the process. This is a placeholder for now. dispatch(processStart(editRequestId, editProcessMsg, noop)); // Track the total number of files edited