From 4d6c330398d199ec886f7ac3aaf2918418ff1c0e Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 1 Feb 2024 10:43:46 +0100 Subject: [PATCH] amendments according to code-review --- .../db/changelog/230-hs-office-partner.sql | 4 +- .../hs/office/migration/ImportOfficeData.java | 38 +++++-------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/main/resources/db/changelog/230-hs-office-partner.sql b/src/main/resources/db/changelog/230-hs-office-partner.sql index a093d6eb..d1db4400 100644 --- a/src/main/resources/db/changelog/230-hs-office-partner.sql +++ b/src/main/resources/db/changelog/230-hs-office-partner.sql @@ -33,10 +33,10 @@ create table hs_office_partner ( uuid uuid unique references RbacObject (uuid) initially deferred, partnerNumber numeric(5) unique not null, - partnerRoleUuid uuid not null references hs_office_relationship(uuid) on delete cascade, + partnerRoleUuid uuid not null references hs_office_relationship(uuid), -- TODO: delete in after delete trigger personUuid uuid not null references hs_office_person(uuid), -- TODO: remove, replaced by partnerRoleUuid contactUuid uuid not null references hs_office_contact(uuid), -- TODO: remove, replaced by partnerRoleUuid - detailsUuid uuid not null references hs_office_partner_details(uuid) on delete cascade + detailsUuid uuid not null references hs_office_partner_details(uuid) -- deleted in after delete trigger ); --// diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java index a0d37f30..c9877466 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java @@ -647,7 +647,6 @@ public class ImportOfficeData extends ContextBasedTest { .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("Hostsharing eG") .build(); - assertThat(persons.containsKey(1)).describedAs("overwriting " + persons.get(1) + " index " + 1 + " with " + mandant).isFalse(); persons.put(1, mandant); records.stream() @@ -662,10 +661,7 @@ public class ImportOfficeData extends ContextBasedTest { .relAnchor(mandant) .contact(null) // is set during contacts import depending on assigned roles .build(); - final Integer i3 = relationshipId++; - assertThat(relationships.containsKey(i3)).describedAs("overwriting " + relationships.get(i3) + " index " + i3 - + " with " + partnerRelationship).isFalse(); - relationships.put(i3, partnerRelationship); + relationships.put(relationshipId++, partnerRelationship); final var partner = HsOfficePartnerEntity.builder() .partnerNumber(rec.getInteger("member_id")) @@ -674,9 +670,7 @@ public class ImportOfficeData extends ContextBasedTest { .contact(null) // is set during contacts import depending on assigned roles .person(person) .build(); - final Integer i2 = rec.getInteger("bp_id"); - assertThat(partners.containsKey(i2)).describedAs("overwriting " + partners.get(i2) + " index " + i2 + " with " + partner).isFalse(); - partners.put(i2, partner); + partners.put(rec.getInteger("bp_id"), partner); final var debitor = HsOfficeDebitorEntity.builder() .partner(partner) @@ -688,9 +682,7 @@ public class ImportOfficeData extends ContextBasedTest { .vatBusiness("GROSS".equals(rec.getString("indicator_vat"))) // TODO: remove .vatId(rec.getString("uid_vat")) .build(); - final Integer i1 = rec.getInteger("bp_id"); - assertThat(debitors.containsKey(i1)).describedAs("overwriting " + debitors.get(i1) + " index " + i1 + " with " + debitor).isFalse(); - debitors.put(i1, debitor); + debitors.put(rec.getInteger("bp_id"), debitor); if (isNotBlank(rec.getString("member_since"))) { assertThat(rec.getInteger("member_id")).isEqualTo(partner.getPartnerNumber()); @@ -707,9 +699,7 @@ public class ImportOfficeData extends ContextBasedTest { : HsOfficeReasonForTermination.UNKNOWN) .mainDebitor(debitor) .build(); - final Integer i = rec.getInteger("bp_id"); - assertThat(memberships.containsKey(i)).describedAs("overwriting " + memberships.get(i) + " index " + i + " with " + membership).isFalse(); - memberships.put(i, membership); + memberships.put(rec.getInteger("bp_id"), membership); } }); } @@ -738,9 +728,7 @@ public class ImportOfficeData extends ContextBasedTest { .comment( rec.getString("comment")) .build(); - final Integer i = rec.getInteger("member_share_id"); - assertThat(coopShares.containsKey(i)).describedAs("overwriting " + coopShares.get(i) + " index " + i + " with " + shareTransaction).isFalse(); - coopShares.put(i, shareTransaction); + coopShares.put(rec.getInteger("member_share_id"), shareTransaction); }); } @@ -783,9 +771,7 @@ public class ImportOfficeData extends ContextBasedTest { .comment(rec.getString("comment")) .build(); - final Integer i = rec.getInteger("member_asset_id"); - assertThat(coopAssets.containsKey(i)).describedAs("overwriting " + coopAssets.get(i) + " index " + i + " with " + assetTransaction).isFalse(); - coopAssets.put(i, assetTransaction); + coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction); }); } @@ -919,9 +905,7 @@ public class ImportOfficeData extends ContextBasedTest { .contact(contact) .relType(representative) .build(); - final Integer i = relationshipId++; - assertThat(relationships.containsKey(i)).describedAs("overwriting " + relationships.get(i) + " index " + i + " with " + rel).isFalse(); - relationships.put(i, rel); + relationships.put(relationshipId++, rel); return rel; } @@ -932,9 +916,7 @@ public class ImportOfficeData extends ContextBasedTest { person.setTradeName(contactRecord.getString("firma")); determinePersonType(person, contactRecord.getString("roles")); - final Integer i = contactRecord.getInteger("contact_id"); - assertThat(persons.containsKey(i)).describedAs("overwriting " + persons.get(i) + " index " + i + " with " + person).isFalse(); - persons.put(i, person); + persons.put(contactRecord.getInteger("contact_id"), person); return person; } @@ -989,9 +971,7 @@ public class ImportOfficeData extends ContextBasedTest { contact.setPostalAddress(toAddress(contactRecord)); contact.setPhoneNumbers(toPhoneNumbers(contactRecord)); - final Integer i = contactRecord.getInteger("contact_id"); - assertThat(contacts.containsKey(i)).describedAs("overwriting " + contacts.get(i) + " index " + i + " with " + contact).isFalse(); - contacts.put(i, contact); + contacts.put(contactRecord.getInteger("contact_id"), contact); return contact; }