diff --git a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt index 8ca6378a9..8f67c7ff6 100644 --- a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt +++ b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/dto/DtoConversionHelper.kt @@ -177,7 +177,7 @@ private fun poolToGatePhysicalAddress(address: PhysicalPostalAddressVerboseDto): country = address.country.technicalKey, postalCode = address.postalCode, city = address.city, - administrativeAreaLevel1 = address.administrativeAreaLevel1?.regionCode, + administrativeAreaLevel1 = address.administrativeAreaLevel1?.code, administrativeAreaLevel2 = address.administrativeAreaLevel2, administrativeAreaLevel3 = address.administrativeAreaLevel3, district = address.district, @@ -196,7 +196,7 @@ private fun poolToGateAlternativeAddress(address: AlternativePostalAddressVerbos country = address.country.technicalKey, postalCode = address.postalCode, city = address.city, - administrativeAreaLevel1 = address.administrativeAreaLevel1?.regionCode, + administrativeAreaLevel1 = address.administrativeAreaLevel1?.code, deliveryServiceNumber = address.deliveryServiceNumber, deliveryServiceType = address.deliveryServiceType, deliveryServiceQualifier = address.deliveryServiceQualifier diff --git a/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/response/CountrySubdivisionDto.kt b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/response/CountrySubdivisionDto.kt new file mode 100644 index 000000000..6bbb6206f --- /dev/null +++ b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/response/CountrySubdivisionDto.kt @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ******************************************************************************/ + +package org.eclipse.tractusx.bpdm.common.dto.response + +import com.neovisionaries.i18n.CountryCode +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(description = "Country subdivision") +data class CountrySubdivisionDto( + + @get:Schema(description = "Country code") + val countryCode: CountryCode, + + @get:Schema(description = "The country subdivision code according to ISO 3166-2") + val code: String, + + @get:Schema(description = "The name of the country subdivision according to ISO 3166-2") + val name: String +) diff --git a/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/response/RegionDto.kt b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/response/RegionDto.kt index 4a0af5545..25d179671 100644 --- a/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/response/RegionDto.kt +++ b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/dto/response/RegionDto.kt @@ -22,7 +22,7 @@ package org.eclipse.tractusx.bpdm.common.dto.response import com.neovisionaries.i18n.CountryCode import io.swagger.v3.oas.annotations.media.Schema -@Schema(name = "RegionDto", description = "Region within a country") +@Schema(description = "Region within a country") data class RegionDto( @get:Schema(description = "Country code") @@ -33,4 +33,4 @@ data class RegionDto( @get:Schema(description = "Describes the full name of the region within a country according to ISO 3166-214") val regionName: String -) \ No newline at end of file +) diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolMetadataApi.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolMetadataApi.kt index 4bffe2196..3dd64442e 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolMetadataApi.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolMetadataApi.kt @@ -29,6 +29,7 @@ import org.eclipse.tractusx.bpdm.common.dto.FieldQualityRuleDto import org.eclipse.tractusx.bpdm.common.dto.IdentifierBusinessPartnerType import org.eclipse.tractusx.bpdm.common.dto.IdentifierTypeDto import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest +import org.eclipse.tractusx.bpdm.common.dto.response.CountrySubdivisionDto import org.eclipse.tractusx.bpdm.common.dto.response.LegalFormDto import org.eclipse.tractusx.bpdm.common.dto.response.PageDto import org.eclipse.tractusx.bpdm.common.dto.response.RegionDto @@ -168,17 +169,17 @@ interface PoolMetadataApi { fun getRegions(@ParameterObject paginationRequest: PaginationRequest): PageDto @Operation( - summary = "Get page of regions suitable for the administrativeAreaLevel1 address property", - description = "Lists all currently known regions in a paginated result" + summary = "Get page of country subdivisions suitable for the administrativeAreaLevel1 address property", + description = "Lists all currently known country subdivisions according to ISO 3166-2 in a paginated result" ) @ApiResponses( value = [ - ApiResponse(responseCode = "200", description = "Page of existing regions, may be empty"), + ApiResponse(responseCode = "200", description = "Page of existing country subdivisions, may be empty"), ApiResponse(responseCode = "400", description = "On malformed request parameters", content = [Content()]) ] ) @GetMapping("/administrative-areas-level1") @GetExchange("/administrative-areas-level1") - fun getAdminAreasLevel1(@ParameterObject paginationRequest: PaginationRequest): PageDto + fun getAdminAreasLevel1(@ParameterObject paginationRequest: PaginationRequest): PageDto } \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataController.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataController.kt index 750bc9e30..74f80c00e 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataController.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataController.kt @@ -24,6 +24,7 @@ import org.eclipse.tractusx.bpdm.common.dto.FieldQualityRuleDto import org.eclipse.tractusx.bpdm.common.dto.IdentifierBusinessPartnerType import org.eclipse.tractusx.bpdm.common.dto.IdentifierTypeDto import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest +import org.eclipse.tractusx.bpdm.common.dto.response.CountrySubdivisionDto import org.eclipse.tractusx.bpdm.common.dto.response.LegalFormDto import org.eclipse.tractusx.bpdm.common.dto.response.PageDto import org.eclipse.tractusx.bpdm.common.dto.response.RegionDto @@ -71,8 +72,8 @@ class MetadataController( } @PreAuthorize("hasAuthority(@poolSecurityConfigProperties.getReadMetaDataAsRole())") - override fun getAdminAreasLevel1(paginationRequest: PaginationRequest): PageDto { - return metadataService.getRegions(paginationRequest) + override fun getAdminAreasLevel1(paginationRequest: PaginationRequest): PageDto { + return metadataService.getCountrySubdivisions(paginationRequest) } @PreAuthorize("hasAuthority(@poolSecurityConfigProperties.getReadMetaDataAsRole())") diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/MetadataService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/MetadataService.kt index 443aac27a..bbd625808 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/MetadataService.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/MetadataService.kt @@ -23,6 +23,7 @@ import com.neovisionaries.i18n.CountryCode import mu.KotlinLogging import org.eclipse.tractusx.bpdm.common.dto.* import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest +import org.eclipse.tractusx.bpdm.common.dto.response.CountrySubdivisionDto import org.eclipse.tractusx.bpdm.common.dto.response.LegalFormDto import org.eclipse.tractusx.bpdm.common.dto.response.PageDto import org.eclipse.tractusx.bpdm.common.dto.response.RegionDto @@ -178,7 +179,6 @@ class MetadataService( @Transactional fun createRegion(request: RegionDto): RegionDto { - logger.info { "Create new Region with key ${request.regionCode} and name ${request.regionName}" } val region = Region( @@ -187,13 +187,18 @@ class MetadataService( regionName = request.regionName ) - return regionRepository.save(region).toDto() + return regionRepository.save(region).toRegionDto() } fun getRegions(paginationRequest: PaginationRequest): PageDto { val pageRequest = paginationRequest.toPageRequest(RegionRepository.DEFAULT_SORTING) val page = regionRepository.findAll(pageRequest) - return page.toDto(page.content.map { it.toDto() }) + return page.toDto(page.content.map { it.toRegionDto() }) } -} \ No newline at end of file + fun getCountrySubdivisions(paginationRequest: PaginationRequest): PageDto { + val pageRequest = paginationRequest.toPageRequest(RegionRepository.DEFAULT_SORTING) + val page = regionRepository.findAll(pageRequest) + return page.toDto(page.content.map { it.toCountrySubdivisionDto() }) + } +} diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt index fb3ebb893..02632654c 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt @@ -277,6 +277,10 @@ fun PartnerChangelogEntry.toDto(): ChangelogEntryVerboseDto { return ChangelogEntryVerboseDto(bpn, businessPartnerType, createdAt, changelogType) } -fun Region.toDto(): RegionDto { - return RegionDto(countryCode, regionCode, regionName) +fun Region.toRegionDto(): RegionDto { + return RegionDto(countryCode = countryCode, regionCode = regionCode, regionName = regionName) +} + +fun Region.toCountrySubdivisionDto(): CountrySubdivisionDto { + return CountrySubdivisionDto(countryCode = countryCode, code = regionCode, name = regionName) } diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt index b02e2dd93..15c65d56a 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt @@ -437,11 +437,10 @@ class MetadataControllerIT @Autowired constructor( assertThat(firstPage.totalPages).isEqualTo(348) assertThat(firstPage.content.size).isEqualTo(10) - // INSERT INTO bpdm.regions (country_code, region_code, region_name) VALUES ('AD', 'AD-02', 'Canillo'); with(firstPage.content.first()) { assertThat(countryCode).isEqualTo(AD) - assertThat(regionCode).isEqualTo("AD-02") - assertThat(regionName).isEqualTo("Canillo") + assertThat(code).isEqualTo("AD-02") + assertThat(name).isEqualTo("Canillo") } val lastPage = poolClient.metadata.getAdminAreasLevel1(PaginationRequest(347)) @@ -449,11 +448,10 @@ class MetadataControllerIT @Autowired constructor( assertThat(lastPage.totalPages).isEqualTo(348) assertThat(lastPage.content.size).isEqualTo(8) - // INSERT INTO bpdm.regions (country_code, region_code, region_name) VALUES ('ZW', 'ZW-MW', 'Mashonaland West'); with(lastPage.content.last()) { assertThat(countryCode).isEqualTo(ZW) - assertThat(regionCode).isEqualTo("ZW-MW") - assertThat(regionName).isEqualTo("Mashonaland West") + assertThat(code).isEqualTo("ZW-MW") + assertThat(name).isEqualTo("Mashonaland West") } } }