From 907e27ec1924362806df560999b582927a80b9d5 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 12 Mar 2024 10:13:36 +0100 Subject: [PATCH] import-debitor-relationship (into intermediate data structure) (#22) Co-authored-by: Michael Hoennig Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/22 Reviewed-by: Timotheus Pokorra --- .../office/debitor/HsOfficeDebitorEntity.java | 6 ++-- .../HsOfficeRelationshipType.java | 2 +- .../changelog/220-hs-office-relationship.sql | 2 +- .../hs/office/migration/ImportOfficeData.java | 34 +++++++++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java index 29a9452d..0f92c6af 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java @@ -116,7 +116,7 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable { JOIN hs_office_relationship partnerRel ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER' JOIN hs_office_relationship debitorRel - ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND partnerRel.relType = 'ACCOUNTING' + ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND partnerRel.relType = 'DEBITOR' WHERE debitorRel.uuid = debitor.debitorRelUuid) || to_char(debitorNumberSuffix, 'fm00') from hs_office_debitor as debitor @@ -137,7 +137,7 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable { fetchedBySql(""" SELECT * FROM hs_office_relationship AS r - WHERE r.relType = 'ACCOUNTING' AND r.relHolderUuid = ${REF}.debitorRelUuid + WHERE r.relType = 'DEBITOR' AND r.relHolderUuid = ${REF}.debitorRelUuid """), dependsOnColumn("debitorRelUuid")) .createPermission(DELETE).grantedTo("debitorRel", OWNER) @@ -148,7 +148,7 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable { dependsOnColumn("refundBankAccountUuid"), fetchedBySql(""" SELECT * FROM hs_office_relationship AS r - WHERE r.relType = 'ACCOUNTING' AND r.relHolderUuid = ${REF}.debitorRelUuid + WHERE r.relType = 'DEBITOR' AND r.relHolderUuid = ${REF}.debitorRelUuid """) ) .toRole("refundBankAccount", ADMIN).grantRole("debitorRel", AGENT) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipType.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipType.java index 2b9fe60c..57053b1c 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipType.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipType.java @@ -6,7 +6,7 @@ public enum HsOfficeRelationshipType { EX_PARTNER, REPRESENTATIVE, VIP_CONTACT, - ACCOUNTING, + DEBITOR, OPERATIONS, SUBSCRIBER } diff --git a/src/main/resources/db/changelog/220-hs-office-relationship.sql b/src/main/resources/db/changelog/220-hs-office-relationship.sql index 44f9e500..a2abece1 100644 --- a/src/main/resources/db/changelog/220-hs-office-relationship.sql +++ b/src/main/resources/db/changelog/220-hs-office-relationship.sql @@ -9,8 +9,8 @@ CREATE TYPE HsOfficeRelationshipType AS ENUM ( 'PARTNER', 'EX_PARTNER', 'REPRESENTATIVE', + 'DEBITOR', 'VIP_CONTACT', - 'ACCOUNTING', 'OPERATIONS', 'SUBSCRIBER'); 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 929aa919..0c86dc66 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 @@ -175,7 +175,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(1011) + @Order(1019) void verifyBusinessPartners() { assumeThatWeAreImportingControlledTestData(); @@ -220,6 +220,23 @@ public class ImportOfficeData extends ContextBasedTest { @Test @Order(1021) + void buildDebitorRelationships() { + debitors.forEach( (id, debitor) -> { + final var debitorRel = HsOfficeRelationshipEntity.builder() + .relType(HsOfficeRelationshipType.DEBITOR) + .relAnchor(debitor.getPartner().getPartnerRole().getRelHolder()) + .relHolder(debitor.getPartner().getPartnerRole().getRelHolder()) // just 1 debitor/partner in legacy hsadmin + .contact(debitor.getBillingContact()) + .build(); + if (debitorRel.getRelAnchor() != null && debitorRel.getRelHolder() != null && + debitorRel.getContact() != null ) { + relationships.put(relationshipId++, debitorRel); + } + }); + } + + @Test + @Order(1029) void verifyContacts() { assumeThatWeAreImportingControlledTestData(); @@ -289,8 +306,11 @@ public class ImportOfficeData extends ContextBasedTest { 2000013=rel(relAnchor='LP JM GmbH', relType='VIP_CONTACT', relHolder='LP JM GmbH', contact='Frau Tammy Meyer-VIP , JM GmbH'), 2000014=rel(relAnchor='?? Test PS', relType='OPERATIONS', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'), 2000015=rel(relAnchor='?? Test PS', relType='REPRESENTATIVE', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'), - 2000016=rel(relAnchor='NP Mellies, Michael', relType='SUBSCRIBER', relMark='operations-announce', relHolder='NP Fanninga, Frauke', contact='Frau Frauke Fanninga ') - } + 2000016=rel(relAnchor='NP Mellies, Michael', relType='SUBSCRIBER', relMark='operations-announce', relHolder='NP Fanninga, Frauke', contact='Frau Frauke Fanninga '), + 2000017=rel(relAnchor='NP Mellies, Michael', relType='DEBITOR', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '), + 2000018=rel(relAnchor='LP JM GmbH', relType='DEBITOR', relHolder='LP JM GmbH', contact='Frau Dr. Jenny Meyer-Billing , JM GmbH'), + 2000019=rel(relAnchor='?? Test PS', relType='DEBITOR', relHolder='?? Test PS', contact='Petra Schmidt , Test PS') + } """); } @@ -307,7 +327,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(1031) + @Order(1039) void verifySepaMandates() { assumeThatWeAreImportingControlledTestData(); @@ -339,7 +359,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(1041) + @Order(1049) void verifyCoopShares() { assumeThatWeAreImportingControlledTestData(); @@ -366,7 +386,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(1051) + @Order(1059) void verifyCoopAssets() { assumeThatWeAreImportingControlledTestData(); @@ -398,7 +418,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(2001) + @Order(2009) void removeEmptyRelationships() { assumeThatWeAreImportingControlledTestData();