From 1e0583bab2363bbd04d6ffdb07726f51073cf0bd Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 9 Apr 2024 08:31:02 +0200 Subject: [PATCH] add coop-assets-transaction reverse-entry to entity+table --- .../HsOfficeCoopAssetsTransactionEntity.java | 8 ++++++ .../5120-hs-office-coopassets.sql | 17 ++++++------ ...ceCoopAssetsTransactionEntityUnitTest.java | 26 +++++++++++++++++-- 3 files changed, 41 insertions(+), 10 deletions(-) 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 e5aaf789..8959c962 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 @@ -50,6 +50,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO .withProp(HsOfficeCoopAssetsTransactionEntity::getAssetValue) .withProp(HsOfficeCoopAssetsTransactionEntity::getReference) .withProp(HsOfficeCoopAssetsTransactionEntity::getComment) + .withProp(at -> ofNullable(at.getReverseEntry()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null)) .quotedValues(false); @Id @@ -93,6 +94,13 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO @Column(name = "comment") private String comment; + /** + * Optionally, the corresponding transaction for an adjustment transaction, + * linked in both directions. + */ + @OneToOne + @JoinColumn(name = "reverseentryuuid") + private HsOfficeCoopAssetsTransactionEntity reverseEntry; public String getTaggedMemberNumber() { return ofNullable(membership).map(HsOfficeMembershipEntity::toShortString).orElse("M-?????"); 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 2051c833..29ac74f8 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 @@ -17,14 +17,15 @@ 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, - assetValue money, - reference varchar(48), - comment varchar(512) + 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, + assetValue money not null, + reference varchar(48) not null, + reverseEntryUuid uuid references hs_office_coopassetstransaction (uuid), + comment varchar(512) ); --// diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java index 82ba35e3..c7a0690c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java @@ -16,14 +16,36 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest { .valueDate(LocalDate.parse("2020-01-01")) .transactionType(HsOfficeCoopAssetsTransactionType.DEPOSIT) .assetValue(new BigDecimal("128.00")) + .comment("some comment") .build(); + + + final HsOfficeCoopAssetsTransactionEntity givenCoopAssetAdjustmentTransaction = HsOfficeCoopAssetsTransactionEntity.builder() + .membership(TEST_MEMBERSHIP) + .reference("some-ref") + .valueDate(LocalDate.parse("2020-01-15")) + .transactionType(HsOfficeCoopAssetsTransactionType.ADJUSTMENT) + .assetValue(new BigDecimal("-128.00")) + .comment("some comment") + .reverseEntry(givenCoopAssetTransaction) + .build(); + final HsOfficeCoopAssetsTransactionEntity givenEmptyCoopAssetsTransaction = HsOfficeCoopAssetsTransactionEntity.builder().build(); @Test - void toStringContainsAlmostAllPropertiesAccount() { + void toStringContainsAllNonNullProperties() { final var result = givenCoopAssetTransaction.toString(); - assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref)"); + assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref, some comment)"); + } + + @Test + void toStringWithReverseEntryContainsReverseEntry() { + givenCoopAssetTransaction.setReverseEntry(givenCoopAssetAdjustmentTransaction); + + final var result = givenCoopAssetTransaction.toString(); + + assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref, some comment, M-1000101:-128.00)"); } @Test