|
|
|
@ -5,6 +5,7 @@ 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.bankaccount.HsOfficeBankAccountEntity;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
|
|
|
@ -13,8 +14,12 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerDetailsEntity;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity;
|
|
|
|
|
import net.hostsharing.test.JpaAttempt;
|
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
|
import org.junit.jupiter.api.MethodOrderer;
|
|
|
|
|
import org.junit.jupiter.api.Order;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.api.TestMethodOrder;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
|
|
|
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
|
|
@ -48,6 +53,8 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|
|
|
|
private static Map<Integer, HsOfficePartnerEntity> partners = new HashMap<>();
|
|
|
|
|
private static Map<Integer, HsOfficeDebitorEntity> debitors = new HashMap<>();
|
|
|
|
|
private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>();
|
|
|
|
|
private static Map<Integer, HsOfficeSepaMandateEntity> sepaMandates = new HashMap<>();
|
|
|
|
|
private static Map<Integer, HsOfficeBankAccountEntity> bankAccounts = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
@PersistenceContext
|
|
|
|
|
EntityManager em;
|
|
|
|
@ -82,6 +89,18 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Order(3)
|
|
|
|
|
void importSepaMandates() {
|
|
|
|
|
|
|
|
|
|
try (Reader reader = resourceReader("migration/sepa-mandates.csv")) {
|
|
|
|
|
final var records = readAllLines(reader);
|
|
|
|
|
importSepaMandates(records);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Order(10)
|
|
|
|
|
void persistEntities() {
|
|
|
|
@ -93,6 +112,8 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|
|
|
|
partners.forEach((id, partner) -> em.persist(partner));
|
|
|
|
|
debitors.forEach((id, debitor) -> em.persist(debitor));
|
|
|
|
|
memberships.forEach((id, membership) -> em.persist(membership));
|
|
|
|
|
bankAccounts.forEach((id, account) -> em.persist(account));
|
|
|
|
|
sepaMandates.forEach((id, mandate) -> em.persist(mandate));
|
|
|
|
|
}).assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -158,6 +179,33 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void importSepaMandates(final List<String[]> records) {
|
|
|
|
|
records.stream()
|
|
|
|
|
.map(this::trimAll)
|
|
|
|
|
.forEach(record -> {
|
|
|
|
|
|
|
|
|
|
final var debitor = debitors.get(toInt(record[1]));
|
|
|
|
|
|
|
|
|
|
final var sepaMandate = HsOfficeSepaMandateEntity.builder()
|
|
|
|
|
.debitor(debitor)
|
|
|
|
|
.bankAccount(HsOfficeBankAccountEntity.builder()
|
|
|
|
|
.holder(record[2])
|
|
|
|
|
// .bankName(record[3]) // TODO
|
|
|
|
|
.iban(record[4])
|
|
|
|
|
.bic(record[5])
|
|
|
|
|
.build())
|
|
|
|
|
.reference(record[6])
|
|
|
|
|
.agreement(LocalDate.parse(record[7]))
|
|
|
|
|
.validity(toPostgresDateRange(
|
|
|
|
|
toLocalDate(record[8]),
|
|
|
|
|
toLocalDate(record[9])))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
sepaMandates.put(toInt(record[0]), sepaMandate);
|
|
|
|
|
bankAccounts.put(toInt(record[0]), sepaMandate.getBankAccount());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void importContacts(final List<String[]> records) {
|
|
|
|
|
records.stream()
|
|
|
|
|
.map(this::trimAll)
|
|
|
|
@ -266,6 +314,13 @@ public class ImportBusinessPartners extends ContextBasedTest {
|
|
|
|
|
return toLabel(salut, title, firstname, lastname, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LocalDate toLocalDate(final String dateString) {
|
|
|
|
|
if (isNotBlank(dateString)) {
|
|
|
|
|
return LocalDate.parse(dateString);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Integer toInt(final String value) {
|
|
|
|
|
return isNotBlank(value) ? Integer.parseInt(value.trim()) : 0;
|
|
|
|
|
}
|
|
|
|
|