From cc812f230f869d8e7f02045217db0f8702ceacdc Mon Sep 17 00:00:00 2001 From: simonredfern Date: Sat, 6 Dec 2025 02:21:30 +0100 Subject: [PATCH] reference type checks entity record id and entity name only --- .../dynamicEntity/DynamicEntityProvider.scala | 21 ++++++++++++------- .../MapppedDynamicDataProvider.scala | 11 ++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/obp-api/src/main/scala/code/dynamicEntity/DynamicEntityProvider.scala b/obp-api/src/main/scala/code/dynamicEntity/DynamicEntityProvider.scala index 1a0d8db7b..35c13f91c 100644 --- a/obp-api/src/main/scala/code/dynamicEntity/DynamicEntityProvider.scala +++ b/obp-api/src/main/scala/code/dynamicEntity/DynamicEntityProvider.scala @@ -4,6 +4,7 @@ import java.util.regex.Pattern import code.api.util.ErrorMessages.DynamicEntityInstanceValidateFail import code.api.util.{APIUtil, CallContext, NewStyle} +import code.util.Helper.MdcLoggable import com.openbankproject.commons.ExecutionContext.Implicits.global import com.openbankproject.commons.model.enums.{DynamicEntityFieldType, DynamicEntityOperation} import com.openbankproject.commons.model._ @@ -144,7 +145,7 @@ trait DynamicEntityT { } } -object ReferenceType { +object ReferenceType extends MdcLoggable { private def recoverFn(fieldName: String, value: String, entityName: String): PartialFunction[Throwable, String] = { case _: Throwable => s"entity '$entityName' not found by the value '$value', the field name is '$fieldName'." @@ -360,14 +361,18 @@ object ReferenceType { } else { val dynamicEntityName = typeName.replace("reference:", "") val errorMsg = s"""$dynamicEntityName not found by the id value '$value', propertyName is '$propertyName'""" - NewStyle.function.invokeDynamicConnector(DynamicEntityOperation.GET_ONE,dynamicEntityName, None, Some(value), None, None, None, false,callContext) - .recover { - case _: Throwable => errorMsg - } - .map { - case (Full(_), _) => "" - case _ => errorMsg + logger.info(s"========== Validating reference field: propertyName='$propertyName', typeName='$typeName', dynamicEntityName='$dynamicEntityName', value='$value' ==========") + + Future { + val exists = code.DynamicData.MappedDynamicDataProvider.existsById(dynamicEntityName, value) + if (exists) { + logger.info(s"========== Reference validation SUCCESS: propertyName='$propertyName', dynamicEntityName='$dynamicEntityName', value='$value' ==========") + "" + } else { + logger.warn(s"========== Reference validation FAILED: propertyName='$propertyName', dynamicEntityName='$dynamicEntityName', value='$value' ==========") + errorMsg } + } } } } diff --git a/obp-api/src/main/scala/code/dynamicEntity/MapppedDynamicDataProvider.scala b/obp-api/src/main/scala/code/dynamicEntity/MapppedDynamicDataProvider.scala index 7703d9728..b7047e4e3 100644 --- a/obp-api/src/main/scala/code/dynamicEntity/MapppedDynamicDataProvider.scala +++ b/obp-api/src/main/scala/code/dynamicEntity/MapppedDynamicDataProvider.scala @@ -25,6 +25,17 @@ object MappedDynamicDataProvider extends DynamicDataProvider with CustomJsonForm saveOrUpdate(bankId, entityName, requestBody, userId, isPersonalEntity, dynamicData) } + // Separate method for reference validation - only checks ID and entity name exist + def existsById(entityName: String, id: String): Boolean = { + println(s"========== Reference validation: checking if DynamicDataId='$id' exists for DynamicEntityName='$entityName' ==========") + val exists = DynamicData.count( + By(DynamicData.DynamicDataId, id), + By(DynamicData.DynamicEntityName, entityName) + ) > 0 + println(s"========== Reference validation result: exists=$exists ==========") + exists + } + override def get(bankId: Option[String],entityName: String, id: String, userId: Option[String], isPersonalEntity: Boolean): Box[DynamicDataT] = { if(bankId.isEmpty && !isPersonalEntity ){ //isPersonalEntity == false, get all the data, no need for specific userId. //forced the empty also to a error here. this is get Dynamic by Id, if it return Empty, better show the error in this level.