@@ -4,7 +4,13 @@ import CardMappings from '../mappings/VlocityCard';
44import { DebugTimer , QueryTools , SortDirection } from '../utils' ;
55import { NetUtils } from '../utils/net' ;
66import { BaseMigrationTool } from './base' ;
7- import { MigrationResult , MigrationTool , ObjectMapping , UploadRecordResult } from './interfaces' ;
7+ import {
8+ InvalidEntityTypeError ,
9+ MigrationResult ,
10+ MigrationTool ,
11+ ObjectMapping ,
12+ UploadRecordResult ,
13+ } from './interfaces' ;
814import { Connection , Messages } from '@salesforce/core' ;
915import { UX } from '@salesforce/command' ;
1016import { FlexCardAssessmentInfo } from '../../src/utils' ;
@@ -15,6 +21,7 @@ import { Constants } from '../utils/constants/stringContants';
1521export class CardMigrationTool extends BaseMigrationTool implements MigrationTool {
1622 static readonly VLOCITYCARD_NAME = 'VlocityCard__c' ;
1723 static readonly OMNIUICARD_NAME = 'OmniUiCard' ;
24+ static readonly VERSION_PROP = 'Version__c' ;
1825 private readonly allVersions : boolean ;
1926
2027 constructor (
@@ -34,7 +41,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
3441 }
3542
3643 getRecordName ( record : string ) {
37- return record [ 'Name' ] ;
44+ return this . allVersions
45+ ? `${ record [ 'Name' ] } _${ record [ this . namespacePrefix + CardMigrationTool . VERSION_PROP ] } `
46+ : record [ 'Name' ] ;
3847 }
3948
4049 getMappings ( ) : ObjectMapping [ ] {
@@ -104,6 +113,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
104113 const flexCardsAssessmentInfos = this . processCardComponents ( flexCards ) ;
105114 return flexCardsAssessmentInfos ;
106115 } catch ( err ) {
116+ if ( err instanceof InvalidEntityTypeError ) {
117+ throw err ;
118+ }
107119 Logger . error ( this . messages . getMessage ( 'errorDuringFlexCardAssessment' ) , err ) ;
108120 }
109121 }
@@ -148,9 +160,10 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
148160 private async processFlexCard ( flexCard : AnyJson , uniqueNames : Set < string > ) : Promise < FlexCardAssessmentInfo > {
149161 const flexCardName = flexCard [ 'Name' ] ;
150162 Logger . info ( this . messages . getMessage ( 'processingFlexCard' , [ flexCardName ] ) ) ;
163+ const version = flexCard [ this . namespacePrefix + CardMigrationTool . VERSION_PROP ] ;
151164 const flexCardAssessmentInfo : FlexCardAssessmentInfo = {
152- name : flexCardName ,
153- oldName : flexCardName ,
165+ name : this . allVersions ? ` ${ flexCardName } _ ${ version } ` : flexCardName ,
166+ oldName : this . allVersions ? ` ${ flexCardName } _ ${ version } ` : flexCardName ,
154167 id : flexCard [ 'Id' ] ,
155168 dependenciesIP : [ ] ,
156169 dependenciesDR : [ ] ,
@@ -168,7 +181,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
168181 const originalName : string = flexCardName ;
169182 const cleanedName : string = this . cleanName ( originalName ) ;
170183 let assessmentStatus = 'Can be Automated' ;
171- flexCardAssessmentInfo . name = cleanedName ;
184+ flexCardAssessmentInfo . name = this . allVersions ? ` ${ cleanedName } _ ${ version } ` : cleanedName ;
172185 if ( cleanedName !== originalName ) {
173186 flexCardAssessmentInfo . warnings . push (
174187 this . messages . getMessage ( 'cardNameChangeMessage' , [ originalName , cleanedName ] )
@@ -431,7 +444,14 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
431444 this . getCardFields ( ) ,
432445 filters ,
433446 sortFields
434- ) ;
447+ ) . catch ( ( err ) => {
448+ if ( err . errorCode === 'INVALID_TYPE' ) {
449+ throw new InvalidEntityTypeError (
450+ `${ CardMigrationTool . VLOCITYCARD_NAME } type is not found under this namespace`
451+ ) ;
452+ }
453+ throw err ;
454+ } ) ;
435455 } else {
436456 filters . set ( this . namespacePrefix + 'Active__c' , true ) ;
437457 return await QueryTools . queryWithFilter (
@@ -440,7 +460,14 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
440460 CardMigrationTool . VLOCITYCARD_NAME ,
441461 this . getCardFields ( ) ,
442462 filters
443- ) ;
463+ ) . catch ( ( err ) => {
464+ if ( err . errorCode === 'INVALID_TYPE' ) {
465+ throw new InvalidEntityTypeError (
466+ `${ CardMigrationTool . VLOCITYCARD_NAME } type is not found under this namespace`
467+ ) ;
468+ }
469+ throw err ;
470+ } ) ;
444471 }
445472 }
446473
@@ -506,14 +533,14 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
506533 }
507534 const transformedCardAuthorName = transformedCard [ 'AuthorName' ] ;
508535
509- if ( uniqueNames . has ( transformedCardName ) ) {
536+ if ( uniqueNames . has ( transformedCard [ 'Name' ] ) ) {
510537 this . setRecordErrors ( card , this . messages . getMessage ( 'duplicatedCardName' ) ) ;
511538 originalRecords . set ( recordId , card ) ;
512539 return ;
513540 }
514541
515542 // Save the name for duplicated names check
516- uniqueNames . add ( transformedCardName ) ;
543+ uniqueNames . add ( transformedCard [ 'Name' ] ) ;
517544
518545 // Create a map of the original records
519546 originalRecords . set ( recordId , card ) ;
@@ -540,7 +567,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
540567 this . messages . getMessage ( 'cardAuthorNameChangeMessage' , [ transformedCardAuthorName ] )
541568 ) ;
542569 }
543- if ( transformedCardName !== card [ 'Name' ] ) {
570+ if ( transformedCard [ 'Name' ] !== card [ 'Name' ] ) {
544571 uploadResult . newName = transformedCardName ;
545572 uploadResult . warnings . unshift ( this . messages . getMessage ( 'cardNameChangeMessage' , [ transformedCardName ] ) ) ;
546573 }
0 commit comments