From b6b60081fdd3d19d9024e0d8896687aa5bb6336e Mon Sep 17 00:00:00 2001
From: Michael Hoennig <michael@hoennig.de>
Date: Sat, 29 Oct 2022 17:51:14 +0200
Subject: [PATCH] persist memberships+debitors - still with wrong reference

---
 src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java
index 858fbdc..3fd284f 100644
--- a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java
+++ b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java
@@ -60,11 +60,11 @@
 
     @Test
     @Order(1)
-    void importsBusinessPartners() {
+    void importBusinessPartners() {
 
         try (Reader reader = resourceReader("migration/business-partners.csv")) {
             final var records = readAllLines(reader);
-            importsBusinessPartners(records);
+            importBusinessPartners(records);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -72,11 +72,11 @@
 
     @Test
     @Order(2)
-    void importsContacts() {
+    void importContacts() {
 
         try (Reader reader = resourceReader("migration/contacts.csv")) {
             final var records = readAllLines(reader);
-            importsContacts(records);
+            importContacts(records);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -91,7 +91,9 @@
             contacts.forEach((id, contact) -> em.persist(contact));
             persons.forEach((id, person) -> em.persist(person));
             partners.forEach((id, partner) -> em.persist(partner));
-        });
+            debitors.forEach((id, debitor) -> em.persist(debitor));
+            memberships.forEach((id, membership) -> em.persist(membership));
+        }).assertSuccessful();
     }
 
     public List<String[]> readAllLines(Reader reader) throws Exception {
@@ -109,7 +111,7 @@
         }
     }
 
-    private void importsBusinessPartners(final List<String[]> records) {
+    private void importBusinessPartners(final List<String[]> records) {
         records.stream()
                 .map(this::trimAll)
                 .forEach(record -> {
@@ -136,6 +138,7 @@
                             .vatBusiness("GROSS".equals(record[10]))
                             .vatId(record[11])
                             .build();
+                    debitors.put(toInt(record[0]), debitor);
 
                     partners.put(toInt(record[0]), partner);
 
@@ -155,7 +158,7 @@
                 });
     }
 
-    private void importsContacts(final List<String[]> records) {
+    private void importContacts(final List<String[]> records) {
         records.stream()
                 .map(this::trimAll)
                 .forEach(record -> {
@@ -171,6 +174,7 @@
                         person.setGivenName(record[4]);
 
                         initContact(partner.getContact(), record);
+
                     } else {
                         initContact(new HsOfficeContactEntity(), record);
                         // TODO: create relationship

--
Gitblit v1.9.3