Compare commits

..

8 Commits

Author SHA1 Message Date
Michael Hoennig
3998341a5b Merge remote-tracking branch 'origin/master' into rbac-generator-with-conditional-grants 2024-04-08 10:28:43 +02:00
896968e110 Merge pull request 'add-salut-and-title-to-person' (#25) from add-salut-and-title-to-person into master
Reviewed-on: #25
Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
2024-04-08 10:28:09 +02:00
Michael Hoennig
552146a98c add title+salutation to EntityPatcherUnitTest 2024-04-08 10:22:10 +02:00
Michael Hoennig
898aa858b1 toShortString without title+salutation 2024-04-08 10:17:02 +02:00
Michael Hoennig
ca952ce748 merging master + rbac-generation 2024-04-08 10:14:22 +02:00
Michael Hoennig
4438e7abd5 Merge remote-tracking branch 'origin/master' into add-salut-and-title-to-person 2024-04-08 10:08:30 +02:00
Marc O. Sandlus
cc7b8fcf9b some tests 2024-03-18 17:41:58 +01:00
Marc O. Sandlus
1a3fad80ee wip initial commit 2024-03-18 15:40:48 +01:00
7 changed files with 125 additions and 3 deletions

View File

@ -35,6 +35,8 @@ public class HsOfficePersonEntity implements RbacObject, Stringifyable {
private static Stringify<HsOfficePersonEntity> 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);
@ -48,6 +50,12 @@ public class HsOfficePersonEntity implements RbacObject, 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;
@ -68,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) -> {

View File

@ -22,6 +22,8 @@ class HsOfficePersonEntityPatcher implements EntityPatcher<HsOfficePersonPatchRe
.map(HsOfficePersonType::valueOf)
.ifPresent(entity::setPersonType);
OptionalFromJson.of(resource.getTradeName()).ifPresent(entity::setTradeName);
OptionalFromJson.of(resource.getSalutation()).ifPresent(entity::setSalutation);
OptionalFromJson.of(resource.getTitle()).ifPresent(entity::setTitle);
OptionalFromJson.of(resource.getFamilyName()).ifPresent(entity::setFamilyName);
OptionalFromJson.of(resource.getGivenName()).ifPresent(entity::setGivenName);
}

View File

@ -23,6 +23,10 @@ components:
$ref: '#/components/schemas/HsOfficePersonType'
tradeName:
type: string
salutation:
type: string
title:
type: string
givenName:
type: string
familyName:
@ -35,6 +39,10 @@ components:
$ref: '#/components/schemas/HsOfficePersonType'
tradeName:
type: string
salutation:
type: string
title:
type: string
givenName:
type: string
familyName:
@ -51,6 +59,12 @@ components:
tradeName:
type: string
nullable: true
salutation:
type: string
nullable: true
title:
type: string
nullable: true
givenName:
type: string
nullable: true

View File

@ -19,6 +19,8 @@ create table if not exists hs_office_person
uuid uuid unique references RbacObject (uuid) initially deferred,
personType HsOfficePersonType not null,
tradeName varchar(96),
salutation varchar(30),
title varchar(20),
givenName varchar(48),
familyName varchar(48)
);

View File

@ -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

View File

@ -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,

View File

@ -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 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 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')");
}
}