From 74c13d94fdba08e0954327c7649a848aec537374 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 5 Nov 2024 16:18:44 +0100 Subject: [PATCH 01/10] split postalAddress into a map of firma, name, co, street, zipcode, city, country --- .../hs/office/contact/HsOfficeContact.java | 19 ++++++++- .../contact/HsOfficeContactEntityPatcher.java | 3 +- .../HsOfficeRelationRbacRepository.java | 2 +- .../hs-office/hs-office-contact-schemas.yaml | 39 ++++++++++++++++--- .../501-contact/5010-hs-office-contact.sql | 2 +- .../5018-hs-office-contact-test-data.sql | 11 ++++-- .../hs/migration/BaseOfficeDataImport.java | 33 +++++----------- ...OfficeContactControllerAcceptanceTest.java | 31 ++++++++++++--- .../HsOfficeContactPatcherUnitTest.java | 38 +++++++++++++----- .../HsOfficeContactRbacTestEntity.java | 9 ++++- .../HsOfficeContactRealTestEntity.java | 9 ++++- 11 files changed, 142 insertions(+), 54 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java index 62519731..a4267f53 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java @@ -54,8 +54,14 @@ public class HsOfficeContact implements Stringifyable, BaseEntity postalAddress = new HashMap<>(); + + @Transient + private PatchableMapWrapper postalAddressWrapper; @Builder.Default @Setter(AccessLevel.NONE) @@ -75,6 +81,17 @@ public class HsOfficeContact implements Stringifyable, BaseEntity phoneNumbersWrapper; + public PatchableMapWrapper getPostalAddress() { + return PatchableMapWrapper.of( + postalAddressWrapper, + (newWrapper) -> {postalAddressWrapper = newWrapper;}, + postalAddress); + } + + public void putPostalAddress(Map newPostalAddress) { + getPostalAddress().assign(newPostalAddress); + } + public PatchableMapWrapper getEmailAddresses() { return PatchableMapWrapper.of( emailAddressesWrapper, diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java index e08e6bae..356aa950 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java @@ -18,7 +18,8 @@ class HsOfficeContactEntityPatcher implements EntityPatcher entity.getPostalAddress().patch(KeyValueMap.from(resource.getPostalAddress()))); Optional.ofNullable(resource.getEmailAddresses()) .ifPresent(r -> entity.getEmailAddresses().patch(KeyValueMap.from(resource.getEmailAddresses()))); Optional.ofNullable(resource.getPhoneNumbers()) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java index 96d4b8d5..cce31305 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java @@ -47,7 +47,7 @@ public interface HsOfficeRelationRbacRepository extends Repository toAddress(final Record rec) { + final var result = new LinkedHashMap(); final var name = toName( rec.getString("salut"), rec.getString("title"), rec.getString("first_name"), rec.getString("last_name")); if (isNotBlank(name)) - result.append(name + "\n"); - if (isNotBlank(rec.getString("firma"))) - result.append(rec.getString("firma") + "\n"); - if (isNotBlank(rec.getString("co"))) - result.append("c/o " + rec.getString("co") + "\n"); - if (isNotBlank(rec.getString("street"))) - result.append(rec.getString("street") + "\n"); - final var zipcodeAndCity = toZipcodeAndCity(rec); - if (isNotBlank(zipcodeAndCity)) - result.append(zipcodeAndCity + "\n"); - return result.toString(); - } + result.put("name", name); - private String toZipcodeAndCity(final Record rec) { - final var result = new StringBuilder(); - if (isNotBlank(rec.getString("country"))) - result.append(rec.getString("country") + " "); - if (isNotBlank(rec.getString("zipcode"))) - result.append(rec.getString("zipcode") + " "); - if (isNotBlank(rec.getString("city"))) - result.append(rec.getString("city")); - return result.toString(); + List.of("firma", "co", "street", "zipcode", "city", "country").forEach(key -> { + if (isNotBlank(rec.getString(key))) + result.put(key, rec.getString(key)); + }); + return result; } private String toCaption( diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java index 10dd8c75..9ea3ee08 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java @@ -21,10 +21,13 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; +import static java.util.Map.entry; import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid; import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals; import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; @@ -214,7 +217,10 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu "emailAddresses": { "main": "patched@example.org" }, - "postalAddress": "Patched Address", + "postalAddress": { + "co": "P. Patcher", + "street": "Patchstraße 5" + }, "phoneNumbers": { "phone_office": "+01 100 123456" } @@ -229,7 +235,9 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu .body("uuid", isUuidValid()) .body("caption", is("Temp patched contact")) .body("emailAddresses", is(Map.of("main", "patched@example.org"))) - .body("postalAddress", is("Patched Address")) + .body("postalAddress", hasEntry("name", givenContact.getPostalAddress().get("name"))) // unchanged + .body("postalAddress", hasEntry("co", "P. Patcher")) // patched + .body("postalAddress", hasEntry("street", "Patchstraße 5")) // patched .body("phoneNumbers", is(Map.of("phone_office", "+01 100 123456"))); // @formatter:on @@ -239,7 +247,11 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu .matches(person -> { 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.getPostalAddress()).containsAllEntriesOf(Map.ofEntries( + entry("name", givenContact.getPostalAddress().get("name")), + entry("co", "P. Patcher"), + entry("street", "Patchstraße 5") + )); assertThat(person.getPhoneNumbers()).containsExactlyEntriesOf(Map.of("phone_office", "+01 100 123456")); return true; }); @@ -264,7 +276,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu "phone_office": "+01 100 123456" } } - """) + """) .port(port) .when() .patch("http://localhost/api/hs/office/contacts/" + givenContact.getUuid()) @@ -361,8 +373,13 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu final var newContact = HsOfficeContactRbacEntity.builder() .uuid(UUID.randomUUID()) .caption("Temp from " + Context.getCallerMethodNameFromStackFrame(1) ) + .postalAddress(Map.ofEntries( + entry("name", RandomStringUtils.randomAlphabetic(6) + " " + RandomStringUtils.randomAlphabetic(10)), + entry("street", RandomStringUtils.randomAlphabetic(10) + randomInt(1, 99)), + entry("zipcode", "D-" + randomInt(10000, 99999)), + entry("city", RandomStringUtils.randomAlphabetic(10)) + )) .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))) .build(); @@ -378,4 +395,8 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu em.createQuery("DELETE FROM HsOfficeContactRbacEntity c WHERE c.caption LIKE 'Temp %'").executeUpdate(); }).assertSuccessful(); } + + private int randomInt(final int min, final int max) { + return ThreadLocalRandom.current().nextInt(min, max); + } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java index 95b4eb94..c9fe1348 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java @@ -19,6 +19,20 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< > { private static final UUID INITIAL_CONTACT_UUID = UUID.randomUUID(); + + private static final Map PATCH_POSTAL_ADDRESS = patchMap( + entry("name", "Patty Patch"), + entry("street", "Patchstreet 10"), + entry("zipcode", null), + entry("city", "Hamburg") + ); + private static final Map PATCHED_POSTAL_ADDRESS = patchMap( + entry("name", "Patty Patch"), + entry("street", "Patchstreet 10"), + entry("zipcode", "20000"), + entry("city", "Hamburg") + ); + private static final Map PATCH_EMAIL_ADDRESSES = patchMap( entry("main", "patched@example.com"), entry("paul", null), @@ -46,6 +60,11 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< final var entity = new HsOfficeContactRbacEntity(); entity.setUuid(INITIAL_CONTACT_UUID); entity.setCaption("initial caption"); + entity.putPostalAddress(Map.ofEntries( + entry("name", "Ina Initial"), + entry("street", "Initialstraße 50"), + entry("zipcode", "20000"), + entry("city", "Hamburg"))); entity.putEmailAddresses(Map.ofEntries( entry("main", "initial@example.org"), entry("paul", "paul@example.com"), @@ -54,7 +73,6 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< entry("phone_office", "+49 40 12345-00"), entry("phone_mobile", "+49 1555 1234567"), entry("fax", "+49 40 12345-90"))); - entity.setPostalAddress("Initialstraße 50\n20000 Hamburg"); return entity; } @@ -77,24 +95,26 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< "patched caption", HsOfficeContactRbacEntity::setCaption), new SimpleProperty<>( - "resources", + "postalAddress", + HsOfficeContactPatchResource::setEmailAddresses, + PATCH_POSTAL_ADDRESS, + HsOfficeContactRbacEntity::putEmailAddresses, + PATCHED_POSTAL_ADDRESS) + .notNullable(), + new SimpleProperty<>( + "emailAddresses", HsOfficeContactPatchResource::setEmailAddresses, PATCH_EMAIL_ADDRESSES, HsOfficeContactRbacEntity::putEmailAddresses, PATCHED_EMAIL_ADDRESSES) .notNullable(), new SimpleProperty<>( - "resources", + "phoneNumbers", HsOfficeContactPatchResource::setPhoneNumbers, PATCH_PHONE_NUMBERS, HsOfficeContactRbacEntity::putPhoneNumbers, PATCHED_PHONE_NUMBERS) - .notNullable(), - new JsonNullableProperty<>( - "patched given name", - HsOfficeContactPatchResource::setPostalAddress, - "patched given name", - HsOfficeContactRbacEntity::setPostalAddress) + .notNullable() ); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacTestEntity.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacTestEntity.java index ba96f31b..5589cab2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacTestEntity.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacTestEntity.java @@ -2,6 +2,8 @@ package net.hostsharing.hsadminng.hs.office.contact; import java.util.Map; +import static java.util.Map.entry; + public class HsOfficeContactRbacTestEntity { public static final HsOfficeContactRbacEntity TEST_RBAC_CONTACT = hsOfficeContact("some contact", "some-contact@example.com"); @@ -9,7 +11,12 @@ public class HsOfficeContactRbacTestEntity { static public HsOfficeContactRbacEntity hsOfficeContact(final String caption, final String emailAddr) { return HsOfficeContactRbacEntity.builder() .caption(caption) - .postalAddress("address of " + caption) + .postalAddress(Map.ofEntries( + entry("name", "M. Meyer"), + entry("street", "Teststraße 11"), + entry("zipcode", "D-12345"), + entry("city", "Berlin") + )) .emailAddresses(Map.of("main", emailAddr)) .build(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealTestEntity.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealTestEntity.java index d8cdfe1b..c10a9a35 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealTestEntity.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealTestEntity.java @@ -2,6 +2,8 @@ package net.hostsharing.hsadminng.hs.office.contact; import java.util.Map; +import static java.util.Map.entry; + public class HsOfficeContactRealTestEntity { public static final HsOfficeContactRealEntity TEST_REAL_CONTACT = hsOfficeContact("some contact", "some-contact@example.com"); @@ -9,7 +11,12 @@ public class HsOfficeContactRealTestEntity { static public HsOfficeContactRealEntity hsOfficeContact(final String caption, final String emailAddr) { return HsOfficeContactRealEntity.builder() .caption(caption) - .postalAddress("address of " + caption) + .postalAddress(Map.ofEntries( + entry("name", "M. Meyer"), + entry("street", "Teststraße 11"), + entry("zipcode", "D-12345"), + entry("city", "Berlin") + )) .emailAddresses(Map.of("main", emailAddr)) .build(); } -- 2.39.5 From ad30736482972a606679ed0bde665ebfca005df7 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 5 Nov 2024 16:55:12 +0100 Subject: [PATCH 02/10] amend postalAddress in test-data --- .../hs/hosting/asset/HsHostingAssetControllerRestTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java index 9dc5741b..c50e2dfd 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java @@ -110,7 +110,6 @@ public class HsHostingAssetControllerRestTest { "caption": "some fake cloud-server", "alarmContact": { "caption": "some contact", - "postalAddress": "address of some contact", "emailAddresses": { "main": "some-contact@example.com" } @@ -141,7 +140,6 @@ public class HsHostingAssetControllerRestTest { "caption": "some fake managed-server", "alarmContact": { "caption": "some contact", - "postalAddress": "address of some contact", "emailAddresses": { "main": "some-contact@example.com" } -- 2.39.5 From 829c00152ab845616773ac9adf2ad1eb4fce06cf Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 5 Nov 2024 16:55:26 +0100 Subject: [PATCH 03/10] test patch of extra property in postalAddress --- .../office/contact/HsOfficeContactControllerAcceptanceTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java index 9ea3ee08..3fc76a1b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java @@ -218,6 +218,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu "main": "patched@example.org" }, "postalAddress": { + "extra": "Extra Property", "co": "P. Patcher", "street": "Patchstraße 5" }, @@ -236,6 +237,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu .body("caption", is("Temp patched contact")) .body("emailAddresses", is(Map.of("main", "patched@example.org"))) .body("postalAddress", hasEntry("name", givenContact.getPostalAddress().get("name"))) // unchanged + .body("postalAddress", hasEntry("extra", "Extra Property")) // unchanged .body("postalAddress", hasEntry("co", "P. Patcher")) // patched .body("postalAddress", hasEntry("street", "Patchstraße 5")) // patched .body("phoneNumbers", is(Map.of("phone_office", "+01 100 123456"))); -- 2.39.5 From 626db1fa16c7c6f5932c228ce4fe05ed8f7c3dfc Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 5 Nov 2024 17:19:47 +0100 Subject: [PATCH 04/10] fix tests assertions --- .../contact/HsOfficeContactControllerAcceptanceTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java index 3fc76a1b..19bb80a3 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java @@ -288,7 +288,6 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu .body("uuid", isUuidValid()) .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"))); // @formatter:on @@ -297,12 +296,11 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu .matches(person -> { assertThat(person.getCaption()).isEqualTo(givenContact.getCaption()); assertThat(person.getEmailAddresses()).containsExactlyEntriesOf(Map.of("main", "patched@example.org")); - assertThat(person.getPostalAddress()).isEqualTo(givenContact.getPostalAddress()); + assertThat(person.getPostalAddress()).containsExactlyInAnyOrderEntriesOf(givenContact.getPostalAddress()); assertThat(person.getPhoneNumbers()).containsExactlyEntriesOf(Map.of("phone_office", "+01 100 123456")); return true; }); } - } @Nested -- 2.39.5 From 48bc6c9ccfc3e3f72b4a20083127aaec7122848c Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 5 Nov 2024 18:54:39 +0100 Subject: [PATCH 05/10] fix postalAddress format in scenario tests --- .../HsOfficeContactPatcherUnitTest.java | 4 +- ...OfficeDebitorControllerAcceptanceTest.java | 18 +++++---- ...fficeRelationControllerAcceptanceTest.java | 4 +- .../scenarios/HsOfficeScenarioTests.java | 37 +++++++++++++------ .../scenarios/contact/AmendContactData.java | 4 +- .../scenarios/contact/ReplaceContactData.java | 4 +- .../partner/AddRepresentativeToPartner.java | 4 +- .../scenarios/partner/CreatePartner.java | 4 +- 8 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java index c9fe1348..b5a2545c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java @@ -96,9 +96,9 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< HsOfficeContactRbacEntity::setCaption), new SimpleProperty<>( "postalAddress", - HsOfficeContactPatchResource::setEmailAddresses, + HsOfficeContactPatchResource::setPostalAddress, PATCH_POSTAL_ADDRESS, - HsOfficeContactRbacEntity::putEmailAddresses, + HsOfficeContactRbacEntity::putPhoneNumbers, PATCHED_POSTAL_ADDRESS) .notNullable(), new SimpleProperty<>( diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java index 58b715da..a15ffbce 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java @@ -460,9 +460,12 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu "type": "DEBITOR", "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" } + "postalAddress": { + "country": "Germany" + }, + "emailAddresses": { "main": "contact-admin@firstcontact.example.com" }, + "phoneNumbers": { "phone_office": "+49 123 1234567" } + } } }, "debitorNumber": 1000111, @@ -476,10 +479,11 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu "mark": null, "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" } - } + "postalAddress": { + "country": "Germany" + }, + "emailAddresses": { "main": "contact-admin@firstcontact.example.com" }, + "phoneNumbers": { "phone_office": "+49 123 1234567" } }, "details": { "registrationOffice": "Hamburg", diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java index e767ff1c..2dac741b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java @@ -199,7 +199,9 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean "type": "REPRESENTATIVE", "contact": { "caption": "first contact", - "postalAddress": "Vorname Nachname\\nStraße Hnr\\nPLZ Stadt", + "postalAddress": { + "country": "Germany" + }, "emailAddresses": { "main": "contact-admin@firstcontact.example.com" }, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java index 07723a1e..552f8664 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java @@ -55,8 +55,11 @@ class HsOfficeScenarioTests extends ScenarioTest { .given("tradeName", "Test AG") .given("contactCaption", "Test AG - Hamburg") .given("postalAddress", """ - Shanghai-Allee 1 - 20123 Hamburg + "firma": "Test AG", + "street": "Shanghai-Allee 1", + "zipcode": "20123", + "city": "Hamburg", + "country": "Germany" """) .given("officePhoneNumber", "+49 40 654321-0") .given("emailAddress", "hamburg@test-ag.example.org") @@ -75,8 +78,11 @@ class HsOfficeScenarioTests extends ScenarioTest { .given("familyName", "Matthieu") .given("contactCaption", "Michelle Matthieu") .given("postalAddress", """ - An der Wandse 34 - 22123 Hamburg + "name": "Michelle Matthieu", + "street": "An der Wandse 34", + "zipcode": "22123", + "city": "Hamburg", + "country": "Germany" """) .given("officePhoneNumber", "+49 40 123456") .given("emailAddress", "michelle.matthieu@example.org") @@ -94,8 +100,11 @@ class HsOfficeScenarioTests extends ScenarioTest { .given("representativeFamilyName", "Trust") .given("representativeGivenName", "Tracy") .given("representativePostalAddress", """ - An der Alster 100 - 20000 Hamburg + "name": "Michelle Matthieu", + "street": "An der Alster 100", + "zipcode": "20000", + "city": "Hamburg", + "country": "Germany" """) .given("representativePhoneNumber", "+49 40 123456") .given("representativeEMailAddress", "tracy.trust@example.org") @@ -172,12 +181,18 @@ class HsOfficeScenarioTests extends ScenarioTest { void shouldReplaceContactData() { new ReplaceContactData(this) .given("partnerName", "Test AG") - .given("newContactCaption", "Test AG - Norden") + .given("newContactCaption", "Test AG - China") .given("newPostalAddress", """ - Am Hafen 11 - 26506 Norden - """) - .given("newOfficePhoneNumber", "+49 4931 654321-0") + "firma": "Test AG", + "name": "Fi Zhong-Kha", + "building": "Thi Chi Koh Building", + "street": "No.2 Commercial Second Street", + "district": "Niushan Wei Wu", + "city": "Dongguan City", + "province": "Guangdong Province", + "country": "China" + """) + .given("newOfficePhoneNumber", "++15 999 654321" ) .given("newEmailAddress", "norden@test-ag.example.org") .doRun(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java index 8f45d83a..0c0e3021 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java @@ -27,7 +27,9 @@ public class AmendContactData extends UseCase { httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody(""" { "caption": ${newContactCaption???}, - "postalAddress": ${newPostalAddress???}, + "postalAddress": { + %{newPostalAddress???} + }, "phoneNumbers": { "office": ${newOfficePhoneNumber???} }, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java index b4916dda..ed992fca 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java @@ -27,7 +27,9 @@ public class ReplaceContactData extends UseCase { httpPost("/api/hs/office/contacts", usingJsonBody(""" { "caption": ${newContactCaption}, - "postalAddress": ${newPostalAddress???}, + "postalAddress": { + %{newPostalAddress???} + }, "phoneNumbers": { "phone": ${newOfficePhoneNumber???} }, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java index 1914cbb3..c5381684 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java @@ -42,7 +42,9 @@ public class AddRepresentativeToPartner extends UseCase { httpPost("/api/hs/office/contacts", usingJsonBody(""" { "caption": ${contactCaption}, - "postalAddress": ${postalAddress???}, + "postalAddress": { + %{postalAddress???} + }, "phoneNumbers": { "office": ${officePhoneNumber???} }, -- 2.39.5 From 162c8bdc3544c795c2c8301c7e0f3aefe8cc3b40 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 08:43:11 +0100 Subject: [PATCH 06/10] fix putPhoneNumbers->putPostalAddress --- .../hs/office/contact/HsOfficeContactPatcherUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java index b5a2545c..c5850da1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java @@ -98,7 +98,7 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< "postalAddress", HsOfficeContactPatchResource::setPostalAddress, PATCH_POSTAL_ADDRESS, - HsOfficeContactRbacEntity::putPhoneNumbers, + HsOfficeContactRbacEntity::putPostalAddress, PATCHED_POSTAL_ADDRESS) .notNullable(), new SimpleProperty<>( -- 2.39.5 From 11e9ecc95aefff5d1b02c3045c880ce42a5ff84d Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 08:56:29 +0100 Subject: [PATCH 07/10] firma->firm --- .../api-definition/hs-office/hs-office-contact-schemas.yaml | 2 +- .../hsadminng/hs/migration/BaseOfficeDataImport.java | 4 +++- .../hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml index a3067a69..9867921b 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml @@ -50,7 +50,7 @@ components: anyOf: - type: object properties: - firma: + firm: type: string nullable: true name: diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java index b8f5fbf5..70f21e11 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java @@ -1140,8 +1140,10 @@ public abstract class BaseOfficeDataImport extends CsvDataImport { rec.getString("last_name")); if (isNotBlank(name)) result.put("name", name); + if (isNotBlank(rec.getString("firma"))) + result.put("firm", name); - List.of("firma", "co", "street", "zipcode", "city", "country").forEach(key -> { + List.of("co", "street", "zipcode", "city", "country").forEach(key -> { if (isNotBlank(rec.getString(key))) result.put(key, rec.getString(key)); }); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java index 552f8664..0288ab9f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java @@ -55,7 +55,7 @@ class HsOfficeScenarioTests extends ScenarioTest { .given("tradeName", "Test AG") .given("contactCaption", "Test AG - Hamburg") .given("postalAddress", """ - "firma": "Test AG", + "firm": "Test AG", "street": "Shanghai-Allee 1", "zipcode": "20123", "city": "Hamburg", @@ -183,7 +183,7 @@ class HsOfficeScenarioTests extends ScenarioTest { .given("partnerName", "Test AG") .given("newContactCaption", "Test AG - China") .given("newPostalAddress", """ - "firma": "Test AG", + "firm": "Test AG", "name": "Fi Zhong-Kha", "building": "Thi Chi Koh Building", "street": "No.2 Commercial Second Street", -- 2.39.5 From 284b8e125e2899ddbf4b901eccee7dafb705f040 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 08:56:51 +0100 Subject: [PATCH 08/10] add comment about postalAddress sub-properties and compatibility --- .../scenarios/contact/ReplaceContactData.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java index ed992fca..f3e88269 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java @@ -39,16 +39,18 @@ public class ReplaceContactData extends UseCase { } """)) .expecting(CREATED).expecting(JSON), - "Please check first if that contact already exists, if so, use it's UUID below." - ); + "Please check first if that contact already exists, if so, use it's UUID below.", + "If any `postalAddress` sub-properties besides those specified in the API " + + "(currently `firm`, `name`, `co`, `street`, `zipcode`, `city`, `country`) " + + "its values might not appear in external systems."); withTitle("Replace the Contact-Reference in the Partner-Relation", () -> - httpPatch("/api/hs/office/relations/%{partnerRelationUuid}", usingJsonBody(""" - { - "contactUuid": ${Contact: %{newContactCaption}} - } - """)) - .expecting(OK) + httpPatch("/api/hs/office/relations/%{partnerRelationUuid}", usingJsonBody(""" + { + "contactUuid": ${Contact: %{newContactCaption}} + } + """)) + .expecting(OK) ); return null; -- 2.39.5 From f9fa8e506f481e3d9ff86eb8bbeefdb5b55921b0 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 09:10:09 +0100 Subject: [PATCH 09/10] fix patched postalAddress --- .../hs/office/contact/HsOfficeContactPatcherUnitTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java index c5850da1..e11a6a61 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java @@ -29,7 +29,6 @@ class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< private static final Map PATCHED_POSTAL_ADDRESS = patchMap( entry("name", "Patty Patch"), entry("street", "Patchstreet 10"), - entry("zipcode", "20000"), entry("city", "Hamburg") ); -- 2.39.5 From 71280d0379c643e0ad97f5dcdd329c8c42003cf3 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 12:10:59 +0100 Subject: [PATCH 10/10] additionalProperties: true --- .../api-definition/hs-office/hs-office-contact-schemas.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml index 9867921b..90d477dd 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-contact-schemas.yaml @@ -71,7 +71,7 @@ components: country: type: string nullable: true - additionalProperties: false + additionalProperties: true HsOfficeContactEmailAddresses: # forces generating a java.lang.Object containing a Map, instead of a class with fixed properties -- 2.39.5