-
Notifications
You must be signed in to change notification settings - Fork 11
External Tools use cases #353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d576136
feat: external tool use cases
g-saracca 550afa5
test: unit
g-saracca db7e613
test: integration cases
g-saracca aa4bb65
refactor: change mapping
g-saracca fc750c9
skip tests to get pr version generated
g-saracca 5ed2e8a
refactor: rename external tool URL methods and interfaces for clarity
g-saracca 2435a25
feat: add contentType to ExternalTool and ExternalToolPayload interfaces
g-saracca 99286b1
test: remove skips
g-saracca 9b46887
refactor: use types from model instead of repeating
g-saracca 5cec1d2
feat: add toolParams, allowedApiCalls and requirements properties
g-saracca 5ab5852
skip test for now
g-saracca 3c8bb11
Merge develop into fea/352-external-tool-use-cases
g-saracca 40ea333
test: unskip tests now that related backend PR was merged
g-saracca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * @property {boolean} preview - boolean flag to indicate if the request is for previewing the tool or not. | ||
| * @property {string} locale - string specifying the locale for internationalization | ||
| */ | ||
|
|
||
| export interface GetExternalToolDTO { | ||
| preview: boolean | ||
| locale: string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| export interface ExternalTool { | ||
| id: number | ||
| displayName: string | ||
| description: string | ||
| types: ToolType[] | ||
| scope: ToolScope | ||
| contentType?: string // Only present when scope is 'file' | ||
| } | ||
|
|
||
| export enum ToolType { | ||
| Explore = 'explore', | ||
| Configure = 'configure', | ||
| Preview = 'preview', | ||
| Query = 'query' | ||
| } | ||
|
|
||
| export enum ToolScope { | ||
| Dataset = 'dataset', | ||
| File = 'file' | ||
| } | ||
|
|
||
| export interface DatasetExternalToolResolved { | ||
| toolUrlResolved: string | ||
| displayName: string | ||
| datasetId: number | ||
| preview: boolean | ||
| } | ||
|
|
||
| export interface FileExternalToolResolved { | ||
| toolUrlResolved: string | ||
| displayName: string | ||
| fileId: number | ||
| preview: boolean | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/externalTools/domain/repositories/IExternalToolsRepository.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { GetExternalToolDTO } from '../dtos/GetExternalToolDTO' | ||
| import { | ||
| DatasetExternalToolResolved, | ||
| ExternalTool, | ||
| FileExternalToolResolved | ||
| } from '../models/ExternalTool' | ||
|
|
||
| export interface IExternalToolsRepository { | ||
| getExternalTools(): Promise<ExternalTool[]> | ||
| getDatasetExternalToolResolved( | ||
| datasetId: number | string, | ||
| toolId: number, | ||
| getExternalToolDTO: GetExternalToolDTO | ||
| ): Promise<DatasetExternalToolResolved> | ||
| getFileExternalToolResolved( | ||
| fileId: number | string, | ||
| toolId: number, | ||
| getExternalToolDTO: GetExternalToolDTO | ||
| ): Promise<FileExternalToolResolved> | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/externalTools/domain/useCases/GetDatasetExternalToolResolved.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { GetExternalToolDTO } from '../dtos/GetExternalToolDTO' | ||
| import { DatasetExternalToolResolved } from '../models/ExternalTool' | ||
| import { IExternalToolsRepository } from '../repositories/IExternalToolsRepository' | ||
|
|
||
| export class GetDatasetExternalToolResolved implements UseCase<DatasetExternalToolResolved> { | ||
| private externalToolsRepository: IExternalToolsRepository | ||
|
|
||
| constructor(externalToolsRepository: IExternalToolsRepository) { | ||
| this.externalToolsRepository = externalToolsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns a DatasetExternalToolResolved object containing the resolved URL for accessing an external tool that operates at the dataset level. | ||
| * The URL includes necessary authentication tokens and parameters based on the user's permissions and the tool's configuration. | ||
| * Authentication is required for draft or deaccessioned datasets and the user must have ViewUnpublishedDataset permission. | ||
| * | ||
| * @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers). | ||
| * @param {number} toolId - The identifier of the external tool. | ||
| * @param {GetExternalToolDTO} getExternalToolDTO - The GetExternalToolDTO object containing additional parameters for the request. | ||
| * @returns {Promise<DatasetExternalToolResolved>} | ||
| */ | ||
| async execute( | ||
| datasetId: number | string, | ||
| toolId: number, | ||
| getExternalToolDTO: GetExternalToolDTO | ||
| ): Promise<DatasetExternalToolResolved> { | ||
| return await this.externalToolsRepository.getDatasetExternalToolResolved( | ||
| datasetId, | ||
| toolId, | ||
| getExternalToolDTO | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { ExternalTool } from '../models/ExternalTool' | ||
| import { IExternalToolsRepository } from '../repositories/IExternalToolsRepository' | ||
|
|
||
| export class GetExternalTools implements UseCase<ExternalTool[]> { | ||
| private externalToolsRepository: IExternalToolsRepository | ||
|
|
||
| constructor(externalToolsRepository: IExternalToolsRepository) { | ||
| this.externalToolsRepository = externalToolsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns a list containing all the external tools available in the installation. | ||
| * | ||
| * @returns {Promise<ExternalTool[]>} | ||
| */ | ||
| async execute(): Promise<ExternalTool[]> { | ||
| return await this.externalToolsRepository.getExternalTools() | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/externalTools/domain/useCases/GetFileExternalToolResolved.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { GetExternalToolDTO } from '../dtos/GetExternalToolDTO' | ||
| import { FileExternalToolResolved } from '../models/ExternalTool' | ||
| import { IExternalToolsRepository } from '../repositories/IExternalToolsRepository' | ||
|
|
||
| export class GetFileExternalToolResolved implements UseCase<FileExternalToolResolved> { | ||
| private externalToolsRepository: IExternalToolsRepository | ||
|
|
||
| constructor(externalToolsRepository: IExternalToolsRepository) { | ||
| this.externalToolsRepository = externalToolsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns a FileExternalToolResolved object containing the resolved URL for accessing an external tool that operates at the file level. | ||
| * The URL includes necessary authentication tokens and parameters based on the user's permissions and the tool's configuration. | ||
| * Authentication is required for draft, restricted, embargoed, or expired (retention period) files, the user must have appropriate permissions. | ||
| * | ||
| * @param {number | string} [fileId] - The File identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers). | ||
| * @param {number} toolId - The identifier of the external tool. | ||
| * @param {GetExternalToolDTO} getExternalToolDTO - The GetExternalToolDTO object containing additional parameters for the request. | ||
| * @returns {Promise<FileExternalToolResolved>} | ||
| */ | ||
| async execute( | ||
| fileId: number | string, | ||
| toolId: number, | ||
| getExternalToolDTO: GetExternalToolDTO | ||
| ): Promise<FileExternalToolResolved> { | ||
| return await this.externalToolsRepository.getFileExternalToolResolved( | ||
| fileId, | ||
| toolId, | ||
| getExternalToolDTO | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { GetDatasetExternalToolResolved } from './domain/useCases/GetDatasetExternalToolResolved' | ||
| import { GetExternalTools } from './domain/useCases/GetExternalTools' | ||
| import { GetFileExternalToolResolved } from './domain/useCases/GetFileExternalToolResolved' | ||
| import { ExternalToolsRepository } from './infra/ExternalToolsRepository' | ||
|
|
||
| const externalToolsRepository = new ExternalToolsRepository() | ||
|
|
||
| const getExternalTools = new GetExternalTools(externalToolsRepository) | ||
| const getDatasetExternalToolResolved = new GetDatasetExternalToolResolved(externalToolsRepository) | ||
| const getFileExternalToolResolved = new GetFileExternalToolResolved(externalToolsRepository) | ||
|
|
||
| export { | ||
| getExternalTools, | ||
| getDatasetExternalToolResolved, | ||
| getFileExternalToolResolved, | ||
| externalToolsRepository | ||
| } | ||
|
|
||
| export { | ||
| ExternalTool, | ||
| ToolScope, | ||
| ToolType, | ||
| DatasetExternalToolResolved, | ||
| FileExternalToolResolved | ||
| } from './domain/models/ExternalTool' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { IExternalToolsRepository } from '../domain/repositories/IExternalToolsRepository' | ||
| import { ApiRepository } from '../../core/infra/repositories/ApiRepository' | ||
| import { | ||
| DatasetExternalToolResolved, | ||
| ExternalTool, | ||
| FileExternalToolResolved | ||
| } from '../domain/models/ExternalTool' | ||
| import { GetExternalToolDTO } from '../domain/dtos/GetExternalToolDTO' | ||
| import { datasetExternalToolTransformer } from './transformers/datasetExternalToolTransformer' | ||
| import { fileExternalToolTransformer } from './transformers/fileExternalToolTransformer' | ||
| import { externalToolsTransformer } from './transformers/externalToolsTransformer' | ||
|
|
||
| export class ExternalToolsRepository extends ApiRepository implements IExternalToolsRepository { | ||
| private readonly externalToolsResourceName: string = 'externalTools' | ||
|
|
||
| public async getExternalTools(): Promise<ExternalTool[]> { | ||
| return this.doGet(this.buildApiEndpoint(this.externalToolsResourceName)) | ||
| .then((response) => externalToolsTransformer(response)) | ||
| .catch((error) => { | ||
| throw error | ||
| }) | ||
| } | ||
|
|
||
| public async getDatasetExternalToolResolved( | ||
| datasetId: number | string, | ||
| toolId: number, | ||
| getExternalToolDTO: GetExternalToolDTO | ||
| ): Promise<DatasetExternalToolResolved> { | ||
| return this.doPost( | ||
| this.buildApiEndpoint('datasets', `externalTool/${toolId}/toolUrl`, datasetId), | ||
| getExternalToolDTO | ||
| ) | ||
| .then((response) => datasetExternalToolTransformer(response)) | ||
| .catch((error) => { | ||
| throw error | ||
| }) | ||
| } | ||
|
|
||
| public async getFileExternalToolResolved( | ||
| fileId: number | string, | ||
| toolId: number, | ||
| getExternalToolDTO: GetExternalToolDTO | ||
| ): Promise<FileExternalToolResolved> { | ||
| return this.doPost( | ||
| this.buildApiEndpoint('files', `externalTool/${toolId}/toolUrl`, fileId), | ||
| getExternalToolDTO | ||
| ) | ||
| .then((response) => fileExternalToolTransformer(response)) | ||
| .catch((error) => { | ||
| throw error | ||
| }) | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/externalTools/infra/transformers/ExternalToolPayload.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { ToolScope, ToolType } from '../../domain/models/ExternalTool' | ||
|
|
||
| export interface ExternalToolPayload { | ||
| id: number | ||
| displayName: string | ||
| description: string | ||
| types: ToolType[] | ||
| scope: ToolScope | ||
| contentType?: string // Only present when scope is 'file' | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/externalTools/infra/transformers/datasetExternalToolTransformer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { AxiosResponse } from 'axios' | ||
| import { DatasetExternalToolResolved } from '../../domain/models/ExternalTool' | ||
|
|
||
| export const datasetExternalToolTransformer = ( | ||
| response: AxiosResponse<{ | ||
| data: { toolUrl: string; displayName: string; datasetId: number; preview: boolean } | ||
| }> | ||
| ): DatasetExternalToolResolved => { | ||
| const datasetExtTool = response.data.data | ||
|
|
||
| return { | ||
| toolUrlResolved: datasetExtTool.toolUrl, | ||
| displayName: datasetExtTool.displayName, | ||
| datasetId: datasetExtTool.datasetId, | ||
| preview: datasetExtTool.preview | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/externalTools/infra/transformers/externalToolsTransformer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { AxiosResponse } from 'axios' | ||
| import { ExternalTool } from '../../domain/models/ExternalTool' | ||
| import { ExternalToolPayload } from './ExternalToolPayload' | ||
|
|
||
| export const externalToolsTransformer = ( | ||
| response: AxiosResponse<{ | ||
| data: ExternalToolPayload[] | ||
| }> | ||
| ): ExternalTool[] => { | ||
| const tools = response.data.data | ||
|
|
||
| return tools.map((tool) => ({ | ||
| id: tool.id, | ||
| displayName: tool.displayName, | ||
| description: tool.description, | ||
| types: tool.types, | ||
| scope: tool.scope, | ||
| contentType: tool.contentType | ||
| })) | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/externalTools/infra/transformers/fileExternalToolTransformer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { AxiosResponse } from 'axios' | ||
| import { FileExternalToolResolved } from '../../domain/models/ExternalTool' | ||
|
|
||
| export const fileExternalToolTransformer = ( | ||
| response: AxiosResponse<{ | ||
| data: { toolUrl: string; displayName: string; fileId: number; preview: boolean } | ||
| }> | ||
| ): FileExternalToolResolved => { | ||
| const fileExtTool = response.data.data | ||
|
|
||
| return { | ||
| toolUrlResolved: fileExtTool.toolUrl, | ||
| displayName: fileExtTool.displayName, | ||
| fileId: fileExtTool.fileId, | ||
| preview: fileExtTool.preview | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.