From ec1deb890360085f2c540bc1acfed7375e29404c Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Mon, 8 Apr 2024 11:21:22 +0200 Subject: [PATCH] add @Version property to all RBAC-Entities (#34) Co-authored-by: Michael Hoennig Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/34 Reviewed-by: Marc Sandlus --- doc/ideas/rbac-schema-f.md | 3 ++- .../bankaccount/HsOfficeBankAccountEntity.java | 8 ++++---- .../hs/office/contact/HsOfficeContactEntity.java | 5 +++++ .../HsOfficeCoopAssetsTransactionEntity.java | 13 ++++--------- .../HsOfficeCoopSharesTransactionEntity.java | 13 ++++--------- .../hs/office/debitor/HsOfficeDebitorEntity.java | 3 +++ .../office/membership/HsOfficeMembershipEntity.java | 3 +++ .../partner/HsOfficePartnerDetailsEntity.java | 1 + .../hs/office/partner/HsOfficePartnerEntity.java | 11 ++++------- .../hs/office/person/HsOfficePersonEntity.java | 3 +++ .../hs/office/relation/HsOfficeRelationEntity.java | 3 +++ .../sepamandate/HsOfficeSepaMandateEntity.java | 3 +++ .../hsadminng/rbac/rbacdef/RbacView.java | 3 +-- .../hsadminng/rbac/rbacobject/RbacObject.java | 2 ++ .../hsadminng/test/cust/TestCustomerEntity.java | 3 +++ .../2-test/201-test-customer/2010-test-customer.sql | 1 + .../501-contact/5010-hs-office-contact.sql | 1 + .../502-person/5020-hs-office-person.sql | 1 + .../503-relation/5030-hs-office-relation.sql | 1 + .../504-partner/5040-hs-office-partner.sql | 4 +++- .../505-bankaccount/5050-hs-office-bankaccount.sql | 1 + .../506-debitor/5060-hs-office-debitor.sql | 1 + .../507-sepamandate/5070-hs-office-sepamandate.sql | 1 + .../510-membership/5100-hs-office-membership.sql | 1 + .../511-coopshares/5110-hs-office-coopshares.sql | 1 + .../512-coopassets/5120-hs-office-coopassets.sql | 1 + .../HsOfficeRelationRepositoryIntegrationTest.java | 4 +++- .../hsadminng/test/cust/TestCustomer.java | 2 +- .../cust/TestCustomerRepositoryIntegrationTest.java | 6 +++--- 29 files changed, 65 insertions(+), 38 deletions(-) diff --git a/doc/ideas/rbac-schema-f.md b/doc/ideas/rbac-schema-f.md index f1731d4f..c71e7a9b 100644 --- a/doc/ideas/rbac-schema-f.md +++ b/doc/ideas/rbac-schema-f.md @@ -6,7 +6,8 @@ Permissions, Rollen und Grants werden in den INSERT/UPDATE/DELETE-Triggern von G Das folgende Schema soll dabei unterstützen, die richtigen Permissions, Rollen und Grants festzulegen. -An einigen Stellen ist vom *Initiator* die Rede. Als *Initiator* gilt derjenige User, der die Operation (INSERT oder UPDATE) durchführt bzw. dessen primary assumed Rol. (TODO: bisher gibt es nur assumed roles, das Konzept einer primary assumed Role müsste noch eingeführt werden, derzeit nehmen wir dafür immer den `globalAdmin()`. Bevor Kunden aber selbst Objekte anlegen können, muss das geklärt sein.) +An einigen Stellen ist vom *Initiator* die Rede. Als *Initiator* gilt derjenige User, der die Operation (INSERT oder UPDATE) durchführt bzw. eine explizit anzugebende Rolle des Users. +Wird keine solche explizite Rolle angegeben, gilt die granted Rolle als diejenige, als der das Grant erfolgt. #### Typ Root: Objekte, welche nur eine Spezialisierung bzw. Zusatzdaten für andere Objekte bereitstellen (z.B. Partner für Relations vom Typ Partner oder Partner Details für Partner) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java index 6542084e..679e87a2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java @@ -8,10 +8,7 @@ import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import java.io.IOException; import java.util.UUID; @@ -41,6 +38,9 @@ public class HsOfficeBankAccountEntity implements RbacObject, Stringifyable { @GeneratedValue private UUID uuid; + @Version + private int version; + private String holder; private String iban; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java index 1ce3a557..e09d0044 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java @@ -40,6 +40,11 @@ public class HsOfficeContactEntity implements Stringifyable, RbacObject { @GeneratedValue(generator = "UUID") @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") private UUID uuid; + + @Version + private int version; + + @Column(name = "label") private String label; @Column(name = "postaladdress") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java index 49de8f08..e5aaf789 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java @@ -14,15 +14,7 @@ import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; import org.hibernate.annotations.GenericGenerator; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import java.io.IOException; import java.math.BigDecimal; import java.time.LocalDate; @@ -65,6 +57,9 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") private UUID uuid; + @Version + private int version; + @ManyToOne @JoinColumn(name = "membershipuuid") private HsOfficeMembershipEntity membership; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java index 8ab19435..9578cc8f 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java @@ -13,15 +13,7 @@ import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import java.io.IOException; import java.time.LocalDate; import java.util.UUID; @@ -61,6 +53,9 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, RbacO @GeneratedValue private UUID uuid; + @Version + private int version; + @ManyToOne @JoinColumn(name = "membershipuuid") private HsOfficeMembershipEntity membership; 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 509cb165..7a2cb1ec 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 @@ -71,6 +71,9 @@ public class HsOfficeDebitorEntity implements RbacObject, Stringifyable { @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") private UUID uuid; + @Version + private int version; + @ManyToOne @JoinFormula( referencedColumnName = "uuid", 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 26c5706a..6c76c5c8 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 @@ -57,6 +57,9 @@ public class HsOfficeMembershipEntity implements RbacObject, Stringifyable { @GeneratedValue private UUID uuid; + @Version + private int version; + @ManyToOne @JoinColumn(name = "partneruuid") private HsOfficePartnerEntity partner; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java index 6fae8dc0..49ba01c0 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java @@ -43,6 +43,7 @@ public class HsOfficePartnerDetailsEntity implements RbacObject, Stringifyable { @GeneratedValue private UUID uuid; + private @Version int version; private @Column(name = "registrationoffice") String registrationOffice; private @Column(name = "registrationnumber") String registrationNumber; private @Column(name = "birthname") String birthName; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java index 6b019f62..30d45bf7 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java @@ -17,13 +17,7 @@ import net.hostsharing.hsadminng.stringify.Stringifyable; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import java.io.IOException; import java.util.UUID; @@ -66,6 +60,9 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject { @GeneratedValue private UUID uuid; + @Version + private int version; + @Column(name = "partnernumber", columnDefinition = "numeric(5) not null") private Integer partnerNumber; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java index 673d1fc5..f0a45963 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java @@ -44,6 +44,9 @@ public class HsOfficePersonEntity implements RbacObject, Stringifyable { @GeneratedValue private UUID uuid; + @Version + private int version; + @Column(name = "persontype") private HsOfficePersonType personType; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java index 1dbed5cc..c8c41db0 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java @@ -52,6 +52,9 @@ public class HsOfficeRelationEntity implements RbacObject, Stringifyable { @GeneratedValue private UUID uuid; + @Version + private int version; + @ManyToOne @JoinColumn(name = "anchoruuid") private HsOfficePersonEntity anchor; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java index ac831295..a4344abe 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java @@ -50,6 +50,9 @@ public class HsOfficeSepaMandateEntity implements Stringifyable, RbacObject { @GeneratedValue private UUID uuid; + @Version + private int version; + @ManyToOne @JoinColumn(name = "debitoruuid") private HsOfficeDebitorEntity debitor; diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/RbacView.java b/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/RbacView.java index d052b958..96843da0 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/RbacView.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/RbacView.java @@ -426,8 +426,7 @@ public class RbacView { private void verifyVersionColumnExists() { if (stream(rootEntityAlias.entityClass.getDeclaredFields()) .noneMatch(f -> f.getAnnotation(Version.class) != null)) { - // TODO: convert this into throw Exception once RbacEntity is a base class with @Version field - System.err.println("@Version field required in updatable entity " + rootEntityAlias.entityClass); + throw new IllegalArgumentException("@Version field required in updatable entity " + rootEntityAlias.entityClass); } } diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/RbacObject.java b/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/RbacObject.java index 4d7646d1..80927b61 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/RbacObject.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/RbacObject.java @@ -5,4 +5,6 @@ import java.util.UUID; public interface RbacObject { UUID getUuid(); + + int getVersion(); } diff --git a/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerEntity.java b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerEntity.java index 19340440..b962ee79 100644 --- a/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerEntity.java @@ -30,6 +30,9 @@ public class TestCustomerEntity implements RbacObject { @GeneratedValue private UUID uuid; + @Version + private int version; + private String prefix; private int reference; diff --git a/src/main/resources/db/changelog/2-test/201-test-customer/2010-test-customer.sql b/src/main/resources/db/changelog/2-test/201-test-customer/2010-test-customer.sql index 7eb539f7..559ba51a 100644 --- a/src/main/resources/db/changelog/2-test/201-test-customer/2010-test-customer.sql +++ b/src/main/resources/db/changelog/2-test/201-test-customer/2010-test-customer.sql @@ -7,6 +7,7 @@ create table if not exists test_customer ( uuid uuid unique references RbacObject (uuid), + version int not null default 0, reference int not null unique check (reference between 10000 and 99999), prefix character(3) unique, adminUserName varchar(63) diff --git a/src/main/resources/db/changelog/5-hs-office/501-contact/5010-hs-office-contact.sql b/src/main/resources/db/changelog/5-hs-office/501-contact/5010-hs-office-contact.sql index 9b67db1b..d6428651 100644 --- a/src/main/resources/db/changelog/5-hs-office/501-contact/5010-hs-office-contact.sql +++ b/src/main/resources/db/changelog/5-hs-office/501-contact/5010-hs-office-contact.sql @@ -7,6 +7,7 @@ create table if not exists hs_office_contact ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, label varchar(128) not null, postalAddress text, emailAddresses text, -- TODO.feat: change to json diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql index 1b51278b..528b512c 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql @@ -17,6 +17,7 @@ CREATE CAST (character varying as HsOfficePersonType) WITH INOUT AS IMPLICIT; create table if not exists hs_office_person ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, personType HsOfficePersonType not null, tradeName varchar(96), salutation varchar(30), diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql index 8e6e56a1..1c207177 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql @@ -19,6 +19,7 @@ CREATE CAST (character varying as HsOfficeRelationType) WITH INOUT AS IMPLICIT; create table if not exists hs_office_relation ( uuid uuid unique references RbacObject (uuid) initially deferred, -- on delete cascade + version int not null default 0, anchorUuid uuid not null references hs_office_person(uuid), holderUuid uuid not null references hs_office_person(uuid), contactUuid uuid references hs_office_contact(uuid), diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql index d02ed017..a8a88adc 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql @@ -8,6 +8,7 @@ create table hs_office_partner_details ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, registrationOffice varchar(96), registrationNumber varchar(96), birthPlace varchar(96), @@ -32,8 +33,9 @@ call create_journal('hs_office_partner_details'); create table hs_office_partner ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, partnerNumber numeric(5) unique not null, - partnerRelUuid uuid not null references hs_office_relation(uuid), -- deleted in after delete trigger + partnerRelUuid uuid not null references hs_office_relation(uuid), -- deleted in after delete trigger detailsUuid uuid not null references hs_office_partner_details(uuid) -- deleted in after delete trigger ); --// diff --git a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5050-hs-office-bankaccount.sql b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5050-hs-office-bankaccount.sql index 427b0199..e061a3ca 100644 --- a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5050-hs-office-bankaccount.sql +++ b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5050-hs-office-bankaccount.sql @@ -6,6 +6,7 @@ create table hs_office_bankaccount ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, holder varchar(64) not null, iban varchar(34) not null, bic varchar(11) not null diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql index 59ad01e0..39db61e2 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql @@ -7,6 +7,7 @@ create table hs_office_debitor ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, debitorNumberSuffix char(2) not null check (debitorNumberSuffix::text ~ '^[0-9][0-9]$'), debitorRelUuid uuid not null references hs_office_relation(uuid), billable boolean not null default true, diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5070-hs-office-sepamandate.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5070-hs-office-sepamandate.sql index fa60716f..841f429f 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5070-hs-office-sepamandate.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5070-hs-office-sepamandate.sql @@ -7,6 +7,7 @@ create table if not exists hs_office_sepamandate ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, debitorUuid uuid not null references hs_office_debitor(uuid), bankAccountUuid uuid not null references hs_office_bankaccount(uuid), reference varchar(96) not null, diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql index 28ec1249..7abc8699 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql @@ -11,6 +11,7 @@ CREATE CAST (character varying as HsOfficeReasonForTermination) WITH INOUT AS IM create table if not exists hs_office_membership ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, partnerUuid uuid not null references hs_office_partner(uuid), memberNumberSuffix char(2) not null check (memberNumberSuffix::text ~ '^[0-9][0-9]$'), validity daterange not null, diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql index 4ba70ecc..5cef4aea 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql @@ -11,6 +11,7 @@ CREATE CAST (character varying as HsOfficeCoopSharesTransactionType) WITH INOUT create table if not exists hs_office_coopsharestransaction ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, membershipUuid uuid not null references hs_office_membership(uuid), transactionType HsOfficeCoopSharesTransactionType not null, valueDate date not null, diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql index 9a712f3a..2051c833 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql @@ -18,6 +18,7 @@ CREATE CAST (character varying as HsOfficeCoopAssetsTransactionType) WITH INOUT create table if not exists hs_office_coopassetstransaction ( uuid uuid unique references RbacObject (uuid) initially deferred, + version int not null default 0, membershipUuid uuid not null references hs_office_membership(uuid), transactionType HsOfficeCoopAssetsTransactionType not null, valueDate date not null, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java index 77342f0d..cb37536c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java @@ -295,7 +295,9 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea private void assertThatRelationActuallyInDatabase(final HsOfficeRelationEntity saved) { final var found = relationRepo.findByUuid(saved.getUuid()); - assertThat(found).isNotEmpty().get().isNotSameAs(saved).usingRecursiveComparison().isEqualTo(saved); + assertThat(found).isNotEmpty().get() + .isNotSameAs(saved) + .usingRecursiveComparison().ignoringFields("version").isEqualTo(saved); } private void assertThatRelationIsVisibleForUserWithRole( diff --git a/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java index bb00975f..7316ccb1 100644 --- a/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java +++ b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java @@ -7,6 +7,6 @@ public class TestCustomer { static final TestCustomerEntity yyy = hsCustomer("yyy", 10002, "yyy@example.com"); static public TestCustomerEntity hsCustomer(final String prefix, final int reference, final String adminName) { - return new TestCustomerEntity(null, prefix, reference, adminName); + return new TestCustomerEntity(null, 0, prefix, reference, adminName); } } diff --git a/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepositoryIntegrationTest.java index 591ce0eb..b90628a8 100644 --- a/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepositoryIntegrationTest.java @@ -40,7 +40,7 @@ class TestCustomerRepositoryIntegrationTest extends ContextBasedTest { // when final var result = attempt(em, () -> { final var newCustomer = new TestCustomerEntity( - UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); + UUID.randomUUID(), 0, "www", 90001, "customer-admin@www.example.com"); return testCustomerRepository.save(newCustomer); }); @@ -59,7 +59,7 @@ class TestCustomerRepositoryIntegrationTest extends ContextBasedTest { // when final var result = attempt(em, () -> { final var newCustomer = new TestCustomerEntity( - UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); + UUID.randomUUID(), 0, "www", 90001, "customer-admin@www.example.com"); return testCustomerRepository.save(newCustomer); }); @@ -77,7 +77,7 @@ class TestCustomerRepositoryIntegrationTest extends ContextBasedTest { // when final var result = attempt(em, () -> { final var newCustomer = new TestCustomerEntity( - UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); + UUID.randomUUID(), 0, "www", 90001, "customer-admin@www.example.com"); return testCustomerRepository.save(newCustomer); });