From a3418a1d49975612904fb1951c5dd35d42fee6ba Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Thu, 10 Oct 2024 14:48:07 +0200 Subject: [PATCH] import: map for PERSON_TYPES_BY_CONTACT --- .../hs/migration/BaseOfficeDataImport.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java index 7b404165..7d5a14ea 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java @@ -73,23 +73,17 @@ public abstract class BaseOfficeDataImport extends CsvDataImport { -1 ); - private static final List LEGAL_PERSON_CONTACTS = Arrays.asList( - 90641, // we have two persons with same name, but one is the legal person - -1 - ); - private static final List INCORPORATED_FIRM_CONTACTS = Arrays.asList( - -1 - ); - private static final List NATURAL_PERSON_CONTACTS = Arrays.asList( - -1 - ); - private static final List IGNORE_CONTACTS = Arrays.asList( 90547, // Kontakt hat keine Rolle 90312, // es gibt bereits einen partner Contact -1 ); + private static final Map PERSON_TYPES_BY_CONTACT = Map.of( + 90641, HsOfficePersonType.LEGAL_PERSON, + -1, HsOfficePersonType.LEGAL_PERSON + ); + static Map contacts = new WriteOnceMap<>(); static Map persons = new WriteOnceMap<>(); static Map partners = new WriteOnceMap<>(); @@ -971,6 +965,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport { HsOfficePersonEntity contactPerson = partnerPerson; if (!StringUtils.equals(rec.getString("firma"), partnerPerson.getTradeName()) || + partnerPerson.getPersonType() != determinePersonType(rec) || !StringUtils.equals(rec.getString("first_name"), partnerPerson.getGivenName()) || !StringUtils.equals(rec.getString("last_name"), partnerPerson.getFamilyName())) { contactPerson = addPerson(HsOfficePersonEntity.builder().build(), rec); @@ -1087,12 +1082,8 @@ public abstract class BaseOfficeDataImport extends CsvDataImport { String givenName = contactRecord.getString("first_name"); String tradeName = contactRecord.getString("firma"); - if (LEGAL_PERSON_CONTACTS.contains(contactRecord.getString("contact_id"))) { - return HsOfficePersonType.LEGAL_PERSON; - } else if (INCORPORATED_FIRM_CONTACTS.contains(contactRecord.getString("contact_id"))) { - return HsOfficePersonType.INCORPORATED_FIRM; - } else if (NATURAL_PERSON_CONTACTS.contains(contactRecord.getString("contact_id"))) { - return HsOfficePersonType.NATURAL_PERSON; + if (PERSON_TYPES_BY_CONTACT.containsKey(contactRecord.getInteger("contact_id"))) { + return PERSON_TYPES_BY_CONTACT.get(contactRecord.getInteger("contact_id")); } if (tradeName.isBlank() || tradeName.startsWith("verstorben")) {