memberNumber as partnerNumber+memberNumberSuffix #13

Merged
hsh-michaelhoennig merged 78 commits from memberNumberSuffix-and-partnerNumber into master 2024-01-24 15:57:16 +01:00
3 changed files with 62 additions and 27 deletions
Showing only changes of commit 5bf2dd76fe - Show all commits

View File

@ -4,6 +4,7 @@ import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader; import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVReaderBuilder;
import net.hostsharing.hsadminng.context.Context; 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.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; 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.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.*; 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.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; 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 jakarta.validation.constraints.NotNull;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -35,12 +41,23 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
@DataJpaTest @DataJpaTest
@Import({ Context.class, JpaAttempt.class }) @Import({ Context.class, JpaAttempt.class })
@TestMethodOrder(MethodOrderer.OrderAnnotation.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, HsOfficePartnerEntity> partners = new HashMap<>();
private static Map<Integer, HsOfficeDebitorEntity> debitors = new HashMap<>(); private static Map<Integer, HsOfficeDebitorEntity> debitors = new HashMap<>();
private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>(); private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>();
@PersistenceContext
EntityManager em;
@Autowired
JpaAttempt jpaAttempt;
@MockBean
HttpServletRequest request;
@Test @Test
@Order(1) @Order(1)
void importsBusinessPartners() { void importsBusinessPartners() {
@ -65,12 +82,16 @@ public class ImportBusinessPartners {
} }
} }
@AfterAll @Test
static void afterAll() { @Order(10)
System.out.println(partners); void persistEntities() {
System.out.println(debitors); jpaAttempt.transacted( () -> {
System.out.println(memberships); 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 { public List<String[]> readAllLines(Reader reader) throws Exception {
@ -93,12 +114,15 @@ public class ImportBusinessPartners {
.map(this::trimAll) .map(this::trimAll)
.forEach(record -> { .forEach(record -> {
final var person = HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.UNKNOWN) // TODO
.build();
persons.put(toInt(record[0]), person);
final var partner = HsOfficePartnerEntity.builder() final var partner = HsOfficePartnerEntity.builder()
.details(HsOfficePartnerDetailsEntity.builder().build()) .details(HsOfficePartnerDetailsEntity.builder().build())
.contact(HsOfficeContactEntity.builder().build()) .contact(HsOfficeContactEntity.builder().build())
.person(HsOfficePersonEntity.builder() .person(person)
.personType(HsOfficePersonType.UNKNOWN) // TODO
.build())
.build(); .build();
partners.put(toInt(record[0]), partner); partners.put(toInt(record[0]), partner);
@ -136,22 +160,33 @@ public class ImportBusinessPartners {
.map(this::trimAll) .map(this::trimAll)
.forEach(record -> { .forEach(record -> {
final var partner = partners.get(toInt(record[1])); if ( isNotBlank(record[17]) && record[17].contains("billing") ) {
final var contact = partner.getContact(); final var partner = partners.get(toInt(record[1]));
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 person = partner.getPerson(); final var person = partner.getPerson();
person.setTradeName(record[6]); person.setTradeName(record[6]);
// TODO: title+salutation // TODO: title+salutation
person.setFamilyName(record[3]); person.setFamilyName(record[3]);
person.setGivenName(record[4]); 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) { private String[] trimAll(final String[] record) {
for (int i = 0; i < record.length; ++i) { for (int i = 0; i < record.length; ++i) {
if (record[i] != null) { if (record[i] != null) {

View File

@ -4,8 +4,8 @@ spring:
platform: postgres platform: postgres
datasource: datasource:
url: jdbc:tc:postgresql:13.7-bullseye:///spring_boot_testcontainers url-tc: jdbc:tc:postgresql:13.7-bullseye:///spring_boot_testcontainers
url-local: jdbc:postgresql://localhost:5432/postgres url: jdbc:postgresql://localhost:5432/postgres
username: postgres username: postgres
password: password password: password

View File

@ -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 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 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 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 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 121; 12; ; Paule; Schmidt; ; Test PS;; ; ; ; ; ; ; ; ; ps@example.com; billing,operation

1 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 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
2 # eine natürliche Person, implizites contractual 71 7 Herr Michael Mellies Kleine Freiheit 50 26524 Hage DE +49 4931 123456 +49 1522 123456 mih@example.org billing,operation
3 1101; 17; Herr; Michael; Mellies; ; ; ; Kleine Freiheit 50; 26524; Hage; DE; ; +49 4931 123456; +49 1522 123456;; mih@example.org; partner,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
4 # eine juristische Person mit drei separaten Ansprechpartnern, vip-contact und ex-partner 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
5 1200; 20;; ; ; ; JM e.K.;; Wiesenweg 15; 12335; Berlin; DE; +49 30 6666666; +49 30 5555555; ; +49 30 6666666; jm-ex-partner@example.org; ex-partner 121 12 Paule Schmidt Test PS ps@example.com billing,operation