Skip to content

Commit fe061b0

Browse files
Merge pull request #258 from salesforcecli/u/abhinavkumar2/W-16279013
@W-16279013@
2 parents b65aa81 + 07b4e66 commit fe061b0

File tree

19 files changed

+576
-307
lines changed

19 files changed

+576
-307
lines changed

messages/assess.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525
"errorWhileActivatingCard": "Could not activate Card: ",
2626
"errorWhileUploadingCard": "An error ocurred while uploading Card: ",
2727
"errorWhileCreatingElements": "An error ocurred while saving OmniScript elements: ",
28-
"allVersionsDescription": "Migrate all versions of a component"
29-
}
28+
"allVersionsDescription": "Migrate all versions of a component",
29+
"changeMessage": " %s will be changed from %s to %s",
30+
"angularOSWarning": " Angular OmniScript will not be migrated, please convert this to LWC based Omniscript"
31+
}

src/commands/omnistudio/migration/assess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class Assess extends OmniStudioBaseCommand {
4545
DebugTimer.getInstance().start();
4646
const namespace = (this.flags.namespace || 'vlocity_ins') as string;
4747
const apiVersion = (this.flags.apiversion || '55.0') as string;
48-
const allVersions = true;
48+
const allVersions = (this.flags.allversions || false) as boolean;
4949
const conn = this.org.getConnection();
5050
Logger.initialiseLogger(this.ux, this.logger);
5151
const projectDirectory = OmnistudioRelatedObjectMigrationFacade.intializeProject();

src/commands/omnistudio/migration/migrate.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { CardMigrationTool } from '../../../migration/flexcard';
2020
import { OmniScriptExportType, OmniScriptMigrationTool } from '../../../migration/omniscript';
2121
import { Logger } from '../../../utils/logger';
2222
import OmnistudioRelatedObjectMigrationFacade from '../../../migration/related/OmnistudioRelatedObjectMigrationFacade';
23+
import { generatePackageXml } from '../../../utils/generatePackageXml';
2324

2425
// Initialize Messages with the current plugin directory
2526
Messages.importMessagesDirectory(__dirname);
@@ -175,7 +176,11 @@ export default class Migrate extends OmniStudioBaseCommand {
175176
allVersions,
176177
this.org
177178
);
178-
omnistudioRelatedObjectsMigration.migrateAll(objectMigrationResults, []);
179+
const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration.migrateAll(objectMigrationResults, []);
180+
generatePackageXml.createChangeList(
181+
relatedObjectMigrationResult.apexClasses,
182+
relatedObjectMigrationResult.lwcComponents
183+
);
179184
await ResultsBuilder.generate(objectMigrationResults, conn.instanceUrl);
180185

181186
// save timer to debug logger

src/migration/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Connection, Logger, Messages } from '@salesforce/core';
33
import { DebugTimer, QueryTools } from '../utils';
44

55
import { NetUtils } from '../utils/net';
6+
import { Stringutil } from '../utils/StringValue/stringutil';
67
import { TransformData, UploadRecordResult } from './interfaces';
78

89
export class BaseMigrationTool {
@@ -57,8 +58,7 @@ export class BaseMigrationTool {
5758
}
5859

5960
protected cleanName(name: string, allowUnderscores = false): string {
60-
if (!name) return '';
61-
return allowUnderscores ? name.replace(/[^a-z0-9_]+/gi, '') : name.replace(/[^a-z0-9]+/gi, '');
61+
return Stringutil.cleanName(name, allowUnderscores);
6262
}
6363

6464
protected async truncate(objectName: string): Promise<void> {

src/migration/dataraptor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
188188
DebugTimer.getInstance().lap('Query data raptors');
189189
const dataRaptors = await this.getAllDataRaptors();
190190
const dataRaptorAssessmentInfos = this.processDRComponents(dataRaptors);
191-
this.ux.log('dataRaptorAssessmentInfos');
192-
this.ux.log(dataRaptorAssessmentInfos.toString());
191+
/* this.ux.log('dataRaptorAssessmentInfos');
192+
this.ux.log(dataRaptorAssessmentInfos.toString()); */
193193
return dataRaptorAssessmentInfos;
194194
} catch (err) {
195195
this.ux.log(err);

src/migration/interfaces.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,16 @@ export interface RelatedObjectsMigrate {
100100
* @param namespace The namespace used to perform the migration.
101101
* @param migrationCandidates List of candidates to migrate.
102102
*/
103-
migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): void;
103+
migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): string[];
104+
105+
processObjectType(): string;
104106
}
105107

106108
export type LWCComponentMigrationTool = MigrationTool;
107109

108110
export type CustomLabelMigrationTool = MigrationTool;
111+
112+
export interface RelatedObjectMigrationResult {
113+
apexClasses: string[];
114+
lwcComponents: string[];
115+
}

src/migration/omniscript.ts

Lines changed: 97 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { AnyJson } from '@salesforce/ts-types';
44
import OmniScriptMappings from '../mappings/OmniScript';
55
import ElementMappings from '../mappings/Element';
66
import OmniScriptDefinitionMappings from '../mappings/OmniScriptDefinition';
7-
import { DataRaptorAssessmentInfo, DebugTimer, FlexCardAssessmentInfo, QueryTools, SortDirection } from '../utils';
7+
import {
8+
DataRaptorAssessmentInfo,
9+
DebugTimer,
10+
FlexCardAssessmentInfo,
11+
nameLocation,
12+
QueryTools,
13+
SortDirection,
14+
} from '../utils';
815
import { BaseMigrationTool } from './base';
916
import { MigrationResult, MigrationTool, TransformData, UploadRecordResult } from './interfaces';
1017
import { ObjectMapping } from './interfaces';
@@ -13,6 +20,7 @@ import { Connection, Messages, Logger } from '@salesforce/core';
1320
import { UX } from '@salesforce/command';
1421
import { OSAssessmentInfo, OmniAssessmentInfo, IPAssessmentInfo } from '../../src/utils';
1522
import { getAllFunctionMetadata, getReplacedString } from '../utils/formula/FormulaUtil';
23+
import { StringVal } from '../utils/StringValue/stringval';
1624

1725
export class OmniScriptMigrationTool extends BaseMigrationTool implements MigrationTool {
1826
private readonly exportType: OmniScriptExportType;
@@ -190,30 +198,24 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
190198
const osAssessmentInfos: OSAssessmentInfo[] = [];
191199
const ipAssessmentInfos: IPAssessmentInfo[] = [];
192200

193-
const limitedOmniscripts = omniscripts.slice(0, 200);
194-
195201
// Create a set to store existing OmniScript names and also extract DataRaptor and FlexCard names
196202
const existingOmniscriptNames = new Set<string>();
197203
const existingDataRaptorNames = new Set(dataRaptorAssessmentInfos.map((info) => info.name));
198204
const existingFlexCardNames = new Set(flexCardAssessmentInfos.map((info) => info.name));
199205

200206
// First, collect all OmniScript names from the omniscripts array
201-
for (const omniscript of limitedOmniscripts) {
202-
const omniScriptName = `${omniscript[this.namespacePrefix + 'Name']}`;
203-
existingOmniscriptNames.add(omniScriptName);
204-
}
205-
206207
// Now process each OmniScript and its elements
207-
for (const omniscript of limitedOmniscripts) {
208+
for (const omniscript of omniscripts) {
208209
const elements = await this.getAllElementsForOmniScript(omniscript['Id']);
209210

210-
const dependencyIP: string[] = [];
211+
const dependencyIP: nameLocation[] = [];
211212
const missingIP: string[] = [];
212-
const dependencyDR: string[] = [];
213+
const dependencyDR: nameLocation[] = [];
213214
const missingDR: string[] = [];
214-
const dependencyOS: string[] = [];
215+
const dependencyOS: nameLocation[] = [];
215216
const missingOS: string[] = [];
216-
const dependenciesRA: string[] = [];
217+
const dependenciesRA: nameLocation[] = [];
218+
const dependenciesLWC: nameLocation[] = [];
217219
//const missingRA: string[] = [];
218220

219221
for (const elem of elements) {
@@ -223,55 +225,119 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
223225

224226
// Check for OmniScript dependencies
225227
if (type === 'OmniScript') {
226-
const nameVal = `${elemName}_OmniScript`;
228+
const nameVal = `${elemName}`;
227229
const type = propertySet['Type'];
228230
const subtype = propertySet['Sub Type'];
229231
const language = propertySet['Language'];
230232
const osName = type + '_' + subtype + '_' + language;
231-
dependencyOS.push(osName + ' ( ' + nameVal + ' ) <br>');
233+
dependencyOS.push({
234+
name: osName,
235+
location: nameVal,
236+
});
232237
if (!existingOmniscriptNames.has(nameVal)) {
233238
missingOS.push(nameVal);
234239
}
235240
}
236241

237242
// Check for Integration Procedure Action dependencies
238243
if (type === 'Integration Procedure Action') {
239-
const nameVal = `${elemName}_Integration Procedure Action`;
240-
dependencyIP.push(propertySet['integrationProcedureKey'] + ' (' + nameVal + ') <br>');
244+
const nameVal = `${elemName}`;
245+
dependencyIP.push({ name: propertySet['integrationProcedureKey'], location: nameVal });
241246
if (!existingOmniscriptNames.has(nameVal) && !existingFlexCardNames.has(nameVal)) {
242247
missingIP.push(nameVal);
243248
}
244249
}
245250

246251
// Check for DataRaptor dependencies
247252
if (['DataRaptor Extract Action', 'DataRaptor Turbo Action', 'DataRaptor Post Action'].includes(type)) {
248-
const nameVal = `${elemName}_${type}`;
249-
dependencyDR.push(propertySet['bundle'] + ' ( ' + nameVal + ' ) <br>');
253+
const nameVal = `${elemName}`;
254+
dependencyDR.push({ name: propertySet['bundle'], location: nameVal });
250255
if (!existingOmniscriptNames.has(nameVal) && !existingDataRaptorNames.has(nameVal)) {
251256
missingDR.push(nameVal);
252257
}
253258
}
254259

255260
if (type === 'Remote Action') {
256-
const nameVal = `${elemName}_${type}`;
261+
const nameVal = `${elemName}`;
257262
const className = propertySet['remoteClass'];
258263
const methodName = propertySet['remoteMethod'];
259-
dependenciesRA.push(className + '.' + methodName + ' (' + nameVal + ') <br>');
264+
dependenciesRA.push({ name: className + '.' + methodName, location: nameVal });
265+
}
266+
// To handle radio , multiselect
267+
if (propertySet['optionSource'] && propertySet['optionSource']['type'] === 'Custom') {
268+
const nameVal = `${elemName}`;
269+
dependenciesRA.push({ name: propertySet['optionSource']['source'], location: nameVal });
260270
}
261-
}
262271

263-
/*const recordName = `${omniscript[this.namespacePrefix + 'Type__c']}_` +
264-
`${omniscript[this.namespacePrefix + 'SubType__c']}` +
265-
(omniscript[this.namespacePrefix + 'Language__c'] ? `_${omniscript[this.namespacePrefix + 'Language__c']}` : '') +
266-
`_${omniscript[this.namespacePrefix + 'Version__c']}`;*/
272+
if (type === 'Custom Lightning Web Component') {
273+
const nameVal = `${elemName}`;
274+
const lwcName = propertySet['lwcName'];
275+
dependenciesLWC.push({ name: lwcName, location: nameVal });
276+
}
277+
}
267278

268279
const omniProcessType = omniscript[this.namespacePrefix + 'IsProcedure__c']
269280
? 'Integration Procedure'
270281
: 'OmniScript';
271282

283+
const existingType = omniscript[this.namespacePrefix + 'Type__c'];
284+
const existingTypeVal = new StringVal(existingType, 'type');
285+
const existingSubType = omniscript[this.namespacePrefix + 'SubType__c'];
286+
const existingSubTypeVal = new StringVal(existingSubType, 'sub type');
287+
const omniScriptName = omniscript[this.namespacePrefix + 'Name'];
288+
const existingOmniScriptNameVal = new StringVal(omniScriptName, 'name');
289+
290+
const warnings: string[] = [];
291+
292+
const recordName =
293+
`${existingTypeVal.cleanName()}_` +
294+
`${existingSubTypeVal.cleanName()}` +
295+
(omniscript[this.namespacePrefix + 'Language__c']
296+
? `_${omniscript[this.namespacePrefix + 'Language__c']}`
297+
: '') +
298+
`_${omniscript[this.namespacePrefix + 'Version__c']}`;
299+
300+
if (!existingTypeVal.isNameCleaned()) {
301+
warnings.push(
302+
this.messages.getMessage('changeMessage', [
303+
existingTypeVal.type,
304+
existingTypeVal.val,
305+
existingTypeVal.cleanName(),
306+
])
307+
);
308+
}
309+
if (!existingSubTypeVal.isNameCleaned()) {
310+
warnings.push(
311+
this.messages.getMessage('changeMessage', [
312+
existingSubTypeVal.type,
313+
existingSubTypeVal.val,
314+
existingSubTypeVal.cleanName(),
315+
])
316+
);
317+
}
318+
if (!existingOmniScriptNameVal.isNameCleaned()) {
319+
warnings.push(
320+
this.messages.getMessage('changeMessage', [
321+
existingOmniScriptNameVal.type,
322+
existingOmniScriptNameVal.val,
323+
existingOmniScriptNameVal.cleanName(),
324+
])
325+
);
326+
}
327+
if (existingOmniscriptNames.has(recordName)) {
328+
warnings.push(this.messages.getMessage('duplicatedName') + recordName);
329+
} else {
330+
existingOmniscriptNames.add(recordName);
331+
}
332+
272333
if (omniProcessType === 'OmniScript') {
334+
const type = omniscript[this.namespacePrefix + 'IsLwcEnabled__c'] ? 'LWC' : 'Angular';
335+
if (type === 'Angular') {
336+
warnings.unshift(this.messages.getMessage('angularOSWarning'));
337+
}
273338
const osAssessmentInfo: OSAssessmentInfo = {
274-
name: omniscript['Name'],
339+
name: recordName,
340+
type: type,
275341
id: omniscript['Id'],
276342
dependenciesIP: dependencyIP,
277343
missingIP: [],
@@ -280,22 +346,22 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
280346
dependenciesOS: dependencyOS,
281347
missingOS: missingOS,
282348
dependenciesRemoteAction: dependenciesRA,
349+
dependenciesLWC: dependenciesLWC,
283350
infos: [],
284-
warnings: [],
351+
warnings: warnings,
285352
errors: [],
286-
path: '',
287353
};
288354
osAssessmentInfos.push(osAssessmentInfo);
289355
} else {
290356
const ipAssessmentInfo: IPAssessmentInfo = {
291-
name: omniscript['Name'],
357+
name: recordName,
292358
id: omniscript['Id'],
293359
dependenciesIP: dependencyIP,
294360
dependenciesDR: dependencyDR,
295361
dependenciesOS: dependencyOS,
296362
dependenciesRemoteAction: dependenciesRA,
297363
infos: [],
298-
warnings: [],
364+
warnings: warnings,
299365
errors: [],
300366
path: '',
301367
};

src/migration/related/ApexMigration.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
3737
this.vlocityOpenInterface2 = new InterfaceImplements(VLOCITY_OPEN_INTERFACE2, this.namespace);
3838
this.vlocityOpenInterface = new InterfaceImplements(VLOCITY_OPEN_INTERFACE, this.namespace);
3939
}
40+
public processObjectType(): string {
41+
return 'apex';
42+
}
4043
public identifyObjects(migrationResults: MigrationResult[]): Promise<JSON[]> {
4144
throw new Error('Method not implemented.');
4245
}
43-
public migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): void {
44-
this.migrate();
46+
public migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): string[] {
47+
return this.migrate();
4548
}
46-
public migrate(): void {
49+
public migrate(): string[] {
4750
const pwd = shell.pwd();
4851
shell.cd(this.projectPath);
4952
const targetOrg: Org = this.org;
5053
sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
51-
this.processApexFiles(this.projectPath);
54+
const apexAssessmentInfos = this.processApexFiles(this.projectPath);
5255
sfProject.deploy(APEXCLASS, targetOrg.getUsername());
5356
shell.cd(pwd);
57+
return this.mapTOName(apexAssessmentInfos);
5458
}
5559

5660
public assess(): ApexAssessmentInfo[] {
@@ -180,4 +184,10 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
180184
}
181185
`;
182186
}
187+
188+
private mapTOName(apexAssessmentInfos: ApexAssessmentInfo[]): string[] {
189+
return apexAssessmentInfos.map((apexAssessmentInfo) => {
190+
return apexAssessmentInfo.name;
191+
});
192+
}
183193
}

0 commit comments

Comments
 (0)