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 8d9dbfd9b..e07506a19 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.LegalEntityGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateOutputRequest import org.eclipse.tractusx.bpdm.gate.api.model.LsaType -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 4b9bfcdd7..4eac34aee 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 @@ -192,7 +192,7 @@ fun LegalEntityGateInputRequest.toLegalEntity(datatype: OutputInputEnum): LegalE val legalEntity = LegalEntity( externalId = externalId, legalForm = legalEntity.legalForm, - legalName = Name("", legalEntity.legalShortName), + shortName = legalEntity.legalShortName, dataType = datatype ) @@ -219,7 +219,7 @@ fun LegalEntityGateOutputRequest.toLegalEntity(datatype: OutputInputEnum): Legal bpn = bpn, externalId = externalId, legalForm = legalEntity.legalForm, - legalName = Name("", legalEntity.legalShortName), + shortName = legalEntity.legalShortName, dataType = datatype ) @@ -357,9 +357,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