@startuml
hide footbox
participant "Mapping Requestor" as MR
participant "Token Mapping Service" as TMS
title Update Mapping Flow
activate MR
MR->TMS: UpdateMappingStatusByPan request
activate TMS
TMS->TMS: Parse the request json string to request entity
TMS->TMS: Generate database entity 'event log' for the pan
TMS->TMS: Do the request entity validation
TMS->TMS: select records 'Token Mapping' from database\n by pan and status is not deactivated
alt If no record found
TMS->TMS: Throw no record exception;
end
alt If record number > max_allow_num
TMS->TMS: Throw too many records exception;
end
TMS->TMS: Generate database entity 'event log' records for each "Token mapping" records.
TMS->TMS: Call caas service to encrypt newPan and decrypt pans and token form the db.\nAccording to the max_caas_request_num, seperate one large caas request to \n small request.(parallel call)
loop For each found Token Mapping
alt If decrypted pan from the database entity is not equal to the request pan
TMS->TMS:record not identical exception to log and event log
end
alt If current status can be converted to the target status
TMS->TMS:Do the datebase entity update.
TMS->TMS:Update Token Mapping into database.
TMS->TMS: UpdateMappingStatusByPan to log and event log.
else
TMS->TMS: UpdateMappingStatusByPan exception to log and event log.
end
end
alt If all Token Mappings are not identical
TMS->TMS:Throw not identical exception.
else If all TokenMappings are updated failed in db
TMS->TMS:Throw db update failed exception.
else If no Token Mapping updated
TMS->TMS:Throw multi-reason update failed exception.
end
TMS->TMS: Generate MQ message ‘Mapping Change’ for each updated token mapping .\nthen push them to MQ.
TMS->TMS: Generate the response entity
TMS->TMS: Update the entity 'event log' and\n store into database(Asynchronous)
TMS-->MR: UpdateMappingStatusByPan response
deactivate TMS
@enduml