From bece972a4e50a039786803a79a5078527b6d595e Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 13 Oct 2022 18:53:38 +0200 Subject: [PATCH] add SEPA-Mandate entity+repository --- .../net/hostsharing/hsadminng/Stringify.java | 15 ++++++++-- .../office/debitor/HsOfficeDebitorEntity.java | 1 + .../changelog/250-hs-office-sepamandate.sql | 2 +- .../253-hs-office-sepamandate-rbac.sql | 29 +++++++++---------- .../258-hs-office-sepamandate-test-data.sql | 2 +- .../hsadminng/arch/ArchitectureTest.java | 3 +- .../office/partner/TestHsOfficePartner.java | 2 +- src/test/resources/application.yml | 5 ++-- 8 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/Stringify.java b/src/main/java/net/hostsharing/hsadminng/Stringify.java index 7cde6757..4a665b1e 100644 --- a/src/main/java/net/hostsharing/hsadminng/Stringify.java +++ b/src/main/java/net/hostsharing/hsadminng/Stringify.java @@ -1,5 +1,7 @@ package net.hostsharing.hsadminng; +import net.hostsharing.hsadminng.errors.DisplayName; + import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.List; @@ -28,7 +30,16 @@ public final class Stringify { private Stringify(final Class clazz, final String name) { this.clazz = clazz; - this.name = name; + if (name != null) { + this.name = name; + } else { + final var displayName = clazz.getAnnotation(DisplayName.class); + if (displayName != null) { + this.name = displayName.value(); + } else { + this.name = clazz.getSimpleName(); + } + } } public Stringify withProp(final String propName, final Function getter) { @@ -53,7 +64,7 @@ public final class Stringify { }) .map(propVal -> propName(propVal, "=") + optionallyQuoted(propVal)) .collect(Collectors.joining(separator)); - return (name != null ? name : object.getClass().getSimpleName()) + "(" + propValues + ")"; + return name + "(" + propValues + ")"; } public Stringify withSeparator(final String separator) { 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 6c0cbe5f..5887b65f 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 @@ -7,6 +7,7 @@ import net.hostsharing.hsadminng.Stringifyable; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; +import org.apache.commons.lang3.StringUtils; import javax.persistence.*; import java.util.UUID; diff --git a/src/main/resources/db/changelog/250-hs-office-sepamandate.sql b/src/main/resources/db/changelog/250-hs-office-sepamandate.sql index 144d0357..b87b872e 100644 --- a/src/main/resources/db/changelog/250-hs-office-sepamandate.sql +++ b/src/main/resources/db/changelog/250-hs-office-sepamandate.sql @@ -9,7 +9,7 @@ create table if not exists hs_office_sepamandate uuid uuid unique references RbacObject (uuid) initially deferred, debitorUuid uuid not null references hs_office_debitor(uuid), bankAccountUuid uuid not null references hs_office_bankaccount(uuid), - reference varchar(96), + reference varchar(96) not null, validity daterange not null ); --// diff --git a/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql b/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql index 56bbff58..85569e6e 100644 --- a/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql +++ b/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql @@ -1,21 +1,21 @@ --liquibase formatted sql -- ============================================================================ ---changeset hs-office-sepaMandate-rbac-OBJECT:1 endDelimiter:--// +--changeset hs-office-sepamandate-rbac-OBJECT:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -call generateRelatedRbacObject('hs_office_sepaMandate'); +call generateRelatedRbacObject('hs_office_sepamandate'); --// -- ============================================================================ ---changeset hs-office-sepaMandate-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--// +--changeset hs-office-sepamandate-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -call generateRbacRoleDescriptors('hsOfficeSepaMandate', 'hs_office_sepaMandate'); +call generateRbacRoleDescriptors('hsOfficeSepaMandate', 'hs_office_sepamandate'); --// -- ============================================================================ ---changeset hs-office-sepaMandate-rbac-ROLES-CREATION:1 endDelimiter:--// +--changeset hs-office-sepamandate-rbac-ROLES-CREATION:1 endDelimiter:--// -- ---------------------------------------------------------------------------- /* @@ -36,10 +36,8 @@ begin if TG_OP = 'INSERT' then - -- === ATTENTION: code generated from related Mermaid flowchart: === - perform createRoleWithGrants( hsOfficeSepaMandateOwner(NEW), permissions => array['*'], @@ -73,7 +71,6 @@ begin -- === END of code generated from Mermaid flowchart. === - else raise exception 'invalid usage of TRIGGER'; end if; @@ -86,23 +83,23 @@ end; $$; */ create trigger createRbacRolesForHsOfficeSepaMandate_Trigger after insert - on hs_office_sepaMandate + on hs_office_sepamandate for each row execute procedure hsOfficeSepaMandateRbacRolesTrigger(); --// -- ============================================================================ ---changeset hs-office-sepaMandate-rbac-IDENTITY-VIEW:1 endDelimiter:--// +--changeset hs-office-sepamandate-rbac-IDENTITY-VIEW:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -call generateRbacIdentityView('hs_office_sepaMandate', idNameExpression => 'target.reference'); +call generateRbacIdentityView('hs_office_sepamandate', idNameExpression => 'target.reference'); --// -- ============================================================================ ---changeset hs-office-sepaMandate-rbac-RESTRICTED-VIEW:1 endDelimiter:--// +--changeset hs-office-sepamandate-rbac-RESTRICTED-VIEW:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -call generateRbacRestrictedView('hs_office_sepaMandate', +call generateRbacRestrictedView('hs_office_sepamandate', orderby => 'target.reference', columnUpdates => $updates$ validity = new.validity @@ -111,7 +108,7 @@ call generateRbacRestrictedView('hs_office_sepaMandate', -- ============================================================================ ---changeset hs-office-sepaMandate-rbac-NEW-SepaMandate:1 endDelimiter:--// +--changeset hs-office-sepamandate-rbac-NEW-SepaMandate:1 endDelimiter:--// -- ---------------------------------------------------------------------------- /* Creates a global permission for new-sepaMandate and assigns it to the hostsharing admins role. @@ -146,9 +143,9 @@ end; $$; /** Checks if the user or assumed roles are allowed to create a new customer. */ -create trigger hs_office_sepaMandate_insert_trigger +create trigger hs_office_sepamandate_insert_trigger before insert - on hs_office_sepaMandate + on hs_office_sepamandate for each row -- TODO.spec: who is allowed to create new sepaMandates when ( not hasAssumedRole() ) diff --git a/src/main/resources/db/changelog/258-hs-office-sepamandate-test-data.sql b/src/main/resources/db/changelog/258-hs-office-sepamandate-test-data.sql index 7af102a4..d96bfcb5 100644 --- a/src/main/resources/db/changelog/258-hs-office-sepamandate-test-data.sql +++ b/src/main/resources/db/changelog/258-hs-office-sepamandate-test-data.sql @@ -31,7 +31,7 @@ begin raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor; raise notice '- using bankAccount (%): %', relatedBankAccount.uuid, relatedBankAccount; insert - into hs_office_sepaMandate (uuid, debitoruuid, bankAccountuuid, reference, validity) + into hs_office_sepamandate (uuid, debitoruuid, bankAccountuuid, reference, validity) values (uuid_generate_v4(), relatedDebitor.uuid, relatedBankAccount.uuid, 'ref'||idName, daterange('20221001' , '20261231', '[]')); end; $$; --// diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java index b32c41a9..2563ee17 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java @@ -77,7 +77,7 @@ public class ArchitectureTest { public static final ArchRule HsOfficeBankAccountPackageRule = classes() .that().resideInAPackage("..hs.office.bankaccount..") .should().onlyBeAccessed().byClassesThat() - .resideInAnyPackage("..hs.office.bankaccount..", "..hs.office.debitor.."); + .resideInAnyPackage("..hs.office.bankaccount..", "..hs.office.sepamandate..", "..hs.office.debitor.."); @ArchTest @SuppressWarnings("unused") @@ -86,7 +86,6 @@ public class ArchitectureTest { .should().onlyBeAccessed().byClassesThat() .resideInAnyPackage("..hs.office.partner..", "..hs.office.debitor.."); - @ArchTest @SuppressWarnings("unused") public static final ArchRule acceptsAnnotationOnMethodsRule = methods() diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java index 386e3a1c..96f5a5d4 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java @@ -9,7 +9,7 @@ import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGA public class TestHsOfficePartner { - public static final HsOfficePartnerEntity testLtd = HsOfficePartnerWithLegalPerson("Test Ltd."); + public static final HsOfficePartnerEntity testPartner = HsOfficePartnerWithLegalPerson("Test Ltd."); static public HsOfficePartnerEntity HsOfficePartnerWithLegalPerson(final String tradeName) { return HsOfficePartnerEntity.builder() diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index c6e28a1a..a80fa23a 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -30,6 +30,7 @@ spring: logging: level: liquibase: INFO - org.hibernate.SQL: DEBUG - org.hibernate.type.descriptor.sql.BasicBinder: TRACE + X.org.hibernate.SQL: DEBUG + X.org.hibernate.type.descriptor.sql.BasicBinder: TRACE X.org.springframework.jdbc.core: TRACE + net.ttddyy.dsproxy.listener: debug