Merge pull request 'rename contact.label to contact.caption' (#55) from rename-contact-label-to-caption into master

Reviewed-on: #55
Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
Michael Hoennig 2024-05-06 10:09:06 +02:00
commit 6c25dddcda
35 changed files with 191 additions and 191 deletions

View File

@ -36,10 +36,10 @@ public class HsOfficeContactController implements HsOfficeContactsApi {
public ResponseEntity<List<HsOfficeContactResource>> listContacts(
final String currentUser,
final String assumedRoles,
final String label) {
final String caption) {
context.define(currentUser, assumedRoles);
final var entities = contactRepo.findContactByOptionalLabelLike(label);
final var entities = contactRepo.findContactByOptionalCaptionLike(caption);
final var resources = mapper.mapList(entities, HsOfficeContactResource.class);
return ResponseEntity.ok(resources);

View File

@ -38,7 +38,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
public class HsOfficeContactEntity implements Stringifyable, RbacObject {
private static Stringify<HsOfficeContactEntity> toString = stringify(HsOfficeContactEntity.class, "contact")
.withProp(Fields.label, HsOfficeContactEntity::getLabel)
.withProp(Fields.caption, HsOfficeContactEntity::getCaption)
.withProp(Fields.emailAddresses, HsOfficeContactEntity::getEmailAddresses);
@Id
@ -49,8 +49,8 @@ public class HsOfficeContactEntity implements Stringifyable, RbacObject {
@Version
private int version;
@Column(name = "label") // TODO.impl: rename to caption
private String label;
@Column(name = "caption")
private String caption;
@Column(name = "postaladdress")
private String postalAddress; // multiline free-format text
@ -96,13 +96,13 @@ public class HsOfficeContactEntity implements Stringifyable, RbacObject {
@Override
public String toShortString() {
return label;
return caption;
}
public static RbacView rbac() {
return rbacViewFor("contact", HsOfficeContactEntity.class)
.withIdentityView(SQL.projection("label"))
.withUpdatableColumns("label", "postalAddress", "emailAddresses", "phoneNumbers")
.withIdentityView(SQL.projection("caption"))
.withUpdatableColumns("caption", "postalAddress", "emailAddresses", "phoneNumbers")
.createRole(OWNER, (with) -> {
with.owningUser(CREATOR);
with.incomingSuperRole(GLOBAL, ADMIN);

View File

@ -17,7 +17,7 @@ class HsOfficeContactEntityPatcher implements EntityPatcher<HsOfficeContactPatch
@Override
public void apply(final HsOfficeContactPatchResource resource) {
OptionalFromJson.of(resource.getLabel()).ifPresent(entity::setLabel);
OptionalFromJson.of(resource.getCaption()).ifPresent(entity::setCaption);
OptionalFromJson.of(resource.getPostalAddress()).ifPresent(entity::setPostalAddress);
Optional.ofNullable(resource.getEmailAddresses())
.ifPresent(r -> entity.getEmailAddresses().patch(KeyValueMap.from(resource.getEmailAddresses())));

View File

@ -13,10 +13,10 @@ public interface HsOfficeContactRepository extends Repository<HsOfficeContactEnt
@Query("""
SELECT c FROM HsOfficeContactEntity c
WHERE :label is null
OR c.label like concat(cast(:label as text), '%')
WHERE :caption is null
OR c.caption like concat(cast(:caption as text), '%')
""")
List<HsOfficeContactEntity> findContactByOptionalLabelLike(String label);
List<HsOfficeContactEntity> findContactByOptionalCaptionLike(String caption);
HsOfficeContactEntity save(final HsOfficeContactEntity entity);

View File

@ -41,7 +41,7 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
OR person.tradeName like concat(cast(:name as text), '%')
OR person.familyName like concat(cast(:name as text), '%')
OR person.givenName like concat(cast(:name as text), '%')
OR contact.label like concat(cast(:name as text), '%')
OR contact.caption like concat(cast(:name as text), '%')
""")
List<HsOfficeDebitorEntity> findDebitorByOptionalNameLike(String name);

View File

@ -20,7 +20,7 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
JOIN HsOfficePersonEntity person ON person.uuid = rel.holder.uuid
WHERE :name is null
OR partner.details.birthName like concat(cast(:name as text), '%')
OR contact.label like concat(cast(:name as text), '%')
OR contact.caption like concat(cast(:name as text), '%')
OR person.tradeName like concat(cast(:name as text), '%')
OR person.givenName like concat(cast(:name as text), '%')
OR person.familyName like concat(cast(:name as text), '%')

View File

@ -33,10 +33,10 @@ public class HsOfficePersonController implements HsOfficePersonsApi {
public ResponseEntity<List<HsOfficePersonResource>> listPersons(
final String currentUser,
final String assumedRoles,
final String label) {
final String caption) {
context.define(currentUser, assumedRoles);
final var entities = personRepo.findPersonByOptionalNameLike(label);
final var entities = personRepo.findPersonByOptionalNameLike(caption);
final var resources = mapper.mapList(entities, HsOfficePersonResource.class);
return ResponseEntity.ok(resources);

View File

@ -9,7 +9,7 @@ components:
uuid:
type: string
format: uuid
label:
caption:
type: string
postalAddress:
type: string
@ -21,7 +21,7 @@ components:
HsOfficeContactInsert:
type: object
properties:
label:
caption:
type: string
postalAddress:
type: string
@ -30,12 +30,12 @@ components:
phoneNumbers:
$ref: '#/components/schemas/HsOfficeContactPhoneNumbers'
required:
- label
- caption
HsOfficeContactPatch:
type: object
properties:
label:
caption:
type: string
nullable: true
postalAddress:

View File

@ -12,7 +12,7 @@ get:
required: false
schema:
type: string
description: Prefix of label to filter the results.
description: Prefix of caption to filter the results.
responses:
"200":
description: OK

View File

@ -12,7 +12,7 @@ get:
required: false
schema:
type: string
description: Prefix of label to filter the results.
description: Prefix of caption to filter the results.
responses:
"200":
description: OK

View File

@ -8,7 +8,7 @@ create table if not exists hs_office_contact
(
uuid uuid unique references RbacObject (uuid) initially deferred,
version int not null default 0,
label varchar(128) not null,
caption varchar(128) not null,
postalAddress text,
emailAddresses jsonb not null,
phoneNumbers jsonb not null

View File

@ -82,7 +82,7 @@ execute procedure insertTriggerForHsOfficeContact_tf();
call generateRbacIdentityViewFromProjection('hs_office_contact',
$idName$
label
caption
$idName$);
--//
@ -92,10 +92,10 @@ call generateRbacIdentityViewFromProjection('hs_office_contact',
-- ----------------------------------------------------------------------------
call generateRbacRestrictedView('hs_office_contact',
$orderBy$
label
caption
$orderBy$,
$updates$
label = new.label,
caption = new.caption,
postalAddress = new.postalAddress,
emailAddresses = new.emailAddresses,
phoneNumbers = new.phoneNumbers

View File

@ -8,28 +8,28 @@
/*
Creates a single contact test record.
*/
create or replace procedure createHsOfficeContactTestData(contLabel varchar)
create or replace procedure createHsOfficeContactTestData(contCaption varchar)
language plpgsql as $$
declare
currentTask varchar;
postalAddr varchar;
emailAddr varchar;
begin
currentTask = 'creating contact test-data ' || contLabel;
currentTask = 'creating contact test-data ' || contCaption;
execute format('set local hsadminng.currentTask to %L', currentTask);
emailAddr = 'contact-admin@' || cleanIdentifier(contLabel) || '.example.com';
emailAddr = 'contact-admin@' || cleanIdentifier(contCaption) || '.example.com';
call defineContext(currentTask);
perform createRbacUser(emailAddr);
call defineContext(currentTask, null, emailAddr);
postalAddr := E'Vorname Nachname\nStraße Hnr\nPLZ Stadt';
raise notice 'creating test contact: %', contLabel;
raise notice 'creating test contact: %', contCaption;
insert
into hs_office_contact (label, postaladdress, emailaddresses, phonenumbers)
into hs_office_contact (caption, postaladdress, emailaddresses, phonenumbers)
values (
contLabel,
contCaption,
postalAddr,
('{ "main": "' || emailAddr || '" }')::jsonb,
('{ "phone_office": "+49 123 1234567" }')::jsonb

View File

@ -12,7 +12,7 @@ create or replace procedure createHsOfficeRelationTestData(
holderPersonName varchar,
relationType HsOfficeRelationType,
anchorPersonName varchar,
contactLabel varchar,
contactCaption varchar,
mark varchar default null)
language plpgsql as $$
declare
@ -44,9 +44,9 @@ begin
raise exception 'holderPerson "%" not found', holderPersonName;
end if;
select c.* into contact from hs_office_contact c where c.label = contactLabel;
select c.* into contact from hs_office_contact c where c.caption = contactCaption;
if contact is null then
raise exception 'contact "%" not found', contactLabel;
raise exception 'contact "%" not found', contactCaption;
end if;
raise notice 'creating test relation: %', idName;
@ -74,7 +74,7 @@ begin
for t in startCount..endCount
loop
select p.* from hs_office_person p where tradeName = intToVarChar(t, 4) into person;
select c.* from hs_office_contact c where c.label = intToVarChar(t, 4) || '#' || t into contact;
select c.* from hs_office_contact c where c.caption = intToVarChar(t, 4) || '#' || t into contact;
call createHsOfficeRelationTestData(person.uuid, contact.uuid, 'REPRESENTATIVE');
commit;

View File

@ -12,7 +12,7 @@ create or replace procedure createHsOfficePartnerTestData(
mandantTradeName varchar,
newPartnerNumber numeric(5),
partnerPersonName varchar,
contactLabel varchar )
contactCaption varchar )
language plpgsql as $$
declare
currentTask varchar;
@ -22,7 +22,7 @@ declare
relatedPerson hs_office_person;
relatedDetailsUuid uuid;
begin
idName := cleanIdentifier( partnerPersonName|| '-' || contactLabel);
idName := cleanIdentifier( partnerPersonName|| '-' || contactCaption);
currentTask := 'creating partner test-data ' || idName;
call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global:ADMIN');
execute format('set local hsadminng.currentTask to %L', currentTask);

View File

@ -11,7 +11,7 @@
create or replace procedure createHsOfficeDebitorTestData(
withDebitorNumberSuffix numeric(5),
forPartnerPersonName varchar,
forBillingContactLabel varchar,
forBillingContactCaption varchar,
withDefaultPrefix varchar
)
language plpgsql as $$
@ -21,7 +21,7 @@ declare
relatedDebitorRelUuid uuid;
relatedBankAccountUuid uuid;
begin
idName := cleanIdentifier( forPartnerPersonName|| '-' || forBillingContactLabel);
idName := cleanIdentifier( forPartnerPersonName|| '-' || forBillingContactCaption);
currentTask := 'creating debitor test-data ' || idName;
call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global:ADMIN');
execute format('set local hsadminng.currentTask to %L', currentTask);

View File

@ -297,17 +297,17 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
void exactlyTheseBankAccountsAreReturned(
final List<HsOfficeBankAccountEntity> actualResult,
final String... bankaccountLabels) {
final String... bankaccountCaptions) {
assertThat(actualResult)
.extracting(HsOfficeBankAccountEntity::getHolder)
.containsExactlyInAnyOrder(bankaccountLabels);
.containsExactlyInAnyOrder(bankaccountCaptions);
}
void allTheseBankAccountsAreReturned(
final List<HsOfficeBankAccountEntity> actualResult,
final String... bankaccountLabels) {
final String... bankaccountCaptions) {
assertThat(actualResult)
.extracting(HsOfficeBankAccountEntity::getHolder)
.contains(bankaccountLabels);
.contains(bankaccountCaptions);
}
}

View File

@ -70,18 +70,18 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType("application/json")
.body("", lenientlyEquals("""
[
{ "label": "first contact" },
{ "label": "second contact" },
{ "label": "third contact" },
{ "label": "fourth contact" },
{ "label": "fifth contact" },
{ "label": "sixth contact" },
{ "label": "seventh contact" },
{ "label": "eighth contact" },
{ "label": "ninth contact" },
{ "label": "tenth contact" },
{ "label": "eleventh contact" },
{ "label": "twelfth contact" }
{ "caption": "first contact" },
{ "caption": "second contact" },
{ "caption": "third contact" },
{ "caption": "fourth contact" },
{ "caption": "fifth contact" },
{ "caption": "sixth contact" },
{ "caption": "seventh contact" },
{ "caption": "eighth contact" },
{ "caption": "ninth contact" },
{ "caption": "tenth contact" },
{ "caption": "eleventh contact" },
{ "caption": "twelfth contact" }
]
"""
));
@ -103,7 +103,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType(ContentType.JSON)
.body("""
{
"label": "Temp Contact",
"caption": "Temp Contact",
"emailAddresses": {
"main": "test@example.org"
}
@ -116,7 +116,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.statusCode(201)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("label", is("Temp Contact"))
.body("caption", is("Temp Contact"))
.body("emailAddresses", is(Map.of("main", "test@example.org")))
.header("Location", startsWith("http://localhost"))
.extract().header("Location"); // @formatter:on
@ -134,7 +134,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Test
void globalAdmin_withoutAssumedRole_canGetArbitraryContact() {
context.define("superuser-alex@hostsharing.net");
final var givenContactUuid = contactRepo.findContactByOptionalLabelLike("first").get(0).getUuid();
final var givenContactUuid = contactRepo.findContactByOptionalCaptionLike("first").get(0).getUuid();
RestAssured // @formatter:off
.given()
@ -147,7 +147,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType("application/json")
.body("", lenientlyEquals("""
{
"label": "first contact"
"caption": "first contact"
}
""")); // @formatter:on
}
@ -155,7 +155,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Test
void normalUser_canNotGetUnrelatedContact() {
context.define("superuser-alex@hostsharing.net");
final var givenContactUuid = contactRepo.findContactByOptionalLabelLike("first").get(0).getUuid();
final var givenContactUuid = contactRepo.findContactByOptionalCaptionLike("first").get(0).getUuid();
RestAssured // @formatter:off
.given()
@ -170,7 +170,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Test
void contactAdminUser_canGetRelatedContact() {
context.define("superuser-alex@hostsharing.net");
final var givenContactUuid = contactRepo.findContactByOptionalLabelLike("first").get(0).getUuid();
final var givenContactUuid = contactRepo.findContactByOptionalCaptionLike("first").get(0).getUuid();
RestAssured // @formatter:off
.given()
@ -183,7 +183,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType("application/json")
.body("", lenientlyEquals("""
{
"label": "first contact",
"caption": "first contact",
"emailAddresses": {
"main": "contact-admin@firstcontact.example.com"
},
@ -210,7 +210,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType(ContentType.JSON)
.body("""
{
"label": "Temp patched contact",
"caption": "Temp patched contact",
"emailAddresses": {
"main": "patched@example.org"
},
@ -227,7 +227,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.statusCode(200)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("label", is("Temp patched contact"))
.body("caption", is("Temp patched contact"))
.body("emailAddresses", is(Map.of("main", "patched@example.org")))
.body("postalAddress", is("Patched Address"))
.body("phoneNumbers", is(Map.of("phone_office", "+01 100 123456")));
@ -237,7 +237,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net");
assertThat(contactRepo.findByUuid(givenContact.getUuid())).isPresent().get()
.matches(person -> {
assertThat(person.getLabel()).isEqualTo("Temp patched contact");
assertThat(person.getCaption()).isEqualTo("Temp patched contact");
assertThat(person.getEmailAddresses()).containsExactlyEntriesOf(Map.of("main", "patched@example.org"));
assertThat(person.getPostalAddress()).isEqualTo("Patched Address");
assertThat(person.getPhoneNumbers()).containsExactlyEntriesOf(Map.of("phone_office", "+01 100 123456"));
@ -272,7 +272,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
.statusCode(200)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("label", is(givenContact.getLabel()))
.body("caption", is(givenContact.getCaption()))
.body("emailAddresses", is(Map.of("main", "patched@example.org")))
.body("postalAddress", is(givenContact.getPostalAddress()))
.body("phoneNumbers", is(Map.of("phone_office", "+01 100 123456")));
@ -281,7 +281,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
// finally, the contact is actually updated
assertThat(contactRepo.findByUuid(givenContact.getUuid())).isPresent().get()
.matches(person -> {
assertThat(person.getLabel()).isEqualTo(givenContact.getLabel());
assertThat(person.getCaption()).isEqualTo(givenContact.getCaption());
assertThat(person.getEmailAddresses()).containsExactlyEntriesOf(Map.of("main", "patched@example.org"));
assertThat(person.getPostalAddress()).isEqualTo(givenContact.getPostalAddress());
assertThat(person.getPhoneNumbers()).containsExactlyEntriesOf(Map.of("phone_office", "+01 100 123456"));
@ -354,7 +354,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define(creatingUser);
final var newContact = HsOfficeContactEntity.builder()
.uuid(UUID.randomUUID())
.label("Temp from " + Context.getCallerMethodNameFromStackFrame(1) )
.caption("Temp from " + Context.getCallerMethodNameFromStackFrame(1) )
.emailAddresses(Map.of("main", RandomStringUtils.randomAlphabetic(10) + "@example.org"))
.postalAddress("Postal Address " + RandomStringUtils.randomAlphabetic(10))
.phoneNumbers(Map.of("phone_office", "+01 200 " + RandomStringUtils.randomNumeric(8)))
@ -369,7 +369,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
void cleanup() {
jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
em.createQuery("DELETE FROM HsOfficeContactEntity c WHERE c.label LIKE 'Temp %'").executeUpdate();
em.createQuery("DELETE FROM HsOfficeContactEntity c WHERE c.caption LIKE 'Temp %'").executeUpdate();
}).assertSuccessful();
}
}

View File

@ -45,7 +45,7 @@ class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase<
protected HsOfficeContactEntity newInitialEntity() {
final var entity = new HsOfficeContactEntity();
entity.setUuid(INITIAL_CONTACT_UUID);
entity.setLabel("initial label");
entity.setCaption("initial caption");
entity.putEmailAddresses(Map.ofEntries(
entry("main", "initial@example.org"),
entry("paul", "paul@example.com"),
@ -72,10 +72,10 @@ class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase<
protected Stream<Property> propertyTestDescriptors() {
return Stream.of(
new JsonNullableProperty<>(
"label",
HsOfficeContactPatchResource::setLabel,
"patched label",
HsOfficeContactEntity::setLabel),
"caption",
HsOfficeContactPatchResource::setCaption,
"patched caption",
HsOfficeContactEntity::setCaption),
new SimpleProperty<>(
"resources",
HsOfficeContactPatchResource::setEmailAddresses,

View File

@ -13,9 +13,9 @@ class HsOfficeContactEntityUnitTest {
}
@Test
void toStringReturnsLabel() {
final var givenContact = HsOfficeContactEntity.builder().label("given label").build();
assertThat("" + givenContact).isEqualTo("contact(label='given label')");
void toStringReturnsCaption() {
final var givenContact = HsOfficeContactEntity.builder().caption("given caption").build();
assertThat("" + givenContact).isEqualTo("contact(caption='given caption')");
}
}

View File

@ -135,7 +135,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net");
// when
final var result = contactRepo.findContactByOptionalLabelLike(null);
final var result = contactRepo.findContactByOptionalCaptionLike(null);
// then
allTheseContactsAreReturned(result, "first contact", "second contact", "third contact");
@ -148,15 +148,15 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
// when:
context("selfregistered-user-drew@hostsharing.org");
final var result = contactRepo.findContactByOptionalLabelLike(null);
final var result = contactRepo.findContactByOptionalCaptionLike(null);
// then:
exactlyTheseContactsAreReturned(result, givenContact.getLabel());
exactlyTheseContactsAreReturned(result, givenContact.getCaption());
}
}
@Nested
class FindByLabelLike {
class FindByCaptionLike {
@Test
public void globalAdmin_withoutAssumedRole_canViewAllContacts() {
@ -164,7 +164,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net", null);
// when
final var result = contactRepo.findContactByOptionalLabelLike("second");
final var result = contactRepo.findContactByOptionalCaptionLike("second");
// then
exactlyTheseContactsAreReturned(result, "second contact");
@ -177,10 +177,10 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
// when:
context("selfregistered-user-drew@hostsharing.org");
final var result = contactRepo.findContactByOptionalLabelLike(givenContact.getLabel());
final var result = contactRepo.findContactByOptionalCaptionLike(givenContact.getCaption());
// then:
exactlyTheseContactsAreReturned(result, givenContact.getLabel());
exactlyTheseContactsAreReturned(result, givenContact.getCaption());
}
}
@ -203,7 +203,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
result.assertSuccessful();
assertThat(jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", null);
return contactRepo.findContactByOptionalLabelLike(givenContact.getLabel());
return contactRepo.findContactByOptionalCaptionLike(givenContact.getCaption());
}).assertSuccessful().returnedValue()).hasSize(0);
}
@ -222,7 +222,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
result.assertSuccessful();
assertThat(jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", null);
return contactRepo.findContactByOptionalLabelLike(givenContact.getLabel());
return contactRepo.findContactByOptionalCaptionLike(givenContact.getCaption());
}).assertSuccessful().returnedValue()).hasSize(0);
}
@ -287,15 +287,15 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
"some-temporary-contact" + random + "@example.com"));
}
void exactlyTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactLabels) {
void exactlyTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactCaptions) {
assertThat(actualResult)
.extracting(HsOfficeContactEntity::getLabel)
.containsExactlyInAnyOrder(contactLabels);
.extracting(HsOfficeContactEntity::getCaption)
.containsExactlyInAnyOrder(contactCaptions);
}
void allTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactLabels) {
void allTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactCaptions) {
assertThat(actualResult)
.extracting(HsOfficeContactEntity::getLabel)
.contains(contactLabels);
.extracting(HsOfficeContactEntity::getCaption)
.contains(contactCaptions);
}
}

View File

@ -6,10 +6,10 @@ public class TestHsOfficeContact {
public static final HsOfficeContactEntity TEST_CONTACT = hsOfficeContact("some contact", "some-contact@example.com");
static public HsOfficeContactEntity hsOfficeContact(final String label, final String emailAddr) {
static public HsOfficeContactEntity hsOfficeContact(final String caption, final String emailAddr) {
return HsOfficeContactEntity.builder()
.label(label)
.postalAddress("address of " + label)
.caption(caption)
.postalAddress("address of " + caption)
.emailAddresses(Map.of("main", emailAddr))
.build();
}

View File

@ -106,7 +106,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"type": "DEBITOR",
"mark": null,
"contact": {
"label": "first contact",
"caption": "first contact",
"emailAddresses": { "main": "contact-admin@firstcontact.example.com" },
"phoneNumbers": { "phone_office": "+49 123 1234567" }
}
@ -131,7 +131,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"type": "PARTNER",
"mark": null,
"contact": {
"label": "first contact",
"caption": "first contact",
"emailAddresses": { "main": "contact-admin@firstcontact.example.com" },
"phoneNumbers": { "phone_office": "+49 123 1234567" }
}
@ -248,7 +248,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"debitorNumber": 1000212,
"partner": { "partnerNumber": 10002 },
"debitorRel": {
"contact": { "label": "second contact" }
"contact": { "caption": "second contact" }
},
"vatId": null,
"vatCountryCode": null,
@ -268,7 +268,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0);
final var givenBillingPerson = personRepo.findPersonByOptionalNameLike("Fourth").get(0);
@ -308,7 +308,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
.body("uuid", isUuidValid())
.body("vatId", is("VAT123456"))
.body("defaultPrefix", is("for"))
.body("debitorRel.contact.label", is(givenContact.getLabel()))
.body("debitorRel.contact.caption", is(givenContact.getCaption()))
.body("debitorRel.holder.tradeName", is(givenBillingPerson.getTradeName()))
.body("refundBankAccount.holder", is(givenBankAccount.getHolder()))
.header("Location", startsWith("http://localhost"))
@ -325,7 +325,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off
.given()
@ -356,7 +356,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
.statusCode(201)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("debitorRel.contact.label", is(givenContact.getLabel()))
.body("debitorRel.contact.caption", is(givenContact.getCaption()))
.body("partner.partnerRel.holder.tradeName", is(givenPartner.getPartnerRel().getHolder().getTradeName()))
.body("vatId", equalTo(null))
.body("vatCountryCode", equalTo(null))
@ -414,7 +414,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net");
final var givenDebitorRelUuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off
.given()
@ -463,7 +463,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"holder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"},
"type": "DEBITOR",
"contact": {
"label": "first contact",
"caption": "first contact",
"postalAddress": "Vorname Nachname\\nStraße Hnr\\nPLZ Stadt",
"emailAddresses": { "main": "contact-admin@firstcontact.example.com" },
"phoneNumbers": { "phone_office": "+49 123 1234567" }
@ -479,7 +479,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"type": "PARTNER",
"mark": null,
"contact": {
"label": "first contact",
"caption": "first contact",
"postalAddress": "Vorname Nachname\\nStraße Hnr\\nPLZ Stadt",
"emailAddresses": { "main": "contact-admin@firstcontact.example.com" },
"phoneNumbers": { "phone_office": "+49 123 1234567" }
@ -536,7 +536,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
{
"debitorNumber": 1000111,
"partner": { "partnerNumber": 10001 },
"debitorRel": { "contact": { "label": "first contact" } },
"debitorRel": { "contact": { "caption": "first contact" } },
"refundBankAccount": null
}
""")); // @formatter:on
@ -551,7 +551,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor();
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0);
final var location = RestAssured // @formatter:off
.given()
@ -579,7 +579,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"holder": { "tradeName": "Fourth eG" },
"type": "DEBITOR",
"mark": null,
"contact": { "label": "fourth contact" }
"contact": { "caption": "fourth contact" }
},
"debitorNumber": 10004${debitorNumberSuffix},
"debitorNumberSuffix": ${debitorNumberSuffix},
@ -590,7 +590,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"holder": { "tradeName": "Fourth eG" },
"type": "PARTNER",
"mark": null,
"contact": { "label": "fourth contact" }
"contact": { "caption": "fourth contact" }
},
"details": {
"registrationOffice": "Hamburg",
@ -619,7 +619,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
.matches(debitor -> {
assertThat(debitor.getDebitorRel().getHolder().getTradeName())
.isEqualTo(givenDebitor.getDebitorRel().getHolder().getTradeName());
assertThat(debitor.getDebitorRel().getContact().getLabel()).isEqualTo("fourth contact");
assertThat(debitor.getDebitorRel().getContact().getCaption()).isEqualTo("fourth contact");
assertThat(debitor.getVatId()).isEqualTo("VAT222222");
assertThat(debitor.getVatCountryCode()).isEqualTo("AA");
assertThat(debitor.isVatBusiness()).isEqualTo(true);
@ -680,7 +680,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
void contactAdminUser_canNotDeleteRelatedDebitor() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor();
assertThat(givenDebitor.getDebitorRel().getContact().getLabel()).isEqualTo("fourth contact");
assertThat(givenDebitor.getDebitorRel().getContact().getCaption()).isEqualTo("fourth contact");
RestAssured // @formatter:off
.given()
@ -699,7 +699,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
void normalUser_canNotDeleteUnrelatedDebitor() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor();
assertThat(givenDebitor.getDebitorRel().getContact().getLabel()).isEqualTo("fourth contact");
assertThat(givenDebitor.getDebitorRel().getContact().getCaption()).isEqualTo("fourth contact");
RestAssured // @formatter:off
.given()
@ -719,7 +719,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0);
final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
final var newDebitor = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix(nextDebitorSuffix())
.billable(true)

View File

@ -20,7 +20,7 @@ class HsOfficeDebitorEntityUnitTest {
.personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("some billing trade name")
.build())
.contact(HsOfficeContactEntity.builder().label("some label").build())
.contact(HsOfficeContactEntity.builder().caption("some caption").build())
.build();
@Test

View File

@ -84,7 +84,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net");
final var count = debitorRepo.count();
final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH"));
final var givenContact = one(contactRepo.findContactByOptionalLabelLike("first contact"));
final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("first contact"));
// when
final var result = attempt(em, () -> {
@ -116,7 +116,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// given
context("superuser-alex@hostsharing.net");
final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH"));
final var givenContact = one(contactRepo.findContactByOptionalLabelLike("first contact"));
final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("first contact"));
// when
final var result = attempt(em, () -> {
@ -154,7 +154,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
attempt(em, () -> {
final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH"));
final var givenDebitorPerson = one(personRepo.findPersonByOptionalNameLike("Fourth eG"));
final var givenContact = one(contactRepo.findContactByOptionalLabelLike("fourth contact"));
final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("fourth contact"));
final var newDebitor = HsOfficeDebitorEntity.builder()
.debitorNumberSuffix("22")
.debitorRel(HsOfficeRelationEntity.builder()
@ -320,7 +320,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
"hs_office_relation#FourtheG-with-DEBITOR-FourtheG:ADMIN", true);
final var givenNewPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First"));
final var givenNewBillingPerson = one(personRepo.findPersonByOptionalNameLike("Firby"));
final var givenNewContact = one(contactRepo.findContactByOptionalLabelLike("sixth contact"));
final var givenNewContact = one(contactRepo.findContactByOptionalCaptionLike("sixth contact"));
final var givenNewBankAccount = one(bankAccountRepo.findByOptionalHolderLike("first"));
final String givenNewVatId = "NEW-VAT-ID";
final String givenNewVatCountryCode = "NC";
@ -603,13 +603,13 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
private HsOfficeDebitorEntity givenSomeTemporaryDebitor(
final String partnerName,
final String contactLabel,
final String contactCaption,
final String bankAccountHolder,
final String defaultPrefix) {
return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike(partnerName));
final var givenContact = one(contactRepo.findContactByOptionalLabelLike(contactLabel));
final var givenContact = one(contactRepo.findContactByOptionalCaptionLike(contactCaption));
final var givenBankAccount =
bankAccountHolder != null ? one(bankAccountRepo.findByOptionalHolderLike(bankAccountHolder)) : null;
final var newDebitor = HsOfficeDebitorEntity.builder()

View File

@ -241,15 +241,15 @@ public class ImportOfficeData extends ContextBasedTest {
""");
assertThat(toFormattedString(contacts)).isEqualToIgnoringWhitespace("""
{
1101=contact(label='Herr Michael Mellies ', emailAddresses='{ main: mih@example.org }'),
1200=contact(label='JM e.K.', emailAddresses='{ main: jm-ex-partner@example.org }'),
1201=contact(label='Frau Dr. Jenny Meyer-Billing , JM GmbH', emailAddresses='{ main: jm-billing@example.org }'),
1202=contact(label='Herr Andrew Meyer-Operation , JM GmbH', emailAddresses='{ main: am-operation@example.org }'),
1203=contact(label='Herr Philip Meyer-Contract , JM GmbH', emailAddresses='{ main: pm-partner@example.org }'),
1204=contact(label='Frau Tammy Meyer-VIP , JM GmbH', emailAddresses='{ main: tm-vip@example.org }'),
1301=contact(label='Petra Schmidt , Test PS', emailAddresses='{ main: ps@example.com }'),
1401=contact(label='Frau Frauke Fanninga ', emailAddresses='{ main: ff@example.org }'),
1501=contact(label='Frau Cecilia Camus ', emailAddresses='{ main: cc@example.org }')
1101=contact(caption='Herr Michael Mellies ', emailAddresses='{ main: mih@example.org }'),
1200=contact(caption='JM e.K.', emailAddresses='{ main: jm-ex-partner@example.org }'),
1201=contact(caption='Frau Dr. Jenny Meyer-Billing , JM GmbH', emailAddresses='{ main: jm-billing@example.org }'),
1202=contact(caption='Herr Andrew Meyer-Operation , JM GmbH', emailAddresses='{ main: am-operation@example.org }'),
1203=contact(caption='Herr Philip Meyer-Contract , JM GmbH', emailAddresses='{ main: pm-partner@example.org }'),
1204=contact(caption='Frau Tammy Meyer-VIP , JM GmbH', emailAddresses='{ main: tm-vip@example.org }'),
1301=contact(caption='Petra Schmidt , Test PS', emailAddresses='{ main: ps@example.com }'),
1401=contact(caption='Frau Frauke Fanninga ', emailAddresses='{ main: ff@example.org }'),
1501=contact(caption='Frau Cecilia Camus ', emailAddresses='{ main: cc@example.org }')
}
""");
assertThat(toFormattedString(persons)).isEqualToIgnoringWhitespace("""
@ -427,7 +427,7 @@ public class ImportOfficeData extends ContextBasedTest {
assertThat(partnerRel).describedAs("partner " + id + " without partnerRel").isNotNull();
if ( id != 99 ) {
assertThat(partnerRel.getContact()).describedAs("partner " + id + " without partnerRel.contact").isNotNull();
assertThat(partnerRel.getContact().getLabel()).describedAs("partner " + id + " without valid partnerRel.contact").isNotNull();
assertThat(partnerRel.getContact().getCaption()).describedAs("partner " + id + " without valid partnerRel.contact").isNotNull();
assertThat(partnerRel.getHolder()).describedAs("partner " + id + " without partnerRel.relHolder").isNotNull();
assertThat(partnerRel.getHolder().getPersonType()).describedAs("partner " + id + " without valid partnerRel.relHolder").isNotNull();
}
@ -460,7 +460,7 @@ public class ImportOfficeData extends ContextBasedTest {
// avoid a error when persisting the deliberately invalid partner entry #99
final var idsToRemove = new HashSet<Integer>();
relations.forEach( (id, r) -> {
if (r.getContact() == null || r.getContact().getLabel() == null ||
if (r.getContact() == null || r.getContact().getCaption() == null ||
r.getHolder() == null || r.getHolder().getPersonType() == null ) {
idsToRemove.add(id);
}
@ -483,7 +483,7 @@ public class ImportOfficeData extends ContextBasedTest {
final var partnerRole = r.getPartnerRel();
// such a record is in test data to test error messages
if (partnerRole.getContact() == null || partnerRole.getContact().getLabel() == null ||
if (partnerRole.getContact() == null || partnerRole.getContact().getCaption() == null ||
partnerRole.getHolder() == null | partnerRole.getHolder().getPersonType() == null ) {
idsToRemove.add(id);
}
@ -504,7 +504,7 @@ public class ImportOfficeData extends ContextBasedTest {
final var idsToRemove = new HashSet<Integer>();
debitors.forEach( (id, d) -> {
final var debitorRel = d.getDebitorRel();
if (debitorRel.getContact() == null || debitorRel.getContact().getLabel() == null ||
if (debitorRel.getContact() == null || debitorRel.getContact().getCaption() == null ||
debitorRel.getAnchor() == null || debitorRel.getAnchor().getPersonType() == null ||
debitorRel.getHolder() == null || debitorRel.getHolder().getPersonType() == null ) {
idsToRemove.add(id);
@ -1087,7 +1087,7 @@ public class ImportOfficeData extends ContextBasedTest {
private HsOfficeContactEntity initContact(final HsOfficeContactEntity contact, final Record contactRecord) {
contact.setLabel(toLabel(
contact.setCaption(toCaption(
contactRecord.getString("salut"),
contactRecord.getString("title"),
contactRecord.getString("first_name"),
@ -1166,7 +1166,7 @@ public class ImportOfficeData extends ContextBasedTest {
return result.toString();
}
</