Skip to content

Commit 9fb699c

Browse files
Merge pull request #263 from salesforcecli/u/abhinavkumar2/W-17164417
U/abhinavkumar2/w 17164417
2 parents 055ba08 + c85b416 commit 9fb699c

File tree

17 files changed

+263
-134
lines changed

17 files changed

+263
-134
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"@types/jsdom": "^21.1.7",
1616
"@types/lodash.chunk": "^4.2.9",
1717
"@types/shelljs": "^0.8.15",
18-
"cheerio": "^1.0.0",
1918
"jsdom": "^25.0.0",
2019
"lodash.chunk": "^4.2.0",
2120
"open": "^8.4.2",

src/commands/omnistudio/migration/migrate.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,15 @@ export default class Migrate extends OmniStudioBaseCommand {
176176
allVersions,
177177
this.org
178178
);
179-
const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration.migrateAll(objectMigrationResults, []);
179+
const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration.migrateAll(objectMigrationResults, [
180+
'lwc',
181+
'apex',
182+
]);
180183
generatePackageXml.createChangeList(
181-
relatedObjectMigrationResult.apexClasses,
182-
relatedObjectMigrationResult.lwcComponents
184+
relatedObjectMigrationResult.apexAssessmentInfos,
185+
relatedObjectMigrationResult.lwcAssessmentInfos
183186
);
184-
await ResultsBuilder.generate(objectMigrationResults, conn.instanceUrl);
187+
await ResultsBuilder.generate(objectMigrationResults, relatedObjectMigrationResult, conn.instanceUrl);
185188

186189
// save timer to debug logger
187190
this.logger.debug(timer);

src/migration/dataraptor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
6363

6464
// Query all the functionMetadata with all required fields
6565
const functionDefinitionMetadata = await getAllFunctionMetadata(this.namespace, this.connection);
66+
populateRegexForFunctionMetadata(functionDefinitionMetadata);
6667
// Start transforming each dataRaptor
6768
DebugTimer.getInstance().lap('Transform Data Raptor');
6869
let done = 0;

src/migration/interfaces.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,6 @@ export interface NameTransformData {
8383
nameWithSepcialCharactorSet: Set<string>;
8484
}
8585

86-
export interface RelatedObjectsMigrate {
87-
/**
88-
* Identifies migration candidates based on the provided migration results and namespace.
89-
*
90-
* @param migrationResults List of migration results to identify objects from.
91-
* @param namespace The namespace used to identify objects.
92-
* @returns List of identified migration candidates as strings.
93-
*/
94-
identifyObjects(migrationResults: MigrationResult[]): Promise<JSON[]>;
95-
96-
/**
97-
* Private method to perform the migration of related objects based on the provided candidates.
98-
*
99-
* @param migrationResults List of migration results to use for migration.
100-
* @param namespace The namespace used to perform the migration.
101-
* @param migrationCandidates List of candidates to migrate.
102-
*/
103-
migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): string[];
104-
105-
processObjectType(): string;
106-
}
107-
10886
export type LWCComponentMigrationTool = MigrationTool;
10987

11088
export type CustomLabelMigrationTool = MigrationTool;

src/migration/omniscript.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import { NetUtils, RequestMethod } from '../utils/net';
1919
import { Connection, Messages, Logger } from '@salesforce/core';
2020
import { UX } from '@salesforce/command';
2121
import { OSAssessmentInfo, OmniAssessmentInfo, IPAssessmentInfo } from '../../src/utils';
22-
import { getAllFunctionMetadata, getReplacedString } from '../utils/formula/FormulaUtil';
22+
import {
23+
getAllFunctionMetadata,
24+
getReplacedString,
25+
populateRegexForFunctionMetadata,
26+
} from '../utils/formula/FormulaUtil';
2327
import { StringVal } from '../utils/StringValue/stringval';
2428

2529
export class OmniScriptMigrationTool extends BaseMigrationTool implements MigrationTool {
@@ -387,6 +391,8 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
387391
// Get All Records from OmniScript__c (IP & OS Parent Records)
388392
const omniscripts = await this.getAllOmniScripts();
389393
const functionDefinitionMetadata = await getAllFunctionMetadata(this.namespace, this.connection);
394+
populateRegexForFunctionMetadata(functionDefinitionMetadata);
395+
390396
const duplicatedNames = new Set<string>();
391397

392398
// Variables to be returned After Migration

src/migration/related/ApexMigration.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
SingleTokenUpdate,
1313
TokenUpdater,
1414
} from '../../utils/apex/parser/apexparser';
15-
import { MigrationResult, RelatedObjectsMigrate } from '../interfaces';
15+
import { MigrationResult } from '../interfaces';
1616
import { sfProject } from '../../utils/sfcli/project/sfProject';
1717
import { fileutil, File } from '../../utils/file/fileutil';
1818
import { Logger } from '../../utils/logger';
1919
import { ApexAssessmentInfo } from '../../utils';
2020
import { FileDiffUtil } from '../../utils/lwcparser/fileutils/FileDiffUtil';
21+
import { Stringutil } from '../../utils/StringValue/stringutil';
2122
import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration';
2223

2324
const APEXCLASS = 'Apexclass';
@@ -26,7 +27,7 @@ const CALLABLE = 'Callable';
2627
const VLOCITY_OPEN_INTERFACE2 = 'VlocityOpenInterface2';
2728
const VLOCITY_OPEN_INTERFACE = 'VlocityOpenInterface';
2829

29-
export class ApexMigration extends BaseRelatedObjectMigration implements RelatedObjectsMigrate {
30+
export class ApexMigration extends BaseRelatedObjectMigration {
3031
private readonly callableInterface: InterfaceImplements;
3132
private readonly vlocityOpenInterface2: InterfaceImplements;
3233
private readonly vlocityOpenInterface: InterfaceImplements;
@@ -43,25 +44,24 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
4344
public identifyObjects(migrationResults: MigrationResult[]): Promise<JSON[]> {
4445
throw new Error('Method not implemented.');
4546
}
46-
public migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): string[] {
47+
public migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): ApexAssessmentInfo[] {
4748
return this.migrate();
4849
}
49-
public migrate(): string[] {
50+
public migrate(): ApexAssessmentInfo[] {
5051
const pwd = shell.pwd();
5152
shell.cd(this.projectPath);
5253
const targetOrg: Org = this.org;
53-
// sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
54+
sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
5455
const apexAssessmentInfos = this.processApexFiles(this.projectPath);
55-
sfProject.deploy(APEXCLASS, targetOrg.getUsername());
56+
// sfProject.deploy(APEXCLASS, targetOrg.getUsername());
5657
shell.cd(pwd);
57-
return this.mapTOName(apexAssessmentInfos);
58+
return apexAssessmentInfos;
5859
}
5960

6061
public assess(): ApexAssessmentInfo[] {
6162
const pwd = shell.pwd();
6263
shell.cd(this.projectPath);
63-
// const targetOrg: Org = this.org;
64-
// sfProject.retrieve(APEXCLASS, this.org.getUsername());
64+
sfProject.retrieve(APEXCLASS, this.org.getUsername());
6565
const apexAssessmentInfos = this.processApexFiles(this.projectPath);
6666
shell.cd(pwd);
6767
return apexAssessmentInfos;
@@ -158,6 +158,19 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
158158
for (const tokenChange of namespaceChanges.get(this.namespace))
159159
tokenUpdates.push(new SingleTokenUpdate(this.updatedNamespace, tokenChange));
160160
}
161+
162+
const methodParameters = parser.methodParameters;
163+
if (methodParameters.size === 0) return tokenUpdates;
164+
const drParameters = methodParameters.get(ParameterType.DR_NAME);
165+
if (drParameters) {
166+
for (const token of drParameters) {
167+
const newName = `'${Stringutil.cleanName(token.text)}'`;
168+
if (token.text === newName) continue;
169+
Logger.logger.info(`In Apex ${file.name} DR name ${token.text} will be updated to ${newName} `);
170+
Logger.ux.log(`In Apex ${file.name} DR name ${token.text} will be updated to ${newName}`);
171+
tokenUpdates.push(new SingleTokenUpdate(newName, token));
172+
}
173+
}
161174
return tokenUpdates;
162175
}
163176

@@ -184,10 +197,10 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
184197
}
185198
`;
186199
}
187-
188-
private mapTOName(apexAssessmentInfos: ApexAssessmentInfo[]): string[] {
189-
return apexAssessmentInfos.map((apexAssessmentInfo) => {
190-
return apexAssessmentInfo.name;
191-
});
192-
}
200+
/*
201+
private mapTOName(apexAssessmentInfos: ApexAssessmentInfo[]): string[] {
202+
return apexAssessmentInfos.map((apexAssessmentInfo) => {
203+
return apexAssessmentInfo.name;
204+
});
205+
} */
193206
}

src/migration/related/LwcMigration.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as shell from 'shelljs';
33
import { Org } from '@salesforce/core';
44
import { fileutil, File } from '../../utils/file/fileutil';
5-
import { MigrationResult, RelatedObjectsMigrate } from '../interfaces';
5+
import { MigrationResult } from '../interfaces';
66
import { sfProject } from '../../utils/sfcli/project/sfProject';
77
import { Logger } from '../../utils/logger';
88
import { FileProcessorFactory } from '../../utils/lwcparser/fileutils/FileProcessorFactory';
@@ -12,7 +12,7 @@ import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration';
1212
const LWC_DIR_PATH = '/force-app/main/default/lwc';
1313
const LWCTYPE = 'LightningComponentBundle';
1414

15-
export class LwcMigration extends BaseRelatedObjectMigration implements RelatedObjectsMigrate {
15+
export class LwcMigration extends BaseRelatedObjectMigration {
1616
public processObjectType(): string {
1717
return 'lwc';
1818
}
@@ -27,7 +27,7 @@ export class LwcMigration extends BaseRelatedObjectMigration implements RelatedO
2727
const type = 'assessment';
2828
const pwd = shell.pwd();
2929
shell.cd(this.projectPath);
30-
// sfProject.retrieve(LWCTYPE, this.org.getUsername());
30+
sfProject.retrieve(LWCTYPE, this.org.getUsername());
3131
const filesMap = this.processLwcFiles(this.projectPath);
3232
shell.cd(pwd);
3333
return this.processFiles(filesMap, type);
@@ -40,7 +40,7 @@ export class LwcMigration extends BaseRelatedObjectMigration implements RelatedO
4040
sfProject.retrieve(LWCTYPE, targetOrg.getUsername());
4141
const filesMap = this.processLwcFiles(this.projectPath);
4242
const LWCAssessmentInfos = this.processFiles(filesMap, 'migration');
43-
sfProject.deploy(LWCTYPE, targetOrg.getUsername());
43+
// sfProject.deploy(LWCTYPE, targetOrg.getUsername());
4444
shell.cd(pwd);
4545
return LWCAssessmentInfos;
4646
}
@@ -63,13 +63,16 @@ export class LwcMigration extends BaseRelatedObjectMigration implements RelatedO
6363
const jsonData: LWCAssessmentInfo[] = [];
6464
fileMap.forEach((fileList, dir) => {
6565
const changeInfos: FileChangeInfo[] = [];
66-
if (dir !== 'lwc' && !dir.endsWith('English') && !dir.includes('_') && !dir.includes('cf')) {
66+
if (dir !== 'lwc' && !dir.endsWith('English') && !dir.includes('_') && !dir.startsWith('cf')) {
6767
for (const file of fileList) {
6868
if (this.isValideFile(file.name)) {
6969
const processor = FileProcessorFactory.getFileProcessor(file.ext);
7070
if (processor != null) {
7171
const path = file.location;
7272
const name = file.name + file.ext;
73+
if (file.ext === 'xml') {
74+
// if (fileutil.isAutogenratedFile(path)) { }
75+
}
7376
const diff = processor.process(file, type, this.namespace);
7477
if (diff != null) {
7578
const fileInfo: FileChangeInfo = {

src/migration/related/OmnistudioRelatedObjectMigrationFacade.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
/* eslint-disable @typescript-eslint/no-explicit-any */
55
import { Org } from '@salesforce/core';
66
import '../../utils/prototypes';
7-
import { DebugTimer, MigratedObject } from '../../utils';
8-
import { RelatedObjectMigrationResult, RelatedObjectsMigrate } from '../interfaces';
7+
import {
8+
ApexAssessmentInfo,
9+
DebugTimer,
10+
LWCAssessmentInfo,
11+
MigratedObject,
12+
RelatedObjectAssesmentInfo,
13+
} from '../../utils';
914
import { sfProject } from '../../utils/sfcli/project/sfProject';
1015
import { Logger } from '../../utils/logger';
1116
import { ApexMigration } from './ApexMigration';
@@ -44,35 +49,33 @@ export default class OmnistudioRelatedObjectMigrationFacade {
4449
return process.cwd() + '/' + defaultProjectName;
4550
}
4651
}
47-
public migrateAll(migrationResult: MigratedObject[], relatedObjects: string[]): RelatedObjectMigrationResult {
52+
public migrateAll(migrationResult: MigratedObject[], relatedObjects: string[]): RelatedObjectAssesmentInfo {
4853
// Start the debug timer
4954
DebugTimer.getInstance().start();
5055

5156
// Declare an array of MigrationTool
52-
const migrationTools: RelatedObjectsMigrate[] = [];
5357
const projectDirectory: string = OmnistudioRelatedObjectMigrationFacade.intializeProject();
5458
const debugTimer = DebugTimer.getInstance();
5559
debugTimer.start();
5660
// Initialize migration tools based on the relatedObjects parameter
57-
if (relatedObjects.includes('lwc')) {
58-
migrationTools.push(this.createLWCComponentMigrationTool(this.namespace, projectDirectory));
59-
}
60-
if (relatedObjects.includes('labels')) {
61-
migrationTools.push(this.createCustomLabelMigrationTool(this.namespace, this.org));
62-
}
63-
if (relatedObjects.includes('apex')) {
64-
migrationTools.push(this.createApexClassMigrationTool(projectDirectory));
65-
}
66-
const results = new Map<string, string[]>();
61+
const apexMigrator = this.createApexClassMigrationTool(projectDirectory);
62+
const lwcMigrator = this.createLWCComponentMigrationTool(this.namespace, projectDirectory);
63+
let apexAssessmentInfos: ApexAssessmentInfo[] = [];
64+
let lwcAssessmentInfos: LWCAssessmentInfo[] = [];
6765
// Proceed with migration logic
68-
for (const migrationTool of migrationTools) {
69-
try {
70-
results.set(migrationTool.processObjectType(), migrationTool.migrateRelatedObjects(null, null));
71-
} catch (Error) {
72-
// Log the error
73-
Logger.logger.error(Error.message);
74-
}
66+
try {
67+
apexAssessmentInfos = apexMigrator.migrate();
68+
} catch (Error) {
69+
// Log the error
70+
Logger.logger.error(Error.message);
71+
}
72+
try {
73+
lwcAssessmentInfos = lwcMigrator.migrate();
74+
} catch (Error) {
75+
// Log the error
76+
Logger.logger.error(Error.message);
7577
}
78+
7679
// Truncate existing objects if necessary
7780
// Stop the debug timer
7881
const timer = debugTimer.stop();
@@ -81,7 +84,7 @@ export default class OmnistudioRelatedObjectMigrationFacade {
8184
Logger.logger.debug(timer);
8285

8386
// Return results needed for --json flag
84-
return { apexClasses: results.get('apex'), lwcComponents: results.get('lwc') };
87+
return { apexAssessmentInfos, lwcAssessmentInfos };
8588
}
8689

8790
// Factory methods to create instances of specific tools
@@ -90,11 +93,6 @@ export default class OmnistudioRelatedObjectMigrationFacade {
9093
return new LwcMigration(projectPath, this.namespace, this.org);
9194
}
9295

93-
private createCustomLabelMigrationTool(namespace: string, org: Org): RelatedObjectsMigrate {
94-
// Return an instance of CustomLabelMigrationTool when implemented
95-
throw new Error('CustomLabelMigrationTool implementation is not provided yet.');
96-
}
97-
9896
private createApexClassMigrationTool(projectPath: string): ApexMigration {
9997
// Return an instance of ApexClassMigrationTool when implemented
10098
return new ApexMigration(projectPath, this.namespace, this.org);

src/utils/generatePackageXml.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3+
import { ApexAssessmentInfo, LWCAssessmentInfo } from './interfaces';
34

45
export class generatePackageXml {
56
// Method to generate package.xml with additional types
6-
public static createChangeList(apexClasses: string[], lwcComponents: string[]): void {
7-
const apexXml = generatePackageXml.getXmlElementforMembers(apexClasses, 'ApexClass');
8-
const lwcXml = generatePackageXml.getXmlElementforMembers(lwcComponents, 'LightningComponentBundle');
7+
public static createChangeList(
8+
apexAssementInfos: ApexAssessmentInfo[],
9+
lwcAssessmentInfos: LWCAssessmentInfo[]
10+
): void {
11+
const apexXml = generatePackageXml.getXmlElementforMembers(this.getApexclasses(apexAssementInfos), 'ApexClass');
12+
const lwcXml = generatePackageXml.getXmlElementforMembers(
13+
this.getLwcs(lwcAssessmentInfos),
14+
'LightningComponentBundle'
15+
);
916

1017
const additionalTypes = `
1118
<types>
@@ -67,4 +74,18 @@ export class generatePackageXml {
6774
<name>${type}</name>
6875
</types> `;
6976
}
77+
78+
private static getApexclasses(apexAssessmentInfos: ApexAssessmentInfo[]): string[] {
79+
if (!apexAssessmentInfos || apexAssessmentInfos.length === 0) return [];
80+
return apexAssessmentInfos.map((apexAssessmentInfo) => {
81+
return apexAssessmentInfo.name;
82+
});
83+
}
84+
85+
private static getLwcs(lwcAssessmentInfos: LWCAssessmentInfo[]): string[] {
86+
if (!lwcAssessmentInfos || lwcAssessmentInfos.length === 0) return [];
87+
return lwcAssessmentInfos.map((lwcAssessmentInfo) => {
88+
return lwcAssessmentInfo.name;
89+
});
90+
}
7091
}

src/utils/interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export interface AssessmentInfo {
7878
dataRaptorAssessmentInfos: DataRaptorAssessmentInfo[];
7979
}
8080

81+
export interface RelatedObjectAssesmentInfo {
82+
apexAssessmentInfos: ApexAssessmentInfo[];
83+
lwcAssessmentInfos: LWCAssessmentInfo[];
84+
}
8185
export interface FlexCardAssessmentInfo {
8286
name: string;
8387
id: string;

0 commit comments

Comments
 (0)