| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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() { |
| | | jpaAttempt.transacted( () -> { |
| | | jpaAttempt.transacted(() -> { |
| | | context("superuser-alex@hostsharing.net"); // TODO: use real user |
| | | |
| | | contacts.forEach((id, contact) -> em.persist(contact)); |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | }); |
| | | } |
| | | |
| | | 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) |
| | | .forEach(record -> { |
| | | |
| | | if ( isNotBlank(record[17]) && record[17].contains("billing") ) { |
| | | if (isNotBlank(record[17]) && record[17].contains("billing")) { |
| | | |
| | | final var partner = partners.get(toInt(record[1])); |
| | | |
| | |
| | | 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; |
| | | } |