From 6c0c743a54020f3cf1db50b04a0c10adf56af150 Mon Sep 17 00:00:00 2001 From: alexsilva Date: Mon, 22 May 2023 10:23:22 +0100 Subject: [PATCH] fix(gate): Created function for sites and legal entity external id association to the logistic addresses --- .../service/LegalEntityPersistenceService.kt | 2 +- .../bpdm/gate/service/ResponseMappings.kt | 29 ++++++++++++++----- .../gate/service/SitePersistenceService.kt | 5 +++- 3 files changed, 26 insertions(+), 10 deletions(-) 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 ba42f9a2b..1b1785ebb 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 @@ -49,7 +49,7 @@ class LegalEntityPersistenceService( val fullLegalEntity = legalEntity.toLegalEntity() legalEntityRecord.find { it.externalId == legalEntity.externalId }?.let { existingLegalEntity -> - val logisticAddressRecord = gateAddressRepository.findByExternalId(existingLegalEntity.externalId + "_legalAddress") + val logisticAddressRecord = gateAddressRepository.findByExternalId(getMainAddressForLegalEntityExternalId(existingLegalEntity.externalId)) ?: throw BpdmNotFoundException("Business Partner", "Error") updateAddress(logisticAddressRecord, fullLegalEntity.legalAddress) 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 08f096642..612bfbf48 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 @@ -122,7 +122,7 @@ fun SiteGateInputRequest.toSiteGate(legalEntity: LegalEntity): Site { val addressInputRequest = AddressGateInputRequest( address = site.mainAddress, - externalId = externalId + "_site", + externalId = getMainAddressForSiteExternalId(externalId), legalEntityExternalId = externalId ) @@ -154,9 +154,9 @@ fun ChangelogEntry.toGateDto(): ChangelogResponse { fun LegalEntityGateInputRequest.toLegalEntity(): LegalEntity { val addressInputRequest =AddressGateInputRequest( - address= legalEntity.legalAddress, - externalId= externalId+"_legalAddress", - legalEntityExternalId= externalId + address = legalEntity.legalAddress, + externalId = getMainAddressForLegalEntityExternalId(externalId), + legalEntityExternalId = externalId ) val legalEntity= LegalEntity( @@ -175,18 +175,31 @@ fun LegalEntityGateInputRequest.toLegalEntity(): LegalEntity { return legalEntity } + fun toEntityIdentifier(dto: LegalEntityIdentifierDto, legalEntity: LegalEntity): LegalEntityIdentifier { - return LegalEntityIdentifier(dto.value, dto.type,dto.issuingBody, legalEntity) + return LegalEntityIdentifier(dto.value, dto.type, dto.issuingBody, legalEntity) } + fun toEntityState(dto: LegalEntityStateDto, legalEntity: LegalEntity): LegalEntityState { - return LegalEntityState(dto.officialDenotation,dto.validFrom,dto.validTo,dto.type,legalEntity) + return LegalEntityState(dto.officialDenotation, dto.validFrom, dto.validTo, dto.type, legalEntity) } + fun toEntityClassification(dto: ClassificationDto, legalEntity: LegalEntity): Classification { - return Classification(dto.value,dto.code,dto.type,legalEntity) + return Classification(dto.value, dto.code, dto.type, legalEntity) } -fun NameDto.toName(): Name{ + +fun NameDto.toName(): Name { return Name(value, shortName) } + private fun createCurrentnessTimestamp(): Instant { return Instant.now().truncatedTo(ChronoUnit.MICROS) +} + +fun getMainAddressForSiteExternalId(siteExternalId: String): String { + return siteExternalId + "_site" +} + +fun getMainAddressForLegalEntityExternalId(siteExternalId: String): String { + return siteExternalId + "_legalAddress" } \ No newline at end of file diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt index 0f2ef85cb..48ab746a6 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/SitePersistenceService.kt @@ -56,7 +56,10 @@ class SitePersistenceService( siteRecord.find { it.externalId == site.externalId }?.let { existingSite -> val logisticAddressRecord = - addressRepository.findByExternalId(site.externalId + "_site") ?: throw BpdmNotFoundException("Business Partner", "Error") + addressRepository.findByExternalId(getMainAddressForSiteExternalId(site.externalId)) ?: throw BpdmNotFoundException( + "Business Partner", + "Error" + ) updateAddress(logisticAddressRecord, fullSite.mainAddress)