Skip to content

Commit

Permalink
fix(gate): Created function for sites and legal entity external id as…
Browse files Browse the repository at this point in the history
…sociation to the logistic addresses
  • Loading branch information
alexsilva-CGI committed May 23, 2023
1 parent 8c1e08f commit 6c0c743
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fun SiteGateInputRequest.toSiteGate(legalEntity: LegalEntity): Site {

val addressInputRequest = AddressGateInputRequest(
address = site.mainAddress,
externalId = externalId + "_site",
externalId = getMainAddressForSiteExternalId(externalId),
legalEntityExternalId = externalId
)

Expand Down Expand Up @@ -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(
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6c0c743

Please sign in to comment.