Skip to content

Commit

Permalink
fix(gate): Changed ShortName field on Legal Entity, removed Name Enti…
Browse files Browse the repository at this point in the history
…ty. Migration of Address and Sites names to name_parts
  • Loading branch information
alexsilva-CGI committed Jun 29, 2023
1 parent e9a8daf commit e07bb0a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class LegalEntity(
@Column(name = "externalId", nullable = false, unique = true)
var externalId: String,

@Embedded
var legalName: Name,
@Column(name = "name_shortname")
var shortName: String?,

@Column(name = "legal_form_id", nullable = false)
var legalForm: String?,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import org.eclipse.tractusx.bpdm.common.util.replace
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.entity.*
import org.eclipse.tractusx.bpdm.gate.entity.AddressState
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry
import org.eclipse.tractusx.bpdm.gate.entity.LegalEntity
import org.eclipse.tractusx.bpdm.gate.entity.LogisticAddress
import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository
import org.eclipse.tractusx.bpdm.gate.repository.GateAddressRepository
import org.eclipse.tractusx.bpdm.gate.repository.LegalEntityRepository
Expand Down Expand Up @@ -82,7 +85,7 @@ class LegalEntityPersistenceService(
): LegalEntity {
legalEntity.externalId = legalEntityRequest.externalId
legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm
legalEntity.legalName = Name("", shortName = legalEntityRequest.legalEntity.legalShortName)
legalEntity.shortName = legalEntityRequest.legalEntity.legalShortName

legalEntity.states.replace(legalEntityRequest.legalEntity.states.map { toEntityState(it, legalEntity) })
legalEntity.classifications.replace(legalEntityRequest.legalEntity.classifications.map { toEntityClassification(it, legalEntity) })
Expand Down Expand Up @@ -148,7 +151,7 @@ class LegalEntityPersistenceService(
legalEntity.bpn = legalEntityRequest.bpn
legalEntity.externalId = legalEntityRequest.externalId
legalEntity.legalForm = legalEntityRequest.legalEntity.legalForm
legalEntity.legalName = Name("", shortName = legalEntityRequest.legalEntity.legalShortName)
legalEntity.shortName = legalEntityRequest.legalEntity.legalShortName

legalEntity.states.replace(legalEntityRequest.legalEntity.states.map { toEntityState(it, legalEntity) })
legalEntity.classifications.replace(legalEntityRequest.legalEntity.classifications.map { toEntityClassification(it, legalEntity) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fun LegalEntityGateInputRequest.toLegalEntity(datatype: OutputInputEnum): LegalE
val legalEntity = LegalEntity(
externalId = externalId,
legalForm = legalEntity.legalForm,
legalName = Name("", legalEntity.legalShortName),
shortName = legalEntity.legalShortName,
dataType = datatype
)

Expand All @@ -219,7 +219,7 @@ fun LegalEntityGateOutputRequest.toLegalEntity(datatype: OutputInputEnum): Legal
bpn = bpn,
externalId = externalId,
legalForm = legalEntity.legalForm,
legalName = Name("", legalEntity.legalShortName),
shortName = legalEntity.legalShortName,
dataType = datatype
)

Expand Down Expand Up @@ -357,9 +357,10 @@ private fun Street.toStreetDto(): StreetGateDto {
}

fun LegalEntity.toLegalEntityDto(): LegalEntityDto {

return LegalEntityDto(
legalForm = legalForm,
legalShortName = legalName.shortName,
legalShortName = shortName,
states = mapToLegalEntityStateDto(states),
classifications = mapToLegalEntityClassificationsDto(classifications),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
ALTER TABLE logistic_addresses
DROP COLUMN IF EXISTS name;

ALTER TABLE sites
DROP COLUMN IF EXISTS name;

CREATE TABLE name_parts (
id BIGINT NOT NULL,
created_at TIMESTAMP WITH time zone NOT NULL,
Expand All @@ -29,3 +23,18 @@ ALTER TABLE IF EXISTS name_parts
ADD CONSTRAINT fk_address_name_parts FOREIGN KEY (address_id) REFERENCES logistic_addresses,
ADD CONSTRAINT fk_legal_entity_name_parts FOREIGN KEY (legal_entity_id) REFERENCES legal_entities,
ADD CONSTRAINT fk_sites_name_parts FOREIGN KEY (site_id) REFERENCES sites;

INSERT INTO name_parts (address_id, name_part)
SELECT id, name FROM logistic_addresses WHERE name IS NOT NULL;

INSERT INTO name_parts (site_id, name_part)
SELECT id, name FROM sites WHERE name IS NOT NULL;

ALTER TABLE logistic_addresses
DROP COLUMN IF EXISTS name;

ALTER TABLE sites
DROP COLUMN IF EXISTS name;

ALTER TABLE legal_entities
DROP COLUMN IF EXISTS name_value;

0 comments on commit e07bb0a

Please sign in to comment.