Skip to content

Commit

Permalink
fix(gate): Added Name Parts collumn with respective mappings to Site …
Browse files Browse the repository at this point in the history
…and Address
  • Loading branch information
alexsilva-CGI committed Jun 27, 2023
1 parent 1a0e0a1 commit 2476c61
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class LegalEntity(
@Column(name = "legal_form_id", nullable = false)
var legalForm: String?,

@Column(name = "name_parts", nullable = true)
val nameParts: List<String> = emptyList(),

@Column(name = "data_type")
@Enumerated(EnumType.STRING)
var dataType: OutputInputEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class LogisticAddress(
@JoinColumn(name = "site_id")
var site: Site?,

@Column(name = "name")
var name: String? = null,
@Column(name = "name_parts", nullable = true)
var nameParts: Collection<String> = emptyList(),

@Column(name = "data_type")
@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class Site(
@Column(name = "bpn")
var bpn: String? = null,

@Column(name = "name", nullable = false)
var name: String,

@Column(name = "external_id", nullable = false, unique = true)
var externalId: String,

@Column(name = "data_type")
@Enumerated(EnumType.STRING)
var dataType: OutputInputEnum,

@Column(name = "name_parts", nullable = true)
var nameParts: Collection<String> = emptyList(),

@ManyToOne
@JoinColumn(name = "legal_entity_id", nullable = false)
var legalEntity: LegalEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AddressPersistenceService(

private fun updateAddress(address: LogisticAddress, changeAddress: AddressGateInputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) {

address.name = changeAddress.address.nameParts.firstOrNull()
address.nameParts = changeAddress.address.nameParts
address.externalId = changeAddress.externalId
address.legalEntity = legalEntityRecord
address.site = siteRecord
Expand Down Expand Up @@ -107,7 +107,7 @@ class AddressPersistenceService(

private fun updateAddressOutput(address: LogisticAddress, changeAddress: AddressGateOutputRequest, legalEntityRecord: LegalEntity?, siteRecord: Site?) {

address.name = changeAddress.address.nameParts.firstOrNull()
address.nameParts = changeAddress.address.nameParts
address.bpn = changeAddress.bpn
address.externalId = changeAddress.externalId
address.legalEntity = legalEntityRecord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class LegalEntityPersistenceService(

private fun updateAddress(address: LogisticAddress, changeAddress: LogisticAddress) {

address.name = changeAddress.name
address.nameParts = changeAddress.nameParts
address.externalId = changeAddress.externalId
address.legalEntity = changeAddress.legalEntity
address.physicalPostalAddress = changeAddress.physicalPostalAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun AddressGateInputRequest.toAddressGate(legalEntity: LegalEntity?, site: Site?

val logisticAddress = LogisticAddress(
externalId = externalId,
name = address.nameParts.firstOrNull(),
nameParts = address.nameParts,
physicalPostalAddress = address.physicalPostalAddress.toPhysicalPostalAddressEntity(),
alternativePostalAddress = address.alternativePostalAddress?.toAlternativePostalAddressEntity(),
legalEntity = legalEntity,
Expand All @@ -49,7 +49,7 @@ fun AddressGateOutputRequest.toAddressGateOutput(legalEntity: LegalEntity?, site
val logisticAddress = LogisticAddress(
bpn = bpn,
externalId = externalId,
name = address.nameParts.firstOrNull(),
nameParts = address.nameParts,
physicalPostalAddress = address.physicalPostalAddress.toPhysicalPostalAddressEntity(),
alternativePostalAddress = address.alternativePostalAddress?.toAlternativePostalAddressEntity(),
legalEntity = legalEntity,
Expand Down Expand Up @@ -129,7 +129,7 @@ fun SiteGateInputRequest.toSiteGate(legalEntity: LegalEntity, datatype: OutputIn
)

val site = Site(
name = site.nameParts.firstOrNull()?: "",
nameParts = site.nameParts,
externalId = externalId,
legalEntity = legalEntity,
dataType = datatype
Expand All @@ -152,7 +152,7 @@ fun SiteGateOutputRequest.toSiteGate(legalEntity: LegalEntity, datatype: OutputI

val site = Site(
bpn = bpn,
name = site.nameParts.firstOrNull()?: "",
nameParts = site.nameParts,
externalId = externalId,
legalEntity = legalEntity,
dataType = datatype
Expand Down Expand Up @@ -259,7 +259,7 @@ fun LogisticAddress.toAddressGateInputResponse(logisticAddressPage: LogisticAddr
fun LogisticAddress.toLogisticAddressDto(): LogisticAddressGateDto {

val logisticAddress = LogisticAddressGateDto(
nameParts = name?.let { listOf(name!!) }?: emptyList(),
nameParts = nameParts,
states = mapToDtoStates(states),
physicalPostalAddress = physicalPostalAddress.toPhysicalPostalAddress(),
alternativePostalAddress = alternativePostalAddress?.toAlternativePostalAddressDto(),
Expand Down Expand Up @@ -372,7 +372,7 @@ fun LegalEntity.toLegalEntityGateInputResponse(legalEntity: LegalEntity): LegalE
fun Site.toSiteDto(): SiteGateDto {

return SiteGateDto(
nameParts = if(name.isEmpty()) emptyList() else listOf(name),
nameParts = nameParts,
states = mapToDtoSitesStates(states)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SitePersistenceService(

private fun updateSite(site: Site, updatedSite: SiteGateInputRequest, legalEntityRecord: LegalEntity) {

site.name = updatedSite.site.nameParts.firstOrNull() ?: ""
site.nameParts = updatedSite.site.nameParts
site.externalId = updatedSite.externalId
site.legalEntity = legalEntityRecord
site.states.replace(updatedSite.site.states.map { toEntityAddress(it, site) })
Expand All @@ -97,7 +97,7 @@ class SitePersistenceService(

private fun updateAddress(address: LogisticAddress, changeAddress: LogisticAddress) {

address.name = changeAddress.name
address.nameParts = changeAddress.nameParts
address.externalId = changeAddress.externalId
address.legalEntity = changeAddress.legalEntity
address.physicalPostalAddress = changeAddress.physicalPostalAddress
Expand Down Expand Up @@ -145,7 +145,7 @@ class SitePersistenceService(
private fun updateSiteOutput(site: Site, updatedSite: SiteGateOutputRequest, legalEntityRecord: LegalEntity) {

site.bpn = updatedSite.bpn
site.name = updatedSite.site.nameParts.firstOrNull() ?: ""
site.nameParts = updatedSite.site.nameParts
site.externalId = updatedSite.externalId
site.legalEntity = legalEntityRecord
site.states.replace(updatedSite.site.states.map { toEntityAddress(it, site) })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ALTER TABLE legal_entities
ADD COLUMN name_parts VARCHAR(255) NULL;

ALTER TABLE logistic_addresses
DROP COLUMN IF EXISTS name,
ADD COLUMN name_parts VARCHAR(255) NULL;

ALTER TABLE sites
DROP COLUMN IF EXISTS name,
ADD COLUMN name_parts VARCHAR(255) NULL;

0 comments on commit 2476c61

Please sign in to comment.