Skip to content

Commit 0b71db0

Browse files
Merge pull request #252 from salesforcecli/u/sushmita-verma/OSAssessment
W-16673913 : [Execution][Migration Tool]: Add a new Assessment mode for omnistudio components in the Migration Plugin
2 parents 4e993be + 412e0a1 commit 0b71db0

File tree

12 files changed

+767
-23
lines changed

12 files changed

+767
-23
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ out.log
4343
migrationresults.html
4444

4545
oclif.manifest.json
46-
omnistudio_migration
47-
46+
omnistudio_migration

src/commands/omnistudio/migration/assess.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { AssessmentInfo } from '../../../utils/interfaces';
66
import { AssessmentReporter } from '../../../utils/resultsbuilder/assessmentReporter';
77
import { LwcMigration } from '../../../migration/related/LwcMigration';
88
import { ApexMigration } from '../../../migration/related/ApexMigration';
9+
import { OmniScriptExportType, OmniScriptMigrationTool } from '../../../migration/omniscript';
10+
import { CardMigrationTool } from '../../../migration/flexcard';
11+
import { DataRaptorMigrationTool } from '../../../migration/dataraptor';
12+
import { DebugTimer, DataRaptorAssessmentInfo, FlexCardAssessmentInfo } from '../../../utils';
13+
914
import { Logger } from '../../../utils/logger';
1015
import OmnistudioRelatedObjectMigrationFacade from './OmnistudioRelatedObjectMigrationFacade';
1116

@@ -37,19 +42,42 @@ export default class Assess extends OmniStudioBaseCommand {
3742

3843
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3944
public async run(): Promise<any> {
45+
DebugTimer.getInstance().start();
4046
const namespace = (this.flags.namespace || 'vlocity_ins') as string;
4147
const apiVersion = (this.flags.apiversion || '55.0') as string;
48+
const allVersions = true;
4249
const conn = this.org.getConnection();
4350
Logger.initialiseLogger(this.ux, this.logger);
4451
const projectDirectory = OmnistudioRelatedObjectMigrationFacade.intializeProject();
4552
conn.setApiVersion(apiVersion);
4653
const lwcparser = new LwcMigration(projectDirectory, namespace, this.org);
4754
const apexMigrator = new ApexMigration(projectDirectory, namespace, this.org);
55+
const osMigrator = new OmniScriptMigrationTool(
56+
OmniScriptExportType.All,
57+
namespace,
58+
conn,
59+
this.logger,
60+
messages,
61+
this.ux,
62+
allVersions
63+
);
64+
const flexMigrator = new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions);
65+
const drMigrator = new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux);
4866
this.logger.info(namespace);
4967
this.ux.log(`Using Namespace: ${namespace}`);
68+
69+
const dataRaptorAssessmentInfos: DataRaptorAssessmentInfo[] = await drMigrator.assess();
70+
this.ux.log('dataRaptorAssessmentInfos');
71+
this.ux.log(dataRaptorAssessmentInfos.toString());
72+
const flexCardAssessmentInfos: FlexCardAssessmentInfo[] = await flexMigrator.assess();
73+
const omniAssessmentInfo = await osMigrator.assess(dataRaptorAssessmentInfos, flexCardAssessmentInfos);
74+
5075
const assesmentInfo: AssessmentInfo = {
5176
lwcAssessmentInfos: lwcparser.assessment(),
5277
apexAssessmentInfos: apexMigrator.assess(),
78+
dataRaptorAssessmentInfos,
79+
flexCardAssessmentInfos,
80+
omniAssessmentInfo,
5381
};
5482
await AssessmentReporter.generate(assesmentInfo, conn.instanceUrl);
5583
return assesmentInfo;

src/migration/DependencyChecker.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
}

src/migration/dataraptor.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { DebugTimer, QueryTools } from '../utils';
66
import { NetUtils } from '../utils/net';
77
import { BaseMigrationTool } from './base';
88
import { MigrationResult, MigrationTool, ObjectMapping, TransformData, UploadRecordResult } from './interfaces';
9+
import { DataRaptorAssessmentInfo } from '../../src/utils';
10+
911
import { getAllFunctionMetadata, getReplacedString } from '../utils/formula/FormulaUtil';
1012

1113

@@ -173,10 +175,66 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
173175
};
174176
}
175177

178+
public async assess(): Promise<DataRaptorAssessmentInfo[]> {
179+
try {
180+
DebugTimer.getInstance().lap('Query data raptors');
181+
const dataRaptors = await this.getAllDataRaptors();
182+
const dataRaptorAssessmentInfos = this.processDRComponents(dataRaptors);
183+
this.ux.log('dataRaptorAssessmentInfos');
184+
this.ux.log((dataRaptorAssessmentInfos).toString());
185+
return dataRaptorAssessmentInfos;
186+
} catch (err) {
187+
this.ux.log(err);
188+
this.ux.log(err.getMessage());
189+
}
190+
}
191+
192+
public async processDRComponents(dataRaptors: AnyJson[]): Promise<DataRaptorAssessmentInfo[]> {
193+
const dataRaptorAssessmentInfos: DataRaptorAssessmentInfo[] = [];
194+
// Query all the functionMetadata with all required fields
195+
const functionDefinitionMetadata = await getAllFunctionMetadata(this.namespace, this.connection);
196+
197+
// Now process each OmniScript and its elements
198+
for (const dataRaptor of dataRaptors) {
199+
// Await here since processOSComponents is now async
200+
this.ux.log(dataRaptor['Name']);
201+
this.ux.log(dataRaptor[this.namespacePrefix + 'Formula__c']);
202+
var customFunctionString = '';
203+
if (dataRaptor[this.namespacePrefix + 'Formula__c'] != null) {
204+
this.ux.log('formula');
205+
customFunctionString = 'Original Formula :'+ dataRaptor[this.namespacePrefix + 'Formula__c'] + '\n\n' +
206+
'Replaced Formula :Formula'
207+
try {
208+
customFunctionString += 'Replaced Formula :Formula \n\n' + getReplacedString(
209+
this.namespacePrefix,
210+
dataRaptor[this.namespacePrefix + 'Formula__c'],
211+
functionDefinitionMetadata
212+
);
213+
} catch (ex) {
214+
this.logger.error(JSON.stringify(ex));
215+
console.log(
216+
"There was some problem while updating the formula syntax, please check the all the formula's syntax once : " +
217+
dataRaptor[this.namespacePrefix + 'Formula__c']
218+
);
219+
}
220+
}
221+
222+
const dataRaptorAssessmentInfo: DataRaptorAssessmentInfo = {
223+
name: dataRaptor['Name'],
224+
customFunction: customFunctionString,
225+
id: '',
226+
infos: [],
227+
warnings: [],
228+
};
229+
dataRaptorAssessmentInfos.push(dataRaptorAssessmentInfo);
230+
}
231+
return dataRaptorAssessmentInfos;
232+
}
233+
176234

177235
// Get All DRBundle__c records
178236
private async getAllDataRaptors(): Promise<AnyJson[]> {
179-
DebugTimer.getInstance().lap('Query DRBundle');
237+
//DebugTimer.getInstance().lap('Query DRBundle');
180238
return await QueryTools.queryAll(this.connection, this.namespace, DataRaptorMigrationTool.DRBUNDLE_NAME, this.getDRBundleFields());
181239
}
182240

src/migration/flexcard.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BaseMigrationTool } from './base';
77
import { MigrationResult, MigrationTool, ObjectMapping, UploadRecordResult } from './interfaces';
88
import { Connection, Logger, Messages } from '@salesforce/core';
99
import { UX } from '@salesforce/command';
10+
import { FlexCardAssessmentInfo } from '../../src/utils';
1011

1112
export class CardMigrationTool extends BaseMigrationTool implements MigrationTool {
1213
static readonly VLOCITYCARD_NAME = 'VlocityCard__c';
@@ -89,9 +90,45 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
8990
];
9091
}
9192

93+
public async assess(): Promise<FlexCardAssessmentInfo[]> {
94+
try {
95+
const flexCards = await this.getAllActiveCards();
96+
const flexCardsAssessmentInfos = this.processCardComponents(flexCards);
97+
this.ux.log('flexCardsAssessmentInfos');
98+
this.ux.log((flexCardsAssessmentInfos).toString());
99+
return flexCardsAssessmentInfos;
100+
} catch (err) {
101+
this.ux.log(err);
102+
this.ux.log(err.getMessage());
103+
}
104+
}
105+
106+
public async processCardComponents(flexCards: AnyJson[]): Promise<FlexCardAssessmentInfo[]> {
107+
const flexCardAssessmentInfos: FlexCardAssessmentInfo[] = [];
108+
109+
const limitedFlexCards = flexCards.slice(0, 200);
110+
111+
// Now process each OmniScript and its elements
112+
for (const flexCard of limitedFlexCards) {
113+
// Await here since processOSComponents is now async
114+
//this.ux.log(flexCard['Name']);
115+
const flexCardAssessmentInfo: FlexCardAssessmentInfo = {
116+
name: flexCard['Name'],
117+
id: '',
118+
dependenciesIP: null,
119+
dependenciesDR: [],
120+
dependenciesOS: [],
121+
infos: [],
122+
warnings: [],
123+
};
124+
flexCardAssessmentInfos.push(flexCardAssessmentInfo);
125+
}
126+
return flexCardAssessmentInfos;
127+
}
128+
92129
// Query all cards that are active
93130
private async getAllActiveCards(): Promise<AnyJson[]> {
94-
DebugTimer.getInstance().lap('Query Vlocity Cards');
131+
//DebugTimer.getInstance().lap('Query Vlocity Cards');
95132
const filters = new Map<string, any>();
96133
filters.set(this.namespacePrefix + 'CardType__c', 'flex');
97134

0 commit comments

Comments
 (0)