Michael Hoennig
2022-10-29 b6b60081fdd3d19d9024e0d8896687aa5bb6336e
persist memberships+debitors - still with wrong reference
1 files modified
18 ■■■■■ changed files
src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java 18 ●●●●● patch | view | raw | blame | history
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