Skip to content

Commit

Permalink
feat(Cleaning-Service-Dummy): map to L/S/A attribute subclasses in ge…
Browse files Browse the repository at this point in the history
…neric business partner from Orchestrator
  • Loading branch information
nicoprow committed Dec 21, 2023
1 parent 6356c8b commit f962886
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CleaningServiceDummy(

val addressPartner = createAddressRepresentation(genericBusinessPartner)

val addressType = genericBusinessPartner.postalAddress.addressType ?: AddressType.AdditionalAddress
val addressType = genericBusinessPartner.address.addressType ?: AddressType.AdditionalAddress

val legalEntityDto = createLegalEntityRepresentation(addressPartner, addressType, genericBusinessPartner)

Expand All @@ -99,7 +99,7 @@ class CleaningServiceDummy(
fun createSiteDtoIfNeeded(businessPartner: BusinessPartnerGenericDto, addressPartner: LogisticAddressDto): SiteDto? {
if (!shouldCreateSite(businessPartner)) return null

val siteAddressReference = when (businessPartner.postalAddress.addressType) {
val siteAddressReference = when (businessPartner.address.addressType) {
AddressType.SiteMainAddress, AddressType.LegalAndSiteMainAddress -> addressPartner.bpnAReference
else -> generateNewBpnRequestIdentifier()
}
Expand All @@ -121,20 +121,20 @@ class CleaningServiceDummy(

val legalAddress = addressPartner.copy(bpnAReference = legalAddressBpnReference)

val bpnReferenceDto = createBpnReference(genericPartner.legalEntityBpn)
val bpnReferenceDto = createBpnReference(genericPartner.legalEntity.bpnL)

return genericPartner.toLegalEntityDto(bpnReferenceDto, legalAddress)

}

fun createAddressRepresentation(genericPartner: BusinessPartnerGenericDto): LogisticAddressDto {
val bpnReferenceDto = createBpnReference(genericPartner.addressBpn)
val bpnReferenceDto = createBpnReference(genericPartner.address.bpnA)
return genericPartner.toLogisticAddressDto(bpnReferenceDto)
}

fun createSiteRepresentation(genericPartner: BusinessPartnerGenericDto, siteAddressReference: LogisticAddressDto): SiteDto {
val legalName = genericPartner.nameParts.joinToString(" ")
val bpnReferenceDto = createBpnReference(genericPartner.siteBpn)
val bpnReferenceDto = createBpnReference(genericPartner.site.bpnS)
return genericPartner.toSiteDto(bpnReferenceDto, legalName, siteAddressReference)
}

Expand All @@ -150,9 +150,9 @@ class CleaningServiceDummy(
private fun generateNewBpnRequestIdentifier() = BpnReferenceDto(UUID.randomUUID().toString(), BpnReferenceType.BpnRequestIdentifier)

fun shouldCreateSite(genericPartner: BusinessPartnerGenericDto): Boolean {
return genericPartner.postalAddress.addressType == AddressType.SiteMainAddress ||
genericPartner.postalAddress.addressType == AddressType.LegalAndSiteMainAddress ||
genericPartner.siteBpn != null
return genericPartner.address.addressType == AddressType.SiteMainAddress ||
genericPartner.address.addressType == AddressType.LegalAndSiteMainAddress ||
genericPartner.site.bpnS != null
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto,

return LegalEntityDto(
bpnLReference = bpnReferenceDto,
hasChanged = postalAddress.addressType in setOf(AddressType.LegalAddress, AddressType.LegalAndSiteMainAddress),
hasChanged = address.addressType in setOf(AddressType.LegalAddress, AddressType.LegalAndSiteMainAddress),
legalName = nameParts.joinToString(" "),
legalShortName = shortName,
legalShortName = legalEntity.shortName,
identifiers = identifiers.mapNotNull { it.toLegalEntityIdentifierDto() },
legalForm = legalForm,
legalForm = legalEntity.legalForm,
states = states.mapNotNull { it.toLegalEntityState() },
classifications = classifications.map { it.toLegalEntityClassificationDto() },
classifications = legalEntity.classifications.map { it.toLegalEntityClassificationDto() },
legalAddress = legalAddress

)
Expand Down Expand Up @@ -70,12 +70,12 @@ fun BusinessPartnerGenericDto.toLogisticAddressDto(bpnReferenceDto: BpnReference

return LogisticAddressDto(
bpnAReference = bpnReferenceDto,
hasChanged = postalAddress.addressType == AddressType.AdditionalAddress,
hasChanged = address.addressType == AddressType.AdditionalAddress,
name = nameParts.joinToString(" "),
states = emptyList(),
identifiers = emptyList(),
physicalPostalAddress = postalAddress.physicalPostalAddress,
alternativePostalAddress = postalAddress.alternativePostalAddress
physicalPostalAddress = address.physicalPostalAddress,
alternativePostalAddress = address.alternativePostalAddress
)
}

Expand All @@ -84,7 +84,7 @@ fun BusinessPartnerGenericDto.toSiteDto(bpnReferenceDto: BpnReferenceDto, legalN

return SiteDto(
bpnSReference = bpnReferenceDto,
hasChanged = postalAddress.addressType in setOf(AddressType.SiteMainAddress, AddressType.LegalAndSiteMainAddress),
hasChanged = address.addressType in setOf(AddressType.SiteMainAddress, AddressType.LegalAndSiteMainAddress),
name = legalName,
states = states.mapNotNull { it.toSiteState() },
mainAddress = siteAddressReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CleaningServiceDummyTest @Autowired constructor(

val result = cleaningServiceDummy.processCleaningTask(taskStepReservationEntryDto)

val expectedBpnA = taskStepReservationEntryDto.businessPartner.generic.addressBpn
val expectedBpnA = taskStepReservationEntryDto.businessPartner.generic.address.bpnA

val resultedAddress = result.businessPartner?.address

Expand Down Expand Up @@ -112,9 +112,9 @@ class CleaningServiceDummyTest @Autowired constructor(

val result = cleaningServiceDummy.processCleaningTask(taskStepReservationEntryDto)

val expectedBpnA = taskStepReservationEntryDto.businessPartner.generic.addressBpn
val expectedBpnA = taskStepReservationEntryDto.businessPartner.generic.address.bpnA

val expectedBpnL = taskStepReservationEntryDto.businessPartner.generic.legalEntityBpn
val expectedBpnL = taskStepReservationEntryDto.businessPartner.generic.legalEntity.bpnL

val resultedAddress = result.businessPartner?.address

Expand Down Expand Up @@ -153,9 +153,9 @@ class CleaningServiceDummyTest @Autowired constructor(

val resultedSite = result.businessPartner?.site

val expectedBpnA = taskStepReservationResponse.businessPartner.generic.addressBpn
val expectedBpnA = taskStepReservationResponse.businessPartner.generic.address.bpnA

val expectedBpnS = taskStepReservationResponse.businessPartner.generic.siteBpn
val expectedBpnS = taskStepReservationResponse.businessPartner.generic.site.bpnS


// legalEntity should Generate new bpnL and legalAddress should use passed bpnA since address type is LegalAndSiteMainAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,41 +101,77 @@ object CommonValues {

private val businessPartnerWithEmptyBpns = BusinessPartnerGenericDto(
nameParts = nameParts,
shortName = shortName,
identifiers = identifiers,
legalForm = legalForm,
states = states,
classifications = classifications,
roles = roles,
ownerBpnL = "ownerBpnL2"
)


val businessPartnerWithBpnA = businessPartnerWithEmptyBpns.copy(
postalAddress = postalAddressForAdditional,
addressBpn = "FixedBPNA"
)


val businessPartnerWithBpnLAndBpnAAndLegalAddressType = businessPartnerWithEmptyBpns.copy(
postalAddress = postalAddressForLegal,
addressBpn = "FixedBPNA",
legalEntityBpn = "FixedBPNL"
)

val businessPartnerWithEmptyBpnLAndAdditionalAddressType = businessPartnerWithEmptyBpns.copy(
postalAddress = postalAddressForAdditional,
ownerBpnL = "ownerBpnL2",
legalEntity = LegalEntityComponent(
shortName = shortName,
legalForm = legalForm,
classifications = classifications
)
)

val businessPartnerWithBpnSAndBpnAAndLegalAndSiteMainAddressType = businessPartnerWithEmptyBpns.copy(
postalAddress = postalAddressForLegalAndSite,
addressBpn = "FixedBPNA",
siteBpn = "FixedBPNS"
)

val businessPartnerWithEmptyBpnAndSiteMainAddressType = businessPartnerWithEmptyBpns.copy(
postalAddress = postalAddressForSite
)
val businessPartnerWithBpnA = with(businessPartnerWithEmptyBpns) {
copy(
address = address.copy(
bpnA = "FixedBPNA",
addressType = postalAddressForAdditional.addressType,
physicalPostalAddress = postalAddressForAdditional.physicalPostalAddress,
alternativePostalAddress = postalAddressForAdditional.alternativePostalAddress
)
)
}


val businessPartnerWithBpnLAndBpnAAndLegalAddressType = with(businessPartnerWithEmptyBpns) {
copy(
address = address.copy(
bpnA = "FixedBPNA",
addressType = postalAddressForLegal.addressType,
physicalPostalAddress = postalAddressForLegal.physicalPostalAddress,
alternativePostalAddress = postalAddressForLegal.alternativePostalAddress
),
legalEntity = legalEntity.copy(
bpnL = "FixedBPNL"
)
)
}

val businessPartnerWithEmptyBpnLAndAdditionalAddressType = with(businessPartnerWithEmptyBpns) {
copy(
address = address.copy(
addressType = postalAddressForAdditional.addressType,
physicalPostalAddress = postalAddressForAdditional.physicalPostalAddress,
alternativePostalAddress = postalAddressForAdditional.alternativePostalAddress
)
)
}

val businessPartnerWithBpnSAndBpnAAndLegalAndSiteMainAddressType = with(businessPartnerWithEmptyBpns) {
copy(
address = address.copy(
bpnA = "FixedBPNA",
addressType = postalAddressForLegalAndSite.addressType,
physicalPostalAddress = postalAddressForLegalAndSite.physicalPostalAddress,
alternativePostalAddress = postalAddressForLegalAndSite.alternativePostalAddress
),
site = site.copy(
bpnS = "FixedBPNS"
)
)
}

val businessPartnerWithEmptyBpnAndSiteMainAddressType = with(businessPartnerWithEmptyBpns) {
copy(
address = address.copy(
addressType = postalAddressForSite.addressType,
physicalPostalAddress = postalAddressForSite.physicalPostalAddress,
alternativePostalAddress = postalAddressForSite.alternativePostalAddress
)
)
}

val expectedLegalEntityDto = LegalEntityDto(
hasChanged = true,
Expand Down

0 comments on commit f962886

Please sign in to comment.