From 4f22dffe5d15bcaede3c7aca058eb10cc5db927a Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 14 Oct 2022 12:37:59 +0200 Subject: [PATCH] use "YYYY-MM-DD" format when writing LocalDate to JSON --- build.gradle | 1 + .../config/JsonObjectMapperConfiguration.java | 4 +++- .../228-hs-office-partner-test-data.sql | 22 ++++++++++++++----- ...OfficePartnerControllerAcceptanceTest.java | 5 +++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index aa293631..ea4367b7 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,7 @@ dependencies { implementation 'org.springdoc:springdoc-openapi-ui:1.6.11' implementation 'org.liquibase:liquibase-core' implementation 'com.vladmihalcea:hibernate-types-55:2.19.2' + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.4' implementation 'org.openapitools:jackson-databind-nullable:0.2.3' implementation 'org.modelmapper:modelmapper:3.1.0' implementation 'org.iban4j:iban4j:3.2.3-RELEASE' diff --git a/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java b/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java index 087b76f2..8c6cb2b3 100644 --- a/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java +++ b/src/main/java/net/hostsharing/hsadminng/config/JsonObjectMapperConfiguration.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.config; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.openapitools.jackson.nullable.JsonNullableModule; import org.springframework.context.annotation.Bean; @@ -14,6 +15,7 @@ public class JsonObjectMapperConfiguration { @Primary public Jackson2ObjectMapperBuilder customObjectMapper() { return new Jackson2ObjectMapperBuilder() - .modules(new JsonNullableModule(), new JavaTimeModule()); + .modules(new JsonNullableModule(), new JavaTimeModule()) + .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); } } diff --git a/src/main/resources/db/changelog/228-hs-office-partner-test-data.sql b/src/main/resources/db/changelog/228-hs-office-partner-test-data.sql index 7e4f5505..45928bfd 100644 --- a/src/main/resources/db/changelog/228-hs-office-partner-test-data.sql +++ b/src/main/resources/db/changelog/228-hs-office-partner-test-data.sql @@ -8,28 +8,37 @@ /* Creates a single partner test record. */ -create or replace procedure createHsOfficePartnerTestData( personTradeName varchar, contactLabel varchar ) +create or replace procedure createHsOfficePartnerTestData( personTradeOrFamilyName varchar, contactLabel varchar ) language plpgsql as $$ declare currentTask varchar; idName varchar; relatedPerson hs_office_person; relatedContact hs_office_contact; + birthday date; begin - idName := cleanIdentifier( personTradeName|| '-' || contactLabel); + idName := cleanIdentifier( personTradeOrFamilyName|| '-' || contactLabel); 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); - select p.* from hs_office_person p where p.tradeName = personTradeName into relatedPerson; - select c.* from hs_office_contact c where c.label = contactLabel into relatedContact; + select p.* from hs_office_person p + where p.tradeName = personTradeOrFamilyName or p.familyName = personTradeOrFamilyName + into relatedPerson; + select c.* from hs_office_contact c + where c.label = contactLabel + into relatedContact; + + if relatedPerson.persontype = 'NATURAL' then + birthday := '1987-10-31'::date; + end if; raise notice 'creating test partner: %', idName; raise notice '- using person (%): %', relatedPerson.uuid, relatedPerson; raise notice '- using contact (%): %', relatedContact.uuid, relatedContact; insert - into hs_office_partner (uuid, personuuid, contactuuid) - values (uuid_generate_v4(), relatedPerson.uuid, relatedContact.uuid); + into hs_office_partner (uuid, personuuid, contactuuid, birthday) + values (uuid_generate_v4(), relatedPerson.uuid, relatedContact.uuid, birthDay); end; $$; --// @@ -67,6 +76,7 @@ do language plpgsql $$ call createHsOfficePartnerTestData('Second e.K.', 'second contact'); call createHsOfficePartnerTestData('Third OHG', 'third contact'); call createHsOfficePartnerTestData('Fourth e.G.', 'forth contact'); + call createHsOfficePartnerTestData('Smith', 'fifth contact'); end; $$; --// diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java index d494b960..e0fe31a1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java @@ -76,6 +76,11 @@ class HsOfficePartnerControllerAcceptanceTest { .contentType("application/json") .body("", lenientlyEquals(""" [ + { + "person": { "familyName": "Smith" }, + "contact": { "label": "fifth contact" }, + "birthday": "1987-10-31" + }, { "person": { "tradeName": "First GmbH" }, "contact": { "label": "first contact" }