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
2 changed files with 59 additions and 4 deletions
Showing only changes of commit d44d2e3e82 - Show all commits

View File

@ -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;
}

View File

@ -1,3 +1,3 @@
sepa_mandat_id; bp_id; bank_customer; bank_name; bank_iban; bank_bic; mandat_ref; mandat_signed; mandat_since; mandat_until; mandat_used
234234; 7; Michael Mellies; ING Bank AG; DE37500105177419788228; INGDDEFFXXX; MH12345; 2004-06-12; 2004-06-15; ; 2022-10-20
235662; 10; JM e.K.; ING Bank AG; DE49500105174516484892; INGDDEFFXXX; JM33344; 2005-06-282; 2005-07-01; ; 2016-01-18
235662; 10; JM e.K.; ING Bank AG; DE49500105174516484892; INGDDEFFXXX; JM33344; 2005-06-28; 2005-07-01; ; 2016-01-18

1 sepa_mandat_id bp_id bank_customer bank_name bank_iban bank_bic mandat_ref mandat_signed mandat_since mandat_until mandat_used
2 234234 17 7 Michael Mellies ING Bank AG DE37500105177419788228 INGDDEFFXXX MH12345 2004-06-12 2004-06-15 2022-10-20
3 235600 235662 20 10 JM e.K. Targobank AG ING Bank AG DE02300209000106531065 DE49500105174516484892 CMCIDEDD INGDDEFFXXX JM33344 2004-01-15 2005-06-28 2004-01-20 2005-07-01 2005-06-27 2016-01-18