db-migration #10
@ -60,11 +60,11 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void importsBusinessPartners() {
|
void importBusinessPartners() {
|
||||||
|
|
||||||
try (Reader reader = resourceReader("migration/business-partners.csv")) {
|
try (Reader reader = resourceReader("migration/business-partners.csv")) {
|
||||||
final var records = readAllLines(reader);
|
final var records = readAllLines(reader);
|
||||||
importsBusinessPartners(records);
|
importBusinessPartners(records);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -72,11 +72,11 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void importsContacts() {
|
void importContacts() {
|
||||||
|
|
||||||
try (Reader reader = resourceReader("migration/contacts.csv")) {
|
try (Reader reader = resourceReader("migration/contacts.csv")) {
|
||||||
final var records = readAllLines(reader);
|
final var records = readAllLines(reader);
|
||||||
importsContacts(records);
|
importContacts(records);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -91,7 +91,9 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|||||||
contacts.forEach((id, contact) -> em.persist(contact));
|
contacts.forEach((id, contact) -> em.persist(contact));
|
||||||
persons.forEach((id, person) -> em.persist(person));
|
persons.forEach((id, person) -> em.persist(person));
|
||||||
partners.forEach((id, partner) -> em.persist(partner));
|
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 {
|
public List<String[]> readAllLines(Reader reader) throws Exception {
|
||||||
@ -109,7 +111,7 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importsBusinessPartners(final List<String[]> records) {
|
private void importBusinessPartners(final List<String[]> records) {
|
||||||
records.stream()
|
records.stream()
|
||||||
.map(this::trimAll)
|
.map(this::trimAll)
|
||||||
.forEach(record -> {
|
.forEach(record -> {
|
||||||
@ -136,6 +138,7 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|||||||
.vatBusiness("GROSS".equals(record[10]))
|
.vatBusiness("GROSS".equals(record[10]))
|
||||||
.vatId(record[11])
|
.vatId(record[11])
|
||||||
.build();
|
.build();
|
||||||
|
debitors.put(toInt(record[0]), debitor);
|
||||||
|
|
||||||
partners.put(toInt(record[0]), partner);
|
partners.put(toInt(record[0]), partner);
|
||||||
|
|
||||||
@ -155,7 +158,7 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importsContacts(final List<String[]> records) {
|
private void importContacts(final List<String[]> records) {
|
||||||
records.stream()
|
records.stream()
|
||||||
.map(this::trimAll)
|
.map(this::trimAll)
|
||||||
.forEach(record -> {
|
.forEach(record -> {
|
||||||
@ -171,6 +174,7 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|||||||
person.setGivenName(record[4]);
|
person.setGivenName(record[4]);
|
||||||
|
|
||||||
initContact(partner.getContact(), record);
|
initContact(partner.getContact(), record);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
initContact(new HsOfficeContactEntity(), record);
|
initContact(new HsOfficeContactEntity(), record);
|
||||||
// TODO: create relationship
|
// TODO: create relationship
|
||||||
|
Loading…
Reference in New Issue
Block a user