Skip to content

Commit ab19669

Browse files
Fix: Throw error
1 parent 71e5d7d commit ab19669

File tree

2 files changed

+158
-31
lines changed

2 files changed

+158
-31
lines changed
Lines changed: 116 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import * as os from 'os';
22
import { flags } from '@salesforce/command';
3-
import { Messages } from '@salesforce/core';
3+
import { Messages, Connection } from '@salesforce/core';
44
import OmniStudioBaseCommand from '../../basecommand';
55
import { AssessmentInfo } from '../../../utils/interfaces';
66
import { AssessmentReporter } from '../../../utils/resultsbuilder/assessmentReporter';
7-
import { LwcMigration } from '../../../migration/related/LwcMigration';
8-
import { ApexMigration } from '../../../migration/related/ApexMigration';
97
import { OmniScriptExportType, OmniScriptMigrationTool } from '../../../migration/omniscript';
108
import { CardMigrationTool } from '../../../migration/flexcard';
119
import { DataRaptorMigrationTool } from '../../../migration/dataraptor';
12-
import { DebugTimer, DataRaptorAssessmentInfo, FlexCardAssessmentInfo } from '../../../utils';
10+
import { DebugTimer } from '../../../utils';
1311

1412
import { Logger } from '../../../utils/logger';
1513
import OmnistudioRelatedObjectMigrationFacade from '../../../migration/related/OmnistudioRelatedObjectMigrationFacade';
@@ -39,6 +37,10 @@ export default class Assess extends OmniStudioBaseCommand {
3937
description: messages.getMessage('allVersionsDescription'),
4038
required: false,
4139
}),
40+
relatedobjects: flags.string({
41+
char: 'r',
42+
description: messages.getMessage('apexLwc'),
43+
}),
4244
};
4345

4446
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -47,6 +49,8 @@ export default class Assess extends OmniStudioBaseCommand {
4749
const namespace = (this.flags.namespace || 'vlocity_ins') as string;
4850
const apiVersion = (this.flags.apiversion || '55.0') as string;
4951
const allVersions = (this.flags.allversions || false) as boolean;
52+
const assessOnly = (this.flags.only || '') as string;
53+
const relatedObjects = (this.flags.relatedobjects || '') as string;
5054
const conn = this.org.getConnection();
5155
const orgs: OmnistudioOrgDetails = await OrgUtils.getOrgDetails(conn, namespace);
5256

@@ -61,40 +65,122 @@ export default class Assess extends OmniStudioBaseCommand {
6165
}
6266

6367
Logger.initialiseLogger(this.ux, this.logger);
64-
const projectDirectory = OmnistudioRelatedObjectMigrationFacade.intializeProject();
6568
conn.setApiVersion(apiVersion);
66-
const lwcparser = new LwcMigration(projectDirectory, namespace, this.org);
67-
const apexMigrator = new ApexMigration(projectDirectory, namespace, this.org);
69+
70+
const assesmentInfo: AssessmentInfo = {
71+
lwcAssessmentInfos: [],
72+
apexAssessmentInfos: [],
73+
dataRaptorAssessmentInfos: [],
74+
flexCardAssessmentInfos: [],
75+
omniAssessmentInfo: {
76+
osAssessmentInfos: [],
77+
ipAssessmentInfos: [],
78+
},
79+
};
80+
81+
// Assess OmniStudio components
82+
await this.assessOmniStudioComponents(assesmentInfo, assessOnly, namespace, conn, allVersions);
83+
84+
// Assess related objects if specified
85+
if (relatedObjects) {
86+
const validOptions = ['apex', 'lwc'];
87+
const objectsToProcess = relatedObjects.split(',').map((obj) => obj.trim());
88+
89+
// Validate input
90+
for (const obj of objectsToProcess) {
91+
if (!validOptions.includes(obj)) {
92+
Logger.logger.warn(`Invalid option provided for -r: ${obj}. Valid options are apex, lwc.`);
93+
}
94+
}
95+
96+
const omnistudioRelatedObjectsMigration = new OmnistudioRelatedObjectMigrationFacade(
97+
namespace,
98+
assessOnly,
99+
allVersions,
100+
this.org
101+
);
102+
const relatedObjectAssessmentResult = omnistudioRelatedObjectsMigration.assessAll(objectsToProcess);
103+
assesmentInfo.lwcAssessmentInfos = relatedObjectAssessmentResult.lwcAssessmentInfos;
104+
assesmentInfo.apexAssessmentInfos = relatedObjectAssessmentResult.apexAssessmentInfos;
105+
}
106+
107+
await AssessmentReporter.generate(assesmentInfo, conn.instanceUrl);
108+
return assesmentInfo;
109+
}
110+
111+
private async assessOmniStudioComponents(
112+
assesmentInfo: AssessmentInfo,
113+
assessOnly: string,
114+
namespace: string,
115+
conn: Connection,
116+
allVersions: boolean
117+
): Promise<void> {
118+
this.logger.info(namespace);
119+
this.ux.log(`Using Namespace: ${namespace}`);
120+
if (!assessOnly) {
121+
// If no specific component is specified, assess all components
122+
await this.assessDataRaptors(assesmentInfo, namespace, conn);
123+
await this.assessFlexCards(assesmentInfo, namespace, conn, allVersions);
124+
await this.assessOmniScripts(assesmentInfo, namespace, conn, allVersions, OmniScriptExportType.OS);
125+
return;
126+
}
127+
128+
switch (assessOnly) {
129+
case 'dr':
130+
await this.assessDataRaptors(assesmentInfo, namespace, conn);
131+
break;
132+
case 'fc':
133+
await this.assessFlexCards(assesmentInfo, namespace, conn, allVersions);
134+
break;
135+
case 'os':
136+
await this.assessOmniScripts(assesmentInfo, namespace, conn, allVersions, OmniScriptExportType.OS);
137+
break;
138+
case 'ip':
139+
await this.assessOmniScripts(assesmentInfo, namespace, conn, allVersions, OmniScriptExportType.IP);
140+
break;
141+
default:
142+
throw new Error(messages.getMessage('invalidOnlyFlag'));
143+
}
144+
}
145+
146+
private async assessDataRaptors(assesmentInfo: AssessmentInfo, namespace: string, conn: Connection): Promise<void> {
147+
const drMigrator = new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux);
148+
assesmentInfo.dataRaptorAssessmentInfos = await drMigrator.assess();
149+
if (assesmentInfo.dataRaptorAssessmentInfos) {
150+
this.ux.log('dataRaptorAssessmentInfos');
151+
this.ux.log(assesmentInfo.dataRaptorAssessmentInfos.toString());
152+
}
153+
}
154+
155+
private async assessFlexCards(
156+
assesmentInfo: AssessmentInfo,
157+
namespace: string,
158+
conn: Connection,
159+
allVersions: boolean
160+
): Promise<void> {
161+
const flexMigrator = new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions);
162+
assesmentInfo.flexCardAssessmentInfos = await flexMigrator.assess();
163+
}
164+
165+
private async assessOmniScripts(
166+
assesmentInfo: AssessmentInfo,
167+
namespace: string,
168+
conn: Connection,
169+
allVersions: boolean,
170+
exportType: OmniScriptExportType
171+
): Promise<void> {
68172
const osMigrator = new OmniScriptMigrationTool(
69-
OmniScriptExportType.All,
173+
exportType,
70174
namespace,
71175
conn,
72176
this.logger,
73177
messages,
74178
this.ux,
75179
allVersions
76180
);
77-
const flexMigrator = new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions);
78-
const drMigrator = new DataRaptorMigrationTool(namespace, conn, this.logger, messages, this.ux);
79-
this.logger.info(namespace);
80-
this.ux.log(`Using Namespace: ${namespace}`);
81-
82-
const dataRaptorAssessmentInfos: DataRaptorAssessmentInfo[] = await drMigrator.assess();
83-
if (dataRaptorAssessmentInfos) {
84-
this.ux.log('dataRaptorAssessmentInfos');
85-
this.ux.log(dataRaptorAssessmentInfos.toString());
86-
}
87-
const flexCardAssessmentInfos: FlexCardAssessmentInfo[] = await flexMigrator.assess();
88-
const omniAssessmentInfo = await osMigrator.assess(dataRaptorAssessmentInfos, flexCardAssessmentInfos);
89-
90-
const assesmentInfo: AssessmentInfo = {
91-
lwcAssessmentInfos: lwcparser.assessment(),
92-
apexAssessmentInfos: apexMigrator.assess(),
93-
dataRaptorAssessmentInfos,
94-
flexCardAssessmentInfos,
95-
omniAssessmentInfo,
96-
};
97-
await AssessmentReporter.generate(assesmentInfo, conn.instanceUrl);
98-
return assesmentInfo;
181+
assesmentInfo.omniAssessmentInfo = await osMigrator.assess(
182+
assesmentInfo.dataRaptorAssessmentInfos,
183+
assesmentInfo.flexCardAssessmentInfos
184+
);
99185
}
100186
}

src/migration/related/OmnistudioRelatedObjectMigrationFacade.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,48 @@ export default class OmnistudioRelatedObjectMigrationFacade {
108108
Logger.logger.error(Error.message);
109109
}
110110

111-
// Truncate existing objects if necessary
111+
// Stop the debug timer
112+
const timer = debugTimer.stop();
113+
114+
// Save timer to debug logger
115+
Logger.logger.debug(timer);
116+
117+
// Return results needed for --json flag
118+
return { apexAssessmentInfos, lwcAssessmentInfos };
119+
}
120+
121+
public assessAll(relatedObjects: string[]): RelatedObjectAssesmentInfo {
122+
// Start the debug timer
123+
DebugTimer.getInstance().start();
124+
125+
// Declare an array of MigrationTool
126+
const projectDirectory: string = OmnistudioRelatedObjectMigrationFacade.intializeProject();
127+
const debugTimer = DebugTimer.getInstance();
128+
debugTimer.start();
129+
130+
let apexAssessmentInfos: ApexAssessmentInfo[] = [];
131+
let lwcAssessmentInfos: LWCAssessmentInfo[] = [];
132+
133+
// Proceed with assessment logic
134+
try {
135+
if (relatedObjects.includes('apex')) {
136+
const apexMigrator = new ApexMigration(projectDirectory, this.namespace, this.org);
137+
apexAssessmentInfos = apexMigrator.assess();
138+
}
139+
} catch (Error) {
140+
// Log the error
141+
Logger.logger.error(Error.message);
142+
}
143+
try {
144+
if (relatedObjects.includes('lwc')) {
145+
const lwcparser = new LwcMigration(projectDirectory, this.namespace, this.org);
146+
lwcAssessmentInfos = lwcparser.assessment();
147+
}
148+
} catch (Error) {
149+
// Log the error
150+
Logger.logger.error(Error.message);
151+
}
152+
112153
// Stop the debug timer
113154
const timer = debugTimer.stop();
114155

0 commit comments

Comments
 (0)