Skip to content

Commit 9d7ff51

Browse files
authored
Merge pull request #395 from sf-kishore-kurri/u/kkurri/W-19081579
feat: @W-19081579: Omnistudio License validation and additional fixes
2 parents c0cce8b + b592850 commit 9d7ff51

File tree

7 files changed

+631
-22
lines changed

7 files changed

+631
-22
lines changed

messages/assess.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
"angularOSWarning": " Angular Omniscript will not be migrated, please convert this to LWC based Omniscript",
3434
"relatedObjectGA": "Please select the type of component to assess: 'apex' for Apex classes, 'lwc' for Lightning Web Components, 'flexipage' for FlexiPages, or 'apex,lwc,flexipage' if you want to include all types.",
3535
"apexLwc": "Please select the type of component to assess: 'apex' for Apex classes.",
36-
"invalidNamespace": "The namespace you have passed is not valid namespace, the valid namespace of your org is ",
36+
"unknownNamespace": "Org doesn't have Omnistudio namespace(s) configured",
3737
"noPackageInstalled": "No package installed on given org.",
3838
"alreadyStandardModel": "The org is already on standard data model.",
39+
"noOmniStudioLicenses": "OmniStudio licenses are not found in the org. OmniStudio licenses are required for migration assessment",
3940
"invalidRelatedObjectsOption": "Invalid option provided for -r: %s. Valid options are apex, lwc, expsites, flexipage.",
4041
"formulaSyntaxError": "There was some problem while updating the formula syntax, please check the all the formula's syntax once : %s",
4142
"errorDuringFlexCardAssessment": "Error during FlexCard assessment",

messages/migrate.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
"allVersionsDescription": "Migrate all versions of a component",
3434
"relatedObjectGA": "Please select the type of components to migrate: 'apex' for Apex classes, 'lwc' for Lightning Web Components, 'flexipage' for FlexiPages, 'expsites' for Experience Sites, or 'apex,lwc,flexipage,expsites' if you want to include all types.",
3535
"apexLwc": "Please select the type of components to migrate: 'apex' for Apex classes.",
36-
"invalidNamespace": "The namespace you have passed is not valid namespace, the valid namespace of your org is ",
36+
"unknownNamespace": "Org doesn't have Omnistudio namespace(s) configured",
3737
"noPackageInstalled": "No package installed on given org.",
3838
"alreadyStandardModel": "The org is already on standard data model.",
39+
"noOmniStudioLicenses": "OmniStudio licenses are not found in the org. OmniStudio licenses are required for migration",
3940
"invalidRelatedObjectsOption": "Invalid option provided for -r: %s. Valid options are apex, lwc, expsites, flexipage.",
4041
"userConsentMessage": "By proceeding further, you hereby consent to the use, accept changes to your custom code and the accompanying terms and conditions associated with the use of the OmniStudio Migration Tool. Do you want to proceed? [y/n]",
4142
"userDeclinedConsent": "User declined consent, will not process %s .",
@@ -132,15 +133,15 @@
132133
"flexipagesWithChanges": "Found %s FlexiPages with changes",
133134
"omniGlobalAutoNumberPrefEnabled": "Successfully enabled OmniGlobalAutoNumberPref org preference",
134135
"errorEnablingOmniGlobalAutoNumberPref": "We couldn't enable the Omni Global Auto Number setting. Turn on the Omni Global Auto Number setting manually, and try again. See <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Set Up Omni Global Auto Number</a>.",
135-
"performingPreMigrationChecks": "Performing pre-migration checks for Omni Global Auto Number...",
136+
"performingPreMigrationChecks": "Performing pre-migration checks for Omni Global Auto Number",
136137
"preMigrationChecksPassed": "Pre-migration checks passed. Proceeding with Omni Global Auto Number migration.",
137138
"preMigrationChecksFailed": "Pre-migration checks failed. Migration cannot proceed.",
138139
"globalAutoNumberPrefEnabledError": "The Omni Global Auto Number setting is enabled and global auto numbers have already been migrated.",
139140
"bothRollbackFlagsEnabledError": "We couldn't turn on Omni Global Auto Number. Disable the RollBackDRChanges and RollBackIPChanges <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Omni Interaction Configurations</a>, and try again.",
140141
"rollbackIPFlagEnabledError": "We couldn't turn on Omni Global Auto Number. Disable the RollBackIPChanges <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Omni Interaction Configurations</a> and try again.",
141142
"rollbackDRFlagEnabledError": "We couldn't turn on Omni Global Auto Number. Disable the RollBackDRChanges <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Omni Interaction Configurations</a> and try again.",
142143
"errorCheckingRollbackFlags": "Error checking rollback flags status.",
143-
"startingPostMigrationCleanup": "Starting post-migration cleanup for Omni Global Auto Number...",
144+
"startingPostMigrationCleanup": "Starting post-migration cleanup for Omni Global Auto Number",
144145
"postMigrationCleanupCompleted": "Post-migration cleanup completed successfully.",
145146
"errorDuringPostMigrationCleanup": "We’ve encountered an error during the post-migration cleanup. Try again later.",
146147
"duplicatedGlobalAutoNumberName": "Duplicated Omni Global Auto Number name",

src/commands/omnistudio/migration/assess.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ProjectPathUtil } from '../../../utils/projectPathUtil';
2020
import { PreMigrate } from '../../../migration/premigrate';
2121
import { PostMigrate } from '../../../migration/postMigrate';
2222
import { CustomLabelsUtil } from '../../../utils/customLabels';
23+
import { ValidatorService } from '../../../utils/validatorService';
2324

2425
Messages.importMessagesDirectory(__dirname);
2526
const messages = Messages.loadMessages('@salesforce/plugin-omnistudio-migration-tool', 'assess');
@@ -78,16 +79,11 @@ export default class Assess extends OmniStudioBaseCommand {
7879
const apiVersion = conn.getApiVersion();
7980
const orgs: OmnistudioOrgDetails = await OrgUtils.getOrgDetails(conn);
8081

81-
if (!orgs.hasValidNamespace) {
82-
Logger.warn(messages.getMessage('invalidNamespace') + orgs.packageDetails.namespace);
83-
}
82+
// Perform comprehensive validation using ValidatorService
83+
const validator = new ValidatorService(orgs, conn, messages);
84+
const isValidationPassed = await validator.validate();
8485

85-
if (!orgs.packageDetails) {
86-
Logger.error(messages.getMessage('noPackageInstalled'));
87-
return;
88-
}
89-
if (orgs.omniStudioOrgPermissionEnabled) {
90-
Logger.error(messages.getMessage('alreadyStandardModel'));
86+
if (!isValidationPassed) {
9187
return;
9288
}
9389

src/commands/omnistudio/migration/migrate.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ 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 { ValidatorService } from '../../../utils/validatorService';
3435
import { NameMappingRegistry } from '../../../migration/NameMappingRegistry';
3536

3637
// Initialize Messages with the current plugin directory
@@ -91,16 +92,11 @@ export default class Migrate extends OmniStudioBaseCommand {
9192

9293
const orgs: OmnistudioOrgDetails = await OrgUtils.getOrgDetails(conn);
9394

94-
if (!orgs.hasValidNamespace) {
95-
Logger.warn(messages.getMessage('invalidNamespace') + orgs.packageDetails.namespace);
96-
}
95+
// Perform comprehensive validation using ValidatorService
96+
const validator = new ValidatorService(orgs, conn, messages);
97+
const isValidationPassed = await validator.validate();
9798

98-
if (!orgs.packageDetails) {
99-
Logger.error(messages.getMessage('noPackageInstalled'));
100-
return;
101-
}
102-
if (orgs.omniStudioOrgPermissionEnabled) {
103-
Logger.error(messages.getMessage('alreadyStandardModel'));
99+
if (!isValidationPassed) {
104100
return;
105101
}
106102

src/utils/orgUtils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,15 @@ export class OrgUtils {
350350
const pkg = installedOmniPackages[0];
351351
packageDetails.version = `${pkg.MajorVersion}.${pkg.MinorVersion}`;
352352
packageDetails.namespace = pkg.NamespacePrefix;
353+
} else {
354+
// return to validate the org information
355+
return {
356+
packageDetails: undefined,
357+
omniStudioOrgPermissionEnabled: false,
358+
orgDetails: orgDetails[0],
359+
dataModel: undefined,
360+
hasValidNamespace: false,
361+
};
353362
}
354363

355364
//Execute apex rest resource to get omnistudio org permission

src/utils/validatorService.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Connection, Messages } from '@salesforce/core';
2+
import { Logger } from '../utils/logger';
3+
import { OmnistudioOrgDetails } from './orgUtils';
4+
5+
export class ValidatorService {
6+
private readonly connection: Connection;
7+
private readonly messages: Messages;
8+
private readonly orgs: OmnistudioOrgDetails;
9+
10+
public constructor(orgs: OmnistudioOrgDetails, connection: Connection, messages: Messages) {
11+
this.orgs = orgs;
12+
this.connection = connection;
13+
this.messages = messages;
14+
}
15+
16+
public async validate(): Promise<boolean> {
17+
return (
18+
this.validateNamespace() &&
19+
this.validatePackageInstalled() &&
20+
this.validateOmniStudioOrgPermissionEnabled() &&
21+
(await this.validateOmniStudioLicenses())
22+
);
23+
}
24+
25+
public validatePackageInstalled(): boolean {
26+
const { packageDetails } = this.orgs;
27+
if (!packageDetails) {
28+
Logger.error(this.messages.getMessage('noPackageInstalled'));
29+
return false;
30+
}
31+
return true;
32+
}
33+
34+
public validateOmniStudioOrgPermissionEnabled(): boolean {
35+
const { omniStudioOrgPermissionEnabled } = this.orgs;
36+
if (omniStudioOrgPermissionEnabled) {
37+
Logger.error(this.messages.getMessage('alreadyStandardModel'));
38+
return false;
39+
}
40+
return true;
41+
}
42+
43+
public validateNamespace(): boolean {
44+
const { hasValidNamespace } = this.orgs;
45+
if (!hasValidNamespace) {
46+
Logger.error(this.messages.getMessage('unknownNamespace'));
47+
return false;
48+
}
49+
return true;
50+
}
51+
52+
public async validateOmniStudioLicenses(): Promise<boolean> {
53+
try {
54+
const query =
55+
"SELECT count(DeveloperName) total FROM PermissionSetLicense WHERE PermissionSetLicenseKey LIKE 'OmniStudio%' AND Status = 'Active'";
56+
const result = await this.connection.query<{ total: string }>(query);
57+
58+
// Salesforce returns records as an array in result.records
59+
if (result?.records && result?.records?.length > 0) {
60+
// Since we only get one record with the total count, check if count > 0
61+
const totalCount = Number(result.records[0].total);
62+
if (totalCount > 0) {
63+
return true;
64+
}
65+
}
66+
67+
Logger.error(this.messages.getMessage('noOmniStudioLicenses'));
68+
return false;
69+
} catch (error) {
70+
if (error instanceof Error && error.message) {
71+
Logger.error(`Error validating OmniStudio licenses: ${error.message}`);
72+
} else {
73+
Logger.error('Error validating OmniStudio licenses: Unknown error');
74+
}
75+
return false;
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)