Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (Pool) - Added way to LegalAddress to be Main Site Address in Pool #674

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading