Skip to content

Commit

Permalink
fix(pool):resolved conflitct of AlternativePostalAddressToSaasMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaralexandremorais committed Jun 28, 2023
1 parent 1a0e0a1 commit d307de2
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 905 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressDoc
import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressPartnerDoc
import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LegalEntityDoc
import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.TextDoc
import org.eclipse.tractusx.bpdm.pool.entity.AlternativePostalAddress
import org.eclipse.tractusx.bpdm.pool.entity.LegalEntity
import org.eclipse.tractusx.bpdm.pool.entity.LogisticAddress
import org.eclipse.tractusx.bpdm.pool.entity.PhysicalPostalAddress
import org.springframework.stereotype.Service

/**
Expand Down Expand Up @@ -56,7 +58,7 @@ class DocumentMappingService {

val addresses: MutableList<AddressPartnerDoc> = mutableListOf()
val list = listOfNotNull(logisticAddress.name)
addresses.add(toAddressPartnerDoc(list,(PhysicalPostalAddressToSaasMapping(logisticAddress.physicalPostalAddress)), logisticAddress.bpn))
addresses.add(toAddressPartnerDoc(list, (logisticAddress.physicalPostalAddress), logisticAddress.bpn))
// TODO OpenSearch indexing doesn't work as expected when creating two AddressPartnerDocs with the same BPN (which is the ID), only last is indexed!
// For now don't index alternativePostalAddress, since this would override (more important) physicalPostalAddress!
// if (logisticAddress.alternativePostalAddress != null) {
Expand All @@ -73,30 +75,41 @@ class DocumentMappingService {

val addresses: MutableList<AddressDoc> = mutableListOf()

addresses.add(toAddressDoc((PhysicalPostalAddressToSaasMapping(logisticAddress.physicalPostalAddress))))
addresses.add(toAddressDoc(logisticAddress.physicalPostalAddress))
if (logisticAddress.alternativePostalAddress != null) {
addresses.add(toAddressDoc((AlternativePostalAddressToSaasMapping(logisticAddress.alternativePostalAddress!!))))
addresses.add(toAddressDoc((logisticAddress.alternativePostalAddress!!)))
}

return addresses
}

fun toAddressPartnerDoc(name: List<String>, address: AddressToSaasMapping, bpn: String): AddressPartnerDoc {
fun toAddressPartnerDoc(name: List<String>, address: PhysicalPostalAddress, bpn: String): AddressPartnerDoc {
return AddressPartnerDoc(
bpn = bpn,
name = name
)
}


fun toAddressDoc(address: AddressToSaasMapping): AddressDoc {
fun toAddressDoc(address: PhysicalPostalAddress): AddressDoc {
return AddressDoc(
administrativeAreas = address.administrativeAreas().map { TextDoc(it) },
postCodes = address.postcodes().map { TextDoc(it) },
localities = address.localities().map { TextDoc(it) },
thoroughfares = address.thoroughfares().map { TextDoc(it) },
premises = address.premises().map { TextDoc(it) },
postalDeliveryPoints = address.postalDeliveryPoints().map { TextDoc(it) }
administrativeAreas = setOf(TextDoc(address.administrativeAreaLevel2.toString())),
postCodes = setOf(TextDoc(address.postCode.toString())),
localities = setOf(TextDoc("")),
thoroughfares = setOf(TextDoc("")),
premises = setOf(TextDoc("")),
postalDeliveryPoints = setOf(TextDoc(""))
)
}

fun toAddressDoc(address: AlternativePostalAddress): AddressDoc {
return AddressDoc(
administrativeAreas = setOf(TextDoc(address.administrativeAreaLevel2.toString())),
postCodes = setOf(TextDoc(address.postCode.toString())),
localities = setOf(TextDoc("")),
thoroughfares = setOf(TextDoc("")),
premises = setOf(TextDoc("")),
postalDeliveryPoints = setOf(TextDoc(""))
)
}

Expand Down

This file was deleted.

Loading

0 comments on commit d307de2

Please sign in to comment.