Skip to content

Commit e396f3f

Browse files
Merge pull request #267 from salesforcecli/u/abhinavkumar2/demofeedbacks
@W-17258174@
2 parents 611a9ad + a294bf4 commit e396f3f

File tree

15 files changed

+212
-118
lines changed

15 files changed

+212
-118
lines changed

src/commands/omnistudio/migration/migrate.ts

Lines changed: 103 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
99
*/
1010
import * as os from 'os';
11+
import * as fs from 'fs';
1112
import { flags } from '@salesforce/command';
1213
import { Messages } from '@salesforce/core';
1314
import '../../../utils/prototypes';
@@ -72,13 +73,12 @@ export default class Migrate extends OmniStudioBaseCommand {
7273

7374
// Let's time every step
7475
DebugTimer.getInstance().start();
75-
// const includeApex = this.flags.apex
76-
// ? await this.ux.confirm('Do you want to include Apex migration? (yes/no)')
77-
// : false;
78-
76+
let projectPath: string;
77+
let objectsToProcess: string[];
78+
let targetApexNamespace: string;
7979
if (relatedObjects) {
8080
const validOptions = ['apex', 'lwc'];
81-
const objectsToProcess = relatedObjects.split(',').map((obj) => obj.trim());
81+
objectsToProcess = relatedObjects.split(',').map((obj) => obj.trim());
8282
// Validate input
8383
for (const obj of objectsToProcess) {
8484
if (!validOptions.includes(obj)) {
@@ -87,72 +87,20 @@ export default class Migrate extends OmniStudioBaseCommand {
8787
}
8888
// Ask for user consent
8989
const consent = await this.ux.confirm(
90-
'By proceeding further, you hereby consent to the use, accept changes to your custom code, and the accompanying terms and conditions associated with the use of the OmniStudio Migration Tool. Do you want to proceed?'
90+
'By proceeding further, you hereby consent to the use, accept changes to your custom code, and the accompanying terms and conditions associated with the use of the OmniStudio Migration Tool. Do you want to proceed? [y/n]'
9191
);
9292
if (!consent) {
93-
this.ux.log('User declined consent. Aborting the process.');
93+
this.ux.error(`User declined consent, will not process ${relatedObjects} .`);
9494
} else {
95-
const projectPath = await this.ux.prompt('Enter the project path for processing:');
96-
this.ux.log(`Using project path: ${projectPath}`);
97-
OmnistudioRelatedObjectMigrationFacade.intializeProject(projectPath);
95+
projectPath = await this.getProjectPath(relatedObjects, projectPath);
96+
targetApexNamespace = await this.getTargetApexNamespace(objectsToProcess, targetApexNamespace);
9897
}
9998
}
10099

101100
// const includeLwc = this.flags.lwc ? await this.ux.confirm('Do you want to include LWC migration? (yes/no)') : false;
102101
// Register the migration objects
103102
let migrationObjects: MigrationTool[] = [];
104-
if (!migrateOnly) {
105-
migrationObjects = [
106-
new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux),
107-
new OmniScriptMigrationTool(
108-
OmniScriptExportType.All,
109-
namespace,
110-
conn,
111-
this.logger,
112-
messages,
113-
this.ux,
114-
allVersions
115-
),
116-
new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions),
117-
];
118-
} else {
119-
switch (migrateOnly) {
120-
case 'os':
121-
migrationObjects.push(
122-
new OmniScriptMigrationTool(
123-
OmniScriptExportType.OS,
124-
namespace,
125-
conn,
126-
this.logger,
127-
messages,
128-
this.ux,
129-
allVersions
130-
)
131-
);
132-
break;
133-
case 'ip':
134-
migrationObjects.push(
135-
new OmniScriptMigrationTool(
136-
OmniScriptExportType.IP,
137-
namespace,
138-
conn,
139-
this.logger,
140-
messages,
141-
this.ux,
142-
allVersions
143-
)
144-
);
145-
break;
146-
case 'fc':
147-
migrationObjects.push(new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions));
148-
break;
149-
case 'dr':
150-
migrationObjects.push(new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux));
151-
break;
152-
default:
153-
throw new Error(messages.getMessage('invalidOnlyFlag'));
154-
}
155-
}
103+
migrationObjects = this.getMigrationObjects(migrateOnly, migrationObjects, namespace, conn, allVersions);
156104
// Migrate individual objects
157105
const debugTimer = DebugTimer.getInstance();
158106
let objectMigrationResults: MigratedObject[] = [];
@@ -206,10 +154,12 @@ export default class Migrate extends OmniStudioBaseCommand {
206154
allVersions,
207155
this.org
208156
);
209-
const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration.migrateAll(objectMigrationResults, [
210-
'lwc',
211-
'apex',
212-
]);
157+
const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration.migrateAll(
158+
objectMigrationResults,
159+
objectsToProcess,
160+
projectPath,
161+
targetApexNamespace
162+
);
213163
generatePackageXml.createChangeList(
214164
relatedObjectMigrationResult.apexAssessmentInfos,
215165
relatedObjectMigrationResult.lwcAssessmentInfos
@@ -223,6 +173,93 @@ export default class Migrate extends OmniStudioBaseCommand {
223173
return { objectMigrationResults };
224174
}
225175

176+
private getMigrationObjects(
177+
migrateOnly: string,
178+
migrationObjects: MigrationTool[],
179+
namespace: string,
180+
conn,
181+
allVersions: any
182+
): MigrationTool[] {
183+
if (!migrateOnly) {
184+
migrationObjects = [
185+
new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux),
186+
new OmniScriptMigrationTool(
187+
OmniScriptExportType.All,
188+
namespace,
189+
conn,
190+
this.logger,
191+
messages,
192+
this.ux,
193+
allVersions
194+
),
195+
new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions),
196+
];
197+
} else {
198+
switch (migrateOnly) {
199+
case 'os':
200+
migrationObjects.push(
201+
new OmniScriptMigrationTool(
202+
OmniScriptExportType.OS,
203+
namespace,
204+
conn,
205+
this.logger,
206+
messages,
207+
this.ux,
208+
allVersions
209+
)
210+
);
211+
break;
212+
case 'ip':
213+
migrationObjects.push(
214+
new OmniScriptMigrationTool(
215+
OmniScriptExportType.IP,
216+
namespace,
217+
conn,
218+
this.logger,
219+
messages,
220+
this.ux,
221+
allVersions
222+
)
223+
);
224+
break;
225+
case 'fc':
226+
migrationObjects.push(new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions));
227+
break;
228+
case 'dr':
229+
migrationObjects.push(new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux));
230+
break;
231+
default:
232+
throw new Error(messages.getMessage('invalidOnlyFlag'));
233+
}
234+
}
235+
return migrationObjects;
236+
}
237+
238+
private async getProjectPath(relatedObjects: string, projectPath: string): Promise<string> {
239+
const projectPathConfirmation = await this.ux
240+
.confirm(`Do you have a sfdc project where ${relatedObjects} files are already retrieved from org - y
241+
or you want tool to create a project omnistudio_migration in current directory for processing - n ? [y/n]`);
242+
if (projectPathConfirmation) {
243+
projectPath = await this.ux.prompt(`Enter the project path for processing ${relatedObjects} :`);
244+
const projectJsonFile = 'sfdx-project.json';
245+
if (!fs.existsSync(projectPath + '/' + projectJsonFile)) {
246+
throw new Error(`Could not find any ${projectJsonFile} in ${projectPath}.`);
247+
}
248+
this.ux.log(`Using project path: ${projectPath}`);
249+
}
250+
return projectPath;
251+
}
252+
253+
private async getTargetApexNamespace(objectsToProcess: string[], targetApexNamespace: string): Promise<string> {
254+
if (objectsToProcess.includes('apex')) {
255+
targetApexNamespace = await this.ux.prompt(
256+
'Enter the target namespace to be used for calling package Apex classes'
257+
);
258+
this.ux.log(`Using target namespace: ${targetApexNamespace} for calling package Apex classes`);
259+
}
260+
return targetApexNamespace;
261+
}
262+
226263
private mergeRecordAndUploadResults(
227264
migrationResults: MigrationResult,
228265
migrationTool: MigrationTool

src/migration/related/ApexMigration.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export class ApexMigration extends BaseRelatedObjectMigration {
3030
private readonly callableInterface: InterfaceImplements;
3131
private readonly vlocityOpenInterface2: InterfaceImplements;
3232
private readonly vlocityOpenInterface: InterfaceImplements;
33-
private updatedNamespace = 'vlocity_ins';
34-
public constructor(projectPath: string, namespace: string, org: Org) {
33+
private updatedNamespace;
34+
public constructor(projectPath: string, namespace: string, org: Org, targetApexNameSpace?: string) {
3535
super(projectPath, namespace, org);
36+
this.updatedNamespace = targetApexNameSpace ? targetApexNameSpace : namespace;
3637
this.callableInterface = new InterfaceImplements(CALLABLE, this.namespace);
3738
this.vlocityOpenInterface2 = new InterfaceImplements(VLOCITY_OPEN_INTERFACE2, this.namespace);
3839
this.vlocityOpenInterface = new InterfaceImplements(VLOCITY_OPEN_INTERFACE, this.namespace);
@@ -49,10 +50,10 @@ export class ApexMigration extends BaseRelatedObjectMigration {
4950
public migrate(): ApexAssessmentInfo[] {
5051
const pwd = shell.pwd();
5152
shell.cd(this.projectPath);
52-
const targetOrg: Org = this.org;
53-
sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
53+
// const targetOrg: Org = this.org;
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);
5758
return apexAssessmentInfos;
5859
}

src/migration/related/LwcMigration.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-shadow */
22
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
33
import * as shell from 'shelljs';
4-
import { Org } from '@salesforce/core';
54
import { fileutil, File } from '../../utils/file/fileutil';
65
import { sfProject } from '../../utils/sfcli/project/sfProject';
76
import { Logger } from '../../utils/logger';
@@ -36,8 +35,8 @@ export class LwcMigration extends BaseRelatedObjectMigration {
3635
public migrate(): LWCAssessmentInfo[] {
3736
const pwd = shell.pwd();
3837
shell.cd(this.projectPath);
39-
const targetOrg: Org = this.org;
40-
sfProject.retrieve(LWCTYPE, targetOrg.getUsername());
38+
// const targetOrg: Org = this.org;
39+
// sfProject.retrieve(LWCTYPE, targetOrg.getUsername());
4140
const filesMap = this.processLwcFiles(this.projectPath);
4241
const LWCAssessmentInfos = this.processFiles(filesMap, 'migration');
4342
// sfProject.deploy(LWCTYPE, targetOrg.getUsername());
@@ -98,7 +97,9 @@ export class LwcMigration extends BaseRelatedObjectMigration {
9897
changeInfos,
9998
errors,
10099
};
101-
jsonData.push(assesmentInfo);
100+
if (changeInfos && changeInfos.length > 0) {
101+
jsonData.push(assesmentInfo);
102+
}
102103
}
103104
});
104105
return jsonData;

src/migration/related/OmnistudioRelatedObjectMigrationFacade.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/* eslint-disable @typescript-eslint/no-explicit-any */
55
import { Org } from '@salesforce/core';
66
import '../../utils/prototypes';
7+
import * as shell from 'shelljs';
78
import {
89
ApexAssessmentInfo,
910
DebugTimer,
@@ -22,6 +23,8 @@ import { LwcMigration } from './LwcMigration';
2223
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
2324
// or any library that is using the messages framework can also be loaded this way.
2425
// const messages = Messages.loadMessages('@salesforce/plugin-omnistudio-related-object-migration-tool', 'migrate');
26+
const LWCTYPE = 'LightningComponentBundle';
27+
const APEXCLASS = 'Apexclass';
2528

2629
const defaultProjectName = 'omnistudio_migration';
2730
export default class OmnistudioRelatedObjectMigrationFacade {
@@ -42,40 +45,64 @@ export default class OmnistudioRelatedObjectMigrationFacade {
4245
}
4346
public static intializeProject(projectPath?: string): string {
4447
if (projectPath) {
45-
sfProject.create(defaultProjectName, projectPath);
46-
return projectPath + '/' + defaultProjectName;
48+
// sfProject.create(defaultProjectName, projectPath);
49+
return projectPath;
4750
} else {
4851
sfProject.create(defaultProjectName);
4952
return process.cwd() + '/' + defaultProjectName;
5053
}
5154
}
55+
public intializeProjectWithRetrieve(relatedObjects: string[], projectPath?: string): string {
56+
if (projectPath) {
57+
// sfProject.create(defaultProjectName, projectPath);
58+
return projectPath;
59+
} else {
60+
sfProject.create(defaultProjectName);
61+
projectPath = process.cwd() + '/' + defaultProjectName;
62+
const pwd = shell.pwd();
63+
shell.cd(projectPath);
64+
if (relatedObjects.includes('lwc')) {
65+
sfProject.retrieve(LWCTYPE, this.org.getUsername());
66+
}
67+
if (relatedObjects.includes('apex')) {
68+
sfProject.retrieve(APEXCLASS, this.org.getUsername());
69+
}
70+
shell.cd(pwd);
71+
}
72+
return projectPath;
73+
}
5274

5375
public migrateAll(
5476
migrationResult: MigratedObject[],
5577
relatedObjects: string[],
56-
projectPath?: string
78+
projectPath?: string,
79+
targetApexNamespace?: string
5780
): RelatedObjectAssesmentInfo {
5881
// Start the debug timer
5982
DebugTimer.getInstance().start();
6083

6184
// Declare an array of MigrationTool
62-
const projectDirectory: string = OmnistudioRelatedObjectMigrationFacade.intializeProject(projectPath);
85+
const projectDirectory: string = this.intializeProjectWithRetrieve(relatedObjects, projectPath);
6386
const debugTimer = DebugTimer.getInstance();
6487
debugTimer.start();
6588
// Initialize migration tools based on the relatedObjects parameter
66-
const apexMigrator = this.createApexClassMigrationTool(projectDirectory);
89+
const apexMigrator = this.createApexClassMigrationTool(projectDirectory, targetApexNamespace);
6790
const lwcMigrator = this.createLWCComponentMigrationTool(this.namespace, projectDirectory);
6891
let apexAssessmentInfos: ApexAssessmentInfo[] = [];
6992
let lwcAssessmentInfos: LWCAssessmentInfo[] = [];
7093
// Proceed with migration logic
7194
try {
72-
apexAssessmentInfos = apexMigrator.migrate();
95+
if (relatedObjects.includes('apex')) {
96+
apexAssessmentInfos = apexMigrator.migrate();
97+
}
7398
} catch (Error) {
7499
// Log the error
75100
Logger.logger.error(Error.message);
76101
}
77102
try {
78-
lwcAssessmentInfos = lwcMigrator.migrate();
103+
if (relatedObjects.includes('lwc')) {
104+
lwcAssessmentInfos = lwcMigrator.migrate();
105+
}
79106
} catch (Error) {
80107
// Log the error
81108
Logger.logger.error(Error.message);
@@ -98,8 +125,8 @@ export default class OmnistudioRelatedObjectMigrationFacade {
98125
return new LwcMigration(projectPath, this.namespace, this.org);
99126
}
100127

101-
private createApexClassMigrationTool(projectPath: string): ApexMigration {
128+
private createApexClassMigrationTool(projectPath: string, targetApexNamespace?: string): ApexMigration {
102129
// Return an instance of ApexClassMigrationTool when implemented
103-
return new ApexMigration(projectPath, this.namespace, this.org);
130+
return new ApexMigration(projectPath, this.namespace, this.org, targetApexNamespace);
104131
}
105132
}

0 commit comments

Comments
 (0)