mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 18:46:46 +00:00
added implicitly_convert_ids props
This commit is contained in:
parent
4f50a81278
commit
f953386cd1
@ -660,4 +660,7 @@ database_messages_scheduler_interval=3600
|
||||
# FREE_FORM_OTP_INSTRUCTION_TRANSPORT=dummy
|
||||
# COUNTERPARTY_OTP_INSTRUCTION_TRANSPORT=dummy
|
||||
# Possible values: dummy,email,sms
|
||||
# -----------------------------------------------------------------------
|
||||
# -----------------------------------------------------------------------
|
||||
|
||||
# convert Bank_Plan_Text_Reference to OBP-UUID switch. Note: this is in process only for RestConnector now.
|
||||
#implicitly_convert_ids = false
|
||||
@ -9425,30 +9425,38 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
|
||||
* @return modified instance
|
||||
*/
|
||||
private def convertId[T](obj: T, customerIdConverter: String=> String, accountIdConverter: String=> String): T = {
|
||||
ReflectUtils.operateNestedValues(obj)(fieldMirror => {
|
||||
val fieldValue = fieldMirror.get
|
||||
val fieldSymbol: TermSymbol = fieldMirror.symbol
|
||||
val fieldType: Type = fieldSymbol.info
|
||||
val fieldName: String = fieldSymbol.name.toString.trim.toLowerCase
|
||||
|
||||
val ownerSymbol: Type = fieldSymbol.owner.asType.toType
|
||||
|
||||
if(fieldValue == null) {
|
||||
// do nothing
|
||||
} else if (ownerSymbol <:< typeOf[CustomerId] ||
|
||||
(fieldName == "customerid" && fieldType =:= typeOf[String]) ||
|
||||
(ownerSymbol <:< typeOf[Customer] && fieldName == "id" && fieldType =:= typeOf[String])
|
||||
) {
|
||||
val customerRef = customerIdConverter(fieldValue.asInstanceOf[String])
|
||||
fieldMirror.set(customerRef)
|
||||
} else if(ownerSymbol <:< typeOf[AccountId] ||
|
||||
(fieldName == "accountid" && fieldType =:= typeOf[String])
|
||||
) {
|
||||
val accountRef = accountIdConverter(fieldValue.asInstanceOf[String])
|
||||
fieldMirror.set(accountRef)
|
||||
}
|
||||
})
|
||||
obj
|
||||
//1st: We must not convert when connector == mapped. this will ignore the implicitly_convert_ids props.
|
||||
//2rd: if connector != mapped, we still need the `implicitly_convert_ids == true`
|
||||
if(APIUtil.getPropsValue("connector","mapped") != "mapped" && APIUtil.getPropsAsBoolValue("implicitly_convert_ids",false)){
|
||||
ReflectUtils.operateNestedValues(obj)(fieldMirror => {
|
||||
val fieldValue = fieldMirror.get
|
||||
val fieldSymbol: TermSymbol = fieldMirror.symbol
|
||||
val fieldType: Type = fieldSymbol.info
|
||||
val fieldName: String = fieldSymbol.name.toString.trim.toLowerCase
|
||||
|
||||
val ownerSymbol: Type = fieldSymbol.owner.asType.toType
|
||||
|
||||
if(fieldValue == null) {
|
||||
// do nothing
|
||||
} else if (ownerSymbol <:< typeOf[CustomerId] ||
|
||||
(fieldName == "customerid" && fieldType =:= typeOf[String]) ||
|
||||
(ownerSymbol <:< typeOf[Customer] && fieldName == "id" && fieldType =:= typeOf[String])
|
||||
) {
|
||||
val customerRef = customerIdConverter(fieldValue.asInstanceOf[String])
|
||||
fieldMirror.set(customerRef)
|
||||
} else if(ownerSymbol <:< typeOf[AccountId] ||
|
||||
(fieldName == "accountid" && fieldType =:= typeOf[String]) ||
|
||||
(ownerSymbol <:< typeOf[CoreAccount] && fieldName == "id" && fieldType =:= typeOf[String])||
|
||||
(ownerSymbol <:< typeOf[AccountBalance] && fieldName == "id" && fieldType =:= typeOf[String])||
|
||||
(ownerSymbol <:< typeOf[AccountHeld] && fieldName == "id" && fieldType =:= typeOf[String])
|
||||
) {
|
||||
val accountRef = accountIdConverter(fieldValue.asInstanceOf[String])
|
||||
fieldMirror.set(accountRef)
|
||||
}
|
||||
})
|
||||
obj
|
||||
} else
|
||||
obj
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user