From 1a3fad80ee6e07db6bc8e504b314b5074cce6ad2 Mon Sep 17 00:00:00 2001 From: "Marc O. Sandlus" Date: Fri, 2 Feb 2024 09:02:28 +0100 Subject: [PATCH 1/5] wip initial commit --- .../hs/office/person/HsOfficePersonEntity.java | 10 +++++++++- .../office/person/HsOfficePersonEntityPatcher.java | 2 ++ .../hs-office/hs-office-person-schemas.yaml | 14 ++++++++++++++ .../db/changelog/210-hs-office-person.sql | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java index fde3972b..f36ce946 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java @@ -27,6 +27,8 @@ public class HsOfficePersonEntity implements HasUuid, Stringifyable { private static Stringify toString = stringify(HsOfficePersonEntity.class, "person") .withProp(Fields.personType, HsOfficePersonEntity::getPersonType) .withProp(Fields.tradeName, HsOfficePersonEntity::getTradeName) + .withProp(Fields.salutation, HsOfficePersonEntity::getSalutation) + .withProp(Fields.title, HsOfficePersonEntity::getTitle) .withProp(Fields.familyName, HsOfficePersonEntity::getFamilyName) .withProp(Fields.givenName, HsOfficePersonEntity::getGivenName); @@ -40,6 +42,12 @@ public class HsOfficePersonEntity implements HasUuid, Stringifyable { @Column(name = "tradename") private String tradeName; + @Column(name = "salutation") + private String salutation; + + @Column(name = "title") + private String title; + @Column(name = "familyname") private String familyName; @@ -54,6 +62,6 @@ public class HsOfficePersonEntity implements HasUuid, Stringifyable { @Override public String toShortString() { return personType + " " + - (!StringUtils.isEmpty(tradeName) ? tradeName : (familyName + ", " + givenName)); + (!StringUtils.isEmpty(tradeName) ? tradeName : (StringUtils.isEmpty(salutation) ? "" : salutation + " ") + (familyName + ", " + givenName)); } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcher.java index d1d3fa8c..ede3fc03 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcher.java @@ -22,6 +22,8 @@ class HsOfficePersonEntityPatcher implements EntityPatcher Date: Mon, 18 Mar 2024 17:41:58 +0100 Subject: [PATCH 2/5] some tests --- .../person/HsOfficePersonEntityUnitTest.java | 84 ++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java index 1eec872b..9d85fb22 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java @@ -60,19 +60,63 @@ class HsOfficePersonEntityUnitTest { assertThat(actualDisplay).isEqualTo("NP some family name, some given name"); } + @Test + void toShortStringWithSalutationAndTitleReturnsSalutationAndTitle() { + final var givenPersonEntity = HsOfficePersonEntity.builder() + .personType(HsOfficePersonType.NATURAL_PERSON) + .salutation("Frau") + .title("Dr.") + .familyName("some family name") + .givenName("some given name") + .build(); + + final var actualDisplay = givenPersonEntity.toShortString(); + + assertThat(actualDisplay).isEqualTo("NP Frau Dr. some family name, some given name"); + } + + @Test + void toShortStringWithSalutationAndWithoutTitleReturnsSalutation() { + final var givenPersonEntity = HsOfficePersonEntity.builder() + .personType(HsOfficePersonType.NATURAL_PERSON) + .salutation("Frau") + .familyName("some family name") + .givenName("some given name") + .build(); + + final var actualDisplay = givenPersonEntity.toShortString(); + + assertThat(actualDisplay).isEqualTo("NP Frau some family name, some given name"); + } + + @Test + void toShortStringWithoutSalutationAndWithTitleReturnsTitle() { + final var givenPersonEntity = HsOfficePersonEntity.builder() + .personType(HsOfficePersonType.NATURAL_PERSON) + .title("Dr. Dr.") + .familyName("some family name") + .givenName("some given name") + .build(); + + final var actualDisplay = givenPersonEntity.toShortString(); + + assertThat(actualDisplay).isEqualTo("NP Dr. Dr. some family name, some given name"); + } + @Test void toStringWithAllFieldsReturnsAllButUuid() { final var givenPersonEntity = HsOfficePersonEntity.builder() .uuid(UUID.randomUUID()) .personType(HsOfficePersonType.NATURAL_PERSON) .tradeName("some trade name") + .title("Dr.") .familyName("some family name") .givenName("some given name") .build(); final var actualDisplay = givenPersonEntity.toString(); - assertThat(actualDisplay).isEqualTo("person(personType='NP', tradeName='some trade name', familyName='some family name', givenName='some given name')"); + assertThat(actualDisplay).isEqualTo("person(personType='NP', tradeName='some trade name', title='Dr.', familyName='some family name', givenName='some given name')"); } @Test @@ -86,4 +130,42 @@ class HsOfficePersonEntityUnitTest { assertThat(actualDisplay).isEqualTo("person(familyName='some family name', givenName='some given name')"); } + @Test + void toStringWithSalutationAndTitleRetursSalutationAndTitle() { + final var givenPersonEntity = HsOfficePersonEntity.builder() + .salutation("Herr") + .title("Prof. Dr.") + .familyName("some family name") + .givenName("some given name") + .build(); + + final var actualDisplay = givenPersonEntity.toString(); + + assertThat(actualDisplay).isEqualTo("person(salutation='Herr', title='Prof. Dr.', familyName='some family name', givenName='some given name')"); + } + @Test + void toStringWithSalutationAndWithoutTitleSkipsTitle() { + final var givenPersonEntity = HsOfficePersonEntity.builder() + .salutation("Herr") + .familyName("some family name") + .givenName("some given name") + .build(); + + final var actualDisplay = givenPersonEntity.toString(); + + assertThat(actualDisplay).isEqualTo("person(salutation='Herr', familyName='some family name', givenName='some given name')"); + } + @Test + void toStringWithoutSalutationAndWithTitleSkipsSalutation() { + final var givenPersonEntity = HsOfficePersonEntity.builder() + .title("some title") + .familyName("some family name") + .givenName("some given name") + .build(); + + final var actualDisplay = givenPersonEntity.toString(); + + assertThat(actualDisplay).isEqualTo("person(title='some title', familyName='some family name', givenName='some given name')"); + } + } -- 2.39.5 From ca952ce7483234fda04ee1e1f11dfca431b1dfef Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Mon, 8 Apr 2024 10:14:22 +0200 Subject: [PATCH 3/5] merging master + rbac-generation --- .../hsadminng/hs/office/person/HsOfficePersonEntity.java | 2 +- .../5-hs-office/502-person/5023-hs-office-person-rbac.sql | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java index 5f2ad6ec..5f847842 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java @@ -76,7 +76,7 @@ public class HsOfficePersonEntity implements RbacObject, Stringifyable { public static RbacView rbac() { return rbacViewFor("person", HsOfficePersonEntity.class) .withIdentityView(SQL.projection("concat(tradeName, familyName, givenName)")) - .withUpdatableColumns("personType", "tradeName", "givenName", "familyName") + .withUpdatableColumns("personType", "title", "salutation", "tradeName", "givenName", "familyName") .toRole("global", GUEST).grantPermission(INSERT) .createRole(OWNER, (with) -> { diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql index 6dbbf21b..0d983725 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql @@ -138,6 +138,8 @@ call generateRbacRestrictedView('hs_office_person', $orderBy$, $updates$ personType = new.personType, + title = new.title, + salutation = new.salutation, tradeName = new.tradeName, givenName = new.givenName, familyName = new.familyName -- 2.39.5 From 898aa858b129427133a6cf3363f37f866d28f840 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Mon, 8 Apr 2024 10:17:02 +0200 Subject: [PATCH 4/5] toShortString without title+salutation --- .../hsadminng/hs/office/person/HsOfficePersonEntity.java | 2 +- .../hs/office/person/HsOfficePersonEntityUnitTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java index 5f847842..673d1fc5 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java @@ -70,7 +70,7 @@ public class HsOfficePersonEntity implements RbacObject, Stringifyable { @Override public String toShortString() { return personType + " " + - (!StringUtils.isEmpty(tradeName) ? tradeName : (StringUtils.isEmpty(salutation) ? "" : salutation + " ") + (familyName + ", " + givenName)); + (!StringUtils.isEmpty(tradeName) ? tradeName : (familyName + ", " + givenName)); } public static RbacView rbac() { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java index 9d85fb22..19aa3988 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityUnitTest.java @@ -72,7 +72,7 @@ class HsOfficePersonEntityUnitTest { final var actualDisplay = givenPersonEntity.toShortString(); - assertThat(actualDisplay).isEqualTo("NP Frau Dr. some family name, some given name"); + assertThat(actualDisplay).isEqualTo("NP some family name, some given name"); } @Test @@ -100,7 +100,7 @@ class HsOfficePersonEntityUnitTest { final var actualDisplay = givenPersonEntity.toShortString(); - assertThat(actualDisplay).isEqualTo("NP Dr. Dr. some family name, some given name"); + assertThat(actualDisplay).isEqualTo("NP some family name, some given name"); } @Test -- 2.39.5 From 552146a98c51606a32c0fb80a72e80c33207bb58 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Mon, 8 Apr 2024 10:22:10 +0200 Subject: [PATCH 5/5] add title+salutation to EntityPatcherUnitTest --- .../HsOfficePersonEntityPatcherUnitTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcherUnitTest.java index 7fdb0a27..d1dced4d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntityPatcherUnitTest.java @@ -23,7 +23,9 @@ class HsOfficePersonEntityPatcherUnitTest extends PatchUnitTestBase< final var entity = new HsOfficePersonEntity(); entity.setUuid(INITIAL_PERSON_UUID); entity.setPersonType(HsOfficePersonType.LEGAL_PERSON); - entity.setTradeName("initial@example.org"); + entity.setTradeName("initial trade name"); + entity.setTitle("Dr. Init."); + entity.setSalutation("Herr Initial"); entity.setFamilyName("initial postal address"); entity.setGivenName("+01 100 123456789"); return entity; @@ -54,6 +56,16 @@ class HsOfficePersonEntityPatcherUnitTest extends PatchUnitTestBase< HsOfficePersonPatchResource::setTradeName, "patched trade name", HsOfficePersonEntity::setTradeName), + new JsonNullableProperty<>( + "title", + HsOfficePersonPatchResource::setTitle, + "Dr. Patch.", + HsOfficePersonEntity::setTitle), + new JsonNullableProperty<>( + "salutation", + HsOfficePersonPatchResource::setSalutation, + "Hallo Ini", + HsOfficePersonEntity::setSalutation), new JsonNullableProperty<>( "familyName", HsOfficePersonPatchResource::setFamilyName, -- 2.39.5