add SEPA-Mandate entity+repository

This commit is contained in:
Michael Hoennig 2022-10-13 18:53:38 +02:00
parent 7f5b2358d3
commit bece972a4e
8 changed files with 34 additions and 25 deletions

View File

@ -1,5 +1,7 @@
package net.hostsharing.hsadminng; package net.hostsharing.hsadminng;
import net.hostsharing.hsadminng.errors.DisplayName;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,7 +30,16 @@ public final class Stringify<B> {
private Stringify(final Class<B> clazz, final String name) { private Stringify(final Class<B> clazz, final String name) {
this.clazz = clazz; 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<B> withProp(final String propName, final Function<B, ?> getter) { public Stringify<B> withProp(final String propName, final Function<B, ?> getter) {
@ -53,7 +64,7 @@ public final class Stringify<B> {
}) })
.map(propVal -> propName(propVal, "=") + optionallyQuoted(propVal)) .map(propVal -> propName(propVal, "=") + optionallyQuoted(propVal))
.collect(Collectors.joining(separator)); .collect(Collectors.joining(separator));
return (name != null ? name : object.getClass().getSimpleName()) + "(" + propValues + ")"; return name + "(" + propValues + ")";
} }
public Stringify<B> withSeparator(final String separator) { public Stringify<B> withSeparator(final String separator) {

View File

@ -7,6 +7,7 @@ import net.hostsharing.hsadminng.Stringifyable;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.*; import javax.persistence.*;
import java.util.UUID; import java.util.UUID;

View File

@ -9,7 +9,7 @@ create table if not exists hs_office_sepamandate
uuid uuid unique references RbacObject (uuid) initially deferred, uuid uuid unique references RbacObject (uuid) initially deferred,
debitorUuid uuid not null references hs_office_debitor(uuid), debitorUuid uuid not null references hs_office_debitor(uuid),
bankAccountUuid uuid not null references hs_office_bankaccount(uuid), bankAccountUuid uuid not null references hs_office_bankaccount(uuid),
reference varchar(96), reference varchar(96) not null,
validity daterange not null validity daterange not null
); );
--// --//

View File

@ -1,21 +1,21 @@
--liquibase formatted sql --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 if TG_OP = 'INSERT' then
-- === ATTENTION: code generated from related Mermaid flowchart: === -- === ATTENTION: code generated from related Mermaid flowchart: ===
perform createRoleWithGrants( perform createRoleWithGrants(
hsOfficeSepaMandateOwner(NEW), hsOfficeSepaMandateOwner(NEW),
permissions => array['*'], permissions => array['*'],
@ -73,7 +71,6 @@ begin
-- === END of code generated from Mermaid flowchart. === -- === END of code generated from Mermaid flowchart. ===
else else
raise exception 'invalid usage of TRIGGER'; raise exception 'invalid usage of TRIGGER';
end if; end if;
@ -86,23 +83,23 @@ end; $$;
*/ */
create trigger createRbacRolesForHsOfficeSepaMandate_Trigger create trigger createRbacRolesForHsOfficeSepaMandate_Trigger
after insert after insert
on hs_office_sepaMandate on hs_office_sepamandate
for each row for each row
execute procedure hsOfficeSepaMandateRbacRolesTrigger(); 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', orderby => 'target.reference',
columnUpdates => $updates$ columnUpdates => $updates$
validity = new.validity 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. 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. 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 before insert
on hs_office_sepaMandate on hs_office_sepamandate
for each row for each row
-- TODO.spec: who is allowed to create new sepaMandates -- TODO.spec: who is allowed to create new sepaMandates
when ( not hasAssumedRole() ) when ( not hasAssumedRole() )

View File

@ -31,7 +31,7 @@ begin
raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor; raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor;
raise notice '- using bankAccount (%): %', relatedBankAccount.uuid, relatedBankAccount; raise notice '- using bankAccount (%): %', relatedBankAccount.uuid, relatedBankAccount;
insert 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', '[]')); values (uuid_generate_v4(), relatedDebitor.uuid, relatedBankAccount.uuid, 'ref'||idName, daterange('20221001' , '20261231', '[]'));
end; $$; end; $$;
--// --//

View File

@ -77,7 +77,7 @@ public class ArchitectureTest {
public static final ArchRule HsOfficeBankAccountPackageRule = classes() public static final ArchRule HsOfficeBankAccountPackageRule = classes()
.that().resideInAPackage("..hs.office.bankaccount..") .that().resideInAPackage("..hs.office.bankaccount..")
.should().onlyBeAccessed().byClassesThat() .should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.office.bankaccount..", "..hs.office.debitor.."); .resideInAnyPackage("..hs.office.bankaccount..", "..hs.office.sepamandate..", "..hs.office.debitor..");
@ArchTest @ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -86,7 +86,6 @@ public class ArchitectureTest {
.should().onlyBeAccessed().byClassesThat() .should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.office.partner..", "..hs.office.debitor.."); .resideInAnyPackage("..hs.office.partner..", "..hs.office.debitor..");
@ArchTest @ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule acceptsAnnotationOnMethodsRule = methods() public static final ArchRule acceptsAnnotationOnMethodsRule = methods()

View File

@ -9,7 +9,7 @@ import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGA
public class TestHsOfficePartner { 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) { static public HsOfficePartnerEntity HsOfficePartnerWithLegalPerson(final String tradeName) {
return HsOfficePartnerEntity.builder() return HsOfficePartnerEntity.builder()

View File

@ -30,6 +30,7 @@ spring:
logging: logging:
level: level:
liquibase: INFO liquibase: INFO
org.hibernate.SQL: DEBUG X.org.hibernate.SQL: DEBUG
org.hibernate.type.descriptor.sql.BasicBinder: TRACE X.org.hibernate.type.descriptor.sql.BasicBinder: TRACE
X.org.springframework.jdbc.core: TRACE X.org.springframework.jdbc.core: TRACE
net.ttddyy.dsproxy.listener: debug