Skip to content

Commit

Permalink
Merge pull request #312 from catenax-ng/fix/name_parts_persist
Browse files Browse the repository at this point in the history
Fix/name parts persist
  • Loading branch information
nicoprow authored Jun 30, 2023
2 parents 51bbfbe + 012a40b commit 6292cd3
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -59,4 +59,8 @@ class LegalEntity(

@OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true)
val addresses: MutableSet<LogisticAddress> = mutableSetOf()

@OneToMany(mappedBy = "legalEntity", cascade = [CascadeType.ALL], orphanRemoval = true)
val nameParts: MutableSet<NameParts> = mutableSetOf()

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class LogisticAddress(
@JoinColumn(name = "site_id")
var site: Site?,

@Column(name = "name")
var name: String? = null,

@Column(name = "data_type")
@Enumerated(EnumType.STRING)
var dataType: OutputInputEnum,
Expand All @@ -63,4 +60,7 @@ class LogisticAddress(

@OneToMany(mappedBy = "address", cascade = [CascadeType.ALL], orphanRemoval = true)
val states: MutableSet<AddressState> = mutableSetOf()

@OneToMany(mappedBy = "address", cascade = [CascadeType.ALL], orphanRemoval = true)
val nameParts: MutableSet<NameParts> = mutableSetOf()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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<NameParts> = mutableSetOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ class AddressPersistenceService(

private fun updateAddress(address: LogisticAddress, changeAddress: AddressGateInputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) {

address.name = changeAddress.address.nameParts.firstOrNull()
address.externalId = changeAddress.externalId
address.legalEntity = legalEntityRecord
address.site = siteRecord
address.physicalPostalAddress = changeAddress.address.physicalPostalAddress.toPhysicalPostalAddressEntity()
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) })

}

Expand Down Expand Up @@ -107,7 +107,6 @@ class AddressPersistenceService(

private fun updateAddressOutput(address: LogisticAddress, changeAddress: AddressGateOutputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) {

address.name = changeAddress.address.nameParts.firstOrNull()
address.bpn = changeAddress.bpn
address.externalId = changeAddress.externalId
address.legalEntity = legalEntityRecord
Expand All @@ -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) })

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,23 +85,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.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.name = changeAddress.name
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.map { toNameParts(it.namePart, address, null, null) })

}

Expand Down Expand Up @@ -144,11 +151,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.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
}

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

0 comments on commit 6292cd3

Please sign in to comment.