From a27ac13fad4da1f200dbb50b3e04be819e9dcacd Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 25 Jul 2024 11:15:13 +0200 Subject: [PATCH] amendmends after code-review --- .../office/debitor/HsOfficeDebitorEntity.java | 8 +- .../membership/HsOfficeMembershipEntity.java | 3 +- .../partner/HsOfficePartnerRepository.java | 9 -- .../090-log-slow-queries-extensions.sql | 2 +- .../db/changelog/1-rbac/1050-rbac-base.sql | 1 - .../7010-hs-hosting-asset.sql | 2 - ...OfficeDebitorControllerAcceptanceTest.java | 101 +++++++++++++++++- ...fficeDebitorRepositoryIntegrationTest.java | 1 - src/test/resources/application.yml | 11 +- 9 files changed, 113 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java index 75fa9b6d..a9e0ca98 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java @@ -21,6 +21,7 @@ import org.hibernate.annotations.NotFoundAction; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -77,7 +78,7 @@ public class HsOfficeDebitorEntity implements RbacObject, @Version private int version; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinFormula( referencedColumnName = "uuid", value = """ @@ -98,7 +99,7 @@ public class HsOfficeDebitorEntity implements RbacObject, @Pattern(regexp = TWO_DECIMAL_DIGITS) private String debitorNumberSuffix; - @ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = false) + @ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "debitorreluuid", nullable = false) private HsOfficeRelationEntity debitorRel; @@ -117,7 +118,7 @@ public class HsOfficeDebitorEntity implements RbacObject, @Column(name = "vatreversecharge") private boolean vatReverseCharge; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "refundbankaccountuuid") private HsOfficeBankAccountEntity refundBankAccount; @@ -127,6 +128,7 @@ public class HsOfficeDebitorEntity implements RbacObject, @Override public HsOfficeDebitorEntity load() { RbacObject.super.load(); + partner.load(); debitorRel.load(); if (refundBankAccount != null) { refundBankAccount.load(); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java index fe55f653..20dac5c7 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java @@ -21,6 +21,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -80,7 +81,7 @@ public class HsOfficeMembershipEntity implements RbacObject findPartnerByOptionalNameLike(String name); HsOfficePartnerEntity findPartnerByPartnerNumber(Integer partnerNumber); - @Query(""" - SELECT DISTINCT partner - FROM HsOfficePartnerEntity partner - JOIN HsOfficeRelationEntity pRel - ON pRel.uuid = partner.partnerRel.uuid AND pRel.type = 'PARTNER' - WHERE pRel.holder.uuid = :partnerPersonUuid - """) - HsOfficePartnerEntity findPartnerByPartnerPersonUuid(UUID partnerPersonUuid); - HsOfficePartnerEntity save(final HsOfficePartnerEntity entity); long count(); diff --git a/src/main/resources/db/changelog/0-basis/090-log-slow-queries-extensions.sql b/src/main/resources/db/changelog/0-basis/090-log-slow-queries-extensions.sql index dd8aa74f..953004db 100644 --- a/src/main/resources/db/changelog/0-basis/090-log-slow-queries-extensions.sql +++ b/src/main/resources/db/changelog/0-basis/090-log-slow-queries-extensions.sql @@ -3,7 +3,7 @@ -- ============================================================================ -- PG-STAT-STATEMENTS-EXTENSION ---changeset pg-stat-statements-extension:1 runOnChange=true endDelimiter:--// +--changeset pg-stat-statements-extension:1 context:pg_stat_statements endDelimiter:--// -- ---------------------------------------------------------------------------- /* Makes improved uuid generation available. diff --git a/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql b/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql index 86a4527d..6199abcd 100644 --- a/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql +++ b/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql @@ -750,7 +750,6 @@ begin end if; end; $$; -ALTER FUNCTION queryAccessibleObjectUuidsOfSubjectIds SET enable_hashjoin = off; --// -- ============================================================================ diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql index c1c127f0..3b1b54d1 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql @@ -44,8 +44,6 @@ create table if not exists hs_hosting_asset constraint chk_hs_hosting_asset_has_booking_item_or_parent_asset check (bookingItemUuid is not null or parentAssetUuid is not null or type in ('DOMAIN_SETUP', 'IPV4_NUMBER', 'IPV6_NUMBER')) ); --- create index on hs_hosting_asset (identifier); --- create index on hs_hosting_asset (type); --// 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 ef8b4598..737809b7 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 @@ -113,6 +113,38 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu }, "debitorNumber": 1000111, "debitorNumberSuffix": 11, + "partner": { + "partnerNumber": 10001, + "partnerRel": { + "anchor": { + "personType": "LEGAL_PERSON", + "tradeName": "Hostsharing eG", + "givenName": null, + "familyName": null + }, + "holder": { + "personType": "LEGAL_PERSON", + "tradeName": "First GmbH", + "givenName": null, + "familyName": null + }, + "type": "PARTNER", + "mark": null, + "contact": { + "caption": "first contact", + "emailAddresses": { "main": "contact-admin@firstcontact.example.com" }, + "phoneNumbers": { "phone_office": "+49 123 1234567" } + } + }, + "details": { + "registrationOffice": "Hamburg", + "registrationNumber": "RegNo123456789", + "birthName": null, + "birthPlace": null, + "birthday": null, + "dateOfDeath": null + } + }, "billable": true, "vatId": null, "vatCountryCode": null, @@ -136,6 +168,21 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu }, "debitorNumber": 1000212, "debitorNumberSuffix": 12, + "partner": { + "partnerNumber": 10002, + "partnerRel": { + "anchor": {"tradeName": "Hostsharing eG"}, + "holder": {"tradeName": "Second e.K."}, + "type": "PARTNER", + "contact": { + "emailAddresses": { "main": "contact-admin@secondcontact.example.com" } + } + }, + "details": { + "registrationOffice": "Hamburg", + "registrationNumber": "RegNo123456789" + } + }, "billable": true, "vatId": null, "vatCountryCode": null, @@ -155,6 +202,21 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu }, "debitorNumber": 1000313, "debitorNumberSuffix": 13, + "partner": { + "partnerNumber": 10003, + "partnerRel": { + "anchor": {"tradeName": "Hostsharing eG"}, + "holder": {"tradeName": "Third OHG"}, + "type": "PARTNER", + "contact": { + "emailAddresses": { "main": "contact-admin@thirdcontact.example.com" } + } + }, + "details": { + "registrationOffice": "Hamburg", + "registrationNumber": "RegNo123456789" + } + }, "billable": true, "vatId": null, "vatCountryCode": null, @@ -295,6 +357,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body("uuid", isUuidValid()) .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)) .body("vatBusiness", equalTo(false)) @@ -408,6 +471,25 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu }, "debitorNumber": 1000111, "debitorNumberSuffix": 11, + "partner": { + "partnerNumber": 10001, + "partnerRel": { + "anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG"}, + "holder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"}, + "type": "PARTNER", + "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" } + } + }, + "details": { + "registrationOffice": "Hamburg", + "registrationNumber": "RegNo123456789" + } + }, "billable": true, "vatBusiness": true, "vatReverseCharge": false, @@ -501,6 +583,24 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu }, "debitorNumber": 10004${debitorNumberSuffix}, "debitorNumberSuffix": ${debitorNumberSuffix}, + "partner": { + "partnerNumber": 10004, + "partnerRel": { + "anchor": { "tradeName": "Hostsharing eG" }, + "holder": { "tradeName": "Fourth eG" }, + "type": "PARTNER", + "mark": null, + "contact": { "caption": "fourth contact" } + }, + "details": { + "registrationOffice": "Hamburg", + "registrationNumber": "RegNo123456789", + "birthName": null, + "birthPlace": null, + "birthday": null, + "dateOfDeath": null + } + }, "billable": true, "vatId": "VAT222222", "vatCountryCode": "AA", @@ -623,7 +723,6 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var newDebitor = HsOfficeDebitorEntity.builder() - .partner(givenPartner) .debitorNumberSuffix(nextDebitorSuffix()) .billable(true) .debitorRel( diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java index d9c9f72c..f3986f4f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java @@ -613,7 +613,6 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var givenBankAccount = bankAccountHolder != null ? one(bankAccountRepo.findByOptionalHolderLike(bankAccountHolder)) : null; final var newDebitor = HsOfficeDebitorEntity.builder() - .partner(givenPartner) .debitorNumberSuffix("20") .debitorRel(HsOfficeRelationEntity.builder() .type(HsOfficeRelationType.DEBITOR) diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 293e6f72..7ae587f3 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -26,10 +26,9 @@ spring: liquibase: change-log: classpath:/db/changelog/db.changelog-master.yaml - contexts: tc,test,dev + contexts: tc,test,dev,pg_stat_statements -# FIXME: re-activate? -#logging: -# level: -# liquibase: INFO -# net.ttddyy.dsproxy.listener: DEBUG +logging: + level: + liquibase: INFO + net.ttddyy.dsproxy.listener: DEBUG