Skip to content

Commit

Permalink
feat(pool): #556 Refactor RequestValidationService
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-exxcellent committed Nov 21, 2023
1 parent c84d462 commit 2b83f8d
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ class BusinessPartnerBuildService(
logger.info { "Create ${requests.size} new legal entities" }


val errorsByRequest = requestValidationService.validateLegalEntityCreates(requests.associateWith { it.legalEntity })
val errorsByRequestAddress =
requestValidationService.validateLegalEntityCreatesAddresses(requests.associateWith { it.legalAddress })

val errors = errorsByRequest.flatMap { it.value } + errorsByRequestAddress.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) || errorsByRequestAddress.containsKey(it) }
val errorsByRequest = requestValidationService.validateLegalEntityCreates(requests)
val errors = errorsByRequest.flatMap { it.value }
val validRequests = requests.filterNot { errorsByRequest.containsKey(it) }

val legalEntityMetadataMap = metadataService.getMetadata(requests.map { it.legalEntity }).toMapping()
val addressMetadataMap = metadataService.getMetadata(requests.map { it.legalAddress }).toMapping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ class MetadataService(
return AddressMetadataDto(idTypes, regions)
}

fun getRegions(requests: Collection<IBaseLogisticAddressDto>): Set<Region> {

val regionKeys = requests.mapNotNull { it.physicalPostalAddress?.adminLevel1Key() }
.plus(requests.mapNotNull { it.alternativePostalAddress?.adminLevel1Key() })
.toSet()
val regions = regionRepository.findByRegionCodeIn(regionKeys)
return regions
}

fun getIdentifiers(requests: Collection<IBaseLogisticAddressDto>): Set<IdentifierType> {
val idTypeKeys = requests.flatMap { it.identifiers }.map { it.type }.toSet()
val idTypes = identifierTypeRepository.findByBusinessPartnerTypeAndTechnicalKeyIn(IdentifierBusinessPartnerType.ADDRESS, idTypeKeys)
return idTypes
}


/**
* If no country rule exists use default rules
*/
Expand Down
Loading

0 comments on commit 2b83f8d

Please sign in to comment.