From cf4718c9f4346f4962497d95d4254e3308a09d78 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 11 Apr 2024 07:41:20 +0200 Subject: [PATCH] add reverse mapping for assetsharestx-adjustment --- .../HsOfficeCoopAssetsTransactionEntity.java | 4 ++++ .../hs-office-coopassets-schemas.yaml | 10 ++++++---- ...etsTransactionControllerAcceptanceTest.java | 18 ++++++++++++++++-- ...tsTransactionRepositoryIntegrationTest.java | 10 +++++----- 4 files changed, 31 insertions(+), 11 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 223852b5..0975e14d 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 @@ -51,6 +51,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO .withProp(HsOfficeCoopAssetsTransactionEntity::getReference) .withProp(HsOfficeCoopAssetsTransactionEntity::getComment) .withProp(at -> ofNullable(at.getAdjustedAssetTx()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null)) + .withProp(at -> ofNullable(at.getAdjustmentAssetTx()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null)) .quotedValues(false); @Id @@ -101,6 +102,9 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO @JoinColumn(name = "adjustedassettxuuid") private HsOfficeCoopAssetsTransactionEntity adjustedAssetTx; + @OneToOne(mappedBy = "adjustedAssetTx") + private HsOfficeCoopAssetsTransactionEntity adjustmentAssetTx; + public String getTaggedMemberNumber() { return ofNullable(membership).map(HsOfficeMembershipEntity::toShortString).orElse("M-?????"); } diff --git a/src/main/resources/api-definition/hs-office/hs-office-coopassets-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-coopassets-schemas.yaml index 8f31e062..0c937767 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-coopassets-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-coopassets-schemas.yaml @@ -33,12 +33,14 @@ components: comment: type: string adjustedAssetTx: - $ref: '#/components/schemas/HsOfficeAdjustedCoopAssetsTransaction' + $ref: '#/components/schemas/HsOfficeReferencedCoopAssetsTransaction' + adjustmentAssetTx: + $ref: '#/components/schemas/HsOfficeReferencedCoopAssetsTransaction' - HsOfficeAdjustedCoopAssetsTransaction: + HsOfficeReferencedCoopAssetsTransaction: description: - Similar to `HsOfficeCoopAssetsTransaction` but without the `reverseEntry`, - otherwise the JSON would be recursive. + Similar to `HsOfficeCoopAssetsTransaction` but without the self-referencing properties + (`adjustedAssetTx` and `adjustmentAssetTx`), to avoid recursive JSON. type: object properties: uuid: diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java index 1d9bebbe..7e484b33 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java @@ -110,14 +110,28 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased "assetValue": 128.00, "valueDate": "2022-10-20", "reference": "ref 1000202-3", - "comment": "some loss" + "comment": "some loss", + "adjustmentAssetTx": { + "transactionType": "ADJUSTMENT", + "assetValue": -128.00, + "valueDate": "2022-10-21", + "reference": "ref 1000202-3", + "comment": "some adjustment" + } }, { "transactionType": "ADJUSTMENT", "assetValue": -128.00, "valueDate": "2022-10-21", "reference": "ref 1000202-3", - "comment": "some adjustment" + "comment": "some adjustment", + "adjustedAssetTx": { + "transactionType": "DEPOSIT", + "assetValue": 128.00, + "valueDate": "2022-10-20", + "reference": "ref 1000202-3", + "comment": "some loss" + } } ] """)); // @formatter:on diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java index 44adc58b..ae5b33c2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java @@ -142,17 +142,17 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase result, "CoopAssetsTransaction(M-1000101: 2010-03-15, DEPOSIT, 320.00, ref 1000101-1, initial deposit)", "CoopAssetsTransaction(M-1000101: 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)", - "CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss)", + "CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss, M-1000101:-128.00)", "CoopAssetsTransaction(M-1000101: 2022-10-21, ADJUSTMENT, -128.00, ref 1000101-3, some adjustment, M-1000101:+128.00)", "CoopAssetsTransaction(M-1000202: 2010-03-15, DEPOSIT, 320.00, ref 1000202-1, initial deposit)", "CoopAssetsTransaction(M-1000202: 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)", - "CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss)", + "CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss, M-1000202:-128.00)", "CoopAssetsTransaction(M-1000202: 2022-10-21, ADJUSTMENT, -128.00, ref 1000202-3, some adjustment, M-1000202:+128.00)", "CoopAssetsTransaction(M-1000303: 2010-03-15, DEPOSIT, 320.00, ref 1000303-1, initial deposit)", "CoopAssetsTransaction(M-1000303: 2021-09-01, DISBURSAL, -128.00, ref 1000303-2, partial disbursal)", - "CoopAssetsTransaction(M-1000303: 2022-10-20, DEPOSIT, 128.00, ref 1000303-3, some loss)", + "CoopAssetsTransaction(M-1000303: 2022-10-20, DEPOSIT, 128.00, ref 1000303-3, some loss, M-1000303:-128.00)", "CoopAssetsTransaction(M-1000303: 2022-10-21, ADJUSTMENT, -128.00, ref 1000303-3, some adjustment, M-1000303:+128.00)"); } @@ -173,7 +173,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase result, "CoopAssetsTransaction(M-1000202: 2010-03-15, DEPOSIT, 320.00, ref 1000202-1, initial deposit)", "CoopAssetsTransaction(M-1000202: 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)", - "CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss)", + "CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss, M-1000202:-128.00)", "CoopAssetsTransaction(M-1000202: 2022-10-21, ADJUSTMENT, -128.00, ref 1000202-3, some adjustment, M-1000202:+128.00)"); } @@ -211,7 +211,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase result, "CoopAssetsTransaction(M-1000101: 2010-03-15, DEPOSIT, 320.00, ref 1000101-1, initial deposit)", "CoopAssetsTransaction(M-1000101: 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)", - "CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss)", + "CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss, M-1000101:-128.00)", "CoopAssetsTransaction(M-1000101: 2022-10-21, ADJUSTMENT, -128.00, ref 1000101-3, some adjustment, M-1000101:+128.00)"); } }