From 53280edbfdaac76626aef470e2ae83a3fc28cf72 Mon Sep 17 00:00:00 2001 From: dolfinus Date: Wed, 4 Mar 2020 17:19:43 +0300 Subject: [PATCH] HCX-54 Fix hid.Hydra#deleteEntityAddress --- .../bss/connectors/hid/hydra/Address.groovy | 71 ++++++++++--------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Address.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Address.groovy index 0cba2152..8b475609 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Address.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Address.groovy @@ -562,6 +562,24 @@ trait Address { } } + private Boolean isSubjectAddress(def entityAddressId, def entityTypeId = null, def entityId = null) { + if (notEmpty(entityTypeId) || notEmpty(entityId)) { + return isSubject(entityTypeId ?: entityId) + } else { + LinkedHashMap objAddress = getObjAddress(entityAddressId) + if (objAddress) { + return false + } + + LinkedHashMap subjAddress = getSubjAddress(entityAddressId) + if (subjAddress) { + return true + } + } + + return null + } + private Map putEntityAddress(Map input) { LinkedHashMap params = mergeParams([ entityAddressId : null, @@ -584,7 +602,15 @@ trait Address { endDate : null ], input) - Boolean isSubj = isSubject(params.entityTypeId ?: params.entityId) + Boolean isSubj = false + + if (notEmpty(params.entityAddressId)) { + isSubj = isSubjectAddress(params.entityAddressId, params.entityTypeId, params.entityId) + } + + if (isSubj == null) { + throw new Exception ("No address found!") + } if (isSubj) { params.subjAddressId = params.entityAddressId @@ -723,40 +749,15 @@ trait Address { Boolean isSubj = false - if (params.entityAddressId) { - if (params.entityTypeId || params.entityId) { - isSubj = isSubject(params.entityTypeId ?: params.entityId) - } else { - LinkedHashMap objAddress = getEntityAddress( - entityAddressId : params.entityAddressId, - entityId : params.entityId, - addressId : params.addressId, - addrTypeId : params.addrTypeId, - bindAddrTypeId : params.bindAddrTypeId, - stateId : params.stateId, - isMain : params.isMain - ) - LinkedHashMap subjAddress = getEntityAddress( - entityType : 'SUBJ_TYPE_Company', - entityAddressId : params.entityAddressId, - entityId : params.entityId, - addressId : params.addressId, - addrTypeId : params.addrTypeId, - bindAddrTypeId : params.bindAddrTypeId, - stateId : params.stateId, - isMain : params.isMain - ) - if (objAddress) { - isSubj = false - } else if (subjAddress) { - isSubj = true - } else { - logger.info("No address found!") - return true - } + if (notEmpty(params.entityAddressId)) { + isSubj = isSubjectAddress(params.entityAddressId, params.entityTypeId, params.entityId) + + if (isSubj == null) { + logger.info("No address found!") + return true } } else { - LinkedHashMap address = getEntityAddress( + LinkedHashMap address = getEntityAddressBy( addressId : params.addressId, entityTypeId : params.entityTypeId, entityId : params.entityId, @@ -771,10 +772,10 @@ trait Address { } if (address.n_obj_address_id) { isSubj = false - params.entityAddressId = address?.n_obj_address_id + params.entityAddressId = address.n_obj_address_id } else { isSubj = true - params.entityAddressId = address?.n_subj_address_id + params.entityAddressId = address.n_subj_address_id } }