refactoring determinePersonType
This commit is contained in:
parent
7914c9a9b8
commit
6254cb0fcc
@ -69,12 +69,25 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
||||
512167, // 11139, partner without contractual contact
|
||||
512170, // 11142, partner without contractual contact
|
||||
511725, // 10764, partner without contractual contact
|
||||
512177, // 11149, partner without contractual contact
|
||||
// 512171, // 11143, partner without partner contact -- exception
|
||||
-1
|
||||
);
|
||||
|
||||
private static final List<Integer> LEGAL_PERSON_CONTACTS = Arrays.asList(
|
||||
90641, // we have two persons with same name, but one is the legal person
|
||||
-1
|
||||
);
|
||||
private static final List<Integer> INCORPORATED_FIRM_CONTACTS = Arrays.asList(
|
||||
-1
|
||||
);
|
||||
private static final List<Integer> NATURAL_PERSON_CONTACTS = Arrays.asList(
|
||||
-1
|
||||
);
|
||||
|
||||
private static final List<Integer> IGNORE_CONTACTS = Arrays.asList(
|
||||
90547, // Kontakt hat keine Rolle
|
||||
90312, // es gibt bereits einen partner Contact
|
||||
-1
|
||||
);
|
||||
|
||||
@ -1080,30 +1093,53 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
||||
person.setGivenName(contactRecord.getString("first_name"));
|
||||
person.setFamilyName(contactRecord.getString("last_name"));
|
||||
person.setTradeName(contactRecord.getString("firma"));
|
||||
determinePersonType(person, contactRecord.getString("roles"));
|
||||
person.setPersonType(determinePersonType(contactRecord));
|
||||
|
||||
persons.put(contactRecord.getInteger("contact_id"), person);
|
||||
return person;
|
||||
}
|
||||
|
||||
private static void determinePersonType(final HsOfficePersonEntity person, final String roles) {
|
||||
if (person.getTradeName().isBlank()) {
|
||||
person.setPersonType(HsOfficePersonType.NATURAL_PERSON);
|
||||
private static HsOfficePersonType determinePersonType(final Record contactRecord) {
|
||||
String roles = contactRecord.getString("roles");
|
||||
String country = contactRecord.getString("country");
|
||||
String familyName = contactRecord.getString("last_name");
|
||||
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 (tradeName.isBlank() || tradeName.startsWith("verstorben")) {
|
||||
return HsOfficePersonType.NATURAL_PERSON;
|
||||
} else
|
||||
// contractual && !partner with a firm and a natural person name
|
||||
// should actually be split up into two persons
|
||||
// but the legacy database consists such records
|
||||
if (roles.contains("contractual") && !roles.contains("partner") &&
|
||||
!person.getFamilyName().isBlank() && !person.getGivenName().isBlank()) {
|
||||
person.setPersonType(HsOfficePersonType.NATURAL_PERSON);
|
||||
} else if (endsWithWord(person.getTradeName(), "e.K.", "e.G.", "eG", "GmbH", "AG", "KG")) {
|
||||
person.setPersonType(HsOfficePersonType.LEGAL_PERSON);
|
||||
} else if (endsWithWord(person.getTradeName(), "OHG")) {
|
||||
person.setPersonType(HsOfficePersonType.INCORPORATED_FIRM);
|
||||
} else if (endsWithWord(person.getTradeName(), "GbR")) {
|
||||
person.setPersonType(HsOfficePersonType.INCORPORATED_FIRM);
|
||||
|
||||
if (endsWithWord(tradeName, "OHG", "GbR", "KG", "UG")) {
|
||||
return HsOfficePersonType.INCORPORATED_FIRM; // Personengesellschaft. Gesellschafter haften persönlich.
|
||||
} else if (containsWord(tradeName, "e.K.", "e.G.", "eG", "gGmbH", "GmbH", "mbH", "AG", "e.V.", "eV", "e.V")
|
||||
|| tradeName.toLowerCase().contains("haftungsbeschränkt")
|
||||
|| tradeName.toLowerCase().contains("stiftung")
|
||||
|| tradeName.toLowerCase().contains("stichting")
|
||||
|| tradeName.toLowerCase().contains("foundation")
|
||||
|| tradeName.toLowerCase().contains("schule")
|
||||
|| tradeName.toLowerCase().contains("Landkreis")
|
||||
|| tradeName.toLowerCase().contains("Behörde")
|
||||
|| tradeName.toLowerCase().contains("Bezirksamt")
|
||||
) {
|
||||
return HsOfficePersonType.LEGAL_PERSON; // Haftungsbeschränkt
|
||||
} else if (roles.contains("contractual") && !roles.contains("partner") &&
|
||||
!familyName.isBlank() && !givenName.isBlank()) {
|
||||
// REPRESENTATIVES are always natural persons
|
||||
return HsOfficePersonType.NATURAL_PERSON;
|
||||
} else {
|
||||
person.setPersonType(HsOfficePersonType.UNKNOWN_PERSON_TYPE);
|
||||
return HsOfficePersonType.UNKNOWN_PERSON_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1117,6 +1153,19 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean containsWord(final String value, final String... endings) {
|
||||
final var lowerCaseValue = value.toLowerCase();
|
||||
for (String ending : endings) {
|
||||
if (lowerCaseValue.isEqualTo(ending.toLowerCase()) ||
|
||||
lowerCaseValue.startsWith(ending.toLowerCase() + " ") ||
|
||||
lowerCaseValue.contains(" " + ending.toLowerCase() + " ") ||
|
||||
lowerCaseValue.endsWith(" " + ending.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void verifyContainsOnlyKnownRoles(final String roles) {
|
||||
final var allowedRolesSet = stream(KNOWN_ROLES).collect(Collectors.toSet());
|
||||
final var givenRolesSet = stream(roles.replace(" ", "").split(",")).collect(Collectors.toSet());
|
||||
|
@ -61,6 +61,6 @@ public class ImportOfficeData extends BaseOfficeDataImport {
|
||||
|
||||
@BeforeEach
|
||||
void check() {
|
||||
assertThat(jdbcUrl).isEqualTo("jdbc:tc:postgresql:15.5-bookworm:///importOfficeDataTC");
|
||||
//assertThat(jdbcUrl).isEqualTo("jdbc:tc:postgresql:15.5-bookworm:///importOfficeDataTC");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user