Skip to content

Commit 07b4e66

Browse files
feat: added summary
1 parent 73fe389 commit 07b4e66

File tree

12 files changed

+410
-245
lines changed

12 files changed

+410
-245
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/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/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
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class Stringutil {
2+
public static cleanName(name: string, allowUnderscores = false): string {
3+
if (!name) return '';
4+
return allowUnderscores ? name.replace(/[^a-z0-9_]+/gi, '') : name.replace(/[^a-z0-9]+/gi, '');
5+
}
6+
}

src/utils/StringValue/stringval.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Stringutil } from './stringutil';
2+
3+
export class StringVal {
4+
public val: string;
5+
public type: string;
6+
7+
public constructor(val: string, type?: string) {
8+
this.val = val;
9+
this.type = type;
10+
}
11+
12+
public cleanName(allowUnderscores = false): string {
13+
return Stringutil.cleanName(this.val, allowUnderscores);
14+
}
15+
public isNameCleaned(): boolean {
16+
return !this.val || this.val === this.cleanName();
17+
}
18+
}

src/utils/interfaces.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ export interface LWCAssessmentInfo {
2525
export interface OSAssessmentInfo {
2626
name: string;
2727
id: string;
28-
dependenciesIP: string[];
28+
dependenciesIP: nameLocation[];
2929
missingIP: string[];
30-
dependenciesDR: string[];
30+
dependenciesDR: nameLocation[];
3131
missingDR: string[];
32-
dependenciesOS: string[];
32+
dependenciesOS: nameLocation[];
3333
missingOS: string[];
34-
dependenciesRemoteAction: string[];
35-
// missingRemoteAction: AnyJson[];
34+
dependenciesRemoteAction: nameLocation[];
35+
dependenciesLWC: nameLocation[];
36+
type: string;
3637
infos: string[];
3738
warnings: string[];
3839
errors: string[];
39-
path: string;
4040
}
4141

4242
export interface IPAssessmentInfo {
4343
name: string;
4444
id: string;
45-
dependenciesIP: string[];
46-
dependenciesDR: string[];
47-
dependenciesOS: string[];
48-
dependenciesRemoteAction: string[];
45+
dependenciesIP: nameLocation[];
46+
dependenciesDR: nameLocation[];
47+
dependenciesOS: nameLocation[];
48+
dependenciesRemoteAction: nameLocation[];
4949
infos: string[];
5050
warnings: string[];
5151
errors: string[];
@@ -120,7 +120,7 @@ export interface FileProcessor {
120120
process(file: File, type: string, namespace: string): string;
121121
}
122122

123-
export interface nameUrl {
123+
export interface nameLocation {
124124
name: string;
125-
url: string;
125+
location: string;
126126
}

src/utils/json/jsonutil.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* eslint-disable no-prototype-builtins */
2+
/* eslint-disable @typescript-eslint/no-unsafe-call */
3+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
4+
/* eslint-disable @typescript-eslint/no-explicit-any */
5+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
6+
export class jsonutil {
7+
// Recursive method to find a property in the JSON
8+
public static findProperty(obj: any, propertyName: string): any {
9+
if (obj === null || typeof obj !== 'object') {
10+
return null;
11+
}
12+
13+
// Check if the property exists in the current object
14+
if (propertyName in obj) {
15+
return obj[propertyName];
16+
}
17+
18+
// If it's an array, use findInArray
19+
if (Array.isArray(obj)) {
20+
return this.findInArray(obj, propertyName);
21+
}
22+
23+
// Otherwise, search through all keys
24+
for (const key in obj) {
25+
if (obj.hasOwnProperty(key)) {
26+
const result = this.findProperty(obj[key], propertyName);
27+
if (result !== null) {
28+
return result;
29+
}
30+
}
31+
}
32+
33+
return null; // Property not found
34+
}
35+
36+
// Method to find a property in an array
37+
public static findInArray(arr: any[], propertyName: string): any {
38+
for (const item of arr) {
39+
const result = jsonutil.findProperty(item, propertyName);
40+
if (result !== null) {
41+
return result;
42+
}
43+
}
44+
return null; // Property not found in the array
45+
}
46+
}

0 commit comments

Comments
 (0)