Skip to content

Commit 5b06bf6

Browse files
authored
Merge pull request #354 from sf-aastha-paruthi/u/aparuthi/experienceSiteFixes
W-19244322 - Experience Site Fixes: Migrate OS and FC from vLocity wrapper to omnistudio wrapper in experience sites
2 parents b10c37a + d13bc98 commit 5b06bf6

File tree

10 files changed

+87
-64
lines changed

10 files changed

+87
-64
lines changed

messages/assess.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,6 @@
183183
"missingInfo": "Info is missing",
184184
"errorCheckingGlobalAutoNumber": "We couldn’t check whether the Global Auto Number setting is enabled: %s. Try again later.",
185185
"errorMigrationMessage": "Error migrating object: %s",
186-
"nameMappingUndefined": "Name Mapping is undefined"
186+
"nameMappingUndefined": "Name Mapping is undefined",
187+
"experienceSiteException": "Exception occurred while processing experience sites"
187188
}

messages/migrate.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@
195195
"flexcardStorageProcessingStarted": "Started preparing storage for flexcards",
196196
"errorWhileProcessingFlexcardStorage": "Error occurred while processing key for flexcard storage",
197197
"missingInfo": "Info is missing",
198-
"incompleteMigrationDetected": "We couldn’t complete the migration process",
199198
"errorCheckingGlobalAutoNumber": "We couldn’t check whether the Global Auto Number setting is enabled: %s. Try again later.",
200199
"errorMigrationMessage": "Error migrating object: %s",
201-
"nameMappingUndefined": "Name Mapping is undefined"
200+
"nameMappingUndefined": "Name Mapping is undefined",
201+
"experienceSiteException": "Exception occurred while processing experience sites"
202202
}

src/commands/omnistudio/migration/assess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default class Assess extends OmniStudioBaseCommand {
9898

9999
const namespace = orgs.packageDetails.namespace;
100100
let projectPath = '';
101-
const preMigrate: PreMigrate = new PreMigrate(this.org, namespace, conn, this.logger, messages, this.ux);
101+
const preMigrate: PreMigrate = new PreMigrate(namespace, conn, this.logger, messages, this.ux);
102102
if (relatedObjects) {
103103
objectsToProcess = relatedObjects.split(',').map((obj) => obj.trim());
104104
projectPath = await ProjectPathUtil.getProjectPath(messages, true);

src/commands/omnistudio/migration/migrate.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default class Migrate extends OmniStudioBaseCommand {
132132
let projectPath: string;
133133
let objectsToProcess: string[] = [];
134134
let targetApexNamespace: string;
135-
const preMigrate: PreMigrate = new PreMigrate(this.org, namespace, conn, this.logger, messages, this.ux);
135+
const preMigrate: PreMigrate = new PreMigrate(namespace, conn, this.logger, messages, this.ux);
136136
const isExperienceBundleMetadataAPIProgramaticallyEnabled: { value: boolean } = { value: false };
137137
if (relatedObjects) {
138138
const validOptions = [Constants.Apex, Constants.ExpSites, Constants.FlexiPage, Constants.LWC];
@@ -451,11 +451,13 @@ export default class Migrate extends OmniStudioBaseCommand {
451451
let errors: any[] = obj.errors || [];
452452
errors = errors.concat(recordResults.errors || []);
453453

454-
obj.status = recordResults?.skipped
455-
? messages.getMessage('labelStatusSkipped')
456-
: !recordResults || recordResults.hasErrors
457-
? messages.getMessage('labelStatusFailed')
458-
: messages.getMessage('labelStatusComplete');
454+
if (recordResults?.skipped) {
455+
obj.status = messages.getMessage('labelStatusSkipped');
456+
} else if (!recordResults || recordResults.hasErrors) {
457+
obj.status = messages.getMessage('labelStatusFailed');
458+
} else {
459+
obj.status = messages.getMessage('labelStatusComplete');
460+
}
459461
obj.errors = errors;
460462
obj.migratedId = recordResults.id;
461463
obj.warnings = recordResults.warnings;

src/migration/flexcard.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
113113
const flexCards = await this.getAllActiveCards();
114114
Logger.log(this.messages.getMessage('foundFlexCardsToAssess', [flexCards.length]));
115115

116-
const flexCardsAssessmentInfos = this.processCardComponents(flexCards);
116+
const flexCardsAssessmentInfos = await this.processCardComponents(flexCards);
117+
this.prepareAssessmentStorageForFlexcards(flexCardsAssessmentInfos);
117118
return flexCardsAssessmentInfos;
118119
} catch (err) {
119120
if (err instanceof InvalidEntityTypeError) {
@@ -135,9 +136,6 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
135136
try {
136137
const flexCardAssessmentInfo = await this.processFlexCard(flexCard, uniqueNames);
137138
flexCardAssessmentInfos.push(flexCardAssessmentInfo);
138-
139-
// Prepare assessment storage for flexcards
140-
this.prepareAssessmentStorageForFlexcards(flexCardAssessmentInfos);
141139
} catch (e) {
142140
flexCardAssessmentInfos.push({
143141
name: flexCard['Name'],
@@ -638,7 +636,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
638636
flexCardAssessmentInfo.nameMapping === undefined ||
639637
flexCardAssessmentInfo.nameMapping === null
640638
) {
641-
Logger.logVerbose(this.messages.getMessage('missingInfo'));
639+
Logger.error(this.messages.getMessage('missingInfo'));
642640
return;
643641
}
644642

@@ -647,8 +645,8 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
647645
isDuplicate: false,
648646
};
649647

650-
if (flexCardAssessmentInfo.warnings) {
651-
value.error = flexCardAssessmentInfo.warnings;
648+
if (flexCardAssessmentInfo.errors && flexCardAssessmentInfo.errors.length > 0) {
649+
value.error = flexCardAssessmentInfo.errors;
652650
value.migrationSuccess = false;
653651
} else {
654652
value.migrationSuccess = true;
@@ -668,9 +666,8 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
668666
Logger.logVerbose(this.messages.getMessage('errorWhileProcessingFlexcardStorage'));
669667
Logger.error(error);
670668
}
671-
672-
StorageUtil.printMigrationStorage();
673669
}
670+
StorageUtil.printAssessmentStorage();
674671
}
675672

676673
private prepareStorageForFlexcards(
@@ -692,13 +689,13 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
692689

693690
if (newrecord === undefined) {
694691
value.error = ['Migration Failed'];
695-
}
696-
697-
if (newrecord.hasErrors) {
698-
value.error = newrecord.errors;
699-
value.migrationSuccess = false;
700692
} else {
701-
value.migrationSuccess = true;
693+
if (newrecord.hasErrors) {
694+
value.error = newrecord.errors;
695+
value.migrationSuccess = false;
696+
} else {
697+
value.migrationSuccess = true;
698+
}
702699
}
703700

704701
let finalKey = `${oldrecord['Name']}`;

src/migration/omniscript.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
537537

538538
private updateStorageForOmniscriptAssessment(osAssessmentInfo: OSAssessmentInfo[]): void {
539539
if (osAssessmentInfo === undefined || osAssessmentInfo === null) {
540+
Logger.error(this.messages.getMessage('missingInfo'));
540541
return;
541542
}
542543

@@ -559,7 +560,7 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
559560
isDuplicate: false,
560561
};
561562

562-
if (Array.isArray(currentOsRecordInfo.errors) && currentOsRecordInfo.errors.length > 0) {
563+
if (currentOsRecordInfo.errors && currentOsRecordInfo.errors.length > 0) {
563564
value.error = currentOsRecordInfo.errors;
564565
value.migrationSuccess = false;
565566
} else {
@@ -579,7 +580,7 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
579580
storage.osStorage.set(finalKey, value);
580581
}
581582
} catch (error) {
582-
Logger.logVerbose(error);
583+
Logger.error(error);
583584
}
584585
}
585586

@@ -905,11 +906,16 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
905906
isDuplicate: false,
906907
};
907908

908-
if (newrecord.hasErrors) {
909-
value.error = newrecord.errors;
909+
// New record can be undefined
910+
if (newrecord === undefined) {
910911
value.migrationSuccess = false;
911912
} else {
912-
value.migrationSuccess = true;
913+
if (newrecord.hasErrors) {
914+
value.error = newrecord.errors;
915+
value.migrationSuccess = false;
916+
} else {
917+
value.migrationSuccess = true;
918+
}
913919
}
914920

915921
let finalKey = `${oldrecord[this.namespacePrefix + 'Type__c']}${

src/migration/premigrate.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
1-
/* eslint-disable */
2-
3-
import { Connection, Messages, Org } from '@salesforce/core';
1+
import { Connection, Messages } from '@salesforce/core';
42
import { UX } from '@salesforce/command';
53
import { Logger } from '../utils/logger';
64
import { Constants } from '../utils/constants/stringContants';
75
import { OrgPreferences } from '../utils/orgPreferences';
8-
import { BaseMigrationTool } from './base';
96
import { askStringWithTimeout } from '../utils/promptUtil';
7+
import { YES_SHORT, YES_LONG, NO_SHORT, NO_LONG } from '../utils/projectPathUtil';
8+
import { BaseMigrationTool } from './base';
109

1110
export class PreMigrate extends BaseMigrationTool {
12-
private readonly org: Org;
13-
1411
// Source Custom Object Names
15-
constructor(org: Org, namespace: string, connection: Connection, logger: Logger, messages: Messages, ux: UX) {
12+
public constructor(namespace: string, connection: Connection, logger: Logger, messages: Messages, ux: UX) {
1613
super(namespace, connection, logger, messages, ux);
17-
this.org = org;
18-
}
19-
20-
// Just to disable org is unused error coming
21-
public printOrgDetails(): void {
22-
try {
23-
Logger.log(JSON.stringify(this.org));
24-
} catch (e) {
25-
Logger.log(e);
26-
}
2714
}
2815

2916
public async handleExperienceSitePrerequisites(
@@ -67,8 +54,9 @@ export class PreMigrate extends BaseMigrationTool {
6754
// This needs to be behind timeout
6855
private async getExpSiteMetadataEnableConsent(): Promise<boolean> {
6956
const question = this.messages.getMessage('consentForExperienceSites');
57+
const validResponse = false;
7058

71-
while (true) {
59+
while (!validResponse) {
7260
try {
7361
// Get string input from user with timeout
7462
const userInput = await askStringWithTimeout(
@@ -80,19 +68,18 @@ export class PreMigrate extends BaseMigrationTool {
8068
// Validate and convert the input
8169
const normalizedInput = userInput.trim().toLowerCase();
8270

83-
if (normalizedInput === 'y' || normalizedInput === 'yes') {
71+
if (normalizedInput === YES_SHORT || normalizedInput === YES_LONG) {
8472
return true;
85-
} else if (normalizedInput === 'n' || normalizedInput === 'no') {
73+
} else if (normalizedInput === NO_SHORT || normalizedInput === NO_LONG) {
8674
return false;
8775
} else {
8876
// Invalid input - show error and continue loop to re-prompt
8977
Logger.error(this.messages.getMessage('invalidYesNoResponse'));
90-
Logger.log('Please enter "y" or "yes" to consent, "n" or "no" to decline.');
9178
}
9279
} catch (error) {
9380
// Handle timeout or other errors
94-
Logger.error(this.messages.getMessage('failedToGetConsentError', [error.message]));
95-
throw error; // Re-throw to let caller handle timeout
81+
Logger.error(this.messages.getMessage('requestTimedOut'));
82+
process.exit(1);
9683
}
9784
}
9885
}

src/migration/related/ExperienceSiteMigration.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
9797
Logger.logVerbose(this.messages.getMessage('fileNotHavingWrapper'));
9898
}
9999
} catch (err) {
100+
this.populateExceptionInfo(file, experienceSitesAssessmentInfo);
100101
Logger.error(this.messages.getMessage('errorProcessingExperienceSite', [file.name]));
101102
Logger.error(JSON.stringify(err));
102103
}
@@ -168,6 +169,25 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
168169
return experienceSiteAssessmentInfo;
169170
}
170171

172+
private populateExceptionInfo(file: File, experienceSiteAssessmentInfos: ExperienceSiteAssessmentInfo[]): void {
173+
try {
174+
const experienceSiteAssessmentInfo: ExperienceSiteAssessmentInfo = {
175+
name: file.name,
176+
warnings: ['Unknown error occurred'],
177+
errors: [''],
178+
infos: [],
179+
path: file.location,
180+
diff: JSON.stringify([]),
181+
hasOmnistudioContent: false,
182+
status: 'Errors',
183+
};
184+
185+
experienceSiteAssessmentInfos.push(experienceSiteAssessmentInfo);
186+
} catch {
187+
Logger.error(this.messages.getMessage('experienceSiteException'));
188+
}
189+
}
190+
171191
private processRegion(
172192
region: ExpSiteRegion,
173193
experienceSiteAssessmentInfo: ExperienceSiteAssessmentInfo,
@@ -259,16 +279,22 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
259279
): void {
260280
Logger.logVerbose(this.messages.getMessage('processingFlexcardComponent', [JSON.stringify(component)]));
261281
const flexcardName = targetName.substring(2); // cfCardName -> CardName
262-
const targetDataFromStorageFC: FlexcardStorage = storage.fcStorage.get(flexcardName);
282+
const targetDataFromStorageFC: FlexcardStorage = storage.fcStorage.get(flexcardName.toLowerCase());
263283

264284
Logger.logVerbose(this.messages.getMessage('targetData', [JSON.stringify(targetDataFromStorageFC)]));
265285

266286
// Remove later
267287
if (this.shouldAddWarning(targetDataFromStorageFC)) {
268288
const warningMsg: string = this.getWarningMessage(flexcardName, targetDataFromStorageFC);
269289
experienceSiteAssessmentInfo.warnings.push(warningMsg);
290+
experienceSiteAssessmentInfo.status = 'Errors';
270291
} else {
271292
component.componentName = TARGET_COMPONENT_NAME_FC;
293+
294+
const keysToDelete = ['target', 'layout', 'params', 'standalone'];
295+
296+
keysToDelete.forEach((key) => delete currentAttribute[key]);
297+
272298
currentAttribute['flexcardName'] = targetDataFromStorageFC.name;
273299
currentAttribute['objectApiName'] = '{!objectApiName}';
274300
currentAttribute['recordId'] = '{!recordId}';
@@ -285,7 +311,6 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
285311
Logger.logVerbose(this.messages.getMessage('processingOmniscriptComponent', [JSON.stringify(component)]));
286312
// Use storage to find the updated properties
287313
const targetDataFromStorage: OmniScriptStorage = storage.osStorage.get(targetName.toLowerCase());
288-
StorageUtil.printAssessmentStorage();
289314
Logger.logVerbose(this.messages.getMessage('targetData', [JSON.stringify(targetDataFromStorage)]));
290315

291316
if (this.shouldAddWarning(targetDataFromStorage)) {
@@ -303,7 +328,7 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
303328
keysToDelete.forEach((key) => delete currentAttribute[key]);
304329

305330
currentAttribute['direction'] = 'ltr';
306-
currentAttribute['display'] = 'Display button to open Omniscript';
331+
currentAttribute['display'] = 'Display OmniScript on page';
307332
currentAttribute['inlineVariant'] = 'brand';
308333
currentAttribute['language'] =
309334
targetDataFromStorage.language === undefined ? 'English' : targetDataFromStorage.language;

src/utils/resultsbuilder/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class ResultsBuilder {
256256
},
257257
assessmentDate: new Date().toString(),
258258
total: result.length,
259-
filterGroups: [createFilterGroupParam('Filter by Status', 'status', ['Complete', 'Error'])],
259+
filterGroups: [createFilterGroupParam('Filter by Status', 'status', ['Complete', 'Failed'])],
260260
headerGroups: [
261261
{
262262
header: [
@@ -295,13 +295,13 @@ export class ResultsBuilder {
295295
createRowDataParam('path', item.path, false, 1, 1, false),
296296
createRowDataParam(
297297
'status',
298-
item.warnings ? 'Error' : 'Complete', // This is the value which the status key takes
298+
item.warnings && item.warnings.length > 0 ? 'Failed' : 'Complete',
299299
false,
300300
1,
301301
1,
302302
false,
303303
undefined,
304-
item.warnings ? 'Error' : 'Complete' // This is what gets displayed
304+
item.warnings && item.warnings.length > 0 ? 'Failed' : 'Complete'
305305
),
306306
createRowDataParam(
307307
'diff',
@@ -311,17 +311,18 @@ export class ResultsBuilder {
311311
1,
312312
false,
313313
undefined,
314-
FileDiffUtil.getDiffHTML(item.diff, item.name)
314+
FileDiffUtil.getDiffHTML(item.diff, this.rowId.toString())
315315
),
316316
createRowDataParam(
317317
'errors',
318-
item.warnings ? 'Error' : 'Complete',
318+
item.warnings && item.warnings.length > 0 ? 'Failed' : 'Complete',
319319
false,
320320
1,
321321
1,
322322
false,
323323
undefined,
324-
item.warnings
324+
item.warnings,
325+
item.warnings ? 'text-error' : 'text-success'
325326
),
326327
],
327328
})),

test/migration/related/ExperienceSiteMigration.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ describe('ExperienceSiteMigration', () => {
203203
const result = experienceSiteMigration.processExperienceSites('/test/project', Migrate);
204204

205205
// Assert
206-
expect(result).to.be.an('array').that.is.empty;
206+
expect(result).to.be.an('array').that.has.length(1);
207+
expect(result[0].name).to.equal('error.json');
208+
expect(result[0].status).to.equal('Errors');
209+
expect(result[0].errors).to.include('Unknown error occurred');
210+
expect(result[0].hasOmnistudioContent).to.be.false;
207211
expect((Logger.error as sinon.SinonStub).called).to.be.true;
208212
});
209213
});
@@ -269,7 +273,7 @@ describe('ExperienceSiteMigration', () => {
269273
expect(component.componentAttributes.subType).to.equal('TestSubtype');
270274
expect(component.componentAttributes.language).to.equal('English');
271275
expect(component.componentAttributes.direction).to.equal('ltr');
272-
expect(component.componentAttributes.display).to.equal('Display button to open Omniscript');
276+
expect(component.componentAttributes.display).to.equal('Display OmniScript on page');
273277
expect(component.componentAttributes.theme).to.equal('lightning'); // Preserved from original layout
274278
});
275279

0 commit comments

Comments
 (0)