Skip to content

Commit

Permalink
Merge pull request #258 from salesforcecli/u/abhinavkumar2/W-16279013
Browse files Browse the repository at this point in the history
@W-16279013@
  • Loading branch information
AbhinavKumar-sf authored Nov 6, 2024
2 parents b65aa81 + 07b4e66 commit fe061b0
Show file tree
Hide file tree
Showing 19 changed files with 576 additions and 307 deletions.
6 changes: 4 additions & 2 deletions messages/assess.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
"errorWhileActivatingCard": "Could not activate Card: ",
"errorWhileUploadingCard": "An error ocurred while uploading Card: ",
"errorWhileCreatingElements": "An error ocurred while saving OmniScript elements: ",
"allVersionsDescription": "Migrate all versions of a component"
}
"allVersionsDescription": "Migrate all versions of a component",
"changeMessage": " %s will be changed from %s to %s",
"angularOSWarning": " Angular OmniScript will not be migrated, please convert this to LWC based Omniscript"
}
2 changes: 1 addition & 1 deletion src/commands/omnistudio/migration/assess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Assess extends OmniStudioBaseCommand {
DebugTimer.getInstance().start();
const namespace = (this.flags.namespace || 'vlocity_ins') as string;
const apiVersion = (this.flags.apiversion || '55.0') as string;
const allVersions = true;
const allVersions = (this.flags.allversions || false) as boolean;
const conn = this.org.getConnection();
Logger.initialiseLogger(this.ux, this.logger);
const projectDirectory = OmnistudioRelatedObjectMigrationFacade.intializeProject();
Expand Down
7 changes: 6 additions & 1 deletion src/commands/omnistudio/migration/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CardMigrationTool } from '../../../migration/flexcard';
import { OmniScriptExportType, OmniScriptMigrationTool } from '../../../migration/omniscript';
import { Logger } from '../../../utils/logger';
import OmnistudioRelatedObjectMigrationFacade from '../../../migration/related/OmnistudioRelatedObjectMigrationFacade';
import { generatePackageXml } from '../../../utils/generatePackageXml';

// Initialize Messages with the current plugin directory
Messages.importMessagesDirectory(__dirname);
Expand Down Expand Up @@ -175,7 +176,11 @@ export default class Migrate extends OmniStudioBaseCommand {
allVersions,
this.org
);
omnistudioRelatedObjectsMigration.migrateAll(objectMigrationResults, []);
const relatedObjectMigrationResult = omnistudioRelatedObjectsMigration.migrateAll(objectMigrationResults, []);
generatePackageXml.createChangeList(
relatedObjectMigrationResult.apexClasses,
relatedObjectMigrationResult.lwcComponents
);
await ResultsBuilder.generate(objectMigrationResults, conn.instanceUrl);

// save timer to debug logger
Expand Down
4 changes: 2 additions & 2 deletions src/migration/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Connection, Logger, Messages } from '@salesforce/core';
import { DebugTimer, QueryTools } from '../utils';

import { NetUtils } from '../utils/net';
import { Stringutil } from '../utils/StringValue/stringutil';
import { TransformData, UploadRecordResult } from './interfaces';

export class BaseMigrationTool {
Expand Down Expand Up @@ -57,8 +58,7 @@ export class BaseMigrationTool {
}

protected cleanName(name: string, allowUnderscores = false): string {
if (!name) return '';
return allowUnderscores ? name.replace(/[^a-z0-9_]+/gi, '') : name.replace(/[^a-z0-9]+/gi, '');
return Stringutil.cleanName(name, allowUnderscores);
}

protected async truncate(objectName: string): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/migration/dataraptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
DebugTimer.getInstance().lap('Query data raptors');
const dataRaptors = await this.getAllDataRaptors();
const dataRaptorAssessmentInfos = this.processDRComponents(dataRaptors);
this.ux.log('dataRaptorAssessmentInfos');
this.ux.log(dataRaptorAssessmentInfos.toString());
/* this.ux.log('dataRaptorAssessmentInfos');
this.ux.log(dataRaptorAssessmentInfos.toString()); */
return dataRaptorAssessmentInfos;
} catch (err) {
this.ux.log(err);
Expand Down
9 changes: 8 additions & 1 deletion src/migration/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ export interface RelatedObjectsMigrate {
* @param namespace The namespace used to perform the migration.
* @param migrationCandidates List of candidates to migrate.
*/
migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): void;
migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): string[];

processObjectType(): string;
}

export type LWCComponentMigrationTool = MigrationTool;

export type CustomLabelMigrationTool = MigrationTool;

export interface RelatedObjectMigrationResult {
apexClasses: string[];
lwcComponents: string[];
}
128 changes: 97 additions & 31 deletions src/migration/omniscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { AnyJson } from '@salesforce/ts-types';
import OmniScriptMappings from '../mappings/OmniScript';
import ElementMappings from '../mappings/Element';
import OmniScriptDefinitionMappings from '../mappings/OmniScriptDefinition';
import { DataRaptorAssessmentInfo, DebugTimer, FlexCardAssessmentInfo, QueryTools, SortDirection } from '../utils';
import {
DataRaptorAssessmentInfo,
DebugTimer,
FlexCardAssessmentInfo,
nameLocation,
QueryTools,
SortDirection,
} from '../utils';
import { BaseMigrationTool } from './base';
import { MigrationResult, MigrationTool, TransformData, UploadRecordResult } from './interfaces';
import { ObjectMapping } from './interfaces';
Expand All @@ -13,6 +20,7 @@ import { Connection, Messages, Logger } from '@salesforce/core';
import { UX } from '@salesforce/command';
import { OSAssessmentInfo, OmniAssessmentInfo, IPAssessmentInfo } from '../../src/utils';
import { getAllFunctionMetadata, getReplacedString } from '../utils/formula/FormulaUtil';
import { StringVal } from '../utils/StringValue/stringval';

export class OmniScriptMigrationTool extends BaseMigrationTool implements MigrationTool {
private readonly exportType: OmniScriptExportType;
Expand Down Expand Up @@ -190,30 +198,24 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
const osAssessmentInfos: OSAssessmentInfo[] = [];
const ipAssessmentInfos: IPAssessmentInfo[] = [];

const limitedOmniscripts = omniscripts.slice(0, 200);

// Create a set to store existing OmniScript names and also extract DataRaptor and FlexCard names
const existingOmniscriptNames = new Set<string>();
const existingDataRaptorNames = new Set(dataRaptorAssessmentInfos.map((info) => info.name));
const existingFlexCardNames = new Set(flexCardAssessmentInfos.map((info) => info.name));

// First, collect all OmniScript names from the omniscripts array
for (const omniscript of limitedOmniscripts) {
const omniScriptName = `${omniscript[this.namespacePrefix + 'Name']}`;
existingOmniscriptNames.add(omniScriptName);
}

// Now process each OmniScript and its elements
for (const omniscript of limitedOmniscripts) {
for (const omniscript of omniscripts) {
const elements = await this.getAllElementsForOmniScript(omniscript['Id']);

const dependencyIP: string[] = [];
const dependencyIP: nameLocation[] = [];
const missingIP: string[] = [];
const dependencyDR: string[] = [];
const dependencyDR: nameLocation[] = [];
const missingDR: string[] = [];
const dependencyOS: string[] = [];
const dependencyOS: nameLocation[] = [];
const missingOS: string[] = [];
const dependenciesRA: string[] = [];
const dependenciesRA: nameLocation[] = [];
const dependenciesLWC: nameLocation[] = [];
//const missingRA: string[] = [];

for (const elem of elements) {
Expand All @@ -223,55 +225,119 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat

// Check for OmniScript dependencies
if (type === 'OmniScript') {
const nameVal = `${elemName}_OmniScript`;
const nameVal = `${elemName}`;
const type = propertySet['Type'];
const subtype = propertySet['Sub Type'];
const language = propertySet['Language'];
const osName = type + '_' + subtype + '_' + language;
dependencyOS.push(osName + ' ( ' + nameVal + ' ) <br>');
dependencyOS.push({
name: osName,
location: nameVal,
});
if (!existingOmniscriptNames.has(nameVal)) {
missingOS.push(nameVal);
}
}

// Check for Integration Procedure Action dependencies
if (type === 'Integration Procedure Action') {
const nameVal = `${elemName}_Integration Procedure Action`;
dependencyIP.push(propertySet['integrationProcedureKey'] + ' (' + nameVal + ') <br>');
const nameVal = `${elemName}`;
dependencyIP.push({ name: propertySet['integrationProcedureKey'], location: nameVal });
if (!existingOmniscriptNames.has(nameVal) && !existingFlexCardNames.has(nameVal)) {
missingIP.push(nameVal);
}
}

// Check for DataRaptor dependencies
if (['DataRaptor Extract Action', 'DataRaptor Turbo Action', 'DataRaptor Post Action'].includes(type)) {
const nameVal = `${elemName}_${type}`;
dependencyDR.push(propertySet['bundle'] + ' ( ' + nameVal + ' ) <br>');
const nameVal = `${elemName}`;
dependencyDR.push({ name: propertySet['bundle'], location: nameVal });
if (!existingOmniscriptNames.has(nameVal) && !existingDataRaptorNames.has(nameVal)) {
missingDR.push(nameVal);
}
}

if (type === 'Remote Action') {
const nameVal = `${elemName}_${type}`;
const nameVal = `${elemName}`;
const className = propertySet['remoteClass'];
const methodName = propertySet['remoteMethod'];
dependenciesRA.push(className + '.' + methodName + ' (' + nameVal + ') <br>');
dependenciesRA.push({ name: className + '.' + methodName, location: nameVal });
}
// To handle radio , multiselect
if (propertySet['optionSource'] && propertySet['optionSource']['type'] === 'Custom') {
const nameVal = `${elemName}`;
dependenciesRA.push({ name: propertySet['optionSource']['source'], location: nameVal });
}
}

/*const recordName = `${omniscript[this.namespacePrefix + 'Type__c']}_` +
`${omniscript[this.namespacePrefix + 'SubType__c']}` +
(omniscript[this.namespacePrefix + 'Language__c'] ? `_${omniscript[this.namespacePrefix + 'Language__c']}` : '') +
`_${omniscript[this.namespacePrefix + 'Version__c']}`;*/
if (type === 'Custom Lightning Web Component') {
const nameVal = `${elemName}`;
const lwcName = propertySet['lwcName'];
dependenciesLWC.push({ name: lwcName, location: nameVal });
}
}

const omniProcessType = omniscript[this.namespacePrefix + 'IsProcedure__c']
? 'Integration Procedure'
: 'OmniScript';

const existingType = omniscript[this.namespacePrefix + 'Type__c'];
const existingTypeVal = new StringVal(existingType, 'type');
const existingSubType = omniscript[this.namespacePrefix + 'SubType__c'];
const existingSubTypeVal = new StringVal(existingSubType, 'sub type');
const omniScriptName = omniscript[this.namespacePrefix + 'Name'];
const existingOmniScriptNameVal = new StringVal(omniScriptName, 'name');

const warnings: string[] = [];

const recordName =
`${existingTypeVal.cleanName()}_` +
`${existingSubTypeVal.cleanName()}` +
(omniscript[this.namespacePrefix + 'Language__c']
? `_${omniscript[this.namespacePrefix + 'Language__c']}`
: '') +
`_${omniscript[this.namespacePrefix + 'Version__c']}`;

if (!existingTypeVal.isNameCleaned()) {
warnings.push(
this.messages.getMessage('changeMessage', [
existingTypeVal.type,
existingTypeVal.val,
existingTypeVal.cleanName(),
])
);
}
if (!existingSubTypeVal.isNameCleaned()) {
warnings.push(
this.messages.getMessage('changeMessage', [
existingSubTypeVal.type,
existingSubTypeVal.val,
existingSubTypeVal.cleanName(),
])
);
}
if (!existingOmniScriptNameVal.isNameCleaned()) {
warnings.push(
this.messages.getMessage('changeMessage', [
existingOmniScriptNameVal.type,
existingOmniScriptNameVal.val,
existingOmniScriptNameVal.cleanName(),
])
);
}
if (existingOmniscriptNames.has(recordName)) {
warnings.push(this.messages.getMessage('duplicatedName') + recordName);
} else {
existingOmniscriptNames.add(recordName);
}

if (omniProcessType === 'OmniScript') {
const type = omniscript[this.namespacePrefix + 'IsLwcEnabled__c'] ? 'LWC' : 'Angular';
if (type === 'Angular') {
warnings.unshift(this.messages.getMessage('angularOSWarning'));
}
const osAssessmentInfo: OSAssessmentInfo = {
name: omniscript['Name'],
name: recordName,
type: type,
id: omniscript['Id'],
dependenciesIP: dependencyIP,
missingIP: [],
Expand All @@ -280,22 +346,22 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
dependenciesOS: dependencyOS,
missingOS: missingOS,
dependenciesRemoteAction: dependenciesRA,
dependenciesLWC: dependenciesLWC,
infos: [],
warnings: [],
warnings: warnings,
errors: [],
path: '',
};
osAssessmentInfos.push(osAssessmentInfo);
} else {
const ipAssessmentInfo: IPAssessmentInfo = {
name: omniscript['Name'],
name: recordName,
id: omniscript['Id'],
dependenciesIP: dependencyIP,
dependenciesDR: dependencyDR,
dependenciesOS: dependencyOS,
dependenciesRemoteAction: dependenciesRA,
infos: [],
warnings: [],
warnings: warnings,
errors: [],
path: '',
};
Expand Down
18 changes: 14 additions & 4 deletions src/migration/related/ApexMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
this.vlocityOpenInterface2 = new InterfaceImplements(VLOCITY_OPEN_INTERFACE2, this.namespace);
this.vlocityOpenInterface = new InterfaceImplements(VLOCITY_OPEN_INTERFACE, this.namespace);
}
public processObjectType(): string {
return 'apex';
}
public identifyObjects(migrationResults: MigrationResult[]): Promise<JSON[]> {
throw new Error('Method not implemented.');
}
public migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): void {
this.migrate();
public migrateRelatedObjects(migrationResults: MigrationResult[], migrationCandidates: JSON[]): string[] {
return this.migrate();
}
public migrate(): void {
public migrate(): string[] {
const pwd = shell.pwd();
shell.cd(this.projectPath);
const targetOrg: Org = this.org;
sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
this.processApexFiles(this.projectPath);
const apexAssessmentInfos = this.processApexFiles(this.projectPath);
sfProject.deploy(APEXCLASS, targetOrg.getUsername());
shell.cd(pwd);
return this.mapTOName(apexAssessmentInfos);
}

public assess(): ApexAssessmentInfo[] {
Expand Down Expand Up @@ -180,4 +184,10 @@ export class ApexMigration extends BaseRelatedObjectMigration implements Related
}
`;
}

private mapTOName(apexAssessmentInfos: ApexAssessmentInfo[]): string[] {
return apexAssessmentInfos.map((apexAssessmentInfo) => {
return apexAssessmentInfo.name;
});
}
}
Loading

0 comments on commit fe061b0

Please sign in to comment.