Skip to content

Commit

Permalink
Merge pull request #326 from catenax-ng/fix/adress_identifiers
Browse files Browse the repository at this point in the history
fix(gate): fixed the persistence of AddressIdentifier
  • Loading branch information
nicoprow authored Jul 26, 2023
2 parents bf5509d + 800eb47 commit 50b3412
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ class LogisticAddress(

@OneToMany(mappedBy = "address", cascade = [CascadeType.ALL], orphanRemoval = true)
val roles: MutableSet<Roles> = mutableSetOf()

@OneToMany(mappedBy = "address", cascade = [CascadeType.ALL], orphanRemoval = true)
val identifiers: MutableSet<AddressIdentifier> = mutableSetOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AddressPersistenceService(
address.site = siteRecord
address.physicalPostalAddress = changeAddress.address.physicalPostalAddress.toPhysicalPostalAddressEntity()
address.alternativePostalAddress = changeAddress.address.alternativePostalAddress?.toAlternativePostalAddressEntity()

address.identifiers.replace(changeAddress.address.identifiers.distinct().map { toEntityAddressIdentifiers(it, address) })
address.states.replace(changeAddress.address.states.map { toEntityAddress(it, address) })
address.nameParts.replace(changeAddress.address.nameParts.map { toNameParts(it, address, null, null) })
address.roles.replace(changeAddress.address.roles.distinct().map { toRoles(it, null, null, address) })
Expand Down Expand Up @@ -114,7 +114,7 @@ class AddressPersistenceService(
address.site = siteRecord
address.physicalPostalAddress = changeAddress.address.physicalPostalAddress.toPhysicalPostalAddressEntity()
address.alternativePostalAddress = changeAddress.address.alternativePostalAddress?.toAlternativePostalAddressEntity()

address.identifiers.replace(changeAddress.address.identifiers.distinct().map { toEntityAddressIdentifiers(it, address) })
address.states.replace(changeAddress.address.states.map { toEntityAddress(it, address) })
address.nameParts.replace(changeAddress.address.nameParts.map { toNameParts(it, address, null, null) })
address.roles.replace(changeAddress.address.roles.distinct().map { toRoles(it, null, null, address) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class LegalEntityPersistenceService(
address.legalEntity = changeAddress.legalEntity
address.physicalPostalAddress = changeAddress.physicalPostalAddress
address.alternativePostalAddress = changeAddress.alternativePostalAddress

address.identifiers.replace(changeAddress.identifiers.map { toEntityAddressIdentifiers(it.mapToAddressIdentifiersDto(), address) })
address.states.replace(changeAddress.states.map { toEntityAddress(it, address) })
address.nameParts.replace(changeAddress.nameParts.map { toNameParts(it.namePart, address, null, null) })
address.roles.replace(changeAddress.roles.distinct().map { toRoles(it.roleName, null, null, address) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun AddressGateInputRequest.toAddressGate(legalEntity: LegalEntity?, site: Site?
logisticAddress.states.addAll(this.address.states.map { toEntityAddress(it, logisticAddress) }.toSet())
logisticAddress.nameParts.addAll(this.address.nameParts.map { toNameParts(it, logisticAddress, null, null) }.toSet())
logisticAddress.roles.addAll(this.address.roles.distinct().map { toRoles(it, null, null, logisticAddress) }.toSet())

logisticAddress.identifiers.addAll(this.address.identifiers.distinct().map { toEntityAddressIdentifiers(it, logisticAddress) }.toSet())
return logisticAddress
}

Expand All @@ -61,7 +61,7 @@ fun AddressGateOutputRequest.toAddressGateOutput(legalEntity: LegalEntity?, site
logisticAddress.states.addAll(this.address.states.map { toEntityAddress(it, logisticAddress) }.toSet())
logisticAddress.nameParts.addAll(this.address.nameParts.map { toNameParts(it, logisticAddress, null, null) }.toSet())
logisticAddress.roles.addAll(this.address.roles.distinct().map { toRoles(it, null, null, logisticAddress) }.toSet())

logisticAddress.identifiers.addAll(this.address.identifiers.distinct().map { toEntityAddressIdentifiers(it, logisticAddress) }.toSet())
return logisticAddress
}

Expand Down Expand Up @@ -253,6 +253,10 @@ fun toRoles(role: BusinessPartnerRole, legalEntity: LegalEntity?, site: Site?, a
return Roles(legalEntity, address, site, role)
}

fun toEntityAddressIdentifiers(dto: AddressIdentifierDto, address: LogisticAddress): AddressIdentifier {
return AddressIdentifier(dto.value, dto.type, address)
}

fun toEntityState(dto: LegalEntityStateDto, legalEntity: LegalEntity): LegalEntityState {
return LegalEntityState(dto.officialDenotation, dto.validFrom, dto.validTo, dto.type, legalEntity)
}
Expand Down Expand Up @@ -295,6 +299,7 @@ fun LogisticAddress.toLogisticAddressDto(): LogisticAddressGateDto {
roles = roles.map { it.roleName },
physicalPostalAddress = physicalPostalAddress.toPhysicalPostalAddress(),
alternativePostalAddress = alternativePostalAddress?.toAlternativePostalAddressDto(),
identifiers = mapToAddressIdentifiersDto(identifiers)
)

return logisticAddress
Expand Down Expand Up @@ -409,6 +414,14 @@ fun mapToLegalEntityIdentifiersDto(identifiers: MutableSet<LegalEntityIdentifier
return identifiers.map { LegalEntityIdentifierDto(it.value, it.type, it.issuingBody) }
}

fun mapToAddressIdentifiersDto(identifiers: MutableSet<AddressIdentifier>): Collection<AddressIdentifierDto> {
return identifiers.map { AddressIdentifierDto(it.value, it.type) }
}

fun AddressIdentifier.mapToAddressIdentifiersDto(): AddressIdentifierDto {
return AddressIdentifierDto(value, type)
}

//LegalEntity mapping to LegalEntityGateInputResponse
fun LegalEntity.toLegalEntityGateInputResponse(legalEntity: LegalEntity): LegalEntityGateInputDto {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SitePersistenceService(
address.legalEntity = changeAddress.legalEntity
address.physicalPostalAddress = changeAddress.physicalPostalAddress
address.alternativePostalAddress = changeAddress.alternativePostalAddress

address.identifiers.replace(changeAddress.identifiers.map { toEntityAddressIdentifiers(it.mapToAddressIdentifiersDto(), address) })
address.states.replace(changeAddress.states.map { toEntityAddress(it, address) })
address.nameParts.replace(changeAddress.nameParts.map { toNameParts(it.namePart, address, null, null) })
address.roles.replace(changeAddress.roles.distinct().map { toRoles(it.roleName, null, null, address) })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE address_identifiers (
id int8 NOT NULL,
uuid uuid NOT NULL,
created_at timestamp with time zone not null,
updated_at timestamp with time zone not null,
value varchar(255) NOT NULL,
identifier_type_key varchar(255) NOT NULL,
address_id int8 NOT NULL,
CONSTRAINT pk_address_identifiers PRIMARY KEY (id),
CONSTRAINT uc_address_identifiers_uuid UNIQUE (uuid)
);
CREATE INDEX idx_address_identifiers_on_address ON address_identifiers USING btree (address_id);


ALTER TABLE address_identifiers ADD CONSTRAINT fk_address_identifiers_on_address FOREIGN KEY (address_id) REFERENCES logistic_addresses(id);
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,14 @@ internal class AddressControllerInputIT @Autowired constructor(
val paginationValue = PaginationRequest(page, size)
val pageResponse = gateClient.addresses().getAddresses(paginationValue)

assertThat(pageResponse).isEqualTo(
PageDto(
totalElements = totalElements,
totalPages = totalPages,
page = pageValue,
contentSize = contentSize,
content = expectedAddresses
)
val expectedPage = PageDto(
totalElements = totalElements,
totalPages = totalPages,
page = pageValue,
contentSize = contentSize,
content = expectedAddresses
)
assertThat(pageResponse).usingRecursiveComparison().isEqualTo(expectedPage)
}


Expand Down Expand Up @@ -194,15 +193,14 @@ internal class AddressControllerInputIT @Autowired constructor(
val pagination = PaginationRequest(page, size)
val pageResponse = gateClient.addresses().getAddressesByExternalIds(pagination, listExternalIds)

assertThat(pageResponse).isEqualTo(
PageDto(
totalElements = totalElements,
totalPages = totalPages,
page = pageValue,
contentSize = contentSize,
content = expectedAddresses
)
val expectedPage = PageDto(
totalElements = totalElements,
totalPages = totalPages,
page = pageValue,
contentSize = contentSize,
content = expectedAddresses
)
assertThat(pageResponse).usingRecursiveComparison().isEqualTo(expectedPage)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ internal class AddressControllerOutputIT @Autowired constructor(
val paginationValue = PaginationRequest(page, size)
val pageResponse = gateClient.addresses().getAddressesOutput(paginationValue, emptyList())

assertThat(pageResponse).usingRecursiveComparison().ignoringFieldsMatchingRegexes(".*processStartedAt*").isEqualTo(
assertThat(pageResponse).usingRecursiveComparison().ignoringFieldsMatchingRegexes(".*processStartedAt*", ".*identifiers*").isEqualTo(
PageDto(
totalElements = totalElements,
totalPages = totalPages,
Expand Down Expand Up @@ -223,7 +223,7 @@ internal class AddressControllerOutputIT @Autowired constructor(
val paginationValue = PaginationRequest(page, size)
val pageResponse = gateClient.addresses().getAddressesOutput(paginationValue, listOf(CommonValues.externalIdAddress1, CommonValues.externalIdAddress2))

assertThat(pageResponse).usingRecursiveComparison().ignoringFieldsMatchingRegexes(".*processStartedAt*").isEqualTo(
assertThat(pageResponse).usingRecursiveComparison().ignoringFieldsMatchingRegexes(".*processStartedAt*", ".*identifiers*").isEqualTo(
PageDto(
totalElements = totalElements,
totalPages = totalPages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.eclipse.tractusx.bpdm.gate.util

import org.eclipse.tractusx.bpdm.common.dto.AddressIdentifierDto
import org.eclipse.tractusx.bpdm.common.dto.BasePhysicalAddressDto
import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto
import org.eclipse.tractusx.bpdm.common.dto.StreetDto
Expand Down Expand Up @@ -292,6 +293,9 @@ object ResponseValues {
val logisticAddressGateInputResponse1 = AddressGateInputDto(
address = RequestValues.logisticAddress1.copy(
nameParts = listOf(CommonValues.name1),
identifiers = listOf(
AddressIdentifierDto(RequestValues.identifier1.value!!, RequestValues.identifier1.type!!)
)
),
externalId = CommonValues.externalIdAddress1,
legalEntityExternalId = null,
Expand All @@ -300,6 +304,9 @@ object ResponseValues {
val logisticAddressGateInputResponse2 = AddressGateInputDto(
address = RequestValues.logisticAddress2.copy(
nameParts = listOf(CommonValues.name2),
identifiers = listOf(
AddressIdentifierDto(RequestValues.identifier1.value!!, RequestValues.identifier1.type!!)
)
),
externalId = CommonValues.externalIdAddress2,
siteExternalId = null,
Expand Down

0 comments on commit 50b3412

Please sign in to comment.