From 9053f546b4792e13d4e0eb65a8afc6c6b485f59c Mon Sep 17 00:00:00 2001
From: Michael Hoennig <michael@hoennig.de>
Date: Sat, 29 Oct 2022 10:59:03 +0200
Subject: [PATCH] import legacy hsadmin db (WIP)

---
 src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java |   78 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 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
new file mode 100644
index 0000000..59c4a19
--- /dev/null
+++ b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java
@@ -0,0 +1,78 @@
+package net.hostsharing.hsadminng.hs.office.migration;
+
+import com.opencsv.CSVParserBuilder;
+import com.opencsv.CSVReader;
+import com.opencsv.CSVReaderBuilder;
+import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
+import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
+import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
+import org.junit.jupiter.api.Test;
+
+import jakarta.validation.constraints.NotNull;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ImportBusinessPartners {
+
+    private Map<Integer, HsOfficePartnerEntity> partners = new HashMap<>();
+    private Map<Integer, HsOfficeMembershipEntity> members = new HashMap<>();
+
+    @Test
+    void importsBusinessPartners() throws Exception {
+
+        try (Reader reader = resourceReader("migration/business_partners.csv")) {
+            final var records = readAllLines(reader);
+
+            importsBusinessPartners(records);
+
+            assertThat(records).hasSize(4);
+        }
+
+    }
+
+    public List<String[]> readAllLines(Reader reader) throws Exception {
+
+        final var parser = new CSVParserBuilder()
+                .withSeparator(';')
+                .withQuoteChar('"')
+                .build();
+
+        try (CSVReader csvReader = new CSVReaderBuilder(reader)
+                .withSkipLines(1)
+                .withCSVParser(parser)
+                .build()) {
+            return csvReader.readAll();
+        }
+    }
+
+    private void importsBusinessPartners(final List<String[]> records) {
+        records.forEach( record -> {
+
+
+            HsOfficePersonEntity.builder()
+                    .tradeName(record[])
+
+                    .build();
+        });
+    }
+
+    private Reader resourceReader(@NotNull final String resourcePath) {
+        return new InputStreamReader(getClass().getClassLoader().getResourceAsStream(resourcePath));
+    }
+
+    private Reader fileReader(@NotNull final Path filePath) throws IOException {
+        //        Path path = Paths.get(
+        //                ClassLoader.getSystemResource("csv/twoColumn.csv").toURI())
+        //    );
+        return Files.newBufferedReader(filePath);
+    }
+
+}

--
Gitblit v1.9.3