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 d3d69858c..f2e46645e 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 @@ -66,4 +66,6 @@ class LegalEntity( @OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true) val nameParts: MutableSet = mutableSetOf() + @OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true) + val identifiers: MutableSet = mutableSetOf() } diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LegalEntityIdentifier.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LegalEntityIdentifier.kt new file mode 100644 index 000000000..eb72b756b --- /dev/null +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/entity/LegalEntityIdentifier.kt @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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 = "legal_entity_identifiers", + indexes = [ + Index(columnList = "legal_entity_id") + ] +) +class LegalEntityIdentifier( + @Column(name = "`value`", nullable = false) + var value: String, + + @Column(name = "type_id", nullable = false) + var type: String, + + @Column(name = "issuing_body") + var issuingBody: String?, + + @ManyToOne + @JoinColumn(name = "legal_entity_id", nullable = false) + var legalEntity: LegalEntity + +) : BaseEntity() 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 0395803fa..f130319ce 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 @@ -90,6 +90,7 @@ class LegalEntityPersistenceService( 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.identifiers.replace(legalEntityRequest.legalEntity.identifiers.map { toEntityIdentifiers(it, legalEntity) }) legalEntity.roles.replace(legalEntityRequest.roles.distinct().map { toRoles(it, legalEntity, null, null) }) legalEntity.legalAddress = logisticAddressRecord @@ -158,6 +159,7 @@ class LegalEntityPersistenceService( 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.identifiers.replace(legalEntityRequest.legalEntity.identifiers.map { toEntityIdentifiers(it, legalEntity) }) legalEntity.roles.replace(legalEntityRequest.roles.distinct().map { toRoles(it, legalEntity, null, null) }) legalEntity.legalAddress = logisticAddressRecord 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 f6b76acf3..df5ee6c55 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 @@ -212,6 +212,7 @@ fun LegalEntityGateInputRequest.toLegalEntity(datatype: OutputInputEnum): LegalE legalEntity.nameParts.addAll(this.legalNameParts.map { toNameParts(it, null, null, legalEntity) }) legalEntity.roles.addAll(this.roles.distinct().map { toRoles(it, legalEntity, null, null) }) + legalEntity.identifiers.addAll(this.legalEntity.identifiers.map { toEntityIdentifiers(it, legalEntity) }) legalEntity.legalAddress = addressInputRequest.toAddressGate(legalEntity, null, datatype) return legalEntity @@ -258,6 +259,10 @@ fun toEntityClassification(dto: ClassificationDto, legalEntity: LegalEntity): Cl return Classification(dto.value, dto.code, dto.type, legalEntity) } +fun toEntityIdentifiers(dto: LegalEntityIdentifierDto, legalEntity: LegalEntity): LegalEntityIdentifier { + return LegalEntityIdentifier(dto.value, dto.type, dto.issuingBody, legalEntity) +} + fun getMainAddressForSiteExternalId(siteExternalId: String): String { return siteExternalId + "_site" } @@ -358,7 +363,6 @@ fun PhysicalPostalAddress.toPhysicalPostalAddress(): PhysicalPostalAddressGateDt street = street?.toStreetDto(), areaPart = areaDistrictDto ) - } fun GeographicCoordinate.toGeographicCoordinateDto(): GeoCoordinateDto { @@ -386,6 +390,7 @@ fun LegalEntity.toLegalEntityDto(): LegalEntityDto { legalShortName = shortName, states = mapToLegalEntityStateDto(states), classifications = mapToLegalEntityClassificationsDto(classifications), + identifiers = mapToLegalEntityIdentifiersDto(identifiers) ) } @@ -398,6 +403,10 @@ fun mapToLegalEntityClassificationsDto(classification: MutableSet): Collection { + return identifiers.map { LegalEntityIdentifierDto(it.value, it.type, it.issuingBody) } +} + //LegalEntity mapping to LegalEntityGateInputResponse fun LegalEntity.toLegalEntityGateInputResponse(legalEntity: LegalEntity): LegalEntityGateInputDto { diff --git a/bpdm-gate/src/main/resources/db/migration/V4_0_0_7__create_table_legal_entity_identifiers.sql b/bpdm-gate/src/main/resources/db/migration/V4_0_0_7__create_table_legal_entity_identifiers.sql new file mode 100644 index 000000000..1d1855799 --- /dev/null +++ b/bpdm-gate/src/main/resources/db/migration/V4_0_0_7__create_table_legal_entity_identifiers.sql @@ -0,0 +1,15 @@ +CREATE TABLE legal_entity_identifiers ( + id int8 NOT NULL, + uuid uuid NOT NULL, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + value varchar(255) NOT NULL, + type_id varchar(255) NOT NULL, + legal_entity_id int8 NOT NULL, + issuing_body varchar(255) NULL, + CONSTRAINT pk_identifiers PRIMARY KEY (id), + CONSTRAINT uc_identifiers_uuid UNIQUE (uuid) +); +CREATE INDEX idx_9de08b456309ac30a77546592 ON legal_entity_identifiers USING btree (legal_entity_id); + +ALTER TABLE legal_entity_identifiers ADD CONSTRAINT fk_identifiers_on_partner FOREIGN KEY (legal_entity_id) REFERENCES legal_entities(id); \ No newline at end of file