diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/RequestValidationService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/RequestValidationService.kt index 602552d97..51e9b71ff 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/RequestValidationService.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/RequestValidationService.kt @@ -29,6 +29,8 @@ import org.eclipse.tractusx.bpdm.pool.api.model.request.* import org.eclipse.tractusx.bpdm.pool.api.model.response.* import org.eclipse.tractusx.bpdm.pool.dto.LegalEntityMetadataDto import org.eclipse.tractusx.bpdm.pool.repository.* +import org.eclipse.tractusx.orchestrator.api.model.BpnReferenceType +import org.eclipse.tractusx.orchestrator.api.model.BusinessPartnerFullDto import org.eclipse.tractusx.orchestrator.api.model.TaskStepReservationEntryDto import org.springframework.stereotype.Service @@ -43,109 +45,201 @@ class RequestValidationService( private val metadataService: MetadataService ) { - fun validateLegalEntitiesToCreateFromOrchestrator(taskReservationRequests: List): Map>> { + fun validateTasksFromOrchestrator(taskEntries: List, requestMappings: TaskEntryBpnMapping + ): Map>> { - val (requestsWithLegalAddressNull, requestsWithLegalAddressNotNull) = taskReservationRequests.partition { it.businessPartner.legalEntity?.legalAddress == null } + val result = validateLegalEntitiesFromOrchestrator(taskEntries, requestMappings) + + validateSitesFromOrchestrator(taskEntries, requestMappings) + + validateAddressesFromOrchestrator(taskEntries, requestMappings) - val legalAddressBridges = requestsWithLegalAddressNotNull - .map { AddressBridge(address = it.businessPartner.legalEntity?.legalAddress!!, request = it, bpnA = null) } - val additionalAddressBridges = requestsWithLegalAddressNotNull.filter { it.businessPartner.site == null && it.businessPartner.address != null } - .map { AddressBridge(address = it.businessPartner.address!!, request = it, bpnA = null) } + return result.map { + it.key to it.value.distinct() + }.toMap() + } + + private fun isSiteUpdate( businessPartner: BusinessPartnerFullDto, requestMappings: TaskEntryBpnMapping) + = (businessPartner.site?.bpnSReference?.referenceType == BpnReferenceType.Bpn + || (businessPartner.site?.bpnSReference?.referenceType == BpnReferenceType.BpnRequestIdentifier + && requestMappings.hasBpnFor(businessPartner.site?.bpnSReference))) + + private fun isSiteCreate( businessPartner: BusinessPartnerFullDto, requestMappings: TaskEntryBpnMapping) + = (businessPartner.site?.bpnSReference?.referenceType == BpnReferenceType.BpnRequestIdentifier + && !(requestMappings.hasBpnFor(businessPartner.site?.bpnSReference))) + + private fun isLegalEntityUpdate(businessPartner: BusinessPartnerFullDto, requestMappings: TaskEntryBpnMapping ) + = (businessPartner.legalEntity?.bpnLReference?.referenceType == BpnReferenceType.Bpn + || (businessPartner.legalEntity?.bpnLReference?.referenceType == BpnReferenceType.BpnRequestIdentifier + && requestMappings.hasBpnFor(businessPartner.legalEntity?.bpnLReference))) + + private fun isLegalEntityCreate(businessPartner: BusinessPartnerFullDto, requestMappings: TaskEntryBpnMapping) + = (businessPartner.legalEntity?.bpnLReference?.referenceType == BpnReferenceType.BpnRequestIdentifier + && !(requestMappings.hasBpnFor(businessPartner.legalEntity?.bpnLReference))) + + private fun validateLegalEntitiesFromOrchestrator(taskEntries: List, requestMappings: TaskEntryBpnMapping): Map>> { + + val legalEntitiesToCreate = taskEntries + .filter { + isLegalEntityCreate(it.businessPartner, requestMappings) + } + val legalEntitiesToUpdate = taskEntries + .filter { + isLegalEntityUpdate(it.businessPartner, requestMappings) + } + + val requestsWithLegalAddressNull = legalEntitiesToCreate.filter { it.businessPartner.legalEntity?.legalAddress == null } + + val createBridges = legalEntitiesToCreate.map { + LegalEntityBridge(legalEntity = it.businessPartner.legalEntity!!, request = it, bpnL = null) + } + val updateBridges = legalEntitiesToUpdate.map { + LegalEntityBridge( + legalEntity = it.businessPartner.legalEntity!!, request = it, bpnL = requestMappings.getBpn(it.businessPartner.legalEntity?.bpnLReference!!)!! + ) + } val legalAddressEmptyErrorsByRequest = requestsWithLegalAddressNull.associateWith { listOf(ErrorInfo(LegalEntityCreateError.LegalAddressIdentifierNotFound, "legal address of legal entity is Empty", it.getRequestKey())) } + val leCreateErrorsByRequest = validateLegalEntitiesToCreate(createBridges) + val leUpdateErrorsByRequest = validateLegalEntitiesToUpdate(updateBridges) + val duplicateValidations = validateLegalEntityDuplicates(createBridges+updateBridges) + val result = mergeMapsWithCollectionInValue(leCreateErrorsByRequest, leUpdateErrorsByRequest, duplicateValidations, legalAddressEmptyErrorsByRequest) - val addressErrorsByRequest = validateAddresses(legalAddressBridges + additionalAddressBridges, leCreateMessages) - val leErrorsByRequest = validateLegalEntitiesToCreate(requestsWithLegalAddressNotNull.map { - LegalEntityBridge(legalEntity = it.businessPartner.legalEntity, request = it) - }) - return mergeMapsWithCollectionInValue(leErrorsByRequest, addressErrorsByRequest, legalAddressEmptyErrorsByRequest) + return result } - fun validateLegalEntitiesToUpdateFromOrchestrator(taskReservationRequests: List): Map>> { + private fun validateSitesFromOrchestrator(taskEntries: List, requestMappings: TaskEntryBpnMapping): Map>> { - val legalAddressBridges = taskReservationRequests - .map { - AddressBridge( - address = it.businessPartner.legalEntity?.legalAddress!!, - request = it, - bpnA = it.businessPartner.legalEntity?.legalAddress?.bpnAReference?.referenceValue!! - ) - } + val requestsWithMainAddressNull = taskEntries.filter { + it.businessPartner.site != null && it.businessPartner.site?.mainAddress == null + } + val mainAddressEmptyErrorsByRequest = requestsWithMainAddressNull.associateWith { + listOf(ErrorInfo(SiteCreateError.MainAddressIdentifierNotFound, "Site main address is Empty", it.getRequestKey())) + } - val additionalAddressBridges = taskReservationRequests.filter { it.businessPartner.site == null && it.businessPartner.address != null } - .map { - AddressBridge( - address = it.businessPartner.address!!, - request = it, - bpnA = it.businessPartner.address?.bpnAReference?.referenceValue, - ) + val sitesToUpdate = taskEntries + .filter { + isSiteUpdate(it.businessPartner, requestMappings) } - val leErrorsByRequest = validateLegalEntitiesToUpdate(taskReservationRequests.map { - LegalEntityUpdateBridge( - legalEntity = it.businessPartner.legalEntity!!, - request = it, - bpnL = it.businessPartner.legalEntity?.bpnLReference?.referenceValue!! - ) + val siteErrorsByRequest = validateSitesToUpdate(sitesToUpdate.map { + SiteUpdateBridge( request = it, bpnS = requestMappings.getBpn(it.businessPartner.site?.bpnSReference!!)!! ) }) - val addressErrorsByRequest = validateAddresses(legalAddressBridges + additionalAddressBridges, leUpdateMessages) - return mergeMapsWithCollectionInValue(leErrorsByRequest, addressErrorsByRequest) + + return mergeMapsWithCollectionInValue(siteErrorsByRequest, mainAddressEmptyErrorsByRequest) } - fun validateSitesToCreateFromOrchestrator(taskReservationRequests: List): Map>> { + private fun validateAddressesFromOrchestrator(taskEntries: List, requestMappings: TaskEntryBpnMapping): Map>> { - // parents have to be checked in the legal entity validation - val (requestsWithMainAddressNull, requestsWithMainAddressNotNull) = taskReservationRequests.partition { it.businessPartner.site?.mainAddress == null } + val taskWithLegalAddress = taskEntries + .filter{ it.businessPartner.legalEntity?.legalAddress != null + && (it.businessPartner.site == null || it.businessPartner.site?.mainAddress != null)} - val siteMainAddressBridges = requestsWithMainAddressNotNull - .map { - AddressBridge(address = it.businessPartner.site?.mainAddress!!, request = it, bpnA = null) - } - val additionalAddressBridges = requestsWithMainAddressNotNull - .filter { it.businessPartner.site != null && it.businessPartner.address != null } - .map { - AddressBridge(address = it.businessPartner.address!!, request = it, bpnA = null) + val leCreateAddresses = taskWithLegalAddress.flatMap{getAddressCreateBridgesFromLegalEntity(it, requestMappings)} + val leUpdateAddresses = taskWithLegalAddress.flatMap{getAddressUpdateBridgesFromLegalEntity(it, requestMappings)} + val siteCreateAddresses = taskWithLegalAddress.flatMap{getAddressCreateBridgesFromSite(it, requestMappings)} + val siteUpdateAddresses = taskWithLegalAddress.flatMap{getAddressUpdateBridgesFromSite(it, requestMappings)} + + return mergeMapsWithCollectionInValue (validateAddresses(leCreateAddresses, leCreateMessages), + validateAddresses(leUpdateAddresses, leUpdateMessages), + validateAddresses(siteCreateAddresses, siteCreateMessages), + validateAddresses(siteUpdateAddresses, siteUpdateMessages), + validateAddressDuplicates(leCreateAddresses+ leUpdateAddresses+ siteCreateAddresses+ siteUpdateAddresses) + ) + } + + fun getAddressCreateBridgesFromLegalEntity(task: TaskStepReservationEntryDto, requestMappings: TaskEntryBpnMapping): List { + + val allAddresses: MutableList = mutableListOf() + val businessPartner = task.businessPartner + if ( isLegalEntityCreate(businessPartner, requestMappings)) { + allAddresses.add(AddressBridge(address = businessPartner.legalEntity?.legalAddress!!, request = task, bpnA = null)) + if ( businessPartner.site == null && businessPartner.address != null) { + allAddresses.add( AddressBridge(address = businessPartner.address!!, request = task, bpnA = null)) } + } + return allAddresses + } - val mainAddressEmptyErrorsByRequest = requestsWithMainAddressNull.associateWith { - listOf(ErrorInfo(SiteCreateError.MainAddressIdentifierNotFound, "Site main address is Empty", it.getRequestKey())) + fun getAddressUpdateBridgesFromLegalEntity(task: TaskStepReservationEntryDto, requestMappings: TaskEntryBpnMapping): List { + + val allAddresses: MutableList = mutableListOf() + val businessPartner = task.businessPartner + if ( isLegalEntityUpdate(businessPartner, requestMappings)) { + allAddresses.add(AddressBridge( + address = businessPartner.legalEntity?.legalAddress!!, request = task, + bpnA = requestMappings.getBpn(businessPartner.legalEntity?.legalAddress?.bpnAReference!!) + )) + if ( businessPartner.site == null && businessPartner.address != null) { + allAddresses.add( AddressBridge( + address = businessPartner.address!!, + request = task, + bpnA = requestMappings.getBpn(businessPartner.address?.bpnAReference!!), + )) + } } - val addressErrorsByRequest = validateAddresses(siteMainAddressBridges + additionalAddressBridges, siteCreateMessages) - return mergeMapsWithCollectionInValue(addressErrorsByRequest, mainAddressEmptyErrorsByRequest) + return allAddresses } - fun validateSitesToUpdateFromOrchestrator(taskReservationRequests: List): Map>> { + fun getAddressCreateBridgesFromSite(task: TaskStepReservationEntryDto, requestMappings: TaskEntryBpnMapping): List { - val siteMainAddressBridges = taskReservationRequests.map { - AddressBridge( - address = it.businessPartner.site?.mainAddress!!, - request = it, - bpnA = it.businessPartner.site?.mainAddress?.bpnAReference?.referenceValue!! - ) + val allAddresses: MutableList = mutableListOf() + val businessPartner = task.businessPartner + if ( isSiteCreate(businessPartner, requestMappings)) { + allAddresses.add(AddressBridge(address = businessPartner.site?.mainAddress!!, request = task, bpnA = null)) + if ( businessPartner.site != null && businessPartner.address != null) { + allAddresses.add( AddressBridge(address = businessPartner.address!!, request = task, bpnA = null)) + } } - val additionalAddressBridges = taskReservationRequests.filter { it.businessPartner.site != null && it.businessPartner.address != null } - .map { - AddressBridge( - address = it.businessPartner.address!!, - request = it, - bpnA = it.businessPartner.address?.bpnAReference?.referenceValue, - ) + return allAddresses + } + + fun getAddressUpdateBridgesFromSite(task: TaskStepReservationEntryDto, requestMappings: TaskEntryBpnMapping): List { + + val allAddresses: MutableList = mutableListOf() + val businessPartner = task.businessPartner + if (isSiteUpdate(businessPartner, requestMappings)) { + allAddresses.add(AddressBridge( + address = businessPartner.site?.mainAddress!!, + request = task, + bpnA = requestMappings.getBpn(businessPartner.site?.mainAddress?.bpnAReference!!) + )) + if ( businessPartner.site != null && businessPartner.address != null) { + allAddresses.add( AddressBridge( + address = businessPartner.address!!, + request = task, + bpnA = requestMappings.getBpn(businessPartner.address?.bpnAReference!!), + )) } + } + return allAddresses + } - val siteErrorsByRequest = validateSitesToUpdate(taskReservationRequests.map { - SiteUpdateBridge( request = it, bpnS = it.businessPartner.site?.bpnSReference?.referenceValue!! ) - }) - val addressErrorsByRequest = validateAddresses(siteMainAddressBridges + additionalAddressBridges, siteUpdateMessages) - return mergeMapsWithCollectionInValue(siteErrorsByRequest, addressErrorsByRequest) + fun validateLegalEntityDuplicates(requestBridges: List): Map>> { + + val legalEntityDtos = requestBridges.map { it.legalEntity } + val duplicatesValidator = ValidateLegalEntityIdentifiersDuplicated(legalEntityDtos, LegalEntityCreateError.LegalEntityDuplicateIdentifier) + + return requestBridges.associate { + it.request to duplicatesValidator.validate(it.legalEntity, it.request, it.bpnL) + }.filterValues { it.isNotEmpty() } + } + + fun validateAddressDuplicates(requestBridges: List): Map>> { + + val addressDtos = requestBridges.map { it.address } + val duplicatesValidator = ValidateAddressIdentifiersDuplicated(addressDtos, LegalEntityCreateError.LegalAddressDuplicateIdentifier) + + return requestBridges.associate { + it.request to duplicatesValidator.validate(it.address, it.request, it.bpnA) + }.filterValues { it.isNotEmpty() } } fun validateLegalEntitiesToCreateFromController(leCreateRequests: Collection): Map>> { val leErrorsByRequest = validateLegalEntitiesToCreate(leCreateRequests.map { - LegalEntityBridge(legalEntity = it.legalEntity, request = it) + LegalEntityBridge(legalEntity = it.legalEntity, request = it, bpnL = null) }) val legalAddressBridges = leCreateRequests.map { AddressBridge(address = it.legalAddress, request = it, bpnA = null) @@ -181,7 +275,7 @@ class RequestValidationService( ): Map>> { val leErrorsByRequest = validateLegalEntitiesToUpdate(leRequests.map { - LegalEntityUpdateBridge(legalEntity = it.legalEntity, request = it, bpnL = it.bpnl) + LegalEntityBridge(legalEntity = it.legalEntity, request = it, bpnL = it.bpnl) }) val addressBpnByLegalEntityBpnL = legalEntityRepository.findDistinctByBpnIn(leRequests.map { it.bpnl }).associate { it.bpn to it.legalAddress.bpn } @@ -193,12 +287,12 @@ class RequestValidationService( } fun validateLegalEntitiesToUpdate( - requestBridges: Collection + requestBridges: Collection ): Map>> { val legalEntityDtos = requestBridges.map { it.legalEntity } val duplicatesValidator = ValidateLegalEntityIdentifiersDuplicated(legalEntityDtos, LegalEntityUpdateError.LegalEntityDuplicateIdentifier) - val existingLegalEntityBpns = legalEntityRepository.findDistinctByBpnIn(requestBridges.map { it.bpnL }).map { it.bpn }.toSet() + val existingLegalEntityBpns = legalEntityRepository.findDistinctByBpnIn(requestBridges.mapNotNull { it.bpnL }).map { it.bpn }.toSet() val existingBpnValidator = ValidateUpdateBpnExists(existingLegalEntityBpns, LegalEntityUpdateError.LegalEntityNotFound) val legalFormValidator = ValidateLegalFormExists(legalEntityDtos, LegalEntityUpdateError.LegalFormNotFound) val identifierValidator = ValidateIdentifierLeTypesExists(legalEntityDtos, LegalEntityUpdateError.LegalEntityIdentifierNotFound) @@ -235,7 +329,7 @@ class RequestValidationService( identifiersDuplicateValidator.validate(legalAddressDto, request, bridge.bpnA) if(validationErrors.isNotEmpty()) { - val existing = result[request]; + val existing = result[request] if (existing == null) { result[request] = validationErrors } else { @@ -243,16 +337,14 @@ class RequestValidationService( } } } - return result; + return result } fun validateSitesToCreateFromController( siteRequests: Collection, ): Map>> { - val siteErrorsByRequest = validateSitesToCreate(siteRequests.map { - SiteCreateBridge(bpnlParent = it.bpnlParent, request = it) - }) + val siteErrorsByRequest = validateSitesToCreate(siteRequests) val addressErrorsByRequest = validateAddresses(siteRequests.map { AddressBridge(address = it.site.mainAddress, request = it, bpnA = null) }, siteCreateMessages) @@ -275,16 +367,16 @@ class RequestValidationService( } fun validateSitesToCreate( - requestBridges: Collection, + requests: Collection, ): Map>> { - val requestedParentBpns = requestBridges.map { it.bpnlParent } + val requestedParentBpns = requests.map { it.bpnlParent } val existingParentBpns = legalEntityRepository.findDistinctByBpnIn(requestedParentBpns).map { it.bpn }.toSet() - return requestBridges.associate { bridge -> + return requests.associate { request -> val validationErrors = - validateParentBpnExists(bridge.bpnlParent, bridge.request.getRequestKey(), existingParentBpns, SiteCreateError.LegalEntityNotFound) - bridge.request to validationErrors + validateParentBpnExists(request.bpnlParent, request.getRequestKey(), existingParentBpns, SiteCreateError.LegalEntityNotFound) + request to validationErrors }.filterValues { it.isNotEmpty() } } @@ -391,8 +483,8 @@ class RequestValidationService( ) { private val existingTypes = metadataService.getIdentifiers(addressDtos).map { it.technicalKey }.toSet() - fun validate(address: IBaseLogisticAddressDto, entityKey: RequestWithKey): Collection> { - val requestedTypes = address.identifiers.map { it.type } + fun validate(addressDto: IBaseLogisticAddressDto, entityKey: RequestWithKey): Collection> { + val requestedTypes = addressDto.identifiers.map { it.type } val missingTypes = requestedTypes - existingTypes return missingTypes.map { @@ -433,8 +525,8 @@ class RequestValidationService( private val errorCode: ERROR ) { - fun validate(bpnToUpdate: String): Collection> { - return if (!existingBpns.contains(bpnToUpdate)) + fun validate(bpnToUpdate: String?): Collection> { + return if (bpnToUpdate != null && !existingBpns.contains(bpnToUpdate)) listOf(ErrorInfo(errorCode, "Business Partner with BPN '$bpnToUpdate' can't be updated as it doesn't exist", bpnToUpdate)) else emptyList() @@ -573,15 +665,9 @@ class RequestValidationService( ) data class LegalEntityBridge( - val legalEntity: IBaseLegalEntityDto?, - val request: RequestWithKey - ) - - data class LegalEntityUpdateBridge( - val legalEntity: IBaseLegalEntityDto, val request: RequestWithKey, - val bpnL: String + val bpnL: String? ) data class AddressBridge( @@ -591,12 +677,6 @@ class RequestValidationService( val bpnA: String? ) - data class SiteCreateBridge( - - val request: RequestWithKey, - val bpnlParent: String - ) - data class SiteUpdateBridge( val request: RequestWithKey, diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskEntryBpnMapping.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskEntryBpnMapping.kt index 88d02fed7..c22cde427 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskEntryBpnMapping.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskEntryBpnMapping.kt @@ -37,7 +37,9 @@ class TaskEntryBpnMapping(taskEntries: List, bpnReq private fun readRequestMappings(taskEntries: List, bpnRequestIdentifierRepository: BpnRequestIdentifierRepository ): MutableMap { val references = taskEntries.mapNotNull { it.businessPartner.legalEntity?.bpnLReference } + + taskEntries.mapNotNull { it.businessPartner.legalEntity?.legalAddress?.bpnAReference } + taskEntries.mapNotNull { it.businessPartner.site?.bpnSReference } + + taskEntries.mapNotNull { it.businessPartner.site?.mainAddress?.bpnAReference } + taskEntries.mapNotNull { it.businessPartner.address?.bpnAReference } val usedRequestIdentifiers: Collection = references.map { it.referenceValue } @@ -49,15 +51,21 @@ class TaskEntryBpnMapping(taskEntries: List, bpnReq return bpnByRequestIdentifier.toMutableMap() } - fun getBpn(bpnLReference: BpnReferenceDto): String? { + fun getBpn(bpnReference: BpnReferenceDto): String? { - return if (bpnLReference.referenceType == BpnReferenceType.BpnRequestIdentifier) { - bpnByRequestIdentifier[bpnLReference.referenceValue] + return if (bpnReference.referenceType == BpnReferenceType.BpnRequestIdentifier) { + bpnByRequestIdentifier[bpnReference.referenceValue] } else { - bpnLReference.referenceValue + bpnReference.referenceValue } } + fun hasBpnFor(bpnReference: BpnReferenceDto?): Boolean { + + return bpnReference != null && bpnByRequestIdentifier.containsKey(bpnReference.referenceValue) + } + + fun addMapping(bpnLReference: BpnReferenceDto, bpn: String) { createdBpnByRequestIdentifier[bpnLReference.referenceValue] = bpn diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepBuildService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepBuildService.kt index f6b4936eb..7753a99c1 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepBuildService.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepBuildService.kt @@ -76,7 +76,10 @@ class TaskStepBuildService( if (businessPartnerDto.site != null) { siteEntity = upsertSite(businessPartnerDto.site, legalEntity, taskEntryBpnMapping, businessPartnerDto) siteResult = businessPartnerDto.site!!.copy( - bpnSReference = BpnReferenceDto(referenceValue = siteEntity.bpn, referenceType = BpnReferenceType.Bpn) + bpnSReference = BpnReferenceDto(referenceValue = siteEntity.bpn, referenceType = BpnReferenceType.Bpn), + mainAddress = businessPartnerDto.site!!.mainAddress!!.copy( + bpnAReference = BpnReferenceDto(referenceValue = siteEntity.mainAddress.bpn, referenceType = BpnReferenceType.Bpn) + ) ) genericBpnA = siteEntity.mainAddress.bpn } diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveService.kt index 20724d1ae..bf7194bb6 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveService.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveService.kt @@ -63,7 +63,7 @@ class TaskStepFetchAndReserveService( val taskEntryBpnMapping = TaskEntryBpnMapping(taskEntries, bpnRequestIdentifierRepository) - val invalidTaskResultsByTaskEntry = validateTasks(taskEntries) + val invalidTaskResultsByTaskEntry = validateTasks(taskEntries, taskEntryBpnMapping) val taskResults = taskEntries.map { @@ -91,23 +91,10 @@ class TaskStepFetchAndReserveService( } } - private fun validateTasks( - taskEntries: List + private fun validateTasks( taskEntries: List, requestMappings: TaskEntryBpnMapping ): Map { - val legalEntitiesToCreate = taskEntries - .filter { it.businessPartner.legalEntity?.bpnLReference?.referenceType == BpnReferenceType.BpnRequestIdentifier } - val legalEntitiesToUpdate = taskEntries - .filter { it.businessPartner.legalEntity?.bpnLReference?.referenceType == BpnReferenceType.Bpn } - val sitesToCreate = taskEntries - .filter { it.businessPartner.site?.bpnSReference?.referenceType == BpnReferenceType.BpnRequestIdentifier } - val sitesToUpdate = taskEntries - .filter { it.businessPartner.site?.bpnSReference?.referenceType == BpnReferenceType.Bpn } - - val validationErrorsByTaskEntry = requestValidationService.validateLegalEntitiesToCreateFromOrchestrator(legalEntitiesToCreate) + - requestValidationService.validateLegalEntitiesToUpdateFromOrchestrator(legalEntitiesToUpdate)+ - requestValidationService.validateSitesToCreateFromOrchestrator(sitesToCreate) + - requestValidationService.validateSitesToUpdateFromOrchestrator(sitesToUpdate) + val validationErrorsByTaskEntry = requestValidationService.validateTasksFromOrchestrator(taskEntries, requestMappings) val taskResultsByTaskEntry = taskEntries .associateWith { taskEntry -> diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt index ff43c0970..c24d9b3b3 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt @@ -37,7 +37,6 @@ import org.eclipse.tractusx.orchestrator.api.model.SiteDto import org.eclipse.tractusx.orchestrator.api.model.SiteStateDto import org.eclipse.tractusx.orchestrator.api.model.StreetDto import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest @@ -239,7 +238,7 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( val fullBpWithLegalEntity = minFullBusinessPartner().copy( legalEntity = minValidLegalEntity( bpnLReference = leRef1, - bpnAReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) + bpnAReference = BpnReferenceDto(referenceValue = "444", referenceType = BpnRequestIdentifier) ).copy( identifiers = listOf( legalEntityIdentifierDto(leRef1.referenceValue, 1L, BusinessPartnerVerboseValues.identifierType1), @@ -397,7 +396,7 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( } @Test - fun `update legal entity with all fields`() { + fun `update legal entity with all fields by BPN`() { val leRefValue = "123" val leAddressRefValue = "222" @@ -415,10 +414,10 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( legalEntity = createResult[0].businessPartner?.legalEntity?.copy( hasChanged = true, legalName = "Changed Legal Entity", - legalAddress = createResult[0].businessPartner?.legalEntity?.legalAddress?.copy( - hasChanged = true, - name = "Changed Address Name" - ) + legalAddress = createResult[0].businessPartner?.legalEntity?.legalAddress?.copy( + hasChanged = true, + name = "Changed Address Name" + ) ) ) val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_2", businessPartner = updatedFullBpLegalEntity!!) @@ -430,6 +429,41 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( compareLegalEntity(updatedLegalEntity, updateResult[0].businessPartner?.legalEntity) } + @Test + fun `update legal entity with all fields by BpnRequestIdentifier`() { + + val leRefValue = "123" + val leAddressRefValue = "222" + val createLegalEntity = minFullBusinessPartner().copy( + legalEntity = fullValidLegalEntity( + bpnLReference = BpnReferenceDto(referenceValue = leRefValue, referenceType = BpnRequestIdentifier), + bpnAReference = BpnReferenceDto(referenceValue = leAddressRefValue, referenceType = BpnRequestIdentifier) + ) + ) + val createResult = upsertGoldenRecordIntoPool(taskId = "TASK_1", businessPartner = createLegalEntity) + assertThat(createResult[0].taskId).isEqualTo("TASK_1") + assertThat(createResult[0].errors.size).isEqualTo(0) + + // Update legal entity with same BpnRequestIdentifier + val updatedFullBpLegalEntity = createLegalEntity.copy( + legalEntity = createLegalEntity.legalEntity?.copy( + hasChanged = true, + legalName = "Changed Legal Entity", + legalAddress = createLegalEntity.legalEntity?.legalAddress?.copy( + hasChanged = true, + name = "Changed Address Name" + ) + ) + ) + val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_2", businessPartner = updatedFullBpLegalEntity) + assertThat(updateResult[0].taskId).isEqualTo("TASK_2") + assertThat(updateResult[0].errors.size).isEqualTo(0) + + val updatedLegalEntity = poolClient.legalEntities.getLegalEntity(updateResult[0].businessPartner?.legalEntity?.bpnLReference?.referenceValue!!) + assertThat(updatedLegalEntity.legalEntity.legalName).isEqualTo("Changed Legal Entity") + compareLegalEntity(updatedLegalEntity, updateResult[0].businessPartner?.legalEntity) + } + @Test fun `update legal entity invalid identifier type `() { @@ -510,7 +544,7 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( val updatedFullBpLegalEntity = createResult[0].businessPartner?.copy( legalEntity = createResult[0].businessPartner?.legalEntity?.copy( - bpnLReference= BpnReferenceDto(referenceValue = "InvalidBPN", referenceType = Bpn), + bpnLReference = BpnReferenceDto(referenceValue = "InvalidBPN", referenceType = Bpn), hasChanged = true, legalName = "Changed Legal Entity", legalAddress = createResult[0].businessPartner?.legalEntity?.legalAddress?.copy( @@ -739,16 +773,18 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( ) ), - ) + ) val createResult = upsertGoldenRecordIntoPool(taskId = "TASK_1", businessPartner = fullBpWithSite) assertThat(createResult[0].taskId).isEqualTo("TASK_1") - val errorDescriptions = createResult[0].errors.map{it.description} - assertThat(errorDescriptions).containsExactlyInAnyOrder("Address administrative area level1 'Invalid' does not exist" - ,"Address administrative area level1 'InvalidAdditional' does not exist" - ,"Address Identifier Type 'InvalidKey1' does not exist" - ,"Address Identifier Type 'InvalidKey2' does not exist") + val errorDescriptions = createResult[0].errors.map { it.description } + assertThat(errorDescriptions).containsExactlyInAnyOrder( + "Address administrative area level1 'Invalid' does not exist", + "Address administrative area level1 'InvalidAdditional' does not exist", + "Address Identifier Type 'InvalidKey1' does not exist", + "Address Identifier Type 'InvalidKey2' does not exist" + ) } @Test @@ -807,10 +843,10 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( val createdSite = poolClient.sites.getSite(createResult[0].businessPartner?.site?.bpnSReference?.referenceValue!!) assertThat(createdSite.site.name).isEqualTo(fullBpWithSite.site?.name) - val updateCopy = fullBpWithSite.copy( - site = fullBpWithSite.site?.copy(name = "ChangedName", hasChanged = true) + val updateCopy = createResult[0].businessPartner?.copy( + site = createResult[0].businessPartner?.site?.copy(name = "ChangedName", hasChanged = true) ) - val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_1", businessPartner = updateCopy) + val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_1", businessPartner = updateCopy!!) val updatedSite = poolClient.sites.getSite(updateResult[0].businessPartner?.site?.bpnSReference?.referenceValue!!) compareSite(updatedSite, updateResult[0].businessPartner?.site) } @@ -836,9 +872,11 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( assertThat(createdSite.site.name).isEqualTo(fullBpWithSite.site?.name) val updateCopy = fullBpWithSite.copy( - site = fullBpWithSite.site?.copy(name = "ChangedName" - , hasChanged = true - , bpnSReference = BpnReferenceDto(referenceValue = "InvalidBPN", referenceType = Bpn),) + site = fullBpWithSite.site?.copy( + name = "ChangedName", + hasChanged = true, + bpnSReference = BpnReferenceDto(referenceValue = "InvalidBPN", referenceType = Bpn), + ) ) val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_1", businessPartner = updateCopy) assertThat(updateResult[0].errors).hasSize(1) @@ -848,13 +886,13 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( @Test fun `update Site with invalid address administration level 1 and invalid identifier`() { - val bpnASiteReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) - val additionalReference = BpnReferenceDto(referenceValue = "7777", referenceType = BpnRequestIdentifier) + val bpnASiteReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) + val additionalReference = BpnReferenceDto(referenceValue = "7777", referenceType = BpnRequestIdentifier) val siteRefValue = "siteRefValue" val fullBpWithSite = minFullBusinessPartner().copy( legalEntity = minValidLegalEntity( bpnLReference = BpnReferenceDto(referenceValue = "123", referenceType = BpnRequestIdentifier), - bpnAReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) + bpnAReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) ), site = minValidSite( bpnSReference = BpnReferenceDto(referenceValue = siteRefValue, referenceType = BpnRequestIdentifier), @@ -890,31 +928,32 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( ) val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_2", businessPartner = updatedFullBpSite!!) assertThat(updateResult[0].taskId).isEqualTo("TASK_2") - val errorDescriptions = updateResult[0].errors.map{it.description} - assertThat(errorDescriptions).containsExactlyInAnyOrder("Address administrative area level1 'Invalid' does not exist" - ,"Address administrative area level1 'InvalidAdditional' does not exist" - ,"Address Identifier Type 'InvalidKey1' does not exist" - ,"Address Identifier Type 'InvalidKey2' does not exist") + val errorDescriptions = updateResult[0].errors.map { it.description } + assertThat(errorDescriptions).containsExactlyInAnyOrder( + "Address administrative area level1 'Invalid' does not exist", + "Address administrative area level1 'InvalidAdditional' does not exist", + "Address Identifier Type 'InvalidKey1' does not exist", + "Address Identifier Type 'InvalidKey2' does not exist" + ) } @Test fun `update Site with duplicated identifiers`() { - val bpnAReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) - val mainAddressRefValue = "mainAddressRefValue" - val additionalAddressReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) + val mainAddressRefValue = BpnReferenceDto(referenceValue = "A222", referenceType = BpnRequestIdentifier) + val additionalAddressReference = BpnReferenceDto(referenceValue = "A333", referenceType = BpnRequestIdentifier) val fullBpWithSite = minFullBusinessPartner().copy( legalEntity = minValidLegalEntity( - bpnLReference = BpnReferenceDto(referenceValue = "123", referenceType = BpnRequestIdentifier), - bpnAReference = BpnReferenceDto(referenceValue = "222", referenceType = BpnRequestIdentifier) + bpnLReference = BpnReferenceDto(referenceValue = "LE123", referenceType = BpnRequestIdentifier), + bpnAReference = BpnReferenceDto(referenceValue = "A111LE", referenceType = BpnRequestIdentifier) ), site = minValidSite( bpnSReference = BpnReferenceDto(referenceValue = "siteRefValue", referenceType = BpnRequestIdentifier), - bpnAReference = BpnReferenceDto(referenceValue = mainAddressRefValue, referenceType = BpnRequestIdentifier) + bpnAReference = mainAddressRefValue ).copy( - mainAddress = minLogisticAddress(bpnAReference).copy( + mainAddress = minLogisticAddress(mainAddressRefValue).copy( identifiers = listOf( - addressIdentifierDto(bpnAReference.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + addressIdentifierDto(mainAddressRefValue.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), ) ) ), @@ -937,16 +976,59 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( hasChanged = true, mainAddress = createResult[0].businessPartner?.site?.mainAddress?.copy( identifiers = listOf( - addressIdentifierDto(bpnAReference.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + addressIdentifierDto(mainAddressRefValue.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), addressIdentifierDto(additionalAddressReference.referenceValue, 2L, TypeKeyNameVerboseDto(addressIdentifierTypeDto2.technicalKey, "")), ) ) ), - ) + ) val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_2", businessPartner = updateCopy!!) assertThat(updateResult[0].errors).hasSize(1) - assertThat(updateResult[0].errors[0].description).isEqualTo("Duplicate Address Identifier: Value 'value_222_2' of type 'ADDR_KEY_TWO'") + assertThat(updateResult[0].errors[0].description).isEqualTo("Duplicate Address Identifier: Value 'value_A333_2' of type 'ADDR_KEY_TWO'") + } + + @Test + fun `update Site with same reference`() { + + val mainAddressRefValue = BpnReferenceDto(referenceValue = "A222", referenceType = BpnRequestIdentifier) + val additionalAddressReference = BpnReferenceDto(referenceValue = "A333", referenceType = BpnRequestIdentifier) + val fullBpWithSite = minFullBusinessPartner().copy( + legalEntity = minValidLegalEntity( + bpnLReference = BpnReferenceDto(referenceValue = "LE123", referenceType = BpnRequestIdentifier), + bpnAReference = BpnReferenceDto(referenceValue = "A111LE", referenceType = BpnRequestIdentifier) + ), + site = minValidSite( + bpnSReference = BpnReferenceDto(referenceValue = "siteRefValue", referenceType = BpnRequestIdentifier), + bpnAReference = mainAddressRefValue + ).copy( + mainAddress = minLogisticAddress(mainAddressRefValue).copy( + identifiers = listOf( + addressIdentifierDto(mainAddressRefValue.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + ) + ) + ), + address = minLogisticAddress( + bpnAReference = additionalAddressReference, + ).copy( + identifiers = listOf( + addressIdentifierDto(mainAddressRefValue.referenceValue, 2L, TypeKeyNameVerboseDto(addressIdentifierTypeDto2.technicalKey, "")), + ) + ) + ) + + val createResult = upsertGoldenRecordIntoPool(taskId = "TASK_1", businessPartner = fullBpWithSite) + val createdSite = poolClient.sites.getSite(createResult[0].businessPartner?.site?.bpnSReference?.referenceValue!!) + assertThat(createdSite.site.name).isEqualTo(fullBpWithSite.site?.name) + + val updateCopy = fullBpWithSite.copy( + site = fullBpWithSite.site?.copy( + name = "ChangedName", + hasChanged = true, + ), + ) + val updateResult = upsertGoldenRecordIntoPool(taskId = "TASK_2", businessPartner = updateCopy) + assertThat(updateResult[0].errors).hasSize(0) } @Test @@ -977,44 +1059,148 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( } @Test - @Disabled - fun `create multiple legal entity without legal name`() { + fun `create multiple legal entity `() { - val referenceIds = (1.. 10000).toList() - val fullBpWithLegalEntity = referenceIds.map{ + val countToTest = 1000 + val referenceIds = (1..countToTest).toList() + val fullBpWithLegalEntity = referenceIds.map { minFullBusinessPartner().copy( legalEntity = fullValidLegalEntity( - bpnLReference = BpnReferenceDto(referenceValue = ""+it, referenceType = BpnRequestIdentifier), - bpnAReference = BpnReferenceDto(referenceValue = "address"+it, referenceType = BpnRequestIdentifier) + bpnLReference = BpnReferenceDto(referenceValue = "" + it, referenceType = BpnRequestIdentifier), + bpnAReference = BpnReferenceDto(referenceValue = "address" + it, referenceType = BpnRequestIdentifier) ) ) } val taskSteps = multipleTaskStep(fullBpWithLegalEntity) val createResults = cleaningStepService.upsertGoldenRecordIntoPool(taskSteps) - assertThat(createResults).hasSize(10000) + assertThat(createResults).hasSize(countToTest) assertThat(createResults.filter { it.errors.isNotEmpty() }).hasSize(0) val updateResults = cleaningStepService.upsertGoldenRecordIntoPool(taskSteps) - assertThat(updateResults).hasSize(10000) + assertThat(updateResults).hasSize(countToTest) assertThat(updateResults.filter { it.errors.isNotEmpty() }).hasSize(0) - val referenceIds2 = (10001.. 20000).toList() - val fullBpWithLegalEntity2 = referenceIds2.map{ + val referenceIds2 = ((countToTest + 1)..(2 * countToTest)).toList() + val fullBpWithLegalEntity2 = referenceIds2.map { minFullBusinessPartner().copy( legalEntity = fullValidLegalEntity( - bpnLReference = BpnReferenceDto(referenceValue = ""+it, referenceType = BpnRequestIdentifier), - bpnAReference = BpnReferenceDto(referenceValue = "address"+it, referenceType = BpnRequestIdentifier) + bpnLReference = BpnReferenceDto(referenceValue = "" + it, referenceType = BpnRequestIdentifier), + bpnAReference = BpnReferenceDto(referenceValue = "address" + it, referenceType = BpnRequestIdentifier) ) ) } val taskSteps2 = multipleTaskStep(fullBpWithLegalEntity2) val createResults2 = cleaningStepService.upsertGoldenRecordIntoPool(taskSteps2) - assertThat(createResults2).hasSize(10000) + assertThat(createResults2).hasSize(countToTest) assertThat(createResults2.filter { it.errors.isNotEmpty() }).hasSize(0) } + @Test + fun `update legal entity and create legal entity in one request`() { + + val leCreateRef1 = BpnReferenceDto(referenceValue = "LE111", referenceType = BpnRequestIdentifier) + val leCreateAddressRef1 = BpnReferenceDto(referenceValue = "LE111A22", referenceType = BpnRequestIdentifier) + val createLegalEntity1 = minFullBusinessPartner().copy( + legalEntity = minValidLegalEntity(bpnLReference = leCreateRef1, bpnAReference = leCreateAddressRef1).copy( + identifiers = listOf( + legalEntityIdentifierDto(leCreateRef1.referenceValue, 1L, BusinessPartnerVerboseValues.identifierType1), + legalEntityIdentifierDto(leCreateRef1.referenceValue, 2L, BusinessPartnerVerboseValues.identifierType2) + ) + ) + ) + val createResult = upsertGoldenRecordIntoPool(taskId = "TASK_1", businessPartner = createLegalEntity1) + assertThat(createResult[0].errors.size).isEqualTo(0) + + val legalEntityIdentifier = legalEntityIdentifierDto(leCreateRef1.referenceValue, 3L, BusinessPartnerVerboseValues.identifierType3) + val updatedFullBpLegalEntity = createResult[0].businessPartner?.copy( + legalEntity = createResult[0].businessPartner?.legalEntity?.copy( + identifiers = listOf( + legalEntityIdentifier, // use identifier in update + legalEntityIdentifierDto(leCreateRef1.referenceValue, 2L, BusinessPartnerVerboseValues.identifierType2) + ), + hasChanged = true, + legalName = "Changed Legal Entity" + ) + ) + val leCreateRef2 = BpnReferenceDto(referenceValue = "LE222", referenceType = BpnRequestIdentifier) + val leCreateAddressRef2 = BpnReferenceDto(referenceValue = "LE222A333", referenceType = BpnRequestIdentifier) + val createLegalEntity2 = minFullBusinessPartner().copy( + legalEntity = minValidLegalEntity(bpnLReference = leCreateRef2, bpnAReference = leCreateAddressRef2).copy( + identifiers = listOf( + legalEntityIdentifier, // use same identifier in create + legalEntityIdentifierDto(leCreateRef2.referenceValue, 1L, BusinessPartnerVerboseValues.identifierType1) + ) + ) + ) + val updateTask = TaskStepReservationEntryDto(taskId = "TASK_2", businessPartner = updatedFullBpLegalEntity!!) + val createTask2 = TaskStepReservationEntryDto(taskId = "TASK_3", businessPartner = createLegalEntity2) + val updateResult = cleaningStepService.upsertGoldenRecordIntoPool(listOf(updateTask, createTask2)) + + assertThat(updateResult[0].taskId).isEqualTo("TASK_2") + assertThat(updateResult[1].taskId).isEqualTo("TASK_3") + assertThat(updateResult[0].errors.size).isEqualTo(1) + assertThat(updateResult[1].errors.size).isEqualTo(1) + assertThat(updateResult[0].errors[0].description).isEqualTo("Duplicate Legal Entity Identifier: Value 'value_LE111_3' of type 'VAT_FR'") + } + + @Test + fun `create legal and create site in one request`() { + + val leCreateRef1 = BpnReferenceDto(referenceValue = "LE111", referenceType = BpnRequestIdentifier) + val leCreateAddressRef1 = BpnReferenceDto(referenceValue = "LE111A11", referenceType = BpnRequestIdentifier) + val additionalAddressLeRef1 = BpnReferenceDto(referenceValue = "LE111A33", referenceType = BpnRequestIdentifier) + val createLegalEntity1 = minFullBusinessPartner().copy( + legalEntity = minValidLegalEntity(bpnLReference = leCreateRef1, bpnAReference = leCreateAddressRef1).copy( + legalAddress = minLogisticAddress(leCreateAddressRef1).copy( + identifiers = listOf( + addressIdentifierDto(leCreateAddressRef1.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + ) + ) + ), + address = minLogisticAddress(additionalAddressLeRef1).copy( + identifiers = listOf( + addressIdentifierDto(additionalAddressLeRef1.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + ) + ) + ) + + val leCreateRef2 = BpnReferenceDto(referenceValue = "LE222", referenceType = BpnRequestIdentifier) + val leCreateAddressRef2 = BpnReferenceDto(referenceValue = "LE222A22", referenceType = BpnRequestIdentifier) + val createSiteRef2 = BpnReferenceDto(referenceValue = "SE333", referenceType = BpnRequestIdentifier) + val mainAddressRef2 = BpnReferenceDto(referenceValue = "SE333A66", referenceType = BpnRequestIdentifier) + val additionalAddressSiteRef2 = BpnReferenceDto(referenceValue = "SE333A88", referenceType = BpnRequestIdentifier) + val createSite1 = minFullBusinessPartner().copy( + legalEntity = minValidLegalEntity(bpnLReference = leCreateRef2, bpnAReference = leCreateAddressRef2).copy( + legalAddress = minLogisticAddress(leCreateAddressRef2).copy( + identifiers = listOf( + addressIdentifierDto(leCreateAddressRef2.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + ) + ) + ), + site = minValidSite(bpnSReference = createSiteRef2, bpnAReference = mainAddressRef2).copy( + mainAddress = minLogisticAddress(mainAddressRef2).copy( + identifiers = listOf( + addressIdentifierDto(mainAddressRef2.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + ) + ) + ), + address = minLogisticAddress(additionalAddressSiteRef2).copy( + identifiers = listOf( + addressIdentifierDto(leCreateAddressRef1.referenceValue, 1L, TypeKeyNameVerboseDto(addressIdentifierTypeDto1.technicalKey, "")), + ) + ) + ) + val updateTask = TaskStepReservationEntryDto(taskId = "TASK_1", businessPartner = createLegalEntity1) + val createTask2 = TaskStepReservationEntryDto(taskId = "TASK_2", businessPartner = createSite1) + val updateResult = cleaningStepService.upsertGoldenRecordIntoPool(listOf(updateTask, createTask2)) + assertThat(updateResult[0].taskId).isEqualTo("TASK_1") + assertThat(updateResult[1].taskId).isEqualTo("TASK_2") + assertThat(updateResult[0].errors.size).isEqualTo(0) + assertThat(updateResult[1].errors.size).isEqualTo(1) + assertThat(updateResult[1].errors[0].description).isEqualTo("Duplicate Address Identifier: Value 'value_LE111A11_1' of type 'ADDR_KEY_ONE'") + } fun upsertGoldenRecordIntoPool(taskId: String, businessPartner: BusinessPartnerFullDto): List { @@ -1034,7 +1220,7 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( fun multipleTaskStep(businessPartners: List): List { - return businessPartners.map{ + return businessPartners.map { TaskStepReservationEntryDto( taskId = it.legalEntity?.bpnLReference?.referenceValue!!, businessPartner = it @@ -1284,7 +1470,7 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( val verboseAlternAddress = verboseAddress.alternativePostalAddress val alternAddress = address?.alternativePostalAddress assertThat(verboseAlternAddress).usingRecursiveComparison() - .ignoringFields(AlternativePostalAddressDto::country.name , AlternativePostalAddressDto::administrativeAreaLevel1.name) + .ignoringFields(AlternativePostalAddressDto::country.name, AlternativePostalAddressDto::administrativeAreaLevel1.name) .isEqualTo(alternAddress) assertThat(verboseAlternAddress?.country?.technicalKey?.name).isEqualTo(alternAddress?.country?.name) assertThat(verboseAlternAddress?.administrativeAreaLevel1?.regionCode).isEqualTo(alternAddress?.administrativeAreaLevel1) @@ -1298,8 +1484,8 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( sortedVerboseStates.indices.forEach { assertThat(sortedVerboseStates[it].type.technicalKey.name).isEqualTo(sortedStates!![it].type.name) assertThat(sortedVerboseStates[it]).usingRecursiveComparison() - .withEqualsForFields(isEqualToIgnoringMilliseconds(), AddressStateDto::validTo.name ) - .withEqualsForFields(isEqualToIgnoringMilliseconds(), AddressStateDto::validFrom.name ) + .withEqualsForFields(isEqualToIgnoringMilliseconds(), AddressStateDto::validTo.name) + .withEqualsForFields(isEqualToIgnoringMilliseconds(), AddressStateDto::validFrom.name) .ignoringFields(AddressStateDto::type.name).isEqualTo(sortedStates[it]) } } @@ -1325,7 +1511,7 @@ class TaskStepFetchAndReserveServiceTest @Autowired constructor( sortedVerboseStates.indices.forEach { assertThat(sortedVerboseStates[it].type.technicalKey.name).isEqualTo(sortedStates[it].type.name) assertThat(sortedVerboseStates[it]).usingRecursiveComparison() - .withEqualsForFields(isEqualToIgnoringMilliseconds(), ILegalEntityStateDto::validTo.name ) + .withEqualsForFields(isEqualToIgnoringMilliseconds(), ILegalEntityStateDto::validTo.name) .withEqualsForFields(isEqualToIgnoringMilliseconds(), ILegalEntityStateDto::validFrom.name) .ignoringFields(ILegalEntityStateDto::type.name) .isEqualTo(sortedStates[it])