Skip to content

Commit

Permalink
feat(api): #172 Rename BPN fields - fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-exxcellent committed May 25, 2023
1 parent 60afcd0 commit a11a942
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PoolUpdateService(
val updateRequests = entriesToUpdate.map {
LegalEntityPartnerUpdateRequest(
legalEntity = it.legalEntity,
bpn = it.bpn!!
bpnl = it.bpn!!
)
}

Expand Down Expand Up @@ -90,7 +90,7 @@ class PoolUpdateService(
val updateRequests = entriesToUpdate.map {
SitePartnerUpdateRequest(
site = it.site,
bpn = it.bpn!!
bpns = it.bpn!!
)
}

Expand Down Expand Up @@ -142,7 +142,7 @@ class PoolUpdateService(
val updateRequests = entriesToUpdate.map {
AddressPartnerUpdateRequest(
address = it.address,
bpn = it.bpn!!
bpna = it.bpn!!
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
@Schema(name = "AddressPartnerUpdateRequest", description = "Request for updating a business partner record of type address")
data class AddressPartnerUpdateRequest(
@Schema(description = "Business Partner Number of this address")
val bpn: String,
val bpna: String,

@field:JsonUnwrapped
val address: LogisticAddressDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
@Schema(name = "LegalEntityUpdateRequest", description = "Request for updating a business partner record of type legal entity")
data class LegalEntityPartnerUpdateRequest(
@Schema(description = "Business Partner Number")
val bpn: String,
val bpnl: String,

@field:JsonUnwrapped
val legalEntity: LegalEntityDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
@Schema(name = "SitePartnerUpdateRequest", description = "Request for updating a business partner record of type site")
data class SitePartnerUpdateRequest(
@Schema(description = "Business Partner Number of this site")
val bpn: String,
val bpns: String,

@field:JsonUnwrapped
val site: SiteDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import org.eclipse.tractusx.bpdm.common.dto.response.type.TypeKeyNameDto
import org.eclipse.tractusx.bpdm.common.dto.saas.BusinessPartnerSaas
import org.eclipse.tractusx.bpdm.common.dto.saas.LegalFormSaas
import org.eclipse.tractusx.bpdm.common.dto.saas.TypeKeyNameUrlSaas
import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toLogisticAddressDto
import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toLegalEntityDto
import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toLogisticAddressDto
import org.eclipse.tractusx.bpdm.common.service.SaasMappings.toSiteDto
import org.eclipse.tractusx.bpdm.pool.api.model.request.*
import org.eclipse.tractusx.bpdm.pool.component.saas.dto.BusinessPartnerWithBpn
Expand Down Expand Up @@ -57,7 +57,7 @@ class SaasToRequestMapper {

fun toLegalEntityUpdateRequest(partnerWithBpn: BusinessPartnerWithBpn): LegalEntityPartnerUpdateRequest {
return LegalEntityPartnerUpdateRequest(
bpn = partnerWithBpn.bpn,
bpnl = partnerWithBpn.bpn,
legalEntity = partnerWithBpn.partner.toLegalEntityDto()
)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ class SaasToRequestMapper {

fun toSiteUpdateRequest(partnerWithBpn: BusinessPartnerWithBpn): SitePartnerUpdateRequest {
return SitePartnerUpdateRequest(
bpn = partnerWithBpn.bpn,
bpns = partnerWithBpn.bpn,
site = partnerWithBpn.partner.toSiteDto()
)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ class SaasToRequestMapper {

fun toAddressUpdateRequest(partnerWithBpn: BusinessPartnerWithBpn): AddressPartnerUpdateRequest {
return AddressPartnerUpdateRequest(
bpn = partnerWithBpn.bpn,
bpna = partnerWithBpn.bpn,
address = partnerWithBpn.partner.toLogisticAddressDto()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class BusinessPartnerBuildService(
val legalEntityMetadataMap = metadataMappingService.mapRequests(requests.map { it.legalEntity })
val addressMetadataMap = metadataMappingService.mapRequests(requests.map { it.legalEntity.legalAddress })

val bpnsToFetch = requests.map { it.bpn }
val bpnsToFetch = requests.map { it.bpnl }
val legalEntities = legalEntityRepository.findDistinctByBpnIn(bpnsToFetch)
businessPartnerFetchService.fetchDependenciesWithLegalAddress(legalEntities)

Expand All @@ -172,7 +172,7 @@ class BusinessPartnerBuildService(
ErrorInfo(LegalEntityUpdateError.LegalEntityNotFound, "Legal entity $it not updated: BPNL not found", it)
}

val requestByBpnMap = requests.associateBy { it.bpn }
val requestByBpnMap = requests.associateBy { it.bpnl }
legalEntities.forEach {
val request = requestByBpnMap.get(it.bpn)!!
updateLegalEntity(it, request.legalEntity, legalEntityMetadataMap)
Expand All @@ -193,7 +193,7 @@ class BusinessPartnerBuildService(

val addressMetadataMap = metadataMappingService.mapRequests(requests.map { it.site.mainAddress })

val bpnsToFetch = requests.map { it.bpn }
val bpnsToFetch = requests.map { it.bpns }
val sites = siteRepository.findDistinctByBpnIn(bpnsToFetch)

val bpnsNotFetched = bpnsToFetch.minus(sites.map { it.bpn }.toSet())
Expand All @@ -204,7 +204,7 @@ class BusinessPartnerBuildService(
changelogService.createChangelogEntries(sites.map { ChangelogEntryDto(it.bpn, ChangelogType.UPDATE, ChangelogSubject.SITE) })
changelogService.createChangelogEntries(sites.map { ChangelogEntryDto(it.mainAddress.bpn, ChangelogType.UPDATE, ChangelogSubject.ADDRESS) })

val requestByBpnMap = requests.associateBy { it.bpn }
val requestByBpnMap = requests.associateBy { it.bpns }
sites.forEach {
val request = requestByBpnMap[it.bpn]!!
updateSite(it, request.site)
Expand All @@ -218,14 +218,14 @@ class BusinessPartnerBuildService(
fun updateAddresses(requests: Collection<AddressPartnerUpdateRequest>): AddressPartnerUpdateResponseWrapper {
logger.info { "Update ${requests.size} business partner addresses" }

val validAddresses = logisticAddressRepository.findDistinctByBpnIn(requests.map { it.bpn })
val validAddresses = logisticAddressRepository.findDistinctByBpnIn(requests.map { it.bpna })
val validBpns = validAddresses.map { it.bpn }.toHashSet()
val (validRequests, invalidRequests) = requests.partition { validBpns.contains(it.bpn) }
val (validRequests, invalidRequests) = requests.partition { validBpns.contains(it.bpna) }
val errors = invalidRequests.map {
ErrorInfo(AddressUpdateError.AddressNotFound, "Address ${it.bpn} not updated: BPNA not found", it.bpn)
ErrorInfo(AddressUpdateError.AddressNotFound, "Address ${it.bpna} not updated: BPNA not found", it.bpna)
}

val requestByBpnMap = requests.associateBy { it.bpn }
val requestByBpnMap = requests.associateBy { it.bpna }
val metadataMap = metadataMappingService.mapRequests(validRequests.map { it.address })

validAddresses.forEach { updateLogisticAddress(it, requestByBpnMap[it.bpn]!!.address, metadataMap) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ class AddressControllerIT @Autowired constructor(
)

val toUpdate = listOf(
RequestValues.addressPartnerUpdate1.copy(bpn = bpnA2),
RequestValues.addressPartnerUpdate2.copy(bpn = bpnA3),
RequestValues.addressPartnerUpdate3.copy(bpn = bpnA1)
RequestValues.addressPartnerUpdate1.copy(bpna = bpnA2),
RequestValues.addressPartnerUpdate2.copy(bpna = bpnA3),
RequestValues.addressPartnerUpdate3.copy(bpna = bpnA1)
)

val response = poolClient.addresses().updateAddresses(toUpdate)
Expand Down Expand Up @@ -417,9 +417,9 @@ class AddressControllerIT @Autowired constructor(
val firstInvalidBpn = "BPNLXXXXXXXX"
val secondInvalidBpn = "BPNAXXXXXXXX"
val toUpdate = listOf(
RequestValues.addressPartnerUpdate2.copy(bpn = bpnA1),
RequestValues.addressPartnerUpdate2.copy(bpn = firstInvalidBpn),
RequestValues.addressPartnerUpdate3.copy(bpn = secondInvalidBpn)
RequestValues.addressPartnerUpdate2.copy(bpna = bpnA1),
RequestValues.addressPartnerUpdate2.copy(bpna = firstInvalidBpn),
RequestValues.addressPartnerUpdate3.copy(bpna = secondInvalidBpn)
)

val response = poolClient.addresses().updateAddresses(toUpdate)
Expand All @@ -435,15 +435,23 @@ class AddressControllerIT @Autowired constructor(
actuals.forEach { assertThat(it.address.bpna).matches(testHelpers.bpnAPattern) }

testHelpers.assertRecursively(actuals)
.ignoringFields("address.bpn", "address.bpnLegalEntity", "address.bpnSite")
.ignoringFields(
AddressPartnerCreateResponse::address.name + "." + LogisticAddressResponse::bpna.name,
AddressPartnerCreateResponse::address.name + "." + LogisticAddressResponse::bpnLegalEntity.name,
AddressPartnerCreateResponse::address.name + "." + LogisticAddressResponse::bpnSite.name
)
.isEqualTo(expected)
}

private fun assertAddressesAreEqual(actuals: Collection<LogisticAddressResponse>, expected: Collection<LogisticAddressResponse>) {
actuals.forEach { assertThat(it.bpna).matches(testHelpers.bpnAPattern) }

testHelpers.assertRecursively(actuals)
.ignoringFields("bpn", "bpnLegalEntity", "bpnSite")
.ignoringFields(
LogisticAddressResponse::bpna.name,
LogisticAddressResponse::bpnLegalEntity.name,
LogisticAddressResponse::bpnSite.name
)
.isEqualTo(expected)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class LegalEntityControllerIT @Autowired constructor(
}

val toUpdate = RequestValues.legalEntityUpdate3.copy(
bpn = givenBpnL
bpnl = givenBpnL
)
val response = poolClient.legalEntities().updateBusinessPartners(listOf(toUpdate))

Expand All @@ -190,8 +190,8 @@ class LegalEntityControllerIT @Autowired constructor(
val bpnA = createdEntity.legalAddress.bpna

val toUpdate = listOf(
RequestValues.legalEntityUpdate3.copy(bpn = "NONEXISTENT"),
RequestValues.legalEntityUpdate3.copy(bpn = bpnL)
RequestValues.legalEntityUpdate3.copy(bpnl = "NONEXISTENT"),
RequestValues.legalEntityUpdate3.copy(bpnl = bpnL)
)

val expected = with(ResponseValues.legalEntityUpsert3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ class SiteControllerIT @Autowired constructor(
)

val toUpdate = listOf(
RequestValues.siteUpdate1.copy(bpn = bpnS3),
RequestValues.siteUpdate2.copy(bpn = bpnS1),
RequestValues.siteUpdate3.copy(bpn = bpnS2)
RequestValues.siteUpdate1.copy(bpns = bpnS3),
RequestValues.siteUpdate2.copy(bpns = bpnS1),
RequestValues.siteUpdate3.copy(bpns = bpnS2)
)

val response = poolClient.sites().updateSite(toUpdate)
Expand Down Expand Up @@ -280,9 +280,9 @@ class SiteControllerIT @Autowired constructor(
)

val toUpdate = listOf(
RequestValues.siteUpdate1.copy(bpn = bpnS2),
RequestValues.siteUpdate2.copy(bpn = bpnS1),
RequestValues.siteUpdate3.copy(bpn = "NONEXISTENT"),
RequestValues.siteUpdate1.copy(bpns = bpnS2),
RequestValues.siteUpdate2.copy(bpns = bpnS1),
RequestValues.siteUpdate3.copy(bpns = "NONEXISTENT"),
)
val response = poolClient.sites().updateSite(toUpdate)

Expand Down Expand Up @@ -353,7 +353,12 @@ class SiteControllerIT @Autowired constructor(
actuals.forEach { assertThat(it.site.bpns).matches(testHelpers.bpnSPattern) }

testHelpers.assertRecursively(actuals)
.ignoringFields("site.bpn", "site.bpnLegalEntity", "mainAddress.bpn", "mainAddress.bpnSite")
.ignoringFields(
SitePartnerCreateResponse::site.name + "." + SiteResponse::bpns.name,
SitePartnerCreateResponse::site.name + "." + SiteResponse::bpnLegalEntity.name,
SitePartnerCreateResponse::mainAddress.name + "." + LogisticAddressResponse::bpna.name,
SitePartnerCreateResponse::mainAddress.name + "." + LogisticAddressResponse::bpnSite.name
)
.isEqualTo(expected)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PartnerChangelogIT @Autowired constructor(

// prepare modified partner to import
val modifiedPartnersToImport = listOf(
RequestValues.legalEntityUpdate3.copy(bpn = bpnL1)
RequestValues.legalEntityUpdate3.copy(bpnl = bpnL1)
)

val timestampBetweenCreateAndUpdate = Instant.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ object RequestValues {
)

val legalEntityUpdate1 = LegalEntityPartnerUpdateRequest(
bpn = CommonValues.bpnL1,
bpnl = CommonValues.bpnL1,
legalEntity = legalEntityCreate1.legalEntity
)

val legalEntityUpdate2 = LegalEntityPartnerUpdateRequest(
bpn = CommonValues.bpnL2,
bpnl = CommonValues.bpnL2,
legalEntity = legalEntityCreate2.legalEntity
)

val legalEntityUpdate3 = LegalEntityPartnerUpdateRequest(
bpn = CommonValues.bpnL3,
bpnl = CommonValues.bpnL3,
legalEntity = legalEntityCreate3.legalEntity
)

Expand All @@ -219,7 +219,7 @@ object RequestValues {
mainAddress = logisticAddress1
),
index = CommonValues.index1,
bpnParent = legalEntityUpdate1.bpn
bpnParent = legalEntityUpdate1.bpnl
)

val siteCreate2 = SitePartnerCreateRequest(
Expand All @@ -229,7 +229,7 @@ object RequestValues {
mainAddress = logisticAddress2
),
index = CommonValues.index2,
bpnParent = legalEntityUpdate2.bpn
bpnParent = legalEntityUpdate2.bpnl
)

val siteCreate3 = SitePartnerCreateRequest(
Expand All @@ -239,54 +239,54 @@ object RequestValues {
mainAddress = logisticAddress3
),
index = CommonValues.index3,
bpnParent = legalEntityUpdate3.bpn
bpnParent = legalEntityUpdate3.bpnl
)

val siteUpdate1 = SitePartnerUpdateRequest(
bpn = CommonValues.bpnS1,
bpns = CommonValues.bpnS1,
site = siteCreate1.site
)

val siteUpdate2 = SitePartnerUpdateRequest(
bpn = CommonValues.bpnS2,
bpns = CommonValues.bpnS2,
site = siteCreate2.site
)

val siteUpdate3 = SitePartnerUpdateRequest(
bpn = CommonValues.bpnS3,
bpns = CommonValues.bpnS3,
site = siteCreate3.site
)

val addressPartnerCreate1 = AddressPartnerCreateRequest(
address = logisticAddress1,
bpnParent = legalEntityUpdate1.bpn,
bpnParent = legalEntityUpdate1.bpnl,
index = CommonValues.index1
)

val addressPartnerCreate2 = AddressPartnerCreateRequest(
address = logisticAddress2,
bpnParent = legalEntityUpdate2.bpn,
bpnParent = legalEntityUpdate2.bpnl,
index = CommonValues.index2
)

val addressPartnerCreate3 = AddressPartnerCreateRequest(
address = logisticAddress3,
bpnParent = legalEntityUpdate3.bpn,
bpnParent = legalEntityUpdate3.bpnl,
index = CommonValues.index3
)

val addressPartnerUpdate1 = AddressPartnerUpdateRequest(
bpn = CommonValues.bpnA1,
bpna = CommonValues.bpnA1,
address = logisticAddress1
)

val addressPartnerUpdate2 = AddressPartnerUpdateRequest(
bpn = CommonValues.bpnA2,
bpna = CommonValues.bpnA2,
address = logisticAddress2
)

val addressPartnerUpdate3 = AddressPartnerUpdateRequest(
bpn = CommonValues.bpnA3,
bpna = CommonValues.bpnA3,
address = logisticAddress3
)

Expand Down

0 comments on commit a11a942

Please sign in to comment.