Skip to content

Commit

Permalink
Merge pull request #191 from catenax-ng/feat/api_remove_admin_level_4
Browse files Browse the repository at this point in the history
Feat/api remove admin level 4
  • Loading branch information
nicoprow authored May 24, 2023
2 parents 5d65502 + fee0bb3 commit 22d05ec
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ
@Schema(name = "AlternativePostalAddress", description = "Alternative Postal Address Part")
data class AlternativePostalAddressDto(

@Schema(description = "Describes the PO Box or private Bag number the delivery should be placed at.")
@get:Schema(description = "Describes the PO Box or private Bag number the delivery should be placed at.")
val deliveryServiceNumber: String = "",

@Schema(description = "The type of this specified delivery")
@get:Schema(description = "The type of this specified delivery")
val deliveryServiceType: DeliveryServiceType = DeliveryServiceType.PO_BOX,

@field:JsonUnwrapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,34 @@ import io.swagger.v3.oas.annotations.media.Schema
@Schema(name = "PostalAdress", description = "Address record for a business partner")
data class BasePostalAddressDto(

@Schema(description = "Geographic coordinates to find this location")
@get:Schema(description = "Geographic coordinates to find this location")
val geographicCoordinates: GeoCoordinateDto? = null,

@Schema(description = "Describes the country")
@get:Schema(description = "Describes the country")
val country: CountryCode,

@Schema(description = "Identifying code of the Region within the country (e.g. Bayern)")
@get:Schema(description = "Identifying code of the Region within the country (e.g. Bayern)")
val administrativeAreaLevel1: String? = null,

@Schema(description = "Further possibility to describe the region/address(e.g. County/Landkreis)")
@get:Schema(description = "Further possibility to describe the region/address(e.g. County/Landkreis)")
val administrativeAreaLevel2: String? = null,

@Schema(description = "Further possibility to describe the region/address(e.g. Township/Gemeinde)")
@get:Schema(description = "Further possibility to describe the region/address(e.g. Township/Gemeinde)")
val administrativeAreaLevel3: String? = null,

@Schema(description = "Further possibility to describe the region/address(e.g. Sub-Province for China/Japan)")
val administrativeAreaLevel4: String? = null,

@Schema(description ="A postal code, also known as postcode, PIN or ZIP Code")

@get:Schema(description = "A postal code, also known as postcode, PIN or ZIP Code")
val postCode: String? = null,

@Schema(description = "The city of the address (Synonym: Town, village, municipality)")
@get:Schema(description = "The city of the address (Synonym: Town, village, municipality)")
val city: String,

@Schema(description = "Divides the city in several smaller areas")
@get:Schema(description = "Divides the city in several smaller areas")
val districtLevel1: String? = null,

@Schema(description = "Divides the DistrictLevel1 in several smaller areas. Synonym: Subdistrict")
@get:Schema(description = "Divides the DistrictLevel1 in several smaller areas. Synonym: Subdistrict")
val districtLevel2: String? = null,

@Schema(description = "Address country")
@get:Schema(description = "Address country")
val street: StreetDto? = null,

)
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializ

@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(name = "PhysicalPostalAddress", description = "Physical Postal Address Part")
data class PhysicalPostalAddressDto (
data class PhysicalPostalAddressDto(

@field:JsonUnwrapped
val baseAddress: BasePostalAddressDto,

@Schema(description = "A separate postal code for a company, also known as postcode, PIN or ZIP Code")
@get:Schema(description = "A separate postal code for a company, also known as postcode, PIN or ZIP Code")
val companyPostCode: String? = null,

@Schema(description = "The practice of designating an area for industrial development")
@get:Schema(description = "The practice of designating an area for industrial development")
val industrialZone: String? = null,

@Schema(description = "Describes a specific building within the address")
@get:Schema(description = "Describes a specific building within the address")
val building: String? = null,

@Schema(description = "Describes the floor/level the delivery shall take place")
@get:Schema(description = "Describes the floor/level the delivery shall take place")
val floor: String? = null,

@Schema(description = "Describes the door/room/suite on the respective floor the delivery shall take place")
@get:Schema(description = "Describes the door/room/suite on the respective floor the delivery shall take place")
val door: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,42 @@ package org.eclipse.tractusx.bpdm.common.dto.response

import com.neovisionaries.i18n.CountryCode
import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.*
import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto
import org.eclipse.tractusx.bpdm.common.dto.NameRegioncodeDto
import org.eclipse.tractusx.bpdm.common.dto.StreetDto
import org.eclipse.tractusx.bpdm.common.dto.response.type.TypeKeyNameDto

@Schema(name = "PostalAddressResponse", description = "Aaddress record of a business partner")
data class BasePostalAddressResponse(

@Schema(description = "Geographic coordinates to find this location")
@get:Schema(description = "Geographic coordinates to find this location")
val geographicCoordinates: GeoCoordinateDto? = null,

@Schema(description = "Describes the full name of the country")
@get:Schema(description = "Describes the full name of the country")
val country: TypeKeyNameDto<CountryCode>,

@Schema(description = "Region within the country")
@get:Schema(description = "Region within the country")
val administrativeAreaLevel1: NameRegioncodeDto? = null,

@Schema(description = "Further possibility to describe the region/address(e.g. County)")
@get:Schema(description = "Further possibility to describe the region/address(e.g. County)")
val administrativeAreaLevel2: String? = null,

@Schema(description = "Further possibility to describe the region/address(e.g. Township)")
@get:Schema(description = "Further possibility to describe the region/address(e.g. Township)")
val administrativeAreaLevel3: String? = null,

@Schema(description = "Further possibility to describe the region/address(e.g. Sub-Province for China/Japan)")
val administrativeAreaLevel4: String? = null,

@Schema(description ="A postal code, also known as postcode, PIN or ZIP Code")
@get:Schema(description = "A postal code, also known as postcode, PIN or ZIP Code")
val postCode: String? = null,

@Schema(description = "The city of the address (Synonym: Town, village, municipality)")
@get:Schema(description = "The city of the address (Synonym: Town, village, municipality)")
val city: String,

@Schema(description = "Divides the city in several smaller areas")
@get:Schema(description = "Divides the city in several smaller areas")
val districtLevel1: String? = null,

@Schema(description = "Divides the DistrictLevel1 in several smaller areas. Synonym: Subdistrict")
@get:Schema(description = "Divides the DistrictLevel1 in several smaller areas. Synonym: Subdistrict")
val districtLevel2: String? = null,

@Schema(description = "Street")
@get:Schema(description = "Street")
val street: StreetDto? = null,

)
)
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ object SaasMappings {
administrativeAreaLevel1 = map.adminAreaLevel1(),
administrativeAreaLevel2 = map.adminAreaLevel2(),
administrativeAreaLevel3 = null,
administrativeAreaLevel4 = null,
postCode = map.postcode(),
districtLevel1 = map.districtLevel1(),
districtLevel2 = map.districtLevel2(),
Expand Down Expand Up @@ -259,7 +258,6 @@ object SaasMappings {
administrativeAreaLevel1 = map.adminAreaLevel1(),
administrativeAreaLevel2 = map.adminAreaLevel2(),
administrativeAreaLevel3 = null,
administrativeAreaLevel4 = null,
postCode = map.postcode(),
districtLevel1 = map.districtLevel1(),
districtLevel2 = map.districtLevel2(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ fun AlternativePostalAddressDto.toAlternativePostalAddressEntity(): AlternativeP
administrativeAreaLevel1 = null, // TODO Add region mapping Logic
administrativeAreaLevel2 = baseAddress.administrativeAreaLevel2,
administrativeAreaLevel3 = baseAddress.administrativeAreaLevel3,
administrativeAreaLevel4 = baseAddress.administrativeAreaLevel4,
postCode = baseAddress.postCode,
city = baseAddress.city,
districtLevel1 = baseAddress.districtLevel1,
Expand All @@ -85,7 +84,6 @@ fun PhysicalPostalAddressDto.toPhysicalPostalAddressEntity(): PhysicalPostalAddr
administrativeAreaLevel1 = null, // TODO Add region mapping Logic
administrativeAreaLevel2 = baseAddress.administrativeAreaLevel2,
administrativeAreaLevel3 = baseAddress.administrativeAreaLevel3,
administrativeAreaLevel4 = baseAddress.administrativeAreaLevel4,
postCode = baseAddress.postCode,
city = baseAddress.city,
districtLevel1 = baseAddress.districtLevel1,
Expand Down Expand Up @@ -153,23 +151,23 @@ fun ChangelogEntry.toGateDto(): ChangelogResponse {

fun LegalEntityGateInputRequest.toLegalEntity(): LegalEntity {

val addressInputRequest =AddressGateInputRequest(
val addressInputRequest = AddressGateInputRequest(
address = legalEntity.legalAddress,
externalId = getMainAddressForLegalEntityExternalId(externalId),
legalEntityExternalId = externalId
)

val legalEntity= LegalEntity(
val legalEntity = LegalEntity(
bpn = bpn,
externalId = externalId,
currentness = createCurrentnessTimestamp(),
legalForm = legalEntity.legalForm,
legalName = legalEntity.legalName.toName()
)

legalEntity.identifiers.addAll( this.legalEntity.identifiers.map {toEntityIdentifier(it,legalEntity)})
legalEntity.states.addAll(this.legalEntity.states.map { toEntityState(it,legalEntity) })
legalEntity.classifications.addAll(this.legalEntity.classifications.map { toEntityClassification(it,legalEntity) })
legalEntity.identifiers.addAll(this.legalEntity.identifiers.map { toEntityIdentifier(it, legalEntity) })
legalEntity.states.addAll(this.legalEntity.states.map { toEntityState(it, legalEntity) })
legalEntity.classifications.addAll(this.legalEntity.classifications.map { toEntityClassification(it, legalEntity) })

legalEntity.legalAddress = addressInputRequest.toAddressGate(legalEntity, null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SaasDtoToSaasAddressMapping(private val postalAdress: BasePostalAddressDto
type = SaasAdministrativeAreaType.COUNTY.toSaasTypeDto()
)
}
// TODO Where can administrativeAreaLevel3 and administrativeAreaLevel4 be stored in SaaS model? It's just ignored for now!
// TODO Where can administrativeAreaLevel3 be stored in SaaS model? It's just ignored for now!
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class SaasDtoToSaasAddressMappingTest {
assertThat(baseAddressDto.administrativeAreaLevel1).isEqualTo(findValue(addressSaas.administrativeAreas, REGION))
assertThat(baseAddressDto.administrativeAreaLevel2).isEqualTo(findValue(addressSaas.administrativeAreas, COUNTY))
assertThat(baseAddressDto.administrativeAreaLevel3).isEqualTo(null)
assertThat(baseAddressDto.administrativeAreaLevel4).isEqualTo(null)
assertThat(baseAddressDto.city).isEqualTo(findValue(addressSaas.localities, SaasLocalityType.CITY))
assertThat(baseAddressDto.country).isEqualTo(addressSaas.country?.shortName)
assertThat(baseAddressDto.districtLevel1).isEqualTo(findValue(addressSaas.localities, SaasLocalityType.DISTRICT))
Expand Down Expand Up @@ -58,7 +57,6 @@ class SaasDtoToSaasAddressMappingTest {
}



@Test
fun mappingAddressDto1Test() {

Expand All @@ -69,7 +67,6 @@ class SaasDtoToSaasAddressMappingTest {
assertThat(baseAddressDto.administrativeAreaLevel1).isEqualTo(findValue(addressSaas.administrativeAreas, REGION))
assertThat(baseAddressDto.administrativeAreaLevel2).isEqualTo(findValue(addressSaas.administrativeAreas, COUNTY))
assertThat(baseAddressDto.administrativeAreaLevel3).isEqualTo(null)
assertThat(baseAddressDto.administrativeAreaLevel4).isEqualTo(null)
assertThat(baseAddressDto.city).isEqualTo(findValue(addressSaas.localities, SaasLocalityType.CITY))
assertThat(baseAddressDto.country).isEqualTo(addressSaas.country?.shortName)
assertThat(baseAddressDto.districtLevel1).isEqualTo(findValue(addressSaas.localities, SaasLocalityType.DISTRICT))
Expand Down Expand Up @@ -98,7 +95,6 @@ class SaasDtoToSaasAddressMappingTest {
assertThat(baseAddressDto.administrativeAreaLevel1).isEqualTo(findValue(addressSaas.administrativeAreas, REGION))
assertThat(baseAddressDto.administrativeAreaLevel2).isEqualTo(findValue(addressSaas.administrativeAreas, COUNTY))
assertThat(baseAddressDto.administrativeAreaLevel3).isEqualTo(null)
assertThat(baseAddressDto.administrativeAreaLevel4).isEqualTo(null)
assertThat(baseAddressDto.city).isEqualTo(findValue(addressSaas.localities, SaasLocalityType.CITY))
assertThat(baseAddressDto.country).isEqualTo(addressSaas.country?.shortName)
assertThat(baseAddressDto.districtLevel1).isEqualTo(findValue(addressSaas.localities, SaasLocalityType.DISTRICT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class BusinessPartnerBuildService(
@Transactional
fun updateLegalEntities(requests: Collection<LegalEntityPartnerUpdateRequest>): LegalEntityPartnerUpdateResponseWrapper {
logger.info { "Update ${requests.size} legal entities" }

val legalEntityMetadataMap = metadataMappingService.mapRequests(requests.map { it.legalEntity })
val addressMetadataMap = metadataMappingService.mapRequests(requests.map { it.legalEntity.legalAddress })

Expand All @@ -173,7 +173,7 @@ class BusinessPartnerBuildService(
}

val requestByBpnMap = requests.associateBy { it.bpn }
legalEntities.forEach {
legalEntities.forEach {
val request = requestByBpnMap.get(it.bpn)!!
updateLegalEntity(it, request.legalEntity, legalEntityMetadataMap)
updateLogisticAddress(it.legalAddress, request.legalEntity.legalAddress, addressMetadataMap)
Expand Down Expand Up @@ -376,15 +376,15 @@ class BusinessPartnerBuildService(
legalEntity: LegalEntity,
metadataMap: AddressMetadataMappingDto
) = createLogisticAddressInternal(dto, bpn, metadataMap)
.also { it.legalEntity = legalEntity }
.also { it.legalEntity = legalEntity }

private fun createLogisticAddress(
dto: LogisticAddressDto,
bpn: String,
site: Site,
metadataMap: AddressMetadataMappingDto
) = createLogisticAddressInternal(dto, bpn, metadataMap)
.also { it.site = site }
.also { it.site = site }

private fun createLogisticAddressInternal(
dto: LogisticAddressDto,
Expand Down Expand Up @@ -431,7 +431,6 @@ class BusinessPartnerBuildService(
administrativeAreaLevel1 = null,
administrativeAreaLevel2 = baseAddress.administrativeAreaLevel2,
administrativeAreaLevel3 = baseAddress.administrativeAreaLevel3,
administrativeAreaLevel4 = baseAddress.administrativeAreaLevel4,
postCode = baseAddress.postCode,
city = baseAddress.city,
districtLevel1 = baseAddress.districtLevel1,
Expand All @@ -457,7 +456,6 @@ class BusinessPartnerBuildService(
administrativeAreaLevel1 = null,
administrativeAreaLevel2 = baseAddress.administrativeAreaLevel2,
administrativeAreaLevel3 = baseAddress.administrativeAreaLevel3,
administrativeAreaLevel4 = baseAddress.administrativeAreaLevel4,
postCode = baseAddress.postCode,
city = baseAddress.city,
districtLevel1 = baseAddress.districtLevel1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ fun PhysicalPostalAddress.toDto(): PhysicalPostalAddressResponse {
administrativeAreaLevel1 = administrativeAreaLevel1?.let { NameRegioncodeDto(it.regionName, it.regionCode) },
administrativeAreaLevel2 = administrativeAreaLevel2,
administrativeAreaLevel3 = administrativeAreaLevel3,
administrativeAreaLevel4 = administrativeAreaLevel4,
postCode = postCode,
city = city,
districtLevel1 = districtLevel1,
Expand All @@ -177,7 +176,6 @@ fun AlternativePostalAddress.toDto(): AlternativePostalAddressResponse {
administrativeAreaLevel1 = administrativeAreaLevel1?.let { NameRegioncodeDto(it.regionName, it.regionCode) },
administrativeAreaLevel2 = administrativeAreaLevel2,
administrativeAreaLevel3 = administrativeAreaLevel3,
administrativeAreaLevel4 = administrativeAreaLevel4,
postCode = postCode,
city = city,
districtLevel1 = districtLevel1,
Expand Down
Loading

0 comments on commit 22d05ec

Please sign in to comment.