Skip to content

Commit

Permalink
feat: added summary
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhinavKumar-sf committed Nov 6, 2024
1 parent 73fe389 commit 07b4e66
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 245 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
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
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
6 changes: 6 additions & 0 deletions src/utils/StringValue/stringutil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Stringutil {
public static cleanName(name: string, allowUnderscores = false): string {
if (!name) return '';
return allowUnderscores ? name.replace(/[^a-z0-9_]+/gi, '') : name.replace(/[^a-z0-9]+/gi, '');
}
}
18 changes: 18 additions & 0 deletions src/utils/StringValue/stringval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Stringutil } from './stringutil';

export class StringVal {
public val: string;
public type: string;

public constructor(val: string, type?: string) {
this.val = val;
this.type = type;
}

public cleanName(allowUnderscores = false): string {
return Stringutil.cleanName(this.val, allowUnderscores);
}
public isNameCleaned(): boolean {
return !this.val || this.val === this.cleanName();
}
}
24 changes: 12 additions & 12 deletions src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ export interface LWCAssessmentInfo {
export interface OSAssessmentInfo {
name: string;
id: string;
dependenciesIP: string[];
dependenciesIP: nameLocation[];
missingIP: string[];
dependenciesDR: string[];
dependenciesDR: nameLocation[];
missingDR: string[];
dependenciesOS: string[];
dependenciesOS: nameLocation[];
missingOS: string[];
dependenciesRemoteAction: string[];
// missingRemoteAction: AnyJson[];
dependenciesRemoteAction: nameLocation[];
dependenciesLWC: nameLocation[];
type: string;
infos: string[];
warnings: string[];
errors: string[];
path: string;
}

export interface IPAssessmentInfo {
name: string;
id: string;
dependenciesIP: string[];
dependenciesDR: string[];
dependenciesOS: string[];
dependenciesRemoteAction: string[];
dependenciesIP: nameLocation[];
dependenciesDR: nameLocation[];
dependenciesOS: nameLocation[];
dependenciesRemoteAction: nameLocation[];
infos: string[];
warnings: string[];
errors: string[];
Expand Down Expand Up @@ -120,7 +120,7 @@ export interface FileProcessor {
process(file: File, type: string, namespace: string): string;
}

export interface nameUrl {
export interface nameLocation {
name: string;
url: string;
location: string;
}
46 changes: 46 additions & 0 deletions src/utils/json/jsonutil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable no-prototype-builtins */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
export class jsonutil {
// Recursive method to find a property in the JSON
public static findProperty(obj: any, propertyName: string): any {
if (obj === null || typeof obj !== 'object') {
return null;
}

// Check if the property exists in the current object
if (propertyName in obj) {
return obj[propertyName];
}

// If it's an array, use findInArray
if (Array.isArray(obj)) {
return this.findInArray(obj, propertyName);
}

// Otherwise, search through all keys
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const result = this.findProperty(obj[key], propertyName);
if (result !== null) {
return result;
}
}
}

return null; // Property not found
}

// Method to find a property in an array
public static findInArray(arr: any[], propertyName: string): any {
for (const item of arr) {
const result = jsonutil.findProperty(item, propertyName);
if (result !== null) {
return result;
}
}
return null; // Property not found in the array
}
}
Loading

0 comments on commit 07b4e66

Please sign in to comment.