|
| 1 | +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ |
| 2 | +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ |
| 3 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 4 | +/* |
| 5 | +import { MigrationTool } from './interfaces'; |
| 6 | +import { OmniScriptMigrationTool } from './omniscript'; |
| 7 | +import { CardMigrationTool } from './flexcard'; |
| 8 | +import { DataRaptorMigrationTool } from './dataraptor'; |
| 9 | +
|
| 10 | +interface DependencyReport { |
| 11 | + name: string; |
| 12 | + type: string; |
| 13 | + id: string; |
| 14 | + missingDependencies: DependencyReport[]; |
| 15 | +} |
| 16 | + */ |
| 17 | + |
| 18 | +export class DependencyChecker { |
| 19 | + /* |
| 20 | + public static async checkDependencies(migrationObjects: MigrationTool[]): Promise<DependencyReport[]> { |
| 21 | + const existingNames = new Set(migrationObjects.map((obj) => obj.getName())); |
| 22 | + const componentsReport: DependencyReport[] = []; |
| 23 | + |
| 24 | + for (const migrationObject of migrationObjects) { |
| 25 | + const dependencies = await this.getDependencies(migrationObject); |
| 26 | + const missing = dependencies.filter((dep) => !existingNames.has(dep)); |
| 27 | + |
| 28 | + const componentReport: DependencyReport = { |
| 29 | + name: migrationObject.getName(), |
| 30 | + type: migrationObject.constructor.name, |
| 31 | + id: migrationObject['Id'], |
| 32 | + missingDependencies: this.getMissingComponents(missing, migrationObjects), |
| 33 | + }; |
| 34 | + |
| 35 | + componentsReport.push(componentReport); |
| 36 | + } |
| 37 | + |
| 38 | + return componentsReport; |
| 39 | + } |
| 40 | + |
| 41 | + private static async getDependencies(migrationObject: MigrationTool): Promise<string[]> { |
| 42 | + const dependencyFetchers = { |
| 43 | + OmniScriptMigrationTool: this.getOmniScriptDependencies, |
| 44 | + CardMigrationTool: this.getCardDependencies, |
| 45 | + DataRaptorMigrationTool: this.getDataRaptorDependencies, |
| 46 | + }; |
| 47 | + |
| 48 | + const fetcher = dependencyFetchers[migrationObject.constructor.name]; |
| 49 | + return fetcher ? await fetcher(migrationObject) : []; |
| 50 | + } |
| 51 | + |
| 52 | + private static async getOmniScriptDependencies(migrationObject: OmniScriptMigrationTool): Promise<string[]> { |
| 53 | + const elements = await migrationObject.getAllElementsForOmniScript(migrationObject.getName()); |
| 54 | + return elements.map((element) => migrationObject.getRecordName(element)); |
| 55 | + } |
| 56 | + |
| 57 | + private static getCardDependencies(migrationObject: CardMigrationTool): string[] { |
| 58 | + return this.fetchIntegrationProceduresAndDataRaptors(migrationObject); |
| 59 | + } |
| 60 | + |
| 61 | + private static getDataRaptorDependencies(migrationObject: DataRaptorMigrationTool): string[] { |
| 62 | + return []; // Implement actual logic for DataRaptor dependencies |
| 63 | + } |
| 64 | + |
| 65 | + private static fetchIntegrationProceduresAndDataRaptors(migrationObject: any): string[] { |
| 66 | + // Replace with actual fetching logic |
| 67 | + return ['IntegrationProcedure1', 'DataRaptor1']; |
| 68 | + } |
| 69 | + |
| 70 | + private static getMissingComponents(missing: string[], migrationObjects: MigrationTool[]): DependencyReport[] { |
| 71 | + const missingReports: DependencyReport[] = []; |
| 72 | + |
| 73 | + for (const dep of missing) { |
| 74 | + const component = migrationObjects.find((obj) => obj.getName() === dep); |
| 75 | + const report = component |
| 76 | + ? this.createReportForFoundComponent(component, dep) |
| 77 | + : this.createReportForUnknownComponent(dep); |
| 78 | + missingReports.push(report); |
| 79 | + } |
| 80 | + |
| 81 | + return missingReports; |
| 82 | + } |
| 83 | + |
| 84 | + private static createReportForFoundComponent(component: MigrationTool, dep: string): DependencyReport { |
| 85 | + return { |
| 86 | + name: component.getName(), |
| 87 | + type: component.constructor.name, |
| 88 | + id: component['Id'], |
| 89 | + missingDependencies: [], |
| 90 | + }; |
| 91 | + } |
| 92 | + |
| 93 | + private static createReportForUnknownComponent(componentName: string): DependencyReport { |
| 94 | + const componentType = this.determineComponentType(componentName); |
| 95 | + return { |
| 96 | + name: componentName, |
| 97 | + type: componentType, |
| 98 | + id: '', |
| 99 | + missingDependencies: [], |
| 100 | + }; |
| 101 | + } |
| 102 | + |
| 103 | + private static determineComponentType(componentName: string): string { |
| 104 | + if (componentName.includes('IntegrationProcedure')) { |
| 105 | + return 'Integration Procedure'; |
| 106 | + } else if (componentName.includes('DataRaptor')) { |
| 107 | + return 'DataRaptor'; |
| 108 | + } else if (componentName.includes('OmniScript')) { |
| 109 | + return 'OmniScript'; |
| 110 | + } else if (componentName.includes('Card')) { |
| 111 | + return 'Flex Card'; |
| 112 | + } |
| 113 | + return 'Unknown'; |
| 114 | + } |
| 115 | + */ |
| 116 | +} |
0 commit comments