diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LegalEntity.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LegalEntity.kt index 7c2b4c75d..da3119a3b 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LegalEntity.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LegalEntity.kt @@ -41,6 +41,9 @@ class LegalEntity( @Column(name = "legal_form_id", nullable = false) var legalForm: String?, + @Column(name = "name_parts", nullable = true) + val nameParts: List = emptyList(), + @Column(name = "data_type") @Enumerated(EnumType.STRING) var dataType: OutputInputEnum diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LogisticAddress.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LogisticAddress.kt index 5e6a1861d..b071e3233 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LogisticAddress.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LogisticAddress.kt @@ -46,8 +46,8 @@ class LogisticAddress( @JoinColumn(name = "site_id") var site: Site?, - @Column(name = "name") - var name: String? = null, + @Column(name = "name_parts", nullable = true) + var nameParts: Collection = emptyList(), @Column(name = "data_type") @Enumerated(EnumType.STRING) diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Site.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Site.kt index 10f926a07..7ef9fd3ae 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Site.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Site.kt @@ -29,9 +29,6 @@ class Site( @Column(name = "bpn") var bpn: String? = null, - @Column(name = "name", nullable = false) - var name: String, - @Column(name = "external_id", nullable = false, unique = true) var externalId: String, @@ -39,6 +36,9 @@ class Site( @Enumerated(EnumType.STRING) var dataType: OutputInputEnum, + @Column(name = "name_parts", nullable = true) + var nameParts: Collection = emptyList(), + @ManyToOne @JoinColumn(name = "legal_entity_id", nullable = false) var legalEntity: LegalEntity, diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressPersistenceService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressPersistenceService.kt index fff779601..2f640068d 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressPersistenceService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressPersistenceService.kt @@ -67,7 +67,7 @@ class AddressPersistenceService( private fun updateAddress(address: LogisticAddress, changeAddress: AddressGateInputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) { - address.name = changeAddress.address.nameParts.firstOrNull() + address.nameParts = changeAddress.address.nameParts address.externalId = changeAddress.externalId address.legalEntity = legalEntityRecord address.site = siteRecord @@ -107,7 +107,7 @@ class AddressPersistenceService( private fun updateAddressOutput(address: LogisticAddress, changeAddress: AddressGateOutputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) { - address.name = changeAddress.address.nameParts.firstOrNull() + address.nameParts = changeAddress.address.nameParts address.bpn = changeAddress.bpn address.externalId = changeAddress.externalId address.legalEntity = legalEntityRecord diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityPersistenceService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityPersistenceService.kt index 5686a4693..a233a8774 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityPersistenceService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityPersistenceService.kt @@ -92,7 +92,7 @@ class LegalEntityPersistenceService( private fun updateAddress(address: LogisticAddress, changeAddress: LogisticAddress) { - address.name = changeAddress.name + address.nameParts = changeAddress.nameParts address.externalId = changeAddress.externalId address.legalEntity = changeAddress.legalEntity address.physicalPostalAddress = changeAddress.physicalPostalAddress diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt index a14b515f2..c5b4ae95a 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt @@ -31,7 +31,7 @@ fun AddressGateInputRequest.toAddressGate(legalEntity: LegalEntity?, site: Site? val logisticAddress = LogisticAddress( externalId = externalId, - name = address.nameParts.firstOrNull(), + nameParts = address.nameParts, physicalPostalAddress = address.physicalPostalAddress.toPhysicalPostalAddressEntity(), alternativePostalAddress = address.alternativePostalAddress?.toAlternativePostalAddressEntity(), legalEntity = legalEntity, @@ -49,7 +49,7 @@ fun AddressGateOutputRequest.toAddressGateOutput(legalEntity: LegalEntity?, site val logisticAddress = LogisticAddress( bpn = bpn, externalId = externalId, - name = address.nameParts.firstOrNull(), + nameParts = address.nameParts, physicalPostalAddress = address.physicalPostalAddress.toPhysicalPostalAddressEntity(), alternativePostalAddress = address.alternativePostalAddress?.toAlternativePostalAddressEntity(), legalEntity = legalEntity, @@ -129,7 +129,7 @@ fun SiteGateInputRequest.toSiteGate(legalEntity: LegalEntity, datatype: OutputIn ) val site = Site( - name = site.nameParts.firstOrNull()?: "", + nameParts = site.nameParts, externalId = externalId, legalEntity = legalEntity, dataType = datatype @@ -152,7 +152,7 @@ fun SiteGateOutputRequest.toSiteGate(legalEntity: LegalEntity, datatype: OutputI val site = Site( bpn = bpn, - name = site.nameParts.firstOrNull()?: "", + nameParts = site.nameParts, externalId = externalId, legalEntity = legalEntity, dataType = datatype @@ -259,7 +259,7 @@ fun LogisticAddress.toAddressGateInputResponse(logisticAddressPage: LogisticAddr fun LogisticAddress.toLogisticAddressDto(): LogisticAddressGateDto { val logisticAddress = LogisticAddressGateDto( - nameParts = name?.let { listOf(name!!) }?: emptyList(), + nameParts = nameParts, states = mapToDtoStates(states), physicalPostalAddress = physicalPostalAddress.toPhysicalPostalAddress(), alternativePostalAddress = alternativePostalAddress?.toAlternativePostalAddressDto(), @@ -372,7 +372,7 @@ fun LegalEntity.toLegalEntityGateInputResponse(legalEntity: LegalEntity): LegalE fun Site.toSiteDto(): SiteGateDto { return SiteGateDto( - nameParts = if(name.isEmpty()) emptyList() else listOf(name), + nameParts = nameParts, states = mapToDtoSitesStates(states) ) } diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt index cb4e465a8..c9bec35c4 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt @@ -88,7 +88,7 @@ class SitePersistenceService( private fun updateSite(site: Site, updatedSite: SiteGateInputRequest, legalEntityRecord: LegalEntity) { - site.name = updatedSite.site.nameParts.firstOrNull() ?: "" + site.nameParts = updatedSite.site.nameParts site.externalId = updatedSite.externalId site.legalEntity = legalEntityRecord site.states.replace(updatedSite.site.states.map { toEntityAddress(it, site) }) @@ -97,7 +97,7 @@ class SitePersistenceService( private fun updateAddress(address: LogisticAddress, changeAddress: LogisticAddress) { - address.name = changeAddress.name + address.nameParts = changeAddress.nameParts address.externalId = changeAddress.externalId address.legalEntity = changeAddress.legalEntity address.physicalPostalAddress = changeAddress.physicalPostalAddress @@ -145,7 +145,7 @@ class SitePersistenceService( private fun updateSiteOutput(site: Site, updatedSite: SiteGateOutputRequest, legalEntityRecord: LegalEntity) { site.bpn = updatedSite.bpn - site.name = updatedSite.site.nameParts.firstOrNull() ?: "" + site.nameParts = updatedSite.site.nameParts site.externalId = updatedSite.externalId site.legalEntity = legalEntityRecord site.states.replace(updatedSite.site.states.map { toEntityAddress(it, site) }) diff --git a/bpdm-gate/src/main/resources/db/migration/V4_0_0_4__add_name_parts_collumn.sql b/bpdm-gate/src/main/resources/db/migration/V4_0_0_4__add_name_parts_collumn.sql new file mode 100644 index 000000000..5cd820834 --- /dev/null +++ b/bpdm-gate/src/main/resources/db/migration/V4_0_0_4__add_name_parts_collumn.sql @@ -0,0 +1,10 @@ +ALTER TABLE legal_entities +ADD COLUMN name_parts VARCHAR(255) NULL; + +ALTER TABLE logistic_addresses +DROP COLUMN IF EXISTS name, +ADD COLUMN name_parts VARCHAR(255) NULL; + +ALTER TABLE sites +DROP COLUMN IF EXISTS name, +ADD COLUMN name_parts VARCHAR(255) NULL; \ No newline at end of file