added implicitly_convert_ids props

This commit is contained in:
hongwei 2019-09-03 18:33:28 +02:00
parent 4f50a81278
commit f953386cd1
2 changed files with 36 additions and 25 deletions

View File

@ -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

View File

@ -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
}
/**