Skip to content

Commit bd95b6d

Browse files
Merge pull request #421 from shaurabh-tiwari-git/relatedObjectUseCase2
@W-19685804 - Related objects migration for Standard Data Model (Use Case2)
2 parents 7ad9664 + c85f1d8 commit bd95b6d

File tree

10 files changed

+734
-27
lines changed

10 files changed

+734
-27
lines changed

messages/assess.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
"manualInterventionForExperienceSite": "We couldn’t process the %s component because no key was found.",
170170
"manualInterventionForExperienceSiteAsFailure": "We couldn’t process the %s component. ",
171171
"manualInterventionForExperienceSiteAsDuplicateKey": "We couldn’t process the %s component because a duplicate key was found. ",
172+
"manualInterventionForExperienceSiteConfiguration": "We couldn’t process the %s Experience site because one of the type/subtype/language is missing in the omnistudio wrapper in experience site configuration.",
172173
"updatingStorageForOmniscipt": "Preparing storage for Omniscripts",
173174
"keyAlreadyInStorage": "The %s %s name already exists in storage.",
174175
"flexcardStorageProcessingStarted": "Preparing storage for Flexcards.",

messages/migrate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
"emptyTargetData": "The Target Name is empty. Check your Experience Cloud site configuration",
165165
"manualInterventionForExperienceSiteAsFailure": "We couldn’t process the %s component.",
166166
"manualInterventionForExperienceSiteAsDuplicateKey": "We couldn’t process the %s component because a duplicate key was found.",
167+
"manualInterventionForExperienceSiteConfiguration": "We couldn’t process the %s Experience site because one of the type/subtype/language is missing in the omnistudio wrapper in experience site configuration.",
167168
"updatingStorageForOmniscipt": "Preparing storage for Omniscripts %s",
168169
"keyAlreadyInStorage": "The %s %s name already exists in storage.",
169170
"flexcardStorageProcessingStarted": "Preparing storage for Flexcards.",

src/migration/flexcard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
234234
flexCardAssessmentInfo.warnings.push(
235235
this.messages.getMessage('needManualInterventionAsSpecialCharsInFlexcardName')
236236
);
237+
flexCardAssessmentInfo.errors.push(
238+
this.messages.getMessage('needManualInterventionAsSpecialCharsInFlexcardName')
239+
);
237240
assessmentStatus = 'Needs Manual Intervention';
238241
}
239242
}
@@ -404,6 +407,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
404407
flexCardAssessmentInfo.warnings.push(
405408
this.messages.getMessage('needManualInterventionAsSpecialCharsInChildFlexcardName')
406409
);
410+
flexCardAssessmentInfo.errors.push(
411+
this.messages.getMessage('needManualInterventionAsSpecialCharsInChildFlexcardName')
412+
);
407413
flexCardAssessmentInfo.migrationStatus = 'Needs Manual Intervention';
408414
}
409415
}

src/migration/interfaces.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,15 @@ export interface ExpSiteComponentAttributes {
175175
richTextValue?: string;
176176
}
177177

178+
export interface OmniScriptStandardKey {
179+
type: string;
180+
subtype: string;
181+
language: string;
182+
}
183+
178184
export interface MigrationStorage {
179185
osStorage: Map<string, OmniScriptStorage>;
186+
osStandardStorage: Map<string, OmniScriptStorage>; // String keys (serialized OmniScriptStandardKey)
180187
fcStorage: Map<string, FlexcardStorage>;
181188
}
182189

src/migration/omniscript.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
MigrationResult,
2020
MigrationStorage,
2121
MigrationTool,
22+
OmniScriptStandardKey,
2223
OmniScriptStorage,
2324
TransformData,
2425
UploadRecordResult,
@@ -657,6 +658,16 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
657658
nameMapping.oldLanguage
658659
)}`;
659660

661+
if (this.IS_STANDARD_DATA_MODEL) {
662+
// Create object key for new storage format
663+
const keyObject: OmniScriptStandardKey = {
664+
type: nameMapping.oldType,
665+
subtype: nameMapping.oldSubtype,
666+
language: nameMapping.oldLanguage,
667+
};
668+
StorageUtil.addStandardOmniScriptToStorage(storage, keyObject, value);
669+
}
670+
660671
finalKey = finalKey.toLowerCase();
661672
if (storage.osStorage.has(finalKey)) {
662673
// Key already exists - handle accordingly
@@ -1175,6 +1186,16 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
11751186
oldrecord[this.getFieldKey('SubType__c')]
11761187
}${this.cleanLanguageName(oldrecord[this.getFieldKey('Language__c')])}`;
11771188

1189+
if (this.IS_STANDARD_DATA_MODEL) {
1190+
// Create object key for new storage format
1191+
const keyObject: OmniScriptStandardKey = {
1192+
type: oldrecord[this.getFieldKey('Type__c')],
1193+
subtype: oldrecord[this.getFieldKey('SubType__c')],
1194+
language: oldrecord[this.getFieldKey('Language__c')],
1195+
};
1196+
StorageUtil.addStandardOmniScriptToStorage(storage, keyObject, value);
1197+
}
1198+
11781199
finalKey = finalKey.toLowerCase();
11791200
if (storage.osStorage.has(finalKey)) {
11801201
// Key already exists - handle accordingly

src/migration/related/ExperienceSiteMigration.ts

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ExpSiteComponent,
1010
ExpSiteComponentAttributes,
1111
MigrationStorage,
12+
OmniScriptStandardKey,
1213
OmniScriptStorage,
1314
ExpSitePageJson,
1415
Storage,
@@ -19,19 +20,22 @@ import { FileDiffUtil } from '../../utils/lwcparser/fileutils/FileDiffUtil';
1920
import { ExperienceSiteAssessmentInfo, ExperienceSiteAssessmentPageInfo } from '../../utils';
2021
import { StorageUtil } from '../../utils/storageUtil';
2122
import { createProgressBar } from '../base';
23+
import { isStandardDataModel } from '../../utils/dataModelService';
2224
import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration';
2325

2426
Messages.importMessagesDirectory(__dirname);
2527

2628
const TARGET_COMPONENT_NAME_OS = 'runtime_omnistudio:omniscript';
2729
const TARGET_COMPONENT_NAME_FC = 'runtime_omnistudio:flexcard';
30+
const TARGET_COMPONENT_NAME_OS_EXP = 'runtime_omnistudio:omniscriptExperienceCloud';
2831
const FLEXCARD_PREFIX = 'cf';
2932

3033
export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
3134
private EXPERIENCE_SITES_PATH: string;
3235
private MIGRATE = 'Migrate';
3336
private ASSESS = 'Assess';
3437
private messages: Messages;
38+
private IS_STANDARD_DATA_MODEL: boolean = isStandardDataModel();
3539

3640
public constructor(projectPath: string, namespace: string, org: Org, messages: Messages) {
3741
super(projectPath, namespace, org);
@@ -235,6 +239,7 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
235239
return;
236240
}
237241

242+
// Check for legacy wrapper component
238243
if (component.componentName === lookupComponentName) {
239244
Logger.logVerbose(this.messages.getMessage('omniWrapperFound'));
240245
experienceSiteAssessmentInfo.hasOmnistudioContent = true;
@@ -250,6 +255,18 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
250255
return;
251256
}
252257

258+
if (this.IS_STANDARD_DATA_MODEL) {
259+
// Check for new LWC components that need reference updates
260+
if (this.isOmnistudioStandardWrapper(component.componentName)) {
261+
Logger.logVerbose(`Found Omnistudio component: ${component.componentName}`);
262+
experienceSiteAssessmentInfo.hasOmnistudioContent = true;
263+
264+
this.updateOmnistudioComponentReferences(component, experienceSiteAssessmentInfo, storage, type);
265+
266+
return;
267+
}
268+
}
269+
253270
const regionsInsideComponent: ExpSiteRegion[] = component.regions;
254271

255272
if (Array.isArray(regionsInsideComponent)) {
@@ -360,6 +377,111 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
360377
return targetData === undefined || targetData.migrationSuccess === false || targetData.isDuplicate === true;
361378
}
362379

380+
/**
381+
* Check if component is an Omnistudio LWC component
382+
*/
383+
private isOmnistudioStandardWrapper(componentName: string): boolean {
384+
return (
385+
componentName === TARGET_COMPONENT_NAME_OS ||
386+
componentName === TARGET_COMPONENT_NAME_FC ||
387+
componentName === TARGET_COMPONENT_NAME_OS_EXP
388+
);
389+
}
390+
391+
/**
392+
* Update references in Omnistudio LWC components
393+
*/
394+
private updateOmnistudioComponentReferences(
395+
component: ExpSiteComponent,
396+
experienceSiteAssessmentInfo: ExperienceSiteAssessmentPageInfo,
397+
storage: MigrationStorage,
398+
type: string
399+
): void {
400+
if (component === undefined || component.componentAttributes === undefined) {
401+
return;
402+
}
403+
const componentName = component.componentName;
404+
const attributes = component.componentAttributes;
405+
406+
if (componentName === TARGET_COMPONENT_NAME_OS || componentName === TARGET_COMPONENT_NAME_OS_EXP) {
407+
this.updateOmniScriptComponentReferences(attributes, experienceSiteAssessmentInfo, storage, type);
408+
} else if (componentName === TARGET_COMPONENT_NAME_FC) {
409+
this.updateFlexCardComponentReferences(attributes, experienceSiteAssessmentInfo, storage, type);
410+
}
411+
}
412+
413+
/**
414+
* Update OmniScript component references (for runtime_omnistudio:omniscript and runtime_omnistudio:omniscriptExperienceCloud)
415+
*/
416+
private updateOmniScriptComponentReferences(
417+
attributes: ExpSiteComponentAttributes,
418+
experienceSiteAssessmentInfo: ExperienceSiteAssessmentPageInfo,
419+
storage: MigrationStorage,
420+
type: string
421+
): void {
422+
const currentType = attributes['type'] as string;
423+
const currentSubType = attributes['subType'] as string;
424+
const currentLanguage = attributes['language'] as string;
425+
426+
if (!currentType || !currentSubType || !currentLanguage) {
427+
const warningMsg = this.messages.getMessage('manualInterventionForExperienceSiteConfiguration', [
428+
experienceSiteAssessmentInfo.name,
429+
]);
430+
experienceSiteAssessmentInfo.warnings.push(warningMsg);
431+
experienceSiteAssessmentInfo.status = type === this.ASSESS ? 'Needs Manual Intervention' : 'Skipped';
432+
return;
433+
}
434+
435+
// Create the OmniScriptStandardKey object for lookup in osStandardStorage
436+
const lookupKey: OmniScriptStandardKey = {
437+
type: currentType,
438+
subtype: currentSubType,
439+
language: currentLanguage,
440+
};
441+
// Look up in osStandardStorage using the object key
442+
const targetDataFromStorage: OmniScriptStorage = StorageUtil.getStandardOmniScript(storage, lookupKey);
443+
444+
if (this.shouldAddWarning(targetDataFromStorage)) {
445+
const originalKey = `${currentType}_${currentSubType}_${currentLanguage}`;
446+
const warningMsg: string = this.getWarningMessage(originalKey, targetDataFromStorage);
447+
experienceSiteAssessmentInfo.warnings.push(warningMsg);
448+
experienceSiteAssessmentInfo.status = type === this.ASSESS ? 'Needs Manual Intervention' : 'Skipped';
449+
} else {
450+
// Update the attributes with the new values from storage
451+
attributes['type'] = targetDataFromStorage.type;
452+
attributes['subType'] = targetDataFromStorage.subtype;
453+
attributes['language'] = targetDataFromStorage.language;
454+
}
455+
}
456+
457+
/**
458+
* Update FlexCard component references (for runtime_omnistudio:flexcard)
459+
*/
460+
private updateFlexCardComponentReferences(
461+
attributes: ExpSiteComponentAttributes,
462+
experienceSiteAssessmentInfo: ExperienceSiteAssessmentPageInfo,
463+
storage: MigrationStorage,
464+
type: string
465+
): void {
466+
const currentFlexCardName = attributes['flexcardName'] as string;
467+
468+
if (!currentFlexCardName) {
469+
return;
470+
}
471+
472+
// Look up in storage to see if this FlexCard was migrated
473+
const targetDataFromStorageFC: FlexcardStorage = storage.fcStorage.get(currentFlexCardName.toLowerCase());
474+
475+
if (this.shouldAddWarning(targetDataFromStorageFC)) {
476+
const warningMsg: string = this.getWarningMessage(currentFlexCardName, targetDataFromStorageFC);
477+
experienceSiteAssessmentInfo.warnings.push(warningMsg);
478+
experienceSiteAssessmentInfo.status = type === this.ASSESS ? 'Needs Manual Intervention' : 'Skipped';
479+
} else {
480+
// Update the flexcardName with the new value from storage
481+
attributes['flexcardName'] = targetDataFromStorageFC.name;
482+
}
483+
}
484+
363485
private getWarningMessage(oldTypeSubtypeLanguage: string, targetDataFromStorage: Storage): string {
364486
if (targetDataFromStorage === undefined) {
365487
// Add log verbose

0 commit comments

Comments
 (0)