Skip to content

Commit

Permalink
feat(pool): eclipse-tractusx#556 write test for pool validation in go…
Browse files Browse the repository at this point in the history
…lden record process
  • Loading branch information
rainer-exxcellent committed Nov 29, 2023
1 parent 24db75a commit d97e202
Show file tree
Hide file tree
Showing 2 changed files with 793 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ class RequestValidationService(
// parents have to be checked in the legal entity validation
val (requestsWithMainAddressNull, requestsWithMainAddressNotNull) = taskReservationRequests.partition { it.businessPartner.site?.mainAddress == null }

val siteMainAddressBridges = requestsWithMainAddressNull
val siteMainAddressBridges = requestsWithMainAddressNotNull
.map {
AddressBridge(address = it.businessPartner.site?.mainAddress!!, request = it, bpn = null)
}
val additionalAddressBridges = requestsWithMainAddressNotNull.filter { it.businessPartner.site != null && it.businessPartner.address != null }
val additionalAddressBridges = requestsWithMainAddressNotNull
.filter { it.businessPartner.site != null && it.businessPartner.address != null }
.map {
AddressBridge(address = it.businessPartner.address!!, request = it, bpn = null)
}
Expand All @@ -125,7 +126,7 @@ class RequestValidationService(
bpn = it.businessPartner.site?.mainAddress?.bpnAReference?.referenceValue!!
)
}
val additionalAddressBridges = taskReservationRequests.filter { it.businessPartner.site == null && it.businessPartner.address != null }
val additionalAddressBridges = taskReservationRequests.filter { it.businessPartner.site != null && it.businessPartner.address != null }
.map {
AddressBridge(
address = it.businessPartner.address!!,
Expand Down Expand Up @@ -216,23 +217,33 @@ class RequestValidationService(
}

fun <ERROR : ErrorCode> validateLegalEntityAndSiteAddresses(
requests: Collection<AddressBridge>, messages: ValidatorMessages<ERROR>
bridges: Collection<AddressBridge>, messages: ValidatorMessages<ERROR>
): Map<RequestWithKey, List<ErrorInfo<ERROR>>> {

val addressDtos = requests.map { it.address }
val regionValidator = ValidateAdministrativeAreaLevel1Exists(addressDtos, messages.regionNotFound)
val addressDtos = bridges.map { it.address }
val adminlevel1Validator = ValidateAdministrativeAreaLevel1Exists(addressDtos, messages.regionNotFound)
val identifiersValidator = ValidateIdentifierTypesExists(addressDtos, messages.identifierNotFound)
val identifiersDuplicateValidator = ValidateAddressIdentifiersDuplicated(addressDtos, messages.duplicateIdentifier)

return requests.associate { bridge ->
val result: MutableMap<RequestWithKey, List<ErrorInfo<ERROR>>> = mutableMapOf()
// there could be second bridge for the same request, e.g. main address and additional address
bridges.forEach{ bridge ->
val legalAddressDto = bridge.address
val request = bridge.request
val request: RequestWithKey = bridge.request
val validationErrors =
regionValidator.validate(legalAddressDto, request) +
adminlevel1Validator.validate(legalAddressDto, request) +
identifiersValidator.validate(legalAddressDto, request) +
identifiersDuplicateValidator.validate(legalAddressDto, request, bridge.bpn)
request to validationErrors
}.filterValues { it.isNotEmpty() }
if(validationErrors.isNotEmpty()) {
val existing = result[request];
if (existing == null) {
result[request] = validationErrors
} else {
result[request] = existing + validationErrors
}
}
}
return result;
}

fun validateSiteCreates(
Expand Down

0 comments on commit d97e202

Please sign in to comment.