Skip to content

Commit

Permalink
Merge pull request #321 from catenax-ng/fix/gate_identifiers_not_retr…
Browse files Browse the repository at this point in the history
…ivied

fix(gate): fixed the persistence of LegalEntityIdentifier
  • Loading branch information
nicoprow authored Jul 7, 2023
2 parents 3752c1b + c66d326 commit 9a0aaa7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ class LegalEntity(
@OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true)
val nameParts: MutableSet<NameParts> = mutableSetOf()

@OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true)
val identifiers: MutableSet<LegalEntityIdentifier> = mutableSetOf()
}
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -358,7 +363,6 @@ fun PhysicalPostalAddress.toPhysicalPostalAddress(): PhysicalPostalAddressGateDt
street = street?.toStreetDto(),
areaPart = areaDistrictDto
)

}

fun GeographicCoordinate.toGeographicCoordinateDto(): GeoCoordinateDto {
Expand Down Expand Up @@ -386,6 +390,7 @@ fun LegalEntity.toLegalEntityDto(): LegalEntityDto {
legalShortName = shortName,
states = mapToLegalEntityStateDto(states),
classifications = mapToLegalEntityClassificationsDto(classifications),
identifiers = mapToLegalEntityIdentifiersDto(identifiers)
)

}
Expand All @@ -398,6 +403,10 @@ fun mapToLegalEntityClassificationsDto(classification: MutableSet<Classification
return classification.map { ClassificationDto(it.value, it.code, it.type) }
}

fun mapToLegalEntityIdentifiersDto(identifiers: MutableSet<LegalEntityIdentifier>): Collection<LegalEntityIdentifierDto> {
return identifiers.map { LegalEntityIdentifierDto(it.value, it.type, it.issuingBody) }
}

//LegalEntity mapping to LegalEntityGateInputResponse
fun LegalEntity.toLegalEntityGateInputResponse(legalEntity: LegalEntity): LegalEntityGateInputDto {

Expand Down
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 9a0aaa7

Please sign in to comment.