| | |
| | | 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.contact.HsOfficeContactEntity; |
| | | import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; |
| | | import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; |
| | |
| | | import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; |
| | | import net.hostsharing.test.JpaAttempt; |
| | | 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.mock.mockito.MockBean; |
| | | 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 java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | |
| | | @DataJpaTest |
| | | @Import({ Context.class, JpaAttempt.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, HsOfficeDebitorEntity> debitors = new HashMap<>(); |
| | | private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>(); |
| | | |
| | | @PersistenceContext |
| | | EntityManager em; |
| | | |
| | | @Autowired |
| | | JpaAttempt jpaAttempt; |
| | | |
| | | @MockBean |
| | | HttpServletRequest request; |
| | | |
| | | @Test |
| | | @Order(1) |
| | |
| | | } |
| | | } |
| | | |
| | | @AfterAll |
| | | static void afterAll() { |
| | | System.out.println(partners); |
| | | System.out.println(debitors); |
| | | System.out.println(memberships); |
| | | @Test |
| | | @Order(10) |
| | | void persistEntities() { |
| | | jpaAttempt.transacted( () -> { |
| | | 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 { |
| | |
| | | .map(this::trimAll) |
| | | .forEach(record -> { |
| | | |
| | | final var person = HsOfficePersonEntity.builder() |
| | | .personType(HsOfficePersonType.UNKNOWN) // TODO |
| | | .build(); |
| | | persons.put(toInt(record[0]), person); |
| | | |
| | | final var partner = HsOfficePartnerEntity.builder() |
| | | .details(HsOfficePartnerDetailsEntity.builder().build()) |
| | | .contact(HsOfficeContactEntity.builder().build()) |
| | | .person(HsOfficePersonEntity.builder() |
| | | .personType(HsOfficePersonType.UNKNOWN) // TODO |
| | | .build()) |
| | | .person(person) |
| | | .build(); |
| | | partners.put(toInt(record[0]), partner); |
| | | |
| | |
| | | .map(this::trimAll) |
| | | .forEach(record -> { |
| | | |
| | | final var partner = partners.get(toInt(record[1])); |
| | | if ( isNotBlank(record[17]) && record[17].contains("billing") ) { |
| | | |
| | | final var contact = partner.getContact(); |
| | | 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 partner = partners.get(toInt(record[1])); |
| | | |
| | | final var person = partner.getPerson(); |
| | | person.setTradeName(record[6]); |
| | | // TODO: title+salutation |
| | | person.setFamilyName(record[3]); |
| | | person.setGivenName(record[4]); |
| | | final var person = partner.getPerson(); |
| | | person.setTradeName(record[6]); |
| | | // TODO: title+salutation |
| | | person.setFamilyName(record[3]); |
| | | 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) { |
| | | for (int i = 0; i < record.length; ++i) { |
| | | if (record[i] != null) { |