Skip to content

Commit e0978be

Browse files
authored
Merge pull request #414 from sf-kishore-kurri/u/kkurri/W-19637353
fix: @W-19637353: Prudential Migration issues
2 parents 1f6c692 + d0b79ab commit e0978be

File tree

12 files changed

+393
-37
lines changed

12 files changed

+393
-37
lines changed

messages/migrate.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
"flexCardMigrationProcessingMessage": "Processing %s Flexcards for migration (%s skipped due to Angular dependencies)",
199199
"noMetadataToDeploy": "No metadata to deploy",
200200
"missingMandatoryField": "Missing mandatory field: %s for %s",
201-
"dataMapperMigrationFailed": "DataMapper migration failed for: %s",
201+
"dataMapperMigrationFailed": "DataMapper migration failed for: %s ",
202202
"dataMapperNameStartsWithNumber": "DataMapper name '%s' starts with a number which causes migration issues. Proposed new name: %s",
203203
"integrationProcedureTypeEmptyAfterCleaning": "Integration Procedure Type '%s' becomes empty after name cleaning. Please provide a valid Type value.",
204204
"integrationProcedureSubtypeEmptyAfterCleaning": "Integration Procedure SubType '%s' becomes empty after name cleaning. Please provide a valid SubType value.",
@@ -244,5 +244,8 @@
244244
"customLabelAssessmentSummary": "Custom Label with same name and different value is already exist without namespace.",
245245
"generatedCustomLabelAssessmentReportPage": "Generated custom label assessment report page %s of %s with %s labels",
246246
"varDeclarationUpdated": "Variable initialization has been updated for target name",
247-
"migrationSuccessfulMessage": "Migration process for org %s is complete and reports are ready for review in the folder %s"
248-
}
247+
"migrationSuccessfulMessage": "Migration process for org %s is complete and reports are ready for review in the folder %s",
248+
"elementValueMapUnexpectedType": "ElementValueMap has unexpected data type '%s' for element '%s'. Expected object format.",
249+
"errorProcessingFormulaInElement": "Error processing formula for key '%s' in element '%s': %s",
250+
"errorProcessingElementValueMap": "Error processing elementValueMap in Integration Procedure element '%s': %s"
251+
}

src/migration/dataraptor.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
175175
continue;
176176
}
177177

178-
duplicatedNames.add(transformedDataRaptor['Name']);
179-
180178
// Create a map of the original records
181179
originalDrRecords.set(recordId, dr);
182180

@@ -191,21 +189,28 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
191189

192190
// Always add the response to track success/failure
193191
if (drUploadResponse && drUploadResponse.success === true) {
194-
const items = await this.getItemsForDataRaptor(dataRaptorItemsData, name, drUploadResponse.id);
192+
// Append the processed DM name into duplicateNames Map
193+
const dataMapperName = transformedDataRaptor[DRBundleMappings.Name];
194+
duplicatedNames.add(dataMapperName);
195195

196-
drUploadResponse.newName = transformedDataRaptor[DRBundleMappings.Name];
196+
const items = await this.getItemsForDataRaptor(dataRaptorItemsData, name, drUploadResponse.id);
197+
drUploadResponse.newName = dataMapperName;
197198

198199
// Move the items
199200
await this.uploadTransformedData(DataRaptorMigrationTool.OMNIDATATRANSFORMITEM_NAME, items);
200201
} else {
201202
// Handle failed migration - add error information
202-
if (!drUploadResponse) {
203+
if (!drUploadResponse?.success) {
204+
Logger.logVerbose(
205+
`\n${this.messages.getMessage('dataMapperMigrationFailed', [name]) + drUploadResponse.errors}`
206+
);
207+
203208
drUploadResponse = {
204209
referenceId: recordId,
205210
id: '',
206211
success: false,
207212
hasErrors: true,
208-
errors: [this.messages.getMessage('dataMapperMigrationFailed', [name])],
213+
errors: [this.messages.getMessage('dataMapperMigrationFailed', [name]) + drUploadResponse.errors],
209214
warnings: [],
210215
newName: '',
211216
};

src/migration/omniscript.ts

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
4343
private readonly allVersions: boolean;
4444

4545
// Reserved keys that should not be used for storing output
46-
private readonly reservedKeys = new Set<string>(['Request', 'Response', 'Condition']);
46+
private readonly reservedKeys = new Set<string>(['Request', 'Response']);
4747

4848
// Tags to validate in PropertySet for reserved key usage
4949
private readonly tagsToValidate = new Set<string>(['additionalOutput']);
@@ -823,19 +823,75 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
823823
const propertySet = JSON.parse(ipElement[`${this.namespacePrefix}PropertySet__c`] || '{}');
824824
this.collectReservedKeys(propertySet, foundReservedKeys);
825825

826-
var originalString = ipElement[`${this.namespacePrefix}PropertySet__c`];
827-
try {
828-
originalString = getReplacedString(
829-
this.namespacePrefix,
830-
ipElement[`${this.namespacePrefix}PropertySet__c`],
831-
functionDefinitionMetadata
832-
);
833-
ipElement[`${this.namespacePrefix}PropertySet__c`] = originalString;
834-
} catch (ex) {
835-
Logger.error('Error processing formula for integration procedure', ex);
836-
Logger.logVerbose(
837-
this.messages.getMessage('formulaSyntaxError', [ipElement[`${this.namespacePrefix}PropertySet__c`]])
838-
);
826+
// Process formulas in elementValueMap instead of entire PropertySet
827+
if (propertySet.elementValueMap) {
828+
let elementValueMap: any = null;
829+
830+
try {
831+
// Handle both string and object formats for elementValueMap
832+
if (typeof propertySet.elementValueMap === 'object' && propertySet.elementValueMap !== null) {
833+
// elementValueMap is already an object, use directly
834+
elementValueMap = propertySet.elementValueMap;
835+
Logger.logVerbose(
836+
`ElementValueMap accessed as object for element: ${ipElement['Name'] || 'Unknown'}`
837+
);
838+
} else {
839+
Logger.warn(
840+
this.messages.getMessage('elementValueMapUnexpectedType', [
841+
typeof propertySet.elementValueMap,
842+
ipElement['Name'] || 'Unknown',
843+
])
844+
);
845+
}
846+
847+
if (elementValueMap) {
848+
let formulasUpdated = false;
849+
850+
// Process each key-value pair in elementValueMap
851+
for (const [key, value] of Object.entries(elementValueMap)) {
852+
if (typeof value === 'string' && value.startsWith('=')) {
853+
// This is a formula that needs processing
854+
try {
855+
const updatedFormula = getReplacedString(
856+
this.namespacePrefix,
857+
value,
858+
functionDefinitionMetadata
859+
);
860+
if (updatedFormula !== value) {
861+
elementValueMap[key] = updatedFormula;
862+
formulasUpdated = true;
863+
Logger.logVerbose(`Updated formula in ${key}: ${value} -> ${updatedFormula}`);
864+
}
865+
} catch (formulaEx) {
866+
Logger.error(
867+
this.messages.getMessage('errorProcessingFormulaInElement', [
868+
key,
869+
ipElement['Name'] || 'Unknown',
870+
formulaEx.message || formulaEx,
871+
])
872+
);
873+
Logger.logVerbose(this.messages.getMessage('formulaSyntaxError', [value]));
874+
}
875+
}
876+
}
877+
878+
// Update PropertySet with modified elementValueMap if any formulas were updated
879+
if (formulasUpdated) {
880+
// Keep as object format
881+
propertySet.elementValueMap = elementValueMap;
882+
}
883+
ipElement[`${this.namespacePrefix}PropertySet__c`] = JSON.stringify(propertySet);
884+
Logger.logVerbose(`Updated PropertySet for element: ${ipElement['Name'] || 'Unknown'}`);
885+
}
886+
} catch (elementValueMapEx) {
887+
Logger.error(
888+
this.messages.getMessage('errorProcessingElementValueMap', [
889+
ipElement['Name'] || 'Unknown',
890+
elementValueMapEx.message || elementValueMapEx,
891+
])
892+
);
893+
Logger.logVerbose(`ElementValueMap content: ${JSON.stringify(propertySet.elementValueMap)}`);
894+
}
839895
}
840896
}
841897
}
@@ -953,7 +1009,6 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
9531009
}
9541010

9551011
// Save the mapped record
956-
duplicatedNames.add(mappedOsName);
9571012
mappedRecords.push(mappedOmniScript);
9581013

9591014
// Save the OmniScript__c records to Standard BPO i.e OmniProcess
@@ -1001,6 +1056,8 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
10011056
'_1';
10021057
}
10031058
// Always set the new name to show the migrated name
1059+
// Add the processednew name to the duplicated set
1060+
duplicatedNames.add(mappedOsName);
10041061
osUploadResponse.newName = mappedOsName;
10051062

10061063
// Only add warning if the name was actually modified
@@ -1068,6 +1125,7 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
10681125
}
10691126
}
10701127

1128+
Logger.logVerbose(e.stack);
10711129
osUploadResponse.errors.push(
10721130
this.messages.getMessage('errorWhileCreatingElements', [this.getName(true)]) + error
10731131
);

src/utils/lwcparser/htmlParser/HTMLParser.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,23 @@ export class HTMLParser {
3434
public replaceTags(namespaceTag: string): Map<string, string> {
3535
const htmlContentMap = new Map<string, string>();
3636
htmlContentMap.set(FileConstant.BASE_CONTENT, this.html);
37-
// Use a regular expression to match <omnistudio-input> to </omnistudio-input>
37+
38+
// Handle empty namespace - no changes should be made
39+
if (!namespaceTag || namespaceTag.trim() === '') {
40+
htmlContentMap.set(FileConstant.MODIFIED_CONTENT, this.html);
41+
return htmlContentMap;
42+
}
43+
44+
// Escape special regex characters in the namespace tag
45+
const escapedNamespaceTag = namespaceTag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
46+
47+
// Use regular expressions with global flag to replace ALL occurrences
48+
const openTagRegex = new RegExp('<' + escapedNamespaceTag, 'g');
49+
const closeTagRegex = new RegExp('</' + escapedNamespaceTag, 'g');
50+
3851
this.html = this.html
39-
.replace('<' + namespaceTag, '<' + DEFAULT_NAMESPACE)
40-
.replace('</' + namespaceTag, '</' + DEFAULT_NAMESPACE);
52+
.replace(openTagRegex, '<' + DEFAULT_NAMESPACE)
53+
.replace(closeTagRegex, '</' + DEFAULT_NAMESPACE);
4154

4255
htmlContentMap.set(FileConstant.MODIFIED_CONTENT, this.html);
4356
return htmlContentMap;

src/utils/sfcli/project/sfProject.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class sfProject {
3939
Logger.log(messages.getMessage('deployingFromManifest'));
4040
const cmd = `sf project deploy start --manifest "${manifestPath}" --target-org "${username}" --async`;
4141
Logger.log(cmd);
42-
const cmdOutput = sfProject.executeCommand(cmd);
42+
const cmdOutput = sfProject.executeCommand(cmd, true);
4343
Logger.logVerbose(`Deploy output: ${cmdOutput}`);
4444
sfProject.processOutput(cmdOutput);
4545
}
@@ -64,9 +64,13 @@ export class sfProject {
6464
}
6565
}
6666

67-
private static executeCommand(cmd: string): string {
67+
private static executeCommand(cmd: string, jsonOutput = false): string {
6868
try {
69-
return cli.exec(`${cmd} --json`);
69+
if (jsonOutput) {
70+
return cli.exec(`${cmd} --json`);
71+
} else {
72+
return cli.exec(`${cmd}`);
73+
}
7074
} catch (error) {
7175
Logger.error(messages.getMessage('sfProjectCommandError', [String(error)]));
7276
throw error;

src/utils/storageUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class StorageUtil {
1414

1515
public static getOmnistudioMigrationStorage(): MigrationStorage {
1616
if (this.omnistudioMigrationStorage === undefined) {
17-
this.omnistudioAssessmentStorage = {
17+
this.omnistudioMigrationStorage = {
1818
osStorage: new Map<string, OmniScriptStorage>(),
1919
fcStorage: new Map<string, FlexcardStorage>(),
2020
};

0 commit comments

Comments
 (0)