db-migration #10
@ -4,6 +4,7 @@ import com.opencsv.CSVParserBuilder;
|
||||
import com.opencsv.CSVReader;
|
||||
import com.opencsv.CSVReaderBuilder;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||
@ -14,9 +15,14 @@ import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||
import net.hostsharing.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@ -35,12 +41,23 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
@DataJpaTest
|
||||
@Import({ Context.class, JpaAttempt.class })
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class ImportBusinessPartners {
|
||||
public class ImportBusinessPartners extends ContextBasedTest {
|
||||
|
||||
private static Map<Integer, HsOfficeContactEntity> contacts = new HashMap<>();
|
||||
private static Map<Integer, HsOfficePersonEntity> persons = new HashMap<>();
|
||||
private static Map<Integer, HsOfficePartnerEntity> partners = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeDebitorEntity> debitors = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>();
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
@Autowired
|
||||
JpaAttempt jpaAttempt;
|
||||
|
||||
@MockBean
|
||||
HttpServletRequest request;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void importsBusinessPartners() {
|
||||
@ -65,12 +82,16 @@ public class ImportBusinessPartners {
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void afterAll() {
|
||||
System.out.println(partners);
|
||||
System.out.println(debitors);
|
||||
System.out.println(memberships);
|
||||
@Test
|
||||
@Order(10)
|
||||
void persistEntities() {
|
||||
jpaAttempt.transacted( () -> {
|
||||
context("superuser-alex@hostsharing.net"); // TODO: use real user
|
||||
|
||||
contacts.forEach((id, contact) -> em.persist(contact));
|
||||
persons.forEach((id, person) -> em.persist(person));
|
||||
partners.forEach((id, partner) -> em.persist(partner));
|
||||
});
|
||||
}
|
||||
|
||||
public List<String[]> readAllLines(Reader reader) throws Exception {
|
||||
@ -93,12 +114,15 @@ public class ImportBusinessPartners {
|
||||
.map(this::trimAll)
|
||||
.forEach(record -> {
|
||||
|
||||
final var person = HsOfficePersonEntity.builder()
|
||||
.personType(HsOfficePersonType.UNKNOWN) // TODO
|
||||
.build();
|
||||
persons.put(toInt(record[0]), person);
|
||||
|
||||
final var partner = HsOfficePartnerEntity.builder()
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.contact(HsOfficeContactEntity.builder().build())
|
||||
.person(HsOfficePersonEntity.builder()
|
||||
.personType(HsOfficePersonType.UNKNOWN) // TODO
|
||||
.build())
|
||||
.person(person)
|
||||
.build();
|
||||
partners.put(toInt(record[0]), partner);
|
||||
|
||||
@ -136,22 +160,33 @@ public class ImportBusinessPartners {
|
||||
.map(this::trimAll)
|
||||
.forEach(record -> {
|
||||
|
||||
final var partner = partners.get(toInt(record[1]));
|
||||
if ( isNotBlank(record[17]) && record[17].contains("billing") ) {
|
||||
|
||||
final var contact = partner.getContact();
|
||||
contact.setLabel(toLabel(record[2], record[5], record[3], record[4], record[6]));
|
||||
contact.setEmailAddresses(record[16]);
|
||||
contact.setPostalAddress(toAddress(record));
|
||||
contact.setPhoneNumbers(toPhoneNumbers(record));
|
||||
final var partner = partners.get(toInt(record[1]));
|
||||
|
||||
final var person = partner.getPerson();
|
||||
person.setTradeName(record[6]);
|
||||
// TODO: title+salutation
|
||||
person.setFamilyName(record[3]);
|
||||
person.setGivenName(record[4]);
|
||||
|
||||
initContact(partner.getContact(), record);
|
||||
} else {
|
||||
initContact(new HsOfficeContactEntity(), record);
|
||||
// TODO: create relationship
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initContact(final HsOfficeContactEntity contact, final String[] record) {
|
||||
contacts.put(toInt(record[0]), contact);
|
||||
|
||||
contact.setLabel(toLabel(record[2], record[5], record[3], record[4], record[6]));
|
||||
contact.setEmailAddresses(record[16]);
|
||||
contact.setPostalAddress(toAddress(record));
|
||||
contact.setPhoneNumbers(toPhoneNumbers(record));
|
||||
}
|
||||
|
||||
private String[] trimAll(final String[] record) {
|
||||
for (int i = 0; i < record.length; ++i) {
|
||||
if (record[i] != null) {
|
||||
|
@ -4,8 +4,8 @@ spring:
|
||||
platform: postgres
|
||||
|
||||
datasource:
|
||||
url: jdbc:tc:postgresql:13.7-bullseye:///spring_boot_testcontainers
|
||||
url-local: jdbc:postgresql://localhost:5432/postgres
|
||||
url-tc: jdbc:tc:postgresql:13.7-bullseye:///spring_boot_testcontainers
|
||||
url: jdbc:postgresql://localhost:5432/postgres
|
||||
username: postgres
|
||||
password: password
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
contact_id; bp_id; salut; first_name; last_name; title; firma; co; street; zipcode;city; country; phone_private; phone_office; phone_mobile; fax; email
|
||||
71; 7; Herr; Michael; Mellies; ; ; ; Kleine Freiheit 50; 26524; Hage; DE; ; +49 4931 123456; +49 1522 123456;; mih@example.org
|
||||
101; 10; Frau; Jenny; Meyer; Dr.; JM e.K.;; Waldweg 5; 11001; Berlin; DE; +49 30 7777777; +49 30 8888888; ; +49 30 9999999; jm@example.org
|
||||
102; 10; Herr; Andrew; Meyer; ; JM e.K.;; Waldweg 5; 11001; Berlin; DE; +49 30 6666666; +49 30 5555555; ; +49 30 9999999; am@example.org
|
||||
121; 12; ; Paule; Schmidt; ; Test PS;; ; ; ; ; ; ; ; ; ps@example.com
|
||||
contact_id; bp_id; salut; first_name; last_name; title; firma; co; street; zipcode;city; country; phone_private; phone_office; phone_mobile; fax; email; roles
|
||||
71; 7; Herr; Michael; Mellies; ; ; ; Kleine Freiheit 50; 26524; Hage; DE; ; +49 4931 123456; +49 1522 123456;; mih@example.org; billing,operation
|
||||
101; 10; Frau; Jenny; Meyer; Dr.; JM e.K.;; Waldweg 5; 11001; Berlin; DE; +49 30 7777777; +49 30 8888888; ; +49 30 9999999; jm@example.org; billing
|
||||
102; 10; Herr; Andrew; Meyer; ; JM e.K.;; Waldweg 5; 11001; Berlin; DE; +49 30 6666666; +49 30 5555555; ; +49 30 9999999; am@example.org; operation
|
||||
121; 12; ; Paule; Schmidt; ; Test PS;; ; ; ; ; ; ; ; ; ps@example.com; billing,operation
|
||||
|
|
Loading…
Reference in New Issue
Block a user