From a3e22b88e4663896dfddd30b4995f6032f56e930 Mon Sep 17 00:00:00 2001 From: alexsilva Date: Mon, 26 Jun 2023 17:12:47 +0100 Subject: [PATCH 1/5] fix(gate): Added Name Parts collumn with respective mappings to Site and Address --- .../eclipse/tractusx/bpdm/gate/entity/LegalEntity.kt | 3 +++ .../tractusx/bpdm/gate/entity/LogisticAddress.kt | 4 ++-- .../org/eclipse/tractusx/bpdm/gate/entity/Site.kt | 6 +++--- .../bpdm/gate/service/AddressPersistenceService.kt | 4 ++-- .../gate/service/LegalEntityPersistenceService.kt | 2 +- .../tractusx/bpdm/gate/service/ResponseMappings.kt | 12 ++++++------ .../bpdm/gate/service/SitePersistenceService.kt | 6 +++--- .../migration/V4_0_0_4__add_name_parts_collumn.sql | 10 ++++++++++ 8 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 bpdm-gate/src/main/resources/db/migration/V4_0_0_4__add_name_parts_collumn.sql 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 d775e4f66..06bc83069 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 605b70e90..075d26089 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 5adbb22e2..530c72e40 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 @@ -35,7 +35,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, @@ -53,7 +53,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, @@ -133,7 +133,7 @@ fun SiteGateInputRequest.toSiteGate(legalEntity: LegalEntity, datatype: OutputIn ) val site = Site( - name = site.nameParts.firstOrNull() ?: "", + nameParts = site.nameParts, externalId = externalId, legalEntity = legalEntity, dataType = datatype @@ -156,7 +156,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 @@ -263,7 +263,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(), @@ -376,7 +376,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 e4ec87f3d..f57e79102 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 From 14f2124b53a47270a92d2155f31fa76dada2c532 Mon Sep 17 00:00:00 2001 From: alexsilva Date: Tue, 27 Jun 2023 16:02:44 +0100 Subject: [PATCH 2/5] fix(gate): Added new Name Parts Table related to Legal Entity, Address and Sites with the respective mappings --- .../tractusx/bpdm/gate/entity/LegalEntity.kt | 7 +- .../bpdm/gate/entity/LogisticAddress.kt | 6 +- .../tractusx/bpdm/gate/entity/NameParts.kt | 69 +++++++++++++++++++ .../eclipse/tractusx/bpdm/gate/entity/Site.kt | 6 +- .../gate/service/AddressPersistenceService.kt | 4 +- .../service/LegalEntityPersistenceService.kt | 14 +++- .../bpdm/gate/service/LegalEntityService.kt | 2 +- .../bpdm/gate/service/ResponseMappings.kt | 37 +++++++--- .../gate/service/SitePersistenceService.kt | 9 +-- .../V4_0_0_4__add_name_parts_collumn.sql | 35 ++++++++-- 10 files changed, 153 insertions(+), 36 deletions(-) create mode 100644 bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/NameParts.kt 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 da3119a3b..55de320c6 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,9 +41,6 @@ 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 @@ -62,4 +59,8 @@ class LegalEntity( @OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true) val addresses: MutableSet = mutableSetOf() + + @OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true) + val nameParts: MutableSet = mutableSetOf() + } 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 b071e3233..1c102d84f 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,9 +46,6 @@ class LogisticAddress( @JoinColumn(name = "site_id") var site: Site?, - @Column(name = "name_parts", nullable = true) - var nameParts: Collection = emptyList(), - @Column(name = "data_type") @Enumerated(EnumType.STRING) var dataType: OutputInputEnum, @@ -63,4 +60,7 @@ class LogisticAddress( @OneToMany(mappedBy = "address", cascade = [CascadeType.ALL], orphanRemoval = true) val states: MutableSet = mutableSetOf() + + @OneToMany(mappedBy = "address", cascade = [CascadeType.ALL], orphanRemoval = true) + val nameParts: MutableSet = mutableSetOf() } \ No newline at end of file diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/NameParts.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/NameParts.kt new file mode 100644 index 000000000..4f7fe0a4e --- /dev/null +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/NameParts.kt @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ + +/******************************************************************************* + * 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.gate.entity + +import jakarta.persistence.* +import org.eclipse.tractusx.bpdm.common.model.BaseEntity + +@Entity +@Table( + name = "name_parts", + indexes = [ + Index(columnList = "address_id"), + Index(columnList = "site_id") + ] +) +class NameParts( + + @ManyToOne + @JoinColumn(name = "address_id", nullable = true) + var address: LogisticAddress?, + + @ManyToOne + @JoinColumn(name = "site_id", nullable = true) + var site: Site?, + + @ManyToOne + @JoinColumn(name = "legal_entity_id", nullable = true) + var legalEntity: LegalEntity?, + + @Column(name = "name_part") + val namePart: String, + + ) : BaseEntity() \ No newline at end of file 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 7ef9fd3ae..1c6a082f6 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 @@ -36,9 +36,6 @@ 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, @@ -54,4 +51,7 @@ class Site( @ManyToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL]) @JoinColumn(name = "main_address_id", nullable = false) lateinit var mainAddress: LogisticAddress + + @OneToMany(mappedBy = "site", cascade = [CascadeType.ALL], orphanRemoval = true) + val nameParts: MutableSet = mutableSetOf() } \ No newline at end of file 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 06bc83069..eadb1a728 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,6 @@ class AddressPersistenceService( private fun updateAddress(address: LogisticAddress, changeAddress: AddressGateInputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) { - address.nameParts = changeAddress.address.nameParts address.externalId = changeAddress.externalId address.legalEntity = legalEntityRecord address.site = siteRecord @@ -75,6 +74,7 @@ class AddressPersistenceService( address.alternativePostalAddress = changeAddress.address.alternativePostalAddress?.toAlternativePostalAddressEntity() address.states.replace(changeAddress.address.states.map { toEntityAddress(it, address) }) + address.nameParts.replace(changeAddress.address.nameParts.map { toNameParts(it, address, null, null) }) } @@ -107,7 +107,6 @@ class AddressPersistenceService( private fun updateAddressOutput(address: LogisticAddress, changeAddress: AddressGateOutputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) { - address.nameParts = changeAddress.address.nameParts address.bpn = changeAddress.bpn address.externalId = changeAddress.externalId address.legalEntity = legalEntityRecord @@ -116,6 +115,7 @@ class AddressPersistenceService( address.alternativePostalAddress = changeAddress.address.alternativePostalAddress?.toAlternativePostalAddressEntity() address.states.replace(changeAddress.address.states.map { toEntityAddress(it, address) }) + address.nameParts.replace(changeAddress.address.nameParts.map { toNameParts(it, address, null, null) }) } 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 075d26089..3eb1ecca9 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 @@ -82,23 +82,27 @@ class LegalEntityPersistenceService( ): LegalEntity { legalEntity.externalId = legalEntityRequest.externalId legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm - legalEntity.legalName = Name(value = legalEntityRequest.legalNameParts[0], shortName = legalEntityRequest.legalEntity.legalShortName) + legalEntity.legalName = Name("", shortName = legalEntityRequest.legalEntity.legalShortName) + legalEntity.states.replace(legalEntityRequest.legalEntity.states.map { toEntityState(it, legalEntity) }) legalEntity.classifications.replace(legalEntityRequest.legalEntity.classifications.map { toEntityClassification(it, legalEntity) }) + legalEntity.nameParts.replace(legalEntityRequest.legalNameParts.map { toNameParts(it, null, null, legalEntity) }) + legalEntity.legalAddress = logisticAddressRecord legalEntity.legalAddress.legalEntity = legalEntity + return legalEntity } private fun updateAddress(address: LogisticAddress, changeAddress: LogisticAddress) { - address.nameParts = changeAddress.nameParts address.externalId = changeAddress.externalId address.legalEntity = changeAddress.legalEntity address.physicalPostalAddress = changeAddress.physicalPostalAddress address.alternativePostalAddress = changeAddress.alternativePostalAddress address.states.replace(changeAddress.states.map { toEntityAddress(it, address) }) + //address.nameParts.replace(changeAddress.nameParts) } @@ -144,11 +148,15 @@ class LegalEntityPersistenceService( legalEntity.bpn = legalEntityRequest.bpn legalEntity.externalId = legalEntityRequest.externalId legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm - legalEntity.legalName = Name(value = legalEntityRequest.legalNameParts[0], shortName = legalEntityRequest.legalEntity.legalShortName) + legalEntity.legalName = Name("", shortName = legalEntityRequest.legalEntity.legalShortName) + legalEntity.states.replace(legalEntityRequest.legalEntity.states.map { toEntityState(it, legalEntity) }) legalEntity.classifications.replace(legalEntityRequest.legalEntity.classifications.map { toEntityClassification(it, legalEntity) }) + legalEntity.nameParts.replace(legalEntityRequest.legalNameParts.map { toNameParts(it, null, null, legalEntity) }) + legalEntity.legalAddress = logisticAddressRecord legalEntity.legalAddress.legalEntity = legalEntity + return legalEntity } diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt index c8bd30c89..697f466bf 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/LegalEntityService.kt @@ -120,7 +120,7 @@ private fun toValidSingleLegalEntity(legalEntity: LegalEntity): LegalEntityGateI return LegalEntityGateInputResponse( legalEntity = legalEntity.toLegalEntityDto(), - legalNameParts = listOf(legalEntity.legalName.value), + legalNameParts = getNamePartValuesToList(legalEntity.nameParts), legalAddress = legalEntity.legalAddress.toAddressGateInputResponse(legalEntity.legalAddress), externalId = legalEntity.externalId ) 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 530c72e40..95e11343b 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 @@ -35,7 +35,6 @@ fun AddressGateInputRequest.toAddressGate(legalEntity: LegalEntity?, site: Site? val logisticAddress = LogisticAddress( externalId = externalId, - nameParts = address.nameParts, physicalPostalAddress = address.physicalPostalAddress.toPhysicalPostalAddressEntity(), alternativePostalAddress = address.alternativePostalAddress?.toAlternativePostalAddressEntity(), legalEntity = legalEntity, @@ -44,6 +43,7 @@ fun AddressGateInputRequest.toAddressGate(legalEntity: LegalEntity?, site: Site? ) logisticAddress.states.addAll(this.address.states.map { toEntityAddress(it, logisticAddress) }.toSet()) + logisticAddress.nameParts.addAll(this.address.nameParts.map { toNameParts(it, logisticAddress, null, null) }.toSet()) return logisticAddress } @@ -53,7 +53,6 @@ fun AddressGateOutputRequest.toAddressGateOutput(legalEntity: LegalEntity?, site val logisticAddress = LogisticAddress( bpn = bpn, externalId = externalId, - nameParts = address.nameParts, physicalPostalAddress = address.physicalPostalAddress.toPhysicalPostalAddressEntity(), alternativePostalAddress = address.alternativePostalAddress?.toAlternativePostalAddressEntity(), legalEntity = legalEntity, @@ -62,6 +61,7 @@ fun AddressGateOutputRequest.toAddressGateOutput(legalEntity: LegalEntity?, site ) logisticAddress.states.addAll(this.address.states.map { toEntityAddress(it, logisticAddress) }.toSet()) + logisticAddress.nameParts.addAll(this.address.nameParts.map { toNameParts(it, logisticAddress, null, null) }.toSet()) return logisticAddress } @@ -70,6 +70,10 @@ fun toEntityAddress(dto: AddressStateDto, address: LogisticAddress): AddressStat return AddressState(dto.description, dto.validFrom, dto.validTo, dto.type, address) } +fun toNameParts(namePartsValue: String, address: LogisticAddress?, site: Site?, legalEntity: LegalEntity?): NameParts { + return NameParts(address, site, legalEntity, namePartsValue) +} + fun AlternativePostalAddressDto.toAlternativePostalAddressEntity(): AlternativePostalAddress { return AlternativePostalAddress( @@ -133,13 +137,14 @@ fun SiteGateInputRequest.toSiteGate(legalEntity: LegalEntity, datatype: OutputIn ) val site = Site( - nameParts = site.nameParts, externalId = externalId, legalEntity = legalEntity, dataType = datatype ) site.states.addAll(this.site.states.map { toEntityAddress(it, site) }.toSet()) + site.nameParts.addAll(this.site.nameParts.map { toNameParts(it, null, site, null) }.toSet()) + site.mainAddress = addressInputRequest.toAddressGate(null, site, datatype) return site @@ -156,13 +161,13 @@ fun SiteGateOutputRequest.toSiteGate(legalEntity: LegalEntity, datatype: OutputI val site = Site( bpn = bpn, - nameParts = site.nameParts, externalId = externalId, legalEntity = legalEntity, dataType = datatype ) site.states.addAll(this.site.states.map { toEntityAddress(it, site) }.toSet()) + site.nameParts.addAll(this.site.nameParts.map { toNameParts(it, null, site, null) }.toSet()) site.mainAddress = addressOutputRequest.toAddressGateOutput(null, site, datatype) return site @@ -191,12 +196,13 @@ fun LegalEntityGateInputRequest.toLegalEntity(datatype: OutputInputEnum): LegalE val legalEntity = LegalEntity( externalId = externalId, legalForm = legalEntity.legalForm, - legalName = Name(legalNameParts[0], legalEntity.legalShortName), + legalName = Name("", legalEntity.legalShortName), dataType = datatype ) legalEntity.states.addAll(this.legalEntity.states.map { toEntityState(it, legalEntity) }) legalEntity.classifications.addAll(this.legalEntity.classifications.map { toEntityClassification(it, legalEntity) }) + legalEntity.nameParts.addAll(this.legalNameParts.map { toNameParts(it, null, null, legalEntity) }) legalEntity.legalAddress = addressInputRequest.toAddressGate(legalEntity, null, datatype) @@ -217,12 +223,13 @@ fun LegalEntityGateOutputRequest.toLegalEntity(datatype: OutputInputEnum): Legal bpn = bpn, externalId = externalId, legalForm = legalEntity.legalForm, - legalName = Name(legalNameParts[0], legalEntity.legalShortName), + legalName = Name("", legalEntity.legalShortName), dataType = datatype ) legalEntity.states.addAll(this.legalEntity.states.map { toEntityState(it, legalEntity) }) legalEntity.classifications.addAll(this.legalEntity.classifications.map { toEntityClassification(it, legalEntity) }) + legalEntity.nameParts.addAll(this.legalNameParts.map { toNameParts(it, null, null, legalEntity) }) legalEntity.legalAddress = addressOutputRequest.toAddressGateOutput(legalEntity, null, datatype) @@ -263,7 +270,7 @@ fun LogisticAddress.toAddressGateInputResponse(logisticAddressPage: LogisticAddr fun LogisticAddress.toLogisticAddressDto(): LogisticAddressGateDto { val logisticAddress = LogisticAddressGateDto( - nameParts = nameParts, + nameParts = getNamePartValues(nameParts), states = mapToDtoStates(states), physicalPostalAddress = physicalPostalAddress.toPhysicalPostalAddress(), alternativePostalAddress = alternativePostalAddress?.toAlternativePostalAddressDto(), @@ -272,6 +279,16 @@ fun LogisticAddress.toLogisticAddressDto(): LogisticAddressGateDto { return logisticAddress } +//Collection +fun getNamePartValues(nameparts: MutableSet): Collection { + return nameparts.map { it.namePart } +} + +//List +fun getNamePartValuesToList(nameparts: MutableSet): List { + return nameparts.map { it.namePart } +} + fun mapToDtoStates(states: MutableSet): Collection { return states.map { AddressStateDto(it.description, it.validFrom, it.validTo, it.type) } } @@ -368,7 +385,7 @@ fun LegalEntity.toLegalEntityGateInputResponse(legalEntity: LegalEntity): LegalE legalEntity = legalEntity.toLegalEntityDto(), legalAddress = legalAddress.toAddressGateInputResponse(legalAddress), externalId = legalEntity.externalId, - legalNameParts = listOf(legalEntity.legalName.value) + legalNameParts = getNamePartValuesToList(nameParts) ) } @@ -376,7 +393,7 @@ fun LegalEntity.toLegalEntityGateInputResponse(legalEntity: LegalEntity): LegalE fun Site.toSiteDto(): SiteGateDto { return SiteGateDto( - nameParts = nameParts, + nameParts = getNamePartValues(nameParts), states = mapToDtoSitesStates(states) ) } @@ -428,7 +445,7 @@ fun LegalEntity.toLegalEntityGateOutputResponse(legalEntity: LegalEntity): Legal return LegalEntityGateOutputResponse( legalEntity = legalEntity.toLegalEntityDto(), - legalNameParts = listOf(legalName.value), + legalNameParts = getNamePartValues(legalEntity.nameParts), externalId = legalEntity.externalId, bpn = legalEntity.bpn!!, legalAddress = legalAddress.toAddressGateOutputResponse(legalAddress) 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 f57e79102..8dda96595 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,23 +88,23 @@ class SitePersistenceService( private fun updateSite(site: Site, updatedSite: SiteGateInputRequest, legalEntityRecord: LegalEntity) { - site.nameParts = updatedSite.site.nameParts site.externalId = updatedSite.externalId site.legalEntity = legalEntityRecord + site.states.replace(updatedSite.site.states.map { toEntityAddress(it, site) }) + site.nameParts.replace(updatedSite.site.nameParts.map { toNameParts(it, null, site, null) }) } private fun updateAddress(address: LogisticAddress, changeAddress: LogisticAddress) { - address.nameParts = changeAddress.nameParts address.externalId = changeAddress.externalId address.legalEntity = changeAddress.legalEntity address.physicalPostalAddress = changeAddress.physicalPostalAddress address.alternativePostalAddress = changeAddress.alternativePostalAddress address.states.replace(changeAddress.states.map { toEntityAddress(it, address) }) - + //address.nameParts.replace(changeAddress.nameParts) } fun toEntityAddress(dto: AddressState, address: LogisticAddress): AddressState { @@ -145,10 +145,11 @@ class SitePersistenceService( private fun updateSiteOutput(site: Site, updatedSite: SiteGateOutputRequest, legalEntityRecord: LegalEntity) { site.bpn = updatedSite.bpn - site.nameParts = updatedSite.site.nameParts site.externalId = updatedSite.externalId site.legalEntity = legalEntityRecord + site.states.replace(updatedSite.site.states.map { toEntityAddress(it, site) }) + site.nameParts.replace(updatedSite.site.nameParts.map { toNameParts(it, null, site, null) }) } } \ No newline at end of file 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 index 5cd820834..53ed6d36c 100644 --- 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 @@ -1,10 +1,31 @@ -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; +DROP COLUMN IF EXISTS name; ALTER TABLE sites -DROP COLUMN IF EXISTS name, -ADD COLUMN name_parts VARCHAR(255) NULL; \ No newline at end of file +DROP COLUMN IF EXISTS name; + +CREATE TABLE name_parts ( + id BIGINT NOT NULL, + created_at TIMESTAMP WITH time zone NOT NULL, + updated_at TIMESTAMP WITH time zone NOT NULL, + uuid UUID NOT NULL, + address_id BIGINT NULL, + site_id BIGINT NULL, + legal_entity_id BIGINT NULL, + name_part VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +); + +CREATE INDEX address_index_name_parts ON name_parts (address_id); + +CREATE INDEX site_index_name_parts ON name_parts (site_id); + +CREATE INDEX legal_entity_name_parts ON name_parts (legal_entity_id); + +ALTER TABLE IF EXISTS name_parts +ADD CONSTRAINT uuid_name_parts_uk UNIQUE (uuid); + +ALTER TABLE IF EXISTS name_parts +ADD CONSTRAINT fk_address_name_parts FOREIGN KEY (address_id) REFERENCES logistic_addresses, +ADD CONSTRAINT fk_legal_entity_name_parts FOREIGN KEY (legal_entity_id) REFERENCES legal_entities, +ADD CONSTRAINT fk_sites_name_parts FOREIGN KEY (site_id) REFERENCES sites; From 00ad8d51a9bc23bf056ff3f9fef77303082152f3 Mon Sep 17 00:00:00 2001 From: alexsilva Date: Tue, 27 Jun 2023 17:19:29 +0100 Subject: [PATCH 3/5] fix(gate): Fixed update for Addresses on Site and LegalEntity update --- .../tractusx/bpdm/gate/service/LegalEntityPersistenceService.kt | 2 +- .../tractusx/bpdm/gate/service/SitePersistenceService.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 3eb1ecca9..27910d561 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 @@ -102,7 +102,7 @@ class LegalEntityPersistenceService( address.alternativePostalAddress = changeAddress.alternativePostalAddress address.states.replace(changeAddress.states.map { toEntityAddress(it, address) }) - //address.nameParts.replace(changeAddress.nameParts) + address.nameParts.replace(changeAddress.nameParts.map { toNameParts(it.namePart, address, null, null) }) } 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 8dda96595..6c513dad0 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 @@ -104,7 +104,7 @@ class SitePersistenceService( address.alternativePostalAddress = changeAddress.alternativePostalAddress address.states.replace(changeAddress.states.map { toEntityAddress(it, address) }) - //address.nameParts.replace(changeAddress.nameParts) + address.nameParts.replace(changeAddress.nameParts.map { toNameParts(it.namePart, address, null, null) }) } fun toEntityAddress(dto: AddressState, address: LogisticAddress): AddressState { From b0d1c9a8be3912d03374911793b4a2afe39c9fbd Mon Sep 17 00:00:00 2001 From: alexsilva Date: Thu, 29 Jun 2023 16:21:36 +0100 Subject: [PATCH 4/5] fix(gate): Changed ShortName field on Legal Entity, removed Name Entity. Migration of Address and Sites names to name_parts --- .../tractusx/bpdm/gate/entity/LegalEntity.kt | 4 +-- .../eclipse/tractusx/bpdm/gate/entity/Name.kt | 32 ------------------- .../service/LegalEntityPersistenceService.kt | 9 ++++-- .../bpdm/gate/service/ResponseMappings.kt | 7 ++-- .../V4_0_0_4__add_name_parts_collumn.sql | 21 ++++++++---- 5 files changed, 27 insertions(+), 46 deletions(-) delete mode 100644 bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Name.kt 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 55de320c6..fbaf4e8ce 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 @@ -35,8 +35,8 @@ class LegalEntity( @Column(name = "externalId", nullable = false, unique = true) var externalId: String, - @Embedded - var legalName: Name, + @Column(name = "name_shortname") + var shortName: String?, @Column(name = "legal_form_id", nullable = false) var legalForm: String?, diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Name.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Name.kt deleted file mode 100644 index d53f69d93..000000000 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/Name.kt +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * 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.gate.entity - -import jakarta.persistence.Column -import jakarta.persistence.Embeddable - -@Embeddable -class Name( - @Column(name = "name_value", nullable = false) - val value: String, - - @Column(name = "name_shortname") - val shortName: String? -) 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 27910d561..fa1f26479 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 @@ -26,7 +26,10 @@ import org.eclipse.tractusx.bpdm.common.util.replace import org.eclipse.tractusx.bpdm.gate.api.model.LsaType import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateOutputRequest -import org.eclipse.tractusx.bpdm.gate.entity.* +import org.eclipse.tractusx.bpdm.gate.entity.AddressState +import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry +import org.eclipse.tractusx.bpdm.gate.entity.LegalEntity +import org.eclipse.tractusx.bpdm.gate.entity.LogisticAddress import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository import org.eclipse.tractusx.bpdm.gate.repository.GateAddressRepository import org.eclipse.tractusx.bpdm.gate.repository.LegalEntityRepository @@ -82,7 +85,7 @@ class LegalEntityPersistenceService( ): LegalEntity { legalEntity.externalId = legalEntityRequest.externalId legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm - legalEntity.legalName = Name("", shortName = legalEntityRequest.legalEntity.legalShortName) + legalEntity.shortName = legalEntityRequest.legalEntity.legalShortName legalEntity.states.replace(legalEntityRequest.legalEntity.states.map { toEntityState(it, legalEntity) }) legalEntity.classifications.replace(legalEntityRequest.legalEntity.classifications.map { toEntityClassification(it, legalEntity) }) @@ -148,7 +151,7 @@ class LegalEntityPersistenceService( legalEntity.bpn = legalEntityRequest.bpn legalEntity.externalId = legalEntityRequest.externalId legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm - legalEntity.legalName = Name("", shortName = legalEntityRequest.legalEntity.legalShortName) + legalEntity.shortName = legalEntityRequest.legalEntity.legalShortName legalEntity.states.replace(legalEntityRequest.legalEntity.states.map { toEntityState(it, legalEntity) }) legalEntity.classifications.replace(legalEntityRequest.legalEntity.classifications.map { toEntityClassification(it, legalEntity) }) 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 95e11343b..a360892ba 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 @@ -196,7 +196,7 @@ fun LegalEntityGateInputRequest.toLegalEntity(datatype: OutputInputEnum): LegalE val legalEntity = LegalEntity( externalId = externalId, legalForm = legalEntity.legalForm, - legalName = Name("", legalEntity.legalShortName), + shortName = legalEntity.legalShortName, dataType = datatype ) @@ -223,7 +223,7 @@ fun LegalEntityGateOutputRequest.toLegalEntity(datatype: OutputInputEnum): Legal bpn = bpn, externalId = externalId, legalForm = legalEntity.legalForm, - legalName = Name("", legalEntity.legalShortName), + shortName = legalEntity.legalShortName, dataType = datatype ) @@ -361,9 +361,10 @@ private fun Street.toStreetDto(): StreetGateDto { } fun LegalEntity.toLegalEntityDto(): LegalEntityDto { + return LegalEntityDto( legalForm = legalForm, - legalShortName = legalName.shortName, + legalShortName = shortName, states = mapToLegalEntityStateDto(states), classifications = mapToLegalEntityClassificationsDto(classifications), ) 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 index 53ed6d36c..131487672 100644 --- 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 @@ -1,9 +1,3 @@ -ALTER TABLE logistic_addresses -DROP COLUMN IF EXISTS name; - -ALTER TABLE sites -DROP COLUMN IF EXISTS name; - CREATE TABLE name_parts ( id BIGINT NOT NULL, created_at TIMESTAMP WITH time zone NOT NULL, @@ -29,3 +23,18 @@ ALTER TABLE IF EXISTS name_parts ADD CONSTRAINT fk_address_name_parts FOREIGN KEY (address_id) REFERENCES logistic_addresses, ADD CONSTRAINT fk_legal_entity_name_parts FOREIGN KEY (legal_entity_id) REFERENCES legal_entities, ADD CONSTRAINT fk_sites_name_parts FOREIGN KEY (site_id) REFERENCES sites; + +INSERT INTO name_parts (address_id, name_part) +SELECT id, name FROM logistic_addresses WHERE name IS NOT NULL; + +INSERT INTO name_parts (site_id, name_part) +SELECT id, name FROM sites WHERE name IS NOT NULL; + +ALTER TABLE logistic_addresses +DROP COLUMN IF EXISTS name; + +ALTER TABLE sites +DROP COLUMN IF EXISTS name; + +ALTER TABLE legal_entities +DROP COLUMN IF EXISTS name_value; \ No newline at end of file From 012a40b9b58f95069f3acfea0f0e0736ec69ffab Mon Sep 17 00:00:00 2001 From: alexsilva Date: Fri, 30 Jun 2023 10:53:15 +0100 Subject: [PATCH 5/5] fix(gate): Fixed migration errors, added Legal Entities name migration to name_parts --- .../migration/V4_0_0_4__add_name_parts_collumn.sql | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 index 131487672..fd9174589 100644 --- 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 @@ -24,11 +24,17 @@ ADD CONSTRAINT fk_address_name_parts FOREIGN KEY (address_id) REFERENCES logisti ADD CONSTRAINT fk_legal_entity_name_parts FOREIGN KEY (legal_entity_id) REFERENCES legal_entities, ADD CONSTRAINT fk_sites_name_parts FOREIGN KEY (site_id) REFERENCES sites; -INSERT INTO name_parts (address_id, name_part) -SELECT id, name FROM logistic_addresses WHERE name IS NOT NULL; +INSERT INTO name_parts (id, address_id, name_part, created_at, updated_at, uuid) +SELECT nextval('bpdm_sequence'), id, name, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, uuid +FROM logistic_addresses WHERE name IS NOT NULL; -INSERT INTO name_parts (site_id, name_part) -SELECT id, name FROM sites WHERE name IS NOT NULL; +INSERT INTO name_parts (id, site_id, name_part, created_at, updated_at, uuid) +SELECT nextval('bpdm_sequence'), id, name, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, uuid +FROM sites WHERE name IS NOT NULL; + +INSERT INTO name_parts (id, legal_entity_id, name_part, created_at, updated_at, uuid) +SELECT nextval('bpdm_sequence'), id, name_shortname, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, uuid +FROM legal_entities WHERE name_shortname IS NOT NULL; ALTER TABLE logistic_addresses DROP COLUMN IF EXISTS name;