From 066e19185c8edf321fcd66a05e8caedb8de5b413 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 26 Jan 2024 10:48:29 +0100 Subject: [PATCH] add partner without contact data to import test data and improve error message --- .../hs/office/migration/ImportOfficeData.java | 116 ++++++++++++++---- .../resources/migration/business-partners.csv | 1 + 2 files changed, 96 insertions(+), 21 deletions(-) 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 df52ced1..68d6fe39 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 @@ -182,7 +182,8 @@ public class ImportOfficeData extends ContextBasedTest { { 17=partner(null null, null), 20=partner(null null, null), - 22=partner(null null, null) + 22=partner(null null, null), + 99=partner(null null, null) } """); assertThat(toFormattedString(contacts)).isEqualTo("{}"); @@ -190,7 +191,9 @@ public class ImportOfficeData extends ContextBasedTest { { 17=debitor(D-1001700: null null, null: mih), 20=debitor(D-1002000: null null, null: xyz), - 22=debitor(D-1102200: null null, null: xxx)} + 22=debitor(D-1102200: null null, null: xxx), + 99=debitor(D-1999900: null null, null: zzz) + } """); assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace(""" { @@ -222,7 +225,8 @@ public class ImportOfficeData extends ContextBasedTest { { 17=partner(NP Mellies, Michael: Herr Michael Mellies ), 20=partner(LP JM GmbH: Herr Philip Meyer-Contract , JM GmbH), - 22=partner(?? Test PS: Petra Schmidt , Test PS) + 22=partner(?? Test PS: Petra Schmidt , Test PS), + 99=partner(null null, null) } """); assertThat(toFormattedString(contacts)).isEqualToIgnoringWhitespace(""" @@ -254,7 +258,8 @@ public class ImportOfficeData extends ContextBasedTest { { 17=debitor(D-1001700: NP Mellies, Michael: mih), 20=debitor(D-1002000: LP JM GmbH: xyz), - 22=debitor(D-1102200: ?? Test PS: xxx) + 22=debitor(D-1102200: ?? Test PS: xxx), + 99=debitor(D-1999900: null null, null: zzz) } """); assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace(""" @@ -269,19 +274,21 @@ public class ImportOfficeData extends ContextBasedTest { 2000000=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '), 2000001=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'), 2000002=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'), - 2000003=rel(relAnchor='NP Mellies, Michael', relType='OPERATIONS', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '), - 2000004=rel(relAnchor='LP JM GmbH', relType='EX_PARTNER', relHolder='LP JM e.K.', contact='JM e.K.'), - 2000005=rel(relAnchor='LP JM GmbH', relType='OPERATIONS', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'), - 2000006=rel(relAnchor='LP JM GmbH', relType='VIP_CONTACT', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'), - 2000007=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='operations-announce', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'), - 2000008=rel(relAnchor='LP JM GmbH', relType='REPRESENTATIVE', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'), - 2000009=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='members-announce', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'), - 2000010=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='customers-announce', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'), - 2000011=rel(relAnchor='LP JM GmbH', relType='VIP_CONTACT', relHolder='LP JM GmbH', contact='Frau Tammy Meyer-VIP , JM GmbH'), - 2000012=rel(relAnchor='?? Test PS', relType='OPERATIONS', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'), - 2000013=rel(relAnchor='?? Test PS', relType='REPRESENTATIVE', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'), - 2000014=rel(relAnchor='NP Mellies, Michael', relType='SUBSCRIBER', relMark='operations-announce', relHolder='NP Fanninga, Frauke', contact='Frau Frauke Fanninga '), - 2000015=rel(relAnchor='NP Mellies, Michael', relType='REPRESENTATIVE', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies ') + 2000003=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='null null, null'), + 2000004=rel(relAnchor='NP Mellies, Michael', relType='OPERATIONS', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '), + 2000005=rel(relAnchor='LP JM GmbH', relType='EX_PARTNER', relHolder='LP JM e.K.', contact='JM e.K.'), + 2000006=rel(relAnchor='LP JM GmbH', relType='OPERATIONS', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'), + 2000007=rel(relAnchor='LP JM GmbH', relType='VIP_CONTACT', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'), + 2000008=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='operations-announce', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'), + 2000009=rel(relAnchor='LP JM GmbH', relType='REPRESENTATIVE', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'), + 2000010=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='members-announce', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'), + 2000011=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='customers-announce', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'), + 2000012=rel(relAnchor='LP JM GmbH', relType='VIP_CONTACT', relHolder='LP JM GmbH', contact='Frau Tammy Meyer-VIP , JM GmbH'), + 2000013=rel(relAnchor='?? Test PS', relType='OPERATIONS', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'), + 2000014=rel(relAnchor='?? Test PS', relType='REPRESENTATIVE', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'), + 2000015=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='REPRESENTATIVE', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '), + 2000017=rel(relAnchor='null null, null', relType='REPRESENTATIVE', relHolder='null null, null') } """); } @@ -378,6 +385,73 @@ public class ImportOfficeData extends ContextBasedTest { @Test @Order(2000) + void verifyAllPartnersHavePersons() { + partners.forEach((id, p) -> { + if ( id != 99 ) { + assertThat(p.getContact()).describedAs("partner " + id + " without contact").isNotNull(); + assertThat(p.getContact().getLabel()).describedAs("partner " + id + " without valid contact").isNotNull(); + assertThat(p.getPerson()).describedAs("partner " + id + " without person").isNotNull(); + assertThat(p.getPerson().getPersonType()).describedAs("partner " + id + " without valid person").isNotNull(); + } + }); + } + + @Test + @Order(2001) + void removeEmptyRelationships() { + assumeThatWeAreImportingControlledTestData(); + + // avoid a error when persisting the deliberetely invalid partner entry #99 + final var idsToRemove = new HashSet(); + relationships.forEach( (id, r) -> { + // such a record + if (r.getContact() == null || r.getContact().getLabel() == null || + r.getRelHolder() == null | r.getRelHolder().getPersonType() == null ) { + idsToRemove.add(id); + } + }); + assertThat(idsToRemove.size()).isEqualTo(2); // only from partner #99 (partner+contractual roles) + idsToRemove.forEach(id -> relationships.remove(id)); + } + + @Test + @Order(2002) + void removeEmptyPartners() { + assumeThatWeAreImportingControlledTestData(); + + // avoid a error when persisting the deliberetely invalid partner entry #99 + final var idsToRemove = new HashSet(); + partners.forEach( (id, r) -> { + // such a record + if (r.getContact() == null || r.getContact().getLabel() == null || + r.getPerson() == null | r.getPerson().getPersonType() == null ) { + idsToRemove.add(id); + } + }); + assertThat(idsToRemove.size()).isEqualTo(1); // only from partner #99 + idsToRemove.forEach(id -> partners.remove(id)); + } + + @Test + @Order(2003) + void removeEmptyDebitors() { + assumeThatWeAreImportingControlledTestData(); + + // avoid a error when persisting the deliberetely invalid partner entry #99 + final var idsToRemove = new HashSet(); + debitors.forEach( (id, r) -> { + // such a record + if (r.getBillingContact() == null || r.getBillingContact().getLabel() == null || + r.getPartner().getPerson() == null | r.getPartner().getPerson().getPersonType() == null ) { + idsToRemove.add(id); + } + }); + assertThat(idsToRemove.size()).isEqualTo(1); // only from partner #99 + idsToRemove.forEach(id -> debitors.remove(id)); + } + + @Test + @Order(3000) @Commit void persistEntities() { @@ -447,13 +521,13 @@ public class ImportOfficeData extends ContextBasedTest { private void persist(final Integer id, final HasUuid entity) { try { - System.out.println("persisting #" + entity.hashCode() + ": " + entity.toString()); + System.out.println("persisting #" + entity.hashCode() + ": " + entity); em.persist(entity); em.flush(); System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid()); - } catch (Exception x) { - System.out.println("failed to persist: " + entity.toString()); - throw x; + } catch (Exception exc) { + System.err.println("failed to persist #" + entity.hashCode() + ": " + entity); + System.err.println(exc); } } diff --git a/src/test/resources/migration/business-partners.csv b/src/test/resources/migration/business-partners.csv index a31c2e9d..3d49d950 100644 --- a/src/test/resources/migration/business-partners.csv +++ b/src/test/resources/migration/business-partners.csv @@ -2,3 +2,4 @@ bp_id;member_id;member_code;member_since;member_until;member_role;author_contrac 17;10017;hsh00-mih;2000-12-06;;Aufsichtsrat;2006-10-15;2001-10-15;false;false;NET;DE-VAT-007 20;10020;hsh00-xyz;2000-12-06;2015-12-31;;;;false;false;GROSS; 22;11022;hsh00-xxx;2021-04-01;;;;;true;true;GROSS; +99;19999;hsh00-zzz;;;;;;false;false;GROSS;