Skip to content

Commit f57178f

Browse files
feat: added apex and lwc in migration report
1 parent 17c21af commit f57178f

File tree

11 files changed

+238
-99
lines changed

11 files changed

+238
-99
lines changed

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/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/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: 4 additions & 4 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
}

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;

src/utils/lwcparser/fileutils/HtmlFileProcessor.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ export class HtmlFileProcessor implements FileProcessor {
1616
const fileDiffUtil = new FileDiffUtil();
1717
const fileContent: Map<string, string> = parse.replaceTags(namespace);
1818
if (fileContent) {
19+
const diff = fileDiffUtil.getFileDiff(
20+
file.name + file.ext,
21+
fileContent.get(FileConstant.BASE_CONTENT),
22+
fileContent.get(FileConstant.MODIFIED_CONTENT)
23+
);
1924
if (type != null && type === 'migration') {
2025
fileutil.saveToFile(filePath, fileContent.get(FileConstant.MODIFIED_CONTENT));
21-
} else {
22-
const diff = fileDiffUtil.getFileDiff(
23-
file.name + file.ext,
24-
fileContent.get(FileConstant.BASE_CONTENT),
25-
fileContent.get(FileConstant.MODIFIED_CONTENT)
26-
);
27-
return diff;
2826
}
27+
return diff;
2928
}
3029
}
3130
}

src/utils/lwcparser/fileutils/JavascriptFileProcessor.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ export class JavascriptFileProcessor implements FileProcessor {
2020
const filePath = file.location;
2121
const fileContent: Map<string, string> = jsParser.replaceImportSource(filePath, namespace);
2222
if (fileContent) {
23+
const diff = fileDiffUtil.getFileDiff(
24+
file.name + file.ext,
25+
fileContent.get(FileConstant.BASE_CONTENT),
26+
fileContent.get(FileConstant.MODIFIED_CONTENT)
27+
);
2328
if (type != null && type === 'migration') {
2429
fileutil.saveToFile(filePath, fileContent.get(FileConstant.MODIFIED_CONTENT));
25-
} else {
26-
const diff = fileDiffUtil.getFileDiff(
27-
file.name + file.ext,
28-
fileContent.get(FileConstant.BASE_CONTENT),
29-
fileContent.get(FileConstant.MODIFIED_CONTENT)
30-
);
31-
return diff;
3230
}
31+
return diff;
3332
}
3433
}
3534
}

src/utils/lwcparser/fileutils/XmlFileProcessor.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ export class XmlFileProcessor implements FileProcessor {
2020
const fileDiffUtil = new FileDiffUtil();
2121
const fileContent: Map<string, string> = parser.removeNode(XML_TAG_TO_REPLACE);
2222
if (fileContent) {
23+
const diff = fileDiffUtil.getFileDiff(
24+
file.name + file.ext,
25+
fileContent.get(FileConstant.BASE_CONTENT),
26+
fileContent.get(FileConstant.MODIFIED_CONTENT)
27+
);
2328
if (type != null && type === 'migration') {
2429
fileutil.saveToFile(filePath, fileContent.get(FileConstant.MODIFIED_CONTENT));
25-
} else {
26-
const diff = fileDiffUtil.getFileDiff(
27-
file.name + file.ext,
28-
fileContent.get(FileConstant.BASE_CONTENT),
29-
fileContent.get(FileConstant.MODIFIED_CONTENT)
30-
);
31-
return diff;
3230
}
31+
return diff;
3332
}
3433
}
3534
}

0 commit comments

Comments
 (0)