Skip to content

Commit

Permalink
Merge pull request #674 from catenax-ng/fix/legal_address_as_site_mai…
Browse files Browse the repository at this point in the history
…n_address

Fix (Pool) - Added way to LegalAddress to be Main Site Address in Pool
  • Loading branch information
nicoprow authored Dec 7, 2023
2 parents 265ef60 + 69adb21 commit 8bd8b0d
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.eclipse.tractusx.bpdm.pool.service

import jakarta.transaction.Transactional
import org.eclipse.tractusx.bpdm.common.dto.AddressType
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.pool.api.model.ChangelogType
import org.eclipse.tractusx.bpdm.pool.dto.AddressMetadataDto
Expand Down Expand Up @@ -73,7 +74,7 @@ class TaskStepBuildService(

var siteEntity: Site? = null
if (businessPartnerDto.site != null) {
siteEntity = upsertSite(businessPartnerDto.site, legalEntity, taskEntryBpnMapping)
siteEntity = upsertSite(businessPartnerDto.site, legalEntity, taskEntryBpnMapping, businessPartnerDto)
siteResult = businessPartnerDto.site!!.copy(
bpnSReference = BpnReferenceDto(referenceValue = siteEntity.bpn, referenceType = BpnReferenceType.Bpn)
)
Expand Down Expand Up @@ -284,7 +285,12 @@ class TaskStepBuildService(
return upsertLe
}

private fun upsertSite(siteDto: SiteDto?, legalEntity: LegalEntity, taskEntryBpnMapping: TaskEntryBpnMapping): Site {
private fun upsertSite(
siteDto: SiteDto?,
legalEntity: LegalEntity,
taskEntryBpnMapping: TaskEntryBpnMapping,
genericBusinessPartner: BusinessPartnerFullDto
): Site {

val bpnSReference = siteDto?.bpnSReference ?: throw BpdmValidationException(CleaningError.BPNS_IS_NULL.message)
val mainAddress = siteDto.mainAddress ?: throw BpdmValidationException(CleaningError.MAINE_ADDRESS_IS_NULL.message)
Expand All @@ -296,10 +302,17 @@ class TaskStepBuildService(
val bpnS = bpnIssuingService.issueSiteBpns(1).single()
val createSite = BusinessPartnerBuildService.createSite(siteDto, bpnS, legalEntity)
taskEntryBpnMapping.addMapping(bpnSReference, bpnS)
val address = createLogisticAddress(mainAddress, taskEntryBpnMapping)
createSite.mainAddress = address
address.site = createSite

val siteMainAddress =
if (genericBusinessPartner.generic.postalAddress.addressType == AddressType.LegalAndSiteMainAddress)
legalEntity.legalAddress
else
createLogisticAddress(mainAddress, taskEntryBpnMapping)

createSite.mainAddress = siteMainAddress
siteMainAddress.site = createSite
createSite

} else {

val updateSite = siteRepository.findByBpn(bpn)
Expand Down

0 comments on commit 8bd8b0d

Please sign in to comment.