1
0

more detailed person type (#12)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/12
Reviewed-by: Michael Hierweck <michael.hierweck@hostsharing.net>
This commit is contained in:
Michael Hoennig
2024-01-24 15:18:44 +01:00
parent fd1bd897b1
commit f150ea2091
29 changed files with 209 additions and 141 deletions

View File

@ -11,7 +11,6 @@ import org.hibernate.annotations.GenericGenerator;
import jakarta.persistence.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.UUID;

View File

@ -35,7 +35,6 @@ public class HsOfficePersonEntity implements HasUuid, Stringifyable {
private UUID uuid;
@Column(name = "persontype")
@Enumerated(EnumType.STRING)
private HsOfficePersonType personType;
@Column(name = "tradename")

View File

@ -1,9 +1,21 @@
package net.hostsharing.hsadminng.hs.office.person;
public enum HsOfficePersonType {
UNKNOWN,
NATURAL,
LEGAL,
SOLE_REPRESENTATION,
JOINT_REPRESENTATION
UNKNOWN_PERSON_TYPE("??"),
NATURAL_PERSON("NP"), // a human being
LEGAL_PERSON("LP"), // incorporated legal entity like A/S, GmbH, e.K., eG, e.V.
INCORPORATED_FIRM("IF"), // registered business partnership like OHG, Partnerschaftsgesellschaft
UNINCORPORATED_FIRM("UF"), // unregistered partnership, association etc. like GbR, ARGE, community of heirs
PUBLIC_INSTITUTION("PI"); // entities under public law like government entities, KdöR, AöR
public final String shortName;
HsOfficePersonType(final String shortName) {
this.shortName = shortName;
}
@Override
public String toString() {
return shortName;
}
}

View File

@ -0,0 +1,29 @@
package net.hostsharing.hsadminng.hs.office.person;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.util.stream.Stream;
@Converter(autoApply = true)
public class HsOfficePersonTypeConverter implements AttributeConverter<HsOfficePersonType, String> {
@Override
public String convertToDatabaseColumn(HsOfficePersonType category) {
if (category == null) {
return null;
}
return category.shortName;
}
@Override
public HsOfficePersonType convertToEntityAttribute(String code) {
if (code == null) {
return null;
}
return Stream.of(HsOfficePersonType.values())
.filter(c -> c.shortName.equals(code))
.findFirst()
.orElseThrow(IllegalArgumentException::new);
}
}

View File

@ -6,10 +6,12 @@ components:
HsOfficePersonType:
type: string
enum:
- NATURAL # a human
- LEGAL # e.g. Corp., Inc., AG, GmbH, eG
- SOLE_REPRESENTATION # e.g. OHG, GbR
- JOINT_REPRESENTATION # e.g. community of heirs
- UNKNOWN_PERSON
- NATURAL_PERSON
- LEGAL_PERSON
- INCORPORATED_FIRM
- UNINCORPORATED_FIRM
- PUBLIC_INSTITUTION
HsOfficePerson:
type: object

View File

@ -770,8 +770,8 @@ do $$
if '${HSADMINNG_POSTGRES_RESTRICTED_USERNAME}'='restricted' then
create role restricted;
grant all privileges on all tables in schema public to restricted;
end if;
-- grant all privileges on all tables in schema public to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
end $$
--//

View File

@ -4,7 +4,13 @@
--changeset hs-office-person-MAIN-TABLE:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
CREATE TYPE HsOfficePersonType AS ENUM ('UNKNOWN', 'NATURAL', 'LEGAL', 'SOLE_REPRESENTATION', 'JOINT_REPRESENTATION');
CREATE TYPE HsOfficePersonType AS ENUM (
'??', -- unknown
'NP', -- natural person
'LP', -- legal person
'IF', -- incorporated firm
'UF', -- unincorporated firm
'PI'); -- public institution
CREATE CAST (character varying as HsOfficePersonType) WITH INOUT AS IMPLICIT;

View File

@ -59,14 +59,14 @@ end; $$;
do language plpgsql $$
begin
call createHsOfficePersonTestData('LEGAL', 'First GmbH');
call createHsOfficePersonTestData('NATURAL', null, 'Smith', 'Peter');
call createHsOfficePersonTestData('LEGAL', 'Second e.K.', 'Sandra', 'Miller');
call createHsOfficePersonTestData('SOLE_REPRESENTATION', 'Third OHG');
call createHsOfficePersonTestData('SOLE_REPRESENTATION', 'Fourth e.G.');
call createHsOfficePersonTestData('JOINT_REPRESENTATION', 'Erben Bessler', 'Mel', 'Bessler');
call createHsOfficePersonTestData('NATURAL', null, 'Bessler', 'Anita');
call createHsOfficePersonTestData('NATURAL', null, 'Winkler', 'Paul');
call createHsOfficePersonTestData('LP', 'First GmbH');
call createHsOfficePersonTestData('NP', null, 'Smith', 'Peter');
call createHsOfficePersonTestData('LP', 'Second e.K.', 'Sandra', 'Miller');
call createHsOfficePersonTestData('IF', 'Third OHG');
call createHsOfficePersonTestData('IF', 'Fourth e.G.');
call createHsOfficePersonTestData('UF', 'Erben Bessler', 'Mel', 'Bessler');
call createHsOfficePersonTestData('NP', null, 'Bessler', 'Anita');
call createHsOfficePersonTestData('NP', null, 'Winkler', 'Paul');
end;
$$;
--//

View File

@ -19,7 +19,6 @@ declare
relatedPerson hs_office_person;
relatedContact hs_office_contact;
relatedDetailsUuid uuid;
birthday date;
begin
idName := cleanIdentifier( personTradeOrFamilyName|| '-' || contactLabel);
currentTask := 'creating partner test-data ' || idName;
@ -33,18 +32,14 @@ begin
where c.label = contactLabel
into relatedContact;
if relatedPerson.persontype = 'NATURAL' then
birthday := '1987-10-31'::date;
end if;
raise notice 'creating test partner: %', idName;
raise notice '- using person (%): %', relatedPerson.uuid, relatedPerson;
raise notice '- using contact (%): %', relatedContact.uuid, relatedContact;
if relatedPerson.persontype = 'NATURAL' then
if relatedPerson.persontype = 'NP' then
insert
into hs_office_partner_details (uuid, birthName, birthday)
values (uuid_generate_v4(), 'Meyer', '1987-10-31')
into hs_office_partner_details (uuid, birthName, birthday, birthPlace)
values (uuid_generate_v4(), 'Meyer', '1987-10-31', 'Hamburg')
returning uuid into relatedDetailsUuid;
else
insert