|
|
@ -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) {
|
|
|
|