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
|
512167, // 11139, partner without contractual contact
|
||||||
512170, // 11142, partner without contractual contact
|
512170, // 11142, partner without contractual contact
|
||||||
511725, // 10764, partner without contractual contact
|
511725, // 10764, partner without contractual contact
|
||||||
|
512177, // 11149, partner without contractual contact
|
||||||
// 512171, // 11143, partner without partner contact -- exception
|
// 512171, // 11143, partner without partner contact -- exception
|
||||||
-1
|
-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(
|
private static final List<Integer> IGNORE_CONTACTS = Arrays.asList(
|
||||||
90547, // Kontakt hat keine Rolle
|
90547, // Kontakt hat keine Rolle
|
||||||
|
90312, // es gibt bereits einen partner Contact
|
||||||
-1
|
-1
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1080,30 +1093,53 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
person.setGivenName(contactRecord.getString("first_name"));
|
person.setGivenName(contactRecord.getString("first_name"));
|
||||||
person.setFamilyName(contactRecord.getString("last_name"));
|
person.setFamilyName(contactRecord.getString("last_name"));
|
||||||
person.setTradeName(contactRecord.getString("firma"));
|
person.setTradeName(contactRecord.getString("firma"));
|
||||||
determinePersonType(person, contactRecord.getString("roles"));
|
person.setPersonType(determinePersonType(contactRecord));
|
||||||
|
|
||||||
persons.put(contactRecord.getInteger("contact_id"), person);
|
persons.put(contactRecord.getInteger("contact_id"), person);
|
||||||
return person;
|
return person;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void determinePersonType(final HsOfficePersonEntity person, final String roles) {
|
private static HsOfficePersonType determinePersonType(final Record contactRecord) {
|
||||||
if (person.getTradeName().isBlank()) {
|
String roles = contactRecord.getString("roles");
|
||||||
person.setPersonType(HsOfficePersonType.NATURAL_PERSON);
|
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
|
} else
|
||||||
// contractual && !partner with a firm and a natural person name
|
// contractual && !partner with a firm and a natural person name
|
||||||
// should actually be split up into two persons
|
// should actually be split up into two persons
|
||||||
// but the legacy database consists such records
|
// but the legacy database consists such records
|
||||||
if (roles.contains("contractual") && !roles.contains("partner") &&
|
|
||||||
!person.getFamilyName().isBlank() && !person.getGivenName().isBlank()) {
|
if (endsWithWord(tradeName, "OHG", "GbR", "KG", "UG")) {
|
||||||
person.setPersonType(HsOfficePersonType.NATURAL_PERSON);
|
return HsOfficePersonType.INCORPORATED_FIRM; // Personengesellschaft. Gesellschafter haften persönlich.
|
||||||
} else if (endsWithWord(person.getTradeName(), "e.K.", "e.G.", "eG", "GmbH", "AG", "KG")) {
|
} else if (containsWord(tradeName, "e.K.", "e.G.", "eG", "gGmbH", "GmbH", "mbH", "AG", "e.V.", "eV", "e.V")
|
||||||
person.setPersonType(HsOfficePersonType.LEGAL_PERSON);
|
|| tradeName.toLowerCase().contains("haftungsbeschränkt")
|
||||||
} else if (endsWithWord(person.getTradeName(), "OHG")) {
|
|| tradeName.toLowerCase().contains("stiftung")
|
||||||
person.setPersonType(HsOfficePersonType.INCORPORATED_FIRM);
|
|| tradeName.toLowerCase().contains("stichting")
|
||||||
} else if (endsWithWord(person.getTradeName(), "GbR")) {
|
|| tradeName.toLowerCase().contains("foundation")
|
||||||
person.setPersonType(HsOfficePersonType.INCORPORATED_FIRM);
|
|| 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 {
|
} else {
|
||||||
person.setPersonType(HsOfficePersonType.UNKNOWN_PERSON_TYPE);
|
return HsOfficePersonType.UNKNOWN_PERSON_TYPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1117,6 +1153,19 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
return false;
|
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) {
|
private void verifyContainsOnlyKnownRoles(final String roles) {
|
||||||
final var allowedRolesSet = stream(KNOWN_ROLES).collect(Collectors.toSet());
|
final var allowedRolesSet = stream(KNOWN_ROLES).collect(Collectors.toSet());
|
||||||
final var givenRolesSet = stream(roles.replace(" ", "").split(",")).collect(Collectors.toSet());
|
final var givenRolesSet = stream(roles.replace(" ", "").split(",")).collect(Collectors.toSet());
|
||||||
|
@ -61,6 +61,6 @@ public class ImportOfficeData extends BaseOfficeDataImport {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void check() {
|
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