Skip to content

Commit

Permalink
remove logic for getting metadata from MMS
Browse files Browse the repository at this point in the history
  • Loading branch information
aswallace committed Dec 19, 2024
1 parent 80d9536 commit e885706
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 200 deletions.
26 changes: 0 additions & 26 deletions packages/core/services/FileService/DatabaseFileService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions packages/core/services/FileService/FileServiceNoop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FileService, { AnnotationNameToValuesMap, SelectionAggregationResult } from ".";
import FileService, { SelectionAggregationResult } from ".";
import { DownloadResolution, DownloadResult } from "../FileDownloadService";
import FileDetail from "../../entity/FileDetail";

Expand All @@ -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<FileDetail[]> {
return Promise.resolve([]);
}
Expand Down
44 changes: 1 addition & 43 deletions packages/core/services/FileService/HttpFileService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

/**
Expand Down Expand Up @@ -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<number, Annotation>
): 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<EditableFileMetadata>(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 }
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions packages/core/services/FileService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,5 @@ export default interface FileService {
): Promise<void>;
getAggregateInformation(fileSelection: FileSelection): Promise<SelectionAggregationResult>;
getCountOfMatchingFiles(fileSet: FileSet): Promise<number>;
getEditableFileMetadata(
fileIds: string[],
annotationIdToAnnotationMap?: Record<number, Annotation>
): Promise<{ [fileId: string]: AnnotationNameToValuesMap }>;
getFiles(request: GetFilesRequest): Promise<FileDetail[]>;
}
2 changes: 0 additions & 2 deletions packages/core/state/interaction/logics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e885706

Please sign in to comment.