Skip to content

Commit 7ad9664

Browse files
Merge pull request #420 from sf-aastha-paruthi/u/aparuthi/StandardDataModelChangesForNameRegistry
@W-19464592 Standard data model changes for name registry
2 parents e126552 + 02fb509 commit 7ad9664

File tree

7 files changed

+851
-34
lines changed

7 files changed

+851
-34
lines changed

src/commands/omnistudio/migration/migrate.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import { YES_SHORT, YES_LONG, NO_SHORT, NO_LONG } from '../../../utils/projectPa
3131
import { PostMigrate } from '../../../migration/postMigrate';
3232
import { PreMigrate } from '../../../migration/premigrate';
3333
import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumber';
34-
import { initializeDataModelService, isStandardDataModel } from '../../../utils/dataModelService';
34+
import {
35+
getFieldKeyForOmniscript,
36+
initializeDataModelService,
37+
isStandardDataModel,
38+
} from '../../../utils/dataModelService';
3539
import { NameMappingRegistry } from '../../../migration/NameMappingRegistry';
3640
import { ValidatorService } from '../../../utils/validatorService';
3741

@@ -554,7 +558,14 @@ export default class Migrate extends OmniStudioBaseCommand {
554558
* Query DataMappers from the org
555559
*/
556560
private async queryDataMappers(conn: any, namespace: string): Promise<any[]> {
557-
const query = `SELECT Id, Name FROM ${namespace}__DRBundle__c WHERE ${namespace}__Type__c != 'Migration'`;
561+
let query;
562+
563+
if (isStandardDataModel()) {
564+
query = "SELECT Id, Name FROM OmniDataTransform WHERE Type != 'Migration'";
565+
} else {
566+
query = `SELECT Id, Name FROM ${namespace}__DRBundle__c WHERE ${namespace}__Type__c != 'Migration'`;
567+
}
568+
558569
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
559570
const result = await conn.query(query);
560571
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
@@ -566,8 +577,14 @@ export default class Migrate extends OmniStudioBaseCommand {
566577
*/
567578
private async queryOmniScripts(conn: any, namespace: string, isProcedure: boolean): Promise<any[]> {
568579
const procedureFilter = isProcedure ? 'true' : 'false';
580+
let query;
581+
569582
// Query all OmniScripts (both LWC and Angular)
570-
const query = `SELECT Id, Name, ${namespace}__Type__c, ${namespace}__SubType__c, ${namespace}__Language__c, ${namespace}__IsProcedure__c, ${namespace}__IsLwcEnabled__c FROM ${namespace}__OmniScript__c WHERE ${namespace}__IsProcedure__c = ${procedureFilter} and ${namespace}__IsActive__c = true`;
583+
if (isStandardDataModel()) {
584+
query = `SELECT Id, Name, Type, SubType, Language, IsIntegrationProcedure, IsWebCompEnabled FROM OmniProcess WHERE IsIntegrationProcedure = ${procedureFilter} and IsActive = true`;
585+
} else {
586+
query = `SELECT Id, Name, ${namespace}__Type__c, ${namespace}__SubType__c, ${namespace}__Language__c, ${namespace}__IsProcedure__c, ${namespace}__IsLwcEnabled__c FROM ${namespace}__OmniScript__c WHERE ${namespace}__IsProcedure__c = ${procedureFilter} and ${namespace}__IsActive__c = true`;
587+
}
571588
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
572589
const result = await conn.query(query);
573590
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
@@ -582,7 +599,7 @@ export default class Migrate extends OmniStudioBaseCommand {
582599
const angular: any[] = [];
583600

584601
for (const omniscript of omniscripts) {
585-
const isLwcEnabled = omniscript[`${namespace}__IsLwcEnabled__c`];
602+
const isLwcEnabled = omniscript[getFieldKeyForOmniscript(namespace, 'IsLwcEnabled__c')];
586603
if (isLwcEnabled) {
587604
lwc.push(omniscript);
588605
} else {
@@ -597,7 +614,13 @@ export default class Migrate extends OmniStudioBaseCommand {
597614
* Query FlexCards from the org
598615
*/
599616
private async queryFlexCards(conn: any, namespace: string): Promise<any[]> {
600-
const query = `SELECT Id, Name FROM ${namespace}__VlocityCard__c WHERE ${namespace}__CardType__c = 'flex' AND ${namespace}__Active__c = true`;
617+
let query;
618+
if (isStandardDataModel()) {
619+
query = 'SELECT Id, Name FROM OmniUiCard WHERE IsActive = true';
620+
} else {
621+
query = `SELECT Id, Name FROM ${namespace}__VlocityCard__c WHERE ${namespace}__CardType__c = 'flex' AND ${namespace}__Active__c = true`;
622+
}
623+
601624
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
602625
const result = await conn.query(query);
603626
// eslint-disable-next-line @typescript-eslint/no-unsafe-return

src/migration/NameMappingRegistry.ts

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8+
import { isStandardDataModel } from '../utils/dataModelService';
89
import { Stringutil } from '../utils/StringValue/stringutil';
910

1011
export interface ComponentNameMapping {
@@ -41,9 +42,6 @@ export class NameMappingRegistry {
4142
// Track Angular OmniScripts that should be skipped (Type_SubType_Language format)
4243
private angularOmniScriptRefs: Set<string> = new Set();
4344

44-
// eslint-disable-next-line @typescript-eslint/no-empty-function
45-
private constructor() {}
46-
4745
public static getInstance(): NameMappingRegistry {
4846
if (!NameMappingRegistry.instance) {
4947
NameMappingRegistry.instance = new NameMappingRegistry();
@@ -151,8 +149,9 @@ export class NameMappingRegistry {
151149
public getOmniScriptCleanedName(type: string, subType: string, language: string | 'English'): string {
152150
const originalName = `${type}_${subType}_${language}`;
153151
// Check if we have a mapping for this OmniScript first
154-
if (this.omniScriptMappings.has(originalName)) {
155-
return this.omniScriptMappings.get(originalName)!;
152+
const mappedName = this.omniScriptMappings.get(originalName);
153+
if (mappedName) {
154+
return mappedName;
156155
}
157156
// Fallback to cleaning individual parts
158157
const cleanedType = Stringutil.cleanName(type);
@@ -279,6 +278,24 @@ export class NameMappingRegistry {
279278
flexCards: any[]
280279
): void {
281280
// Register DataMapper mappings
281+
this.registerDataMappersMapping(dataMappers);
282+
this.registerLwcOmniscriptsMapping(lwcOmniScripts);
283+
this.registerAngularOmniscriptsMapping(angularOmniScripts);
284+
this.registerIntegrationProceduresMapping(integrationProcedures);
285+
this.registerFlexcardsMapping(flexCards);
286+
}
287+
288+
/**
289+
* Update all dependency references with cleaned names
290+
*/
291+
public updateDependencyReferences<T>(componentDefinition: T): T {
292+
// This will be called for each component to update its dependencies
293+
// Implementation depends on the specific structure of each component type
294+
return this.updateObjectReferences(componentDefinition) as T;
295+
}
296+
297+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
298+
private registerDataMappersMapping(dataMappers: any[]): void {
282299
for (const dr of dataMappers) {
283300
this.registerNameMapping({
284301
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
@@ -290,15 +307,23 @@ export class NameMappingRegistry {
290307
recordId: dr.Id,
291308
});
292309
}
310+
}
293311

312+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
313+
private registerLwcOmniscriptsMapping(lwcOmniScripts: any[]): void {
294314
// Register OmniScript mappings
295315
for (const os of lwcOmniScripts) {
296316
// Extract namespace from field names (e.g., vlocity_ins__Type__c -> vlocity_ins)
297-
const fieldNames = Object.keys(os);
298-
const typeField = fieldNames.find((field) => field.endsWith('__Type__c')) || 'Type__c';
299-
const subTypeField = fieldNames.find((field) => field.endsWith('__SubType__c')) || 'SubType__c';
300-
const languageField = fieldNames.find((field) => field.endsWith('__Language__c')) || 'Language__c';
301-
317+
let typeField = 'Type';
318+
let subTypeField = 'SubType';
319+
let languageField = 'Language';
320+
321+
if (!isStandardDataModel()) {
322+
const fieldNames = Object.keys(os);
323+
typeField = fieldNames.find((field) => field.endsWith('__Type__c')) || 'Type__c';
324+
subTypeField = fieldNames.find((field) => field.endsWith('__SubType__c')) || 'SubType__c';
325+
languageField = fieldNames.find((field) => field.endsWith('__Language__c')) || 'Language__c';
326+
}
302327
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
303328
const type = os[typeField];
304329
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
@@ -319,14 +344,23 @@ export class NameMappingRegistry {
319344
recordId: os.Id,
320345
});
321346
}
347+
}
322348

349+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
350+
private registerAngularOmniscriptsMapping(angularOmniScripts: any[]): void {
323351
// Register Angular OmniScript references (to be skipped during migration)
324352
for (const angularOs of angularOmniScripts) {
325353
// Extract namespace from field names (e.g., vlocity_ins__Type__c -> vlocity_ins)
326-
const fieldNames = Object.keys(angularOs);
327-
const typeField = fieldNames.find((field) => field.endsWith('__Type__c')) || 'Type__c';
328-
const subTypeField = fieldNames.find((field) => field.endsWith('__SubType__c')) || 'SubType__c';
329-
const languageField = fieldNames.find((field) => field.endsWith('__Language__c')) || 'Language__c';
354+
let typeField = 'Type';
355+
let subTypeField = 'SubType';
356+
let languageField = 'Language';
357+
358+
if (!isStandardDataModel()) {
359+
const fieldNames = Object.keys(angularOs);
360+
typeField = fieldNames.find((field) => field.endsWith('__Type__c')) || 'Type__c';
361+
subTypeField = fieldNames.find((field) => field.endsWith('__SubType__c')) || 'SubType__c';
362+
languageField = fieldNames.find((field) => field.endsWith('__Language__c')) || 'Language__c';
363+
}
330364

331365
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
332366
const type = angularOs[typeField];
@@ -339,13 +373,21 @@ export class NameMappingRegistry {
339373
const angularRef = `${type}_${subType}_${language}`;
340374
this.registerAngularOmniScript(angularRef);
341375
}
376+
}
342377

378+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
379+
private registerIntegrationProceduresMapping(integrationProcedures: any[]): void {
343380
// Register Integration Procedure mappings
344381
for (const ip of integrationProcedures) {
345-
// Extract namespace from field names (e.g., vlocity_ins__Type__c -> vlocity_ins)
346-
const fieldNames = Object.keys(ip);
347-
const typeField = fieldNames.find((field) => field.endsWith('__Type__c')) || 'Type__c';
348-
const subTypeField = fieldNames.find((field) => field.endsWith('__SubType__c')) || 'SubType__c';
382+
let typeField = 'Type';
383+
let subTypeField = 'SubType';
384+
385+
if (!isStandardDataModel()) {
386+
// Extract namespace from field names (e.g., vlocity_ins__Type__c -> vlocity_ins)
387+
const fieldNames = Object.keys(ip);
388+
typeField = fieldNames.find((field) => field.endsWith('__Type__c')) || 'Type__c';
389+
subTypeField = fieldNames.find((field) => field.endsWith('__SubType__c')) || 'SubType__c';
390+
}
349391

350392
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
351393
const type = ip[typeField];
@@ -366,7 +408,10 @@ export class NameMappingRegistry {
366408
recordId: ip.Id,
367409
});
368410
}
411+
}
369412

413+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
414+
private registerFlexcardsMapping(flexCards: any[]): void {
370415
// Register FlexCard mappings
371416
for (const fc of flexCards) {
372417
this.registerNameMapping({
@@ -381,15 +426,6 @@ export class NameMappingRegistry {
381426
}
382427
}
383428

384-
/**
385-
* Update all dependency references with cleaned names
386-
*/
387-
public updateDependencyReferences<T>(componentDefinition: T): T {
388-
// This will be called for each component to update its dependencies
389-
// Implementation depends on the specific structure of each component type
390-
return this.updateObjectReferences(componentDefinition) as T;
391-
}
392-
393429
/**
394430
* Recursively update references in an object
395431
*/

src/migration/omniscript.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,9 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
13381338

13391339
elementRecord['Id'] = standardElementId;
13401340
elementRecord['OmniProcessId'] = standardOmniProcessId;
1341-
elementsUploadResponse[standardElementId] = response;
1341+
elementsUploadResponse.set(standardElementId, response);
13421342
}
13431343
}
1344-
13451344
// Keep appending upload Info for Elements at each level
13461345
elementsUploadInfo = new Map([
13471346
...Array.from(elementsUploadInfo.entries()),

src/utils/dataModelService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import OmniScriptMappings from '../mappings/OmniScript';
12
import { OmnistudioOrgDetails } from './orgUtils';
23
import { Constants } from './constants/stringContants';
34

@@ -51,3 +52,8 @@ export function isCustomDataModel(): boolean {
5152
const dataModel = getDataModelInfo();
5253
return dataModel === Constants.CustomDataModel;
5354
}
55+
56+
export function getFieldKeyForOmniscript(namespacePrefix: string, fieldName: string): string {
57+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
58+
return isStandardDataModel() ? OmniScriptMappings[fieldName] : namespacePrefix + '__' + fieldName;
59+
}

0 commit comments

Comments
 (0)