Skip to content

Commit 1e2e422

Browse files
authored
Merge pull request #344 from snehaljha-sf/mvp_bug_fixes
fix: more mvp issues
2 parents 6ce7a79 + dd0cd30 commit 1e2e422

File tree

16 files changed

+201
-52
lines changed

16 files changed

+201
-52
lines changed

messages/migrate.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,7 @@
112112
"manuallySwitchDesignerToStandardDataModel": "To complete the setup, please manually run the required Apex code to configure OmniStudio Designers to use the Standard Data Model <br> https://help.salesforce.com/s/articleView?id=xcloud.os_migrate_change_the_sobject_data_model_after_migration.htm&type=5",
113113
"labelStatusSkipped": "Skipped",
114114
"labelStatusFailed": "Failed",
115-
"labelStatusComplete": "Complete"
115+
"labelStatusComplete": "Complete",
116+
"migrationConsentNotGiven": "Couldn't confirm whether assessment errors are resolved",
117+
"migrationConsentMessage": "Ensure that all items in the assessment report are marked as Green before proceeding with the migration. Do you want to proceed?"
116118
}

src/commands/omnistudio/migration/assess.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ export default class Assess extends OmniStudioBaseCommand {
112112
Logger.logVerbose(messages.getMessage('assessmentTargets', [String(this.flags.only || 'all')]));
113113
Logger.logVerbose(messages.getMessage('relatedObjectsInfo', [relatedObjects || 'none']));
114114
Logger.logVerbose(messages.getMessage('allVersionsFlagInfo', [String(allVersions)]));
115-
// Assess OmniStudio components
116-
await this.assessOmniStudioComponents(assesmentInfo, assessOnly, namespace, conn, allVersions);
115+
116+
try {
117+
// Assess OmniStudio components
118+
await this.assessOmniStudioComponents(assesmentInfo, assessOnly, namespace, conn, allVersions);
119+
} catch (error) {
120+
Logger.error(`Cannot assess OmniStudio components within ${namespace}`);
121+
process.exit(1);
122+
}
117123

118124
let objectsToProcess: string[];
119125
// Assess related objects if specified

src/commands/omnistudio/migration/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class Org extends SfdxCommand {
8989

9090
let outputString = '';
9191
if (trialExpirationDate) {
92-
const date = new Date(trialExpirationDate).toDateString();
92+
const date = new Date(trialExpirationDate).toLocaleString();
9393
outputString = messages.getMessage('greetingOrgInfoWithDate', [name, orgName, date]);
9494
} else {
9595
outputString = messages.getMessage('greetingOrgInfo', [name, orgName]);

src/commands/omnistudio/migration/migrate.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ExecuteAnonymousResult } from 'jsforce';
1414
import OmniStudioBaseCommand from '../../basecommand';
1515
import { DataRaptorMigrationTool } from '../../../migration/dataraptor';
1616
import { DebugTimer, MigratedObject, MigratedRecordInfo } from '../../../utils';
17-
import { MigrationResult, MigrationTool } from '../../../migration/interfaces';
17+
import { InvalidEntityTypeError, MigrationResult, MigrationTool } from '../../../migration/interfaces';
1818
import { ResultsBuilder } from '../../../utils/resultsbuilder';
1919
import { CardMigrationTool } from '../../../migration/flexcard';
2020
import { OmniScriptExportType, OmniScriptMigrationTool } from '../../../migration/omniscript';
@@ -26,6 +26,8 @@ import { Constants } from '../../../utils/constants/stringContants';
2626
import { OrgPreferences } from '../../../utils/orgPreferences';
2727
import { AnonymousApexRunner } from '../../../utils/apex/executor/AnonymousApexRunner';
2828
import { ProjectPathUtil } from '../../../utils/projectPathUtil';
29+
import { PromptUtil } from '../../../utils/promptUtil';
30+
import { YES_SHORT, YES_LONG, NO_SHORT, NO_LONG } from '../../../utils/projectPathUtil';
2931

3032
// Initialize Messages with the current plugin directory
3133
Messages.importMessagesDirectory(__dirname);
@@ -117,6 +119,13 @@ export default class Migrate extends OmniStudioBaseCommand {
117119
Logger.log(`Could not enable Omni preferences: ${errMsg}`);
118120
}
119121

122+
// check for confirmation over assessed action items
123+
const migrationConsent = await this.getMigrationConsent();
124+
if (!migrationConsent) {
125+
Logger.log(messages.getMessage('migrationConsentNotGiven'));
126+
return;
127+
}
128+
120129
const namespace = orgs.packageDetails.namespace;
121130
// Let's time every step
122131
DebugTimer.getInstance().start();
@@ -178,7 +187,9 @@ export default class Migrate extends OmniStudioBaseCommand {
178187
);
179188

180189
let actionItems = [];
181-
actionItems = await this.setDesignersToUseStandardDataModel(namespace);
190+
if (!migrateOnly) {
191+
actionItems = await this.setDesignersToUseStandardDataModel(namespace);
192+
}
182193

183194
await ResultsBuilder.generateReport(
184195
objectMigrationResults,
@@ -194,6 +205,34 @@ export default class Migrate extends OmniStudioBaseCommand {
194205
return { objectMigrationResults };
195206
}
196207

208+
private async getMigrationConsent(): Promise<boolean> {
209+
const askWithTimeOut = PromptUtil.askWithTimeOut(messages);
210+
let validResponse = false;
211+
let consent = false;
212+
213+
while (!validResponse) {
214+
try {
215+
const resp = await askWithTimeOut(Logger.prompt.bind(Logger), messages.getMessage('migrationConsentMessage'));
216+
const response = typeof resp === 'string' ? resp.trim().toLowerCase() : '';
217+
218+
if (response === YES_SHORT || response === YES_LONG) {
219+
consent = true;
220+
validResponse = true;
221+
} else if (response === NO_SHORT || response === NO_LONG) {
222+
consent = false;
223+
validResponse = true;
224+
} else {
225+
Logger.error(messages.getMessage('invalidYesNoResponse'));
226+
}
227+
} catch (err) {
228+
Logger.error(messages.getMessage('requestTimedOut'));
229+
process.exit(1);
230+
}
231+
}
232+
233+
return consent;
234+
}
235+
197236
private async setDesignersToUseStandardDataModel(namespace: string): Promise<string[]> {
198237
const userActionMessage: string[] = [];
199238
try {
@@ -252,6 +291,10 @@ export default class Migrate extends OmniStudioBaseCommand {
252291
})
253292
);
254293
} catch (ex: any) {
294+
if (ex instanceof InvalidEntityTypeError) {
295+
Logger.error(ex.message);
296+
process.exit(1);
297+
}
255298
Logger.error('Error migrating object', ex);
256299
objectMigrationResults.push({
257300
name: cls.getName(),
@@ -370,10 +413,11 @@ export default class Migrate extends OmniStudioBaseCommand {
370413
let errors: any[] = obj.errors || [];
371414
errors = errors.concat(recordResults.errors || []);
372415

373-
obj.status =
374-
!recordResults || recordResults.hasErrors
375-
? messages.getMessage('labelStatusFailed')
376-
: messages.getMessage('labelStatusComplete');
416+
obj.status = recordResults?.skipped
417+
? messages.getMessage('labelStatusSkipped')
418+
: !recordResults || recordResults.hasErrors
419+
? messages.getMessage('labelStatusFailed')
420+
: messages.getMessage('labelStatusComplete');
377421
obj.errors = errors;
378422
obj.migratedId = recordResults.id;
379423
obj.warnings = recordResults.warnings;

src/migration/dataraptor.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import DRMapItemMappings from '../mappings/DRMapItem';
55
import { DebugTimer, oldNew, QueryTools } from '../utils';
66
import { NetUtils } from '../utils/net';
77
import { BaseMigrationTool } from './base';
8-
import { MigrationResult, MigrationTool, ObjectMapping, TransformData, UploadRecordResult } from './interfaces';
8+
import {
9+
InvalidEntityTypeError,
10+
MigrationResult,
11+
MigrationTool,
12+
ObjectMapping,
13+
TransformData,
14+
UploadRecordResult,
15+
} from './interfaces';
916
import { DataRaptorAssessmentInfo } from '../../src/utils';
1017

1118
import {
@@ -215,6 +222,9 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
215222
const dataRaptorAssessmentInfos = this.processDRComponents(dataRaptors);
216223
return dataRaptorAssessmentInfos;
217224
} catch (err) {
225+
if (err instanceof InvalidEntityTypeError) {
226+
throw err;
227+
}
218228
Logger.error('Error assessing data mapper', err);
219229
}
220230
}
@@ -349,7 +359,14 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
349359
this.namespace,
350360
DataRaptorMigrationTool.DRBUNDLE_NAME,
351361
this.getDRBundleFields()
352-
);
362+
).catch((err) => {
363+
if (err.errorCode === 'INVALID_TYPE') {
364+
throw new InvalidEntityTypeError(
365+
`${DataRaptorMigrationTool.DRBUNDLE_NAME} type is not found under this namespace`
366+
);
367+
}
368+
throw err;
369+
});
353370
}
354371

355372
// Get All Items
@@ -360,7 +377,10 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
360377
this.namespace,
361378
DataRaptorMigrationTool.DRMAPITEM_NAME,
362379
this.getDRMapItemFields()
363-
);
380+
).catch((err) => {
381+
Logger.error('Error querying data raptor items', err);
382+
return [];
383+
});
364384
}
365385

366386
/*

src/migration/flexcard.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import CardMappings from '../mappings/VlocityCard';
44
import { DebugTimer, QueryTools, SortDirection } from '../utils';
55
import { NetUtils } from '../utils/net';
66
import { BaseMigrationTool } from './base';
7-
import { MigrationResult, MigrationTool, ObjectMapping, UploadRecordResult } from './interfaces';
7+
import {
8+
InvalidEntityTypeError,
9+
MigrationResult,
10+
MigrationTool,
11+
ObjectMapping,
12+
UploadRecordResult,
13+
} from './interfaces';
814
import { Connection, Messages } from '@salesforce/core';
915
import { UX } from '@salesforce/command';
1016
import { FlexCardAssessmentInfo } from '../../src/utils';
@@ -15,6 +21,7 @@ import { Constants } from '../utils/constants/stringContants';
1521
export class CardMigrationTool extends BaseMigrationTool implements MigrationTool {
1622
static readonly VLOCITYCARD_NAME = 'VlocityCard__c';
1723
static readonly OMNIUICARD_NAME = 'OmniUiCard';
24+
static readonly VERSION_PROP = 'Version__c';
1825
private readonly allVersions: boolean;
1926

2027
constructor(
@@ -34,7 +41,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
3441
}
3542

3643
getRecordName(record: string) {
37-
return record['Name'];
44+
return this.allVersions
45+
? `${record['Name']}_${record[this.namespacePrefix + CardMigrationTool.VERSION_PROP]}`
46+
: record['Name'];
3847
}
3948

4049
getMappings(): ObjectMapping[] {
@@ -104,6 +113,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
104113
const flexCardsAssessmentInfos = this.processCardComponents(flexCards);
105114
return flexCardsAssessmentInfos;
106115
} catch (err) {
116+
if (err instanceof InvalidEntityTypeError) {
117+
throw err;
118+
}
107119
Logger.error(this.messages.getMessage('errorDuringFlexCardAssessment'), err);
108120
}
109121
}
@@ -148,9 +160,10 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
148160
private async processFlexCard(flexCard: AnyJson, uniqueNames: Set<string>): Promise<FlexCardAssessmentInfo> {
149161
const flexCardName = flexCard['Name'];
150162
Logger.info(this.messages.getMessage('processingFlexCard', [flexCardName]));
163+
const version = flexCard[this.namespacePrefix + CardMigrationTool.VERSION_PROP];
151164
const flexCardAssessmentInfo: FlexCardAssessmentInfo = {
152-
name: flexCardName,
153-
oldName: flexCardName,
165+
name: this.allVersions ? `${flexCardName}_${version}` : flexCardName,
166+
oldName: this.allVersions ? `${flexCardName}_${version}` : flexCardName,
154167
id: flexCard['Id'],
155168
dependenciesIP: [],
156169
dependenciesDR: [],
@@ -168,7 +181,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
168181
const originalName: string = flexCardName;
169182
const cleanedName: string = this.cleanName(originalName);
170183
let assessmentStatus = 'Can be Automated';
171-
flexCardAssessmentInfo.name = cleanedName;
184+
flexCardAssessmentInfo.name = this.allVersions ? `${cleanedName}_${version}` : cleanedName;
172185
if (cleanedName !== originalName) {
173186
flexCardAssessmentInfo.warnings.push(
174187
this.messages.getMessage('cardNameChangeMessage', [originalName, cleanedName])
@@ -431,7 +444,14 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
431444
this.getCardFields(),
432445
filters,
433446
sortFields
434-
);
447+
).catch((err) => {
448+
if (err.errorCode === 'INVALID_TYPE') {
449+
throw new InvalidEntityTypeError(
450+
`${CardMigrationTool.VLOCITYCARD_NAME} type is not found under this namespace`
451+
);
452+
}
453+
throw err;
454+
});
435455
} else {
436456
filters.set(this.namespacePrefix + 'Active__c', true);
437457
return await QueryTools.queryWithFilter(
@@ -440,7 +460,14 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
440460
CardMigrationTool.VLOCITYCARD_NAME,
441461
this.getCardFields(),
442462
filters
443-
);
463+
).catch((err) => {
464+
if (err.errorCode === 'INVALID_TYPE') {
465+
throw new InvalidEntityTypeError(
466+
`${CardMigrationTool.VLOCITYCARD_NAME} type is not found under this namespace`
467+
);
468+
}
469+
throw err;
470+
});
444471
}
445472
}
446473

@@ -506,14 +533,14 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
506533
}
507534
const transformedCardAuthorName = transformedCard['AuthorName'];
508535

509-
if (uniqueNames.has(transformedCardName)) {
536+
if (uniqueNames.has(transformedCard['Name'])) {
510537
this.setRecordErrors(card, this.messages.getMessage('duplicatedCardName'));
511538
originalRecords.set(recordId, card);
512539
return;
513540
}
514541

515542
// Save the name for duplicated names check
516-
uniqueNames.add(transformedCardName);
543+
uniqueNames.add(transformedCard['Name']);
517544

518545
// Create a map of the original records
519546
originalRecords.set(recordId, card);
@@ -540,7 +567,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
540567
this.messages.getMessage('cardAuthorNameChangeMessage', [transformedCardAuthorName])
541568
);
542569
}
543-
if (transformedCardName !== card['Name']) {
570+
if (transformedCard['Name'] !== card['Name']) {
544571
uploadResult.newName = transformedCardName;
545572
uploadResult.warnings.unshift(this.messages.getMessage('cardNameChangeMessage', [transformedCardName]));
546573
}

src/migration/interfaces.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface UploadRecordResult {
4343
warnings: string[];
4444
hasErrors: boolean;
4545
success?: boolean;
46+
skipped?: boolean;
4647
}
4748

4849
export interface MigrationResult {
@@ -91,3 +92,9 @@ export interface RelatedObjectMigrationResult {
9192
apexClasses: string[];
9293
lwcComponents: string[];
9394
}
95+
96+
export class InvalidEntityTypeError extends Error {
97+
public constructor(message: string) {
98+
super(message);
99+
}
100+
}

0 commit comments

Comments
 (0)