Skip to content

Commit d685a69

Browse files
authored
Merge pull request #347 from snehaljha-sf/mvp_alpha
Mvp alpha merge
2 parents 38d978d + bf45424 commit d685a69

24 files changed

+550
-176
lines changed

messages/migrate.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
"labelStatusSkipped": "Skipped",
118118
"labelStatusFailed": "Failed",
119119
"labelStatusComplete": "Complete",
120+
"migrationConsentNotGiven": "Couldn't confirm whether assessment errors are resolved",
121+
"migrationConsentMessage": "Ensure that all items in the assessment report are marked as Green before proceeding with the migration. Do you want to proceed?",
120122
"retrievingFlexiPages": "Retrieving FlexiPages",
121123
"successfullyRetrievedFlexiPages": "Successfully retrieved %s FlexiPages",
122124
"migratingFlexiPages": "Migrating FlexiPages",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"@types/shelljs": "^0.8.15",
1818
"jsdom": "^25.0.0",
1919
"lodash.chunk": "^4.2.0",
20+
"cli-progress": "^3.12.0",
21+
"diff": "^5.1.0",
2022
"open": "^8.4.2",
2123
"shelljs": "^0.8.5",
2224
"tslib": "^2",
@@ -38,8 +40,6 @@
3840
"@typescript-eslint/eslint-plugin": "^4.2.0",
3941
"@typescript-eslint/parser": "^4.2.0",
4042
"chai": "^4.4.1",
41-
"cli-progress": "^3.12.0",
42-
"diff": "^5.1.0",
4343
"eslint": "^7.27.0",
4444
"eslint-config-oclif": "^3.1",
4545
"eslint-config-prettier": "^8",

src/commands/omnistudio/migration/assess.ts

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

121127
let objectsToProcess: string[];
122128
// 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: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ import { Connection, Messages } from '@salesforce/core';
1313
import OmniStudioBaseCommand from '../../basecommand';
1414
import { DataRaptorMigrationTool } from '../../../migration/dataraptor';
1515
import { DebugTimer, MigratedObject, MigratedRecordInfo } from '../../../utils';
16-
import { MigrationResult, MigrationTool } from '../../../migration/interfaces';
16+
import { InvalidEntityTypeError, MigrationResult, MigrationTool } from '../../../migration/interfaces';
1717
import { ResultsBuilder } from '../../../utils/resultsbuilder';
1818
import { CardMigrationTool } from '../../../migration/flexcard';
1919
import { OmniScriptExportType, OmniScriptMigrationTool } from '../../../migration/omniscript';
20-
import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumber';
2120
import { Logger } from '../../../utils/logger';
2221
import OmnistudioRelatedObjectMigrationFacade from '../../../migration/related/OmnistudioRelatedObjectMigrationFacade';
2322
import { generatePackageXml } from '../../../utils/generatePackageXml';
2423
import { OmnistudioOrgDetails, OrgUtils } from '../../../utils/orgUtils';
2524
import { Constants } from '../../../utils/constants/stringContants';
2625
import { OrgPreferences } from '../../../utils/orgPreferences';
2726
import { ProjectPathUtil } from '../../../utils/projectPathUtil';
27+
import { PromptUtil } from '../../../utils/promptUtil';
28+
import { YES_SHORT, YES_LONG, NO_SHORT, NO_LONG } from '../../../utils/projectPathUtil';
2829
import { PostMigrate } from '../../../migration/postMigrate';
30+
import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumber';
2931

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

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

204-
actionItems = await postMigrate.setDesignersToUseStandardDataModel(namespace);
213+
if (!migrateOnly) {
214+
actionItems = await postMigrate.setDesignersToUseStandardDataModel(namespace);
215+
}
205216
await postMigrate.restoreExperienceAPIMetadataSettings(isExperienceBundleMetadataAPIProgramaticallyEnabled);
206217
const migrationActionItems = this.collectActionItems(objectMigrationResults);
207218
actionItems = [...actionItems, ...migrationActionItems];
@@ -212,13 +223,42 @@ export default class Migrate extends OmniStudioBaseCommand {
212223
conn.instanceUrl,
213224
orgs,
214225
messages,
215-
actionItems
226+
actionItems,
227+
objectsToProcess
216228
);
217229

218230
// Return results needed for --json flag
219231
return { objectMigrationResults };
220232
}
221233

234+
private async getMigrationConsent(): Promise<boolean> {
235+
const askWithTimeOut = PromptUtil.askWithTimeOut(messages);
236+
let validResponse = false;
237+
let consent = false;
238+
239+
while (!validResponse) {
240+
try {
241+
const resp = await askWithTimeOut(Logger.prompt.bind(Logger), messages.getMessage('migrationConsentMessage'));
242+
const response = typeof resp === 'string' ? resp.trim().toLowerCase() : '';
243+
244+
if (response === YES_SHORT || response === YES_LONG) {
245+
consent = true;
246+
validResponse = true;
247+
} else if (response === NO_SHORT || response === NO_LONG) {
248+
consent = false;
249+
validResponse = true;
250+
} else {
251+
Logger.error(messages.getMessage('invalidYesNoResponse'));
252+
}
253+
} catch (err) {
254+
Logger.error(messages.getMessage('requestTimedOut'));
255+
process.exit(1);
256+
}
257+
}
258+
259+
return consent;
260+
}
261+
222262
private async handleExperienceSitePrerequisites(
223263
objectsToProcess: string[],
224264
conn: Connection,
@@ -316,10 +356,14 @@ export default class Migrate extends OmniStudioBaseCommand {
316356
};
317357
})
318358
);
319-
} catch (error: any) {
320-
const errMsg = error instanceof Error ? error.message : String(error);
359+
} catch (ex: any) {
360+
if (ex instanceof InvalidEntityTypeError) {
361+
Logger.error(ex.message);
362+
process.exit(1);
363+
}
364+
const errMsg = ex instanceof Error ? ex.message : String(ex);
321365
Logger.error(messages.getMessage('errorMigrationMessage', [errMsg]));
322-
Logger.logVerbose(error);
366+
Logger.logVerbose(ex);
323367
objectMigrationResults.push({
324368
name: cls.getName(),
325369
data: [],
@@ -459,10 +503,11 @@ export default class Migrate extends OmniStudioBaseCommand {
459503
let errors: any[] = obj.errors || [];
460504
errors = errors.concat(recordResults.errors || []);
461505

462-
obj.status =
463-
!recordResults || recordResults.hasErrors
464-
? messages.getMessage('labelStatusFailed')
465-
: messages.getMessage('labelStatusComplete');
506+
obj.status = recordResults?.skipped
507+
? messages.getMessage('labelStatusSkipped')
508+
: !recordResults || recordResults.hasErrors
509+
? messages.getMessage('labelStatusFailed')
510+
: messages.getMessage('labelStatusComplete');
466511
obj.errors = errors;
467512
obj.migratedId = recordResults.id;
468513
obj.warnings = recordResults.warnings;

src/migration/dataraptor.ts

Lines changed: 31 additions & 4 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
}
@@ -253,8 +263,10 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
253263
type: dataRaptor[this.namespacePrefix + 'Type__c'] || '',
254264
formulaChanges: [],
255265
infos: [],
256-
warnings: [this.messages.getMessage('unexpectedError')],
266+
warnings: [],
267+
errors: [this.messages.getMessage('unexpectedError')],
257268
apexDependencies: [],
269+
migrationStatus: 'Failed',
258270
});
259271
const error = e as Error;
260272
Logger.error('Error processing data mapper', error);
@@ -276,6 +288,7 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
276288
Logger.info(this.messages.getMessage('processingDataRaptor', [drName]));
277289
const warnings: string[] = [];
278290
const existingDRNameVal = new StringVal(drName, 'name');
291+
let assessmentStatus = 'Can be Automated';
279292

280293
if (!existingDRNameVal.isNameCleaned()) {
281294
warnings.push(
@@ -285,9 +298,11 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
285298
existingDRNameVal.cleanName(),
286299
])
287300
);
301+
assessmentStatus = 'Has Warnings';
288302
}
289303
if (existingDataRaptorNames.has(existingDRNameVal.cleanName())) {
290304
warnings.push(this.messages.getMessage('duplicatedName') + ' ' + existingDRNameVal.cleanName());
305+
assessmentStatus = 'Need Manual Intervention';
291306
} else {
292307
existingDataRaptorNames.add(existingDRNameVal.cleanName());
293308
}
@@ -330,6 +345,8 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
330345
infos: [],
331346
apexDependencies: apexDependencies,
332347
warnings: warnings,
348+
errors: [],
349+
migrationStatus: assessmentStatus,
333350
};
334351
return dataRaptorAssessmentInfo;
335352
}
@@ -342,7 +359,14 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
342359
this.namespace,
343360
DataRaptorMigrationTool.DRBUNDLE_NAME,
344361
this.getDRBundleFields()
345-
);
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+
});
346370
}
347371

348372
// Get All Items
@@ -353,7 +377,10 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
353377
this.namespace,
354378
DataRaptorMigrationTool.DRMAPITEM_NAME,
355379
this.getDRMapItemFields()
356-
);
380+
).catch((err) => {
381+
Logger.error('Error querying data raptor items', err);
382+
return [];
383+
});
357384
}
358385

359386
/*

0 commit comments

Comments
 (0)