Skip to content

Commit 4b596f1

Browse files
Merge pull request #246 from salesforcecli/u/abhinavkumar2/W-16276171
U/abhinavkumar2/w 16276171
2 parents e5b9cfc + a132eca commit 4b596f1

31 files changed

+819
-109
lines changed

.gitignore

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

4545
oclif.manifest.json
46+
omnistudio_migration
47+

command-snapshot.json

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
11
[
2-
{
3-
"command": "basecommand",
4-
"plugin": "@salesforce/plugin-omnistudio-migration-tool",
5-
"flags": ["apiversion", "json", "loglevel", "targetusername"],
6-
"alias": []
7-
},
8-
{
9-
"command": "omnistudio:migration:info",
10-
"plugin": "@salesforce/plugin-omnistudio-migration-tool",
11-
"flags": ["allversions", "apiversion", "json", "loglevel", "name", "targetdevhubusername", "targetusername"],
12-
"alias": []
13-
},
14-
{
15-
"command": "omnistudio:migration:migrate",
16-
"plugin": "@salesforce/plugin-omnistudio-migration-tool",
17-
"flags": ["allversions", "apiversion", "json", "loglevel", "namespace", "only", "targetusername"],
18-
"alias": []
19-
}
20-
]
2+
{
3+
"command": "basecommand",
4+
"plugin": "@salesforce/plugin-omnistudio-migration-tool",
5+
"flags": [
6+
"apiversion",
7+
"json",
8+
"loglevel",
9+
"targetusername"
10+
],
11+
"alias": []
12+
},
13+
{
14+
"command": "omnistudio:migration:assess",
15+
"plugin": "@salesforce/plugin-omnistudio-migration-tool",
16+
"flags": [
17+
"allversions",
18+
"apiversion",
19+
"json",
20+
"loglevel",
21+
"namespace",
22+
"only",
23+
"targetusername"
24+
],
25+
"alias": []
26+
},
27+
{
28+
"command": "omnistudio:migration:info",
29+
"plugin": "@salesforce/plugin-omnistudio-migration-tool",
30+
"flags": [
31+
"allversions",
32+
"apiversion",
33+
"json",
34+
"loglevel",
35+
"name",
36+
"targetdevhubusername",
37+
"targetusername"
38+
],
39+
"alias": []
40+
},
41+
{
42+
"command": "omnistudio:migration:migrate",
43+
"plugin": "@salesforce/plugin-omnistudio-migration-tool",
44+
"flags": [
45+
"allversions",
46+
"apiversion",
47+
"json",
48+
"loglevel",
49+
"namespace",
50+
"only",
51+
"targetusername"
52+
],
53+
"alias": []
54+
}
55+
]

messages/assess.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"examples": [
3+
"omnistudio:migration:assess -u [email protected] --namespace=YOUR_PACKAGE_NAMESPACE",
4+
"omnistudio:migration:assess -u [email protected] --namespace=YOUR_PACKAGE_NAMESPACE --only=dr",
5+
"omnistudio:migration:assess -u [email protected] --namespace=YOUR_PACKAGE_NAMESPACE --only=ip",
6+
"omnistudio:migration:assess -u [email protected] --namespace=YOUR_PACKAGE_NAMESPACE --only=os",
7+
"omnistudio:migration:assess -u [email protected] --namespace=YOUR_PACKAGE_NAMESPACE --only=fc"
8+
],
9+
"commandDescription": "print a greeting and your org IDs",
10+
"namespaceFlagDescription": "The namespaced of the package",
11+
"apiVersionFlagDescription": "The Salesforce API version to use",
12+
"errorNoOrgResults": "No results found for the org '%s'.",
13+
"onlyFlagDescription": "Migrate a single element: osip | fc | dr",
14+
"invalidOnlyFlag": "Invalid flag, valid options are: osip | fc | dr",
15+
"couldNotDeactivateOmniProcesses": "Could not deactivate current OmniProcesses",
16+
"couldNotTruncate": "Could not truncate {0}",
17+
"couldNotTruncateOmnniProcess": "Could not truncate OmniProcess. Please make sure your OS/IP is not referenced in an OmniScrirpt or Flex Card.",
18+
"invalidNameTypeSubtypeOrLanguage": "Not a valid Name, Type, SubType or Language",
19+
"invalidOrRepeatingOmniscriptElementNames": "Invalid or Repeating Element Names for Same OmniScript",
20+
"invalidDataRaptorName": "Invalid name, can not have special characters",
21+
"duplicatedCardName": "Duplicated Flex Card name",
22+
"duplicatedDrName": "Duplicated DataRaptor name",
23+
"duplicatedOSName": "Duplicated OmniScript name",
24+
"errorWhileActivatingOs": "Could not activate OmniScript / Integration Procedure: ",
25+
"errorWhileActivatingCard": "Could not activate Card: ",
26+
"errorWhileUploadingCard": "An error ocurred while uploading Card: ",
27+
"errorWhileCreatingElements": "An error ocurred while saving OmniScript elements: ",
28+
"allVersionsDescription": "Migrate all versions of a component"
29+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@salesforce/ts-sinon": "^1",
3737
"@types/babel__traverse": "^7.20.6",
3838
"@types/jsforce": "^1.11.5",
39+
"@types/mocha": "^10.0.8",
3940
"@typescript-eslint/eslint-plugin": "^4.2.0",
4041
"@typescript-eslint/parser": "^4.2.0",
4142
"chai": "^4.4.1",

src/commands/omnistudio/migration/OmnistudioRelatedObjectMigrationFacade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/member-ordering */
12
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
23
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
34
/* eslint-disable @typescript-eslint/no-explicit-any */
@@ -69,7 +70,6 @@ export default class OmnistudioRelatedObjectMigrationFacade {
6970
migrationTool.migrateRelatedObjects(null, null);
7071
} catch (Error) {
7172
// Log the error
72-
Logger.ux.error(Error.message);
7373
Logger.logger.error(Error.message);
7474
return { migrationResult };
7575
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as os from 'os';
2+
import { flags } from '@salesforce/command';
3+
import { Messages } from '@salesforce/core';
4+
import OmniStudioBaseCommand from '../../basecommand';
5+
import { AssessmentInfo } from '../../../utils/interfaces';
6+
import { AssessmentReporter } from '../../../utils/resultsbuilder/assessmentReporter';
7+
import { LwcMigration } from '../../../migration/related/LwcMigration';
8+
import { ApexMigration } from '../../../migration/related/ApexMigration';
9+
import { Logger } from '../../../utils/logger';
10+
import OmnistudioRelatedObjectMigrationFacade from './OmnistudioRelatedObjectMigrationFacade';
11+
12+
Messages.importMessagesDirectory(__dirname);
13+
const messages = Messages.loadMessages('@salesforce/plugin-omnistudio-migration-tool', 'assess');
14+
15+
export default class Assess extends OmniStudioBaseCommand {
16+
public static description = messages.getMessage('commandDescription');
17+
18+
public static examples = messages.getMessage('examples').split(os.EOL);
19+
20+
public static args = [{ name: 'file' }];
21+
22+
protected static flagsConfig = {
23+
namespace: flags.string({
24+
char: 'n',
25+
description: messages.getMessage('namespaceFlagDescription'),
26+
}),
27+
only: flags.string({
28+
char: 'o',
29+
description: messages.getMessage('onlyFlagDescription'),
30+
}),
31+
allversions: flags.boolean({
32+
char: 'a',
33+
description: messages.getMessage('allVersionsDescription'),
34+
required: false,
35+
}),
36+
};
37+
38+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
39+
public async run(): Promise<any> {
40+
const namespace = (this.flags.namespace || 'vlocity_ins') as string;
41+
const apiVersion = (this.flags.apiversion || '55.0') as string;
42+
const conn = this.org.getConnection();
43+
Logger.initialiseLogger(this.ux, this.logger);
44+
const projectDirectory = OmnistudioRelatedObjectMigrationFacade.intializeProject();
45+
conn.setApiVersion(apiVersion);
46+
const lwcparser = new LwcMigration(projectDirectory, namespace, this.org);
47+
const apexMigrator = new ApexMigration(projectDirectory, namespace, this.org);
48+
this.logger.info(namespace);
49+
this.ux.log(`Using Namespace: ${namespace}`);
50+
const assesmentInfo: AssessmentInfo = {
51+
lwcAssessmentInfos: lwcparser.assessment(),
52+
apexAssessmentInfos: apexMigrator.assess(),
53+
};
54+
await AssessmentReporter.generate(assesmentInfo, conn.instanceUrl);
55+
return assesmentInfo;
56+
}
57+
}

src/migration/related/ApexMigration.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { MigrationResult, RelatedObjectsMigrate } from '../interfaces';
1616
import { sfProject } from '../../utils/sfcli/project/sfProject';
1717
import { fileutil, File } from '../../utils/file/fileutil';
1818
import { Logger } from '../../utils/logger';
19+
import { ApexAssessmentInfo } from '../../utils';
20+
import { FileDiffUtil } from '../../utils/lwcparser/fileutils/FileDiffUtil';
1921
import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration';
2022

2123
const APEXCLASS = 'Apexclass';
@@ -50,23 +52,36 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
5052
sfProject.deploy(APEXCLASS, targetOrg.getUsername());
5153
shell.cd(pwd);
5254
}
53-
public processApexFiles(dir: string): File[] {
55+
56+
public assess(): ApexAssessmentInfo[] {
57+
const pwd = shell.pwd();
58+
shell.cd(this.projectPath);
59+
const targetOrg: Org = this.org;
60+
sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
61+
const apexAssessmentInfos = this.processApexFiles(this.projectPath);
62+
shell.cd(pwd);
63+
return apexAssessmentInfos;
64+
}
65+
public processApexFiles(dir: string): ApexAssessmentInfo[] {
5466
dir += APEX_CLASS_PATH;
5567
let files: File[] = [];
5668
files = fileutil.readFilesSync(dir);
69+
const fileAssessmentInfo: ApexAssessmentInfo[] = [];
5770
for (const file of files) {
5871
if (file.ext !== '.cls') continue;
5972
try {
60-
this.processApexFile(file);
73+
const apexAssementInfo = this.processApexFile(file);
74+
if (apexAssementInfo && apexAssementInfo.diff && apexAssementInfo.diff.length === 0) continue;
75+
fileAssessmentInfo.push(apexAssementInfo);
6176
} catch (err) {
6277
Logger.logger.error(`Error processing ${file.name}`);
6378
Logger.logger.error(err);
6479
}
6580
}
66-
return files;
81+
return fileAssessmentInfo;
6782
}
6883

69-
public processApexFile(file: File): void {
84+
public processApexFile(file: File): ApexAssessmentInfo {
7085
const fileContent = fs.readFileSync(file.location, 'utf8');
7186
const interfaces: InterfaceImplements[] = [];
7287
interfaces.push(this.vlocityOpenInterface, this.vlocityOpenInterface2, this.callableInterface);
@@ -95,11 +110,26 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
95110
updateMessages.push('File has been updated to allow calls to Omnistudio components');
96111
tokenUpdates.push(...tokeUpdatesForMethodCalls);
97112
}
113+
let difference = '';
98114
if (tokenUpdates && tokenUpdates.length > 0) {
115+
const updatedContent = parser.rewrite(tokenUpdates);
99116
fs.writeFileSync(file.location, parser.rewrite(tokenUpdates));
117+
difference = new FileDiffUtil().getFileDiff(file.name, fileContent, updatedContent);
118+
}
119+
if (updateMessages.length === 0) {
120+
Logger.logger.info(
121+
`File ${file.name} does not have any omnistudio calls or remote calls. No changes will be applied.`
122+
);
100123
}
101124
const warningMessage: string[] = this.processNonReplacableMethodCalls(file, parser);
102125
Logger.logger.warn(warningMessage);
126+
return {
127+
name: file.name,
128+
warnings: warningMessage,
129+
infos: updateMessages,
130+
path: file.location,
131+
diff: difference,
132+
};
103133
}
104134

105135
private processApexFileForRemotecalls(file: File, parser: ApexASTParser): TokenUpdater[] {

0 commit comments

Comments
 (0)