coop-assets-transaction-reverse-entry #37
@ -65,10 +65,6 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse
|
|||||||
validate(requestBody);
|
validate(requestBody);
|
||||||
|
|
||||||
final var entityToSave = mapper.map(requestBody, HsOfficeCoopAssetsTransactionEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER);
|
final var entityToSave = mapper.map(requestBody, HsOfficeCoopAssetsTransactionEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER);
|
||||||
|
|
||||||
if (entityToSave.getReverseEntry() != null) {
|
|
||||||
entityToSave.getReverseEntry().setReverseEntry(entityToSave);
|
|
||||||
}
|
|
||||||
final var saved = coopAssetsTransactionRepo.save(entityToSave);
|
final var saved = coopAssetsTransactionRepo.save(entityToSave);
|
||||||
|
|
||||||
final var uri =
|
final var uri =
|
||||||
@ -137,7 +133,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse
|
|||||||
|
|
||||||
final BiConsumer<HsOfficeCoopAssetsTransactionInsertResource, HsOfficeCoopAssetsTransactionEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
|
final BiConsumer<HsOfficeCoopAssetsTransactionInsertResource, HsOfficeCoopAssetsTransactionEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
|
||||||
if ( resource.getReverseEntryUuid() != null ) {
|
if ( resource.getReverseEntryUuid() != null ) {
|
||||||
entity.setReverseEntry(coopAssetsTransactionRepo.findByUuid(resource.getReverseEntryUuid())
|
entity.setAdjustedAssetTx(coopAssetsTransactionRepo.findByUuid(resource.getReverseEntryUuid())
|
||||||
.orElseThrow(() -> new EntityNotFoundException("ERROR: [400] reverseEntityUuid %s not found".formatted(resource.getReverseEntryUuid()))));
|
.orElseThrow(() -> new EntityNotFoundException("ERROR: [400] reverseEntityUuid %s not found".formatted(resource.getReverseEntryUuid()))));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -50,7 +50,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO
|
|||||||
.withProp(HsOfficeCoopAssetsTransactionEntity::getAssetValue)
|
.withProp(HsOfficeCoopAssetsTransactionEntity::getAssetValue)
|
||||||
.withProp(HsOfficeCoopAssetsTransactionEntity::getReference)
|
.withProp(HsOfficeCoopAssetsTransactionEntity::getReference)
|
||||||
.withProp(HsOfficeCoopAssetsTransactionEntity::getComment)
|
.withProp(HsOfficeCoopAssetsTransactionEntity::getComment)
|
||||||
.withProp(at -> ofNullable(at.getReverseEntry()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null))
|
.withProp(at -> ofNullable(at.getAdjustedAssetTx()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null))
|
||||||
.quotedValues(false);
|
.quotedValues(false);
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@ -95,12 +95,11 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO
|
|||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optionally, the UUID of the corresponding transaction for an adjustment transaction,
|
* Optionally, the UUID of the corresponding transaction for an adjustment transaction.
|
||||||
* linked in both directions.
|
|
||||||
*/
|
*/
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(name = "reverseentryuuid")
|
@JoinColumn(name = "adjustedassettxuuid")
|
||||||
private HsOfficeCoopAssetsTransactionEntity reverseEntry;
|
private HsOfficeCoopAssetsTransactionEntity adjustedAssetTx;
|
||||||
|
|
||||||
public String getTaggedMemberNumber() {
|
public String getTaggedMemberNumber() {
|
||||||
return ofNullable(membership).map(HsOfficeMembershipEntity::toShortString).orElse("M-?????");
|
return ofNullable(membership).map(HsOfficeMembershipEntity::toShortString).orElse("M-?????");
|
||||||
|
@ -32,10 +32,10 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
comment:
|
comment:
|
||||||
type: string
|
type: string
|
||||||
reverseEntry:
|
adjustedAssetTx:
|
||||||
$ref: '#/components/schemas/HsOfficeCoopAssetsTransactionReverse'
|
$ref: '#/components/schemas/HsOfficeAdjustedCoopAssetsTransaction'
|
||||||
|
|
||||||
HsOfficeCoopAssetsTransactionReverse:
|
HsOfficeAdjustedCoopAssetsTransaction:
|
||||||
description:
|
description:
|
||||||
Similar to `HsOfficeCoopAssetsTransaction` but without the `reverseEntry`,
|
Similar to `HsOfficeCoopAssetsTransaction` but without the `reverseEntry`,
|
||||||
otherwise the JSON would be recursive.
|
otherwise the JSON would be recursive.
|
||||||
|
@ -24,34 +24,20 @@ create table if not exists hs_office_coopassetstransaction
|
|||||||
valueDate date not null,
|
valueDate date not null,
|
||||||
assetValue money not null,
|
assetValue money not null,
|
||||||
reference varchar(48) not null,
|
reference varchar(48) not null,
|
||||||
reverseEntryUuid uuid references hs_office_coopassetstransaction (uuid) deferrable ,
|
adjustedAssetTxUuid uuid unique REFERENCES hs_office_coopassetstransaction(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||||
comment varchar(512)
|
comment varchar(512)
|
||||||
);
|
);
|
||||||
|
--//
|
||||||
|
|
||||||
|
|
||||||
|
-- ============================================================================
|
||||||
|
--changeset hs-office-coopassets-BUSINESS-RULES:1 endDelimiter:--//
|
||||||
|
-- ----------------------------------------------------------------------------
|
||||||
|
|
||||||
alter table hs_office_coopassetstransaction
|
alter table hs_office_coopassetstransaction
|
||||||
add constraint hs_office_coopassetstransaction_reverse_entry_missing
|
add constraint hs_office_coopassetstransaction_reverse_entry_missing
|
||||||
check ( transactionType != 'ADJUSTMENT' or reverseEntryUuid is not null);
|
check ( transactionType = 'ADJUSTMENT' and adjustedAssetTxUuid is not null
|
||||||
|
or transactionType <> 'ADJUSTMENT' and adjustedAssetTxUuid is null);
|
||||||
CREATE OR REPLACE FUNCTION hs_office_coopassetstransaction_reverse_entry_is_reciprocal_tf()
|
|
||||||
RETURNS TRIGGER
|
|
||||||
LANGUAGE plpgsql AS $$
|
|
||||||
BEGIN
|
|
||||||
IF NEW.reverseEntryUuid IS NULL
|
|
||||||
OR NEW.uuid IN (SELECT other.reverseEntryUuid
|
|
||||||
FROM hs_office_coopassetstransaction other
|
|
||||||
WHERE other.uuid = NEW.reverseEntryUuid
|
|
||||||
AND NEW.membershipUuid = other.membershipUuid)
|
|
||||||
THEN
|
|
||||||
RETURN NEW;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
RAISE EXCEPTION 'reverseEntryUuid must refer to a row that has a reference back to this row and belongs to the same membership';
|
|
||||||
END; $$;
|
|
||||||
|
|
||||||
-- FIXME: why does this not work?
|
|
||||||
-- CREATE TRIGGER hs_office_coopassetstransaction_reverse_entry_is_reciprocal_tg
|
|
||||||
-- AFTER INSERT OR UPDATE ON hs_office_coopassetstransaction
|
|
||||||
-- FOR EACH ROW EXECUTE FUNCTION hs_office_coopassetstransaction_reverse_entry_is_reciprocal_tf();
|
|
||||||
--//
|
--//
|
||||||
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
@ -66,9 +52,9 @@ declare
|
|||||||
totalAssetValue money;
|
totalAssetValue money;
|
||||||
begin
|
begin
|
||||||
select sum(cat.assetValue)
|
select sum(cat.assetValue)
|
||||||
from hs_office_coopassetstransaction cat
|
from hs_office_coopassetstransaction cat
|
||||||
where cat.membershipUuid = forMembershipUuid
|
where cat.membershipUuid = forMembershipUuid
|
||||||
into currentAssetValue;
|
into currentAssetValue;
|
||||||
totalAssetValue := currentAssetValue + newAssetValue;
|
totalAssetValue := currentAssetValue + newAssetValue;
|
||||||
if totalAssetValue::numeric < 0 then
|
if totalAssetValue::numeric < 0 then
|
||||||
raise exception '[400] coop assets transaction would result in a negative balance of assets';
|
raise exception '[400] coop assets transaction would result in a negative balance of assets';
|
||||||
@ -79,9 +65,9 @@ end; $$;
|
|||||||
alter table hs_office_coopassetstransaction
|
alter table hs_office_coopassetstransaction
|
||||||
add constraint hs_office_coopassets_positive
|
add constraint hs_office_coopassets_positive
|
||||||
check ( checkAssetsByMembershipUuid(membershipUuid, assetValue) );
|
check ( checkAssetsByMembershipUuid(membershipUuid, assetValue) );
|
||||||
|
|
||||||
--//
|
--//
|
||||||
|
|
||||||
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
--changeset hs-office-coopassets-MAIN-TABLE-JOURNAL:1 endDelimiter:--//
|
--changeset hs-office-coopassets-MAIN-TABLE-JOURNAL:1 endDelimiter:--//
|
||||||
-- ----------------------------------------------------------------------------
|
-- ----------------------------------------------------------------------------
|
||||||
|
@ -17,7 +17,6 @@ declare
|
|||||||
currentTask varchar;
|
currentTask varchar;
|
||||||
membership hs_office_membership;
|
membership hs_office_membership;
|
||||||
lossEntryUuid uuid;
|
lossEntryUuid uuid;
|
||||||
adjustmentEntryUuid uuid;
|
|
||||||
begin
|
begin
|
||||||
currentTask = 'creating coopAssetsTransaction test-data ' || givenPartnerNumber || givenMemberNumberSuffix;
|
currentTask = 'creating coopAssetsTransaction test-data ' || givenPartnerNumber || givenMemberNumberSuffix;
|
||||||
execute format('set local hsadminng.currentTask to %L', currentTask);
|
execute format('set local hsadminng.currentTask to %L', currentTask);
|
||||||
@ -33,14 +32,13 @@ begin
|
|||||||
|
|
||||||
raise notice 'creating test coopAssetsTransaction: %', givenPartnerNumber || givenMemberNumberSuffix;
|
raise notice 'creating test coopAssetsTransaction: %', givenPartnerNumber || givenMemberNumberSuffix;
|
||||||
lossEntryUuid := uuid_generate_v4();
|
lossEntryUuid := uuid_generate_v4();
|
||||||
adjustmentEntryUuid := uuid_generate_v4();
|
|
||||||
insert
|
insert
|
||||||
into hs_office_coopassetstransaction(uuid, membershipuuid, transactiontype, valuedate, assetvalue, reference, comment, reverseEntryUuid)
|
into hs_office_coopassetstransaction(uuid, membershipuuid, transactiontype, valuedate, assetvalue, reference, comment, adjustedAssetTxUuid)
|
||||||
values
|
values
|
||||||
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit', null),
|
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit', null),
|
||||||
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal', null),
|
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal', null),
|
||||||
(lossEntryUuid, membership.uuid, 'LOSS', '2022-10-20', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some loss', adjustmentEntryUuid),
|
(lossEntryUuid, membership.uuid, 'DEPOSIT', '2022-10-20', 128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some loss', null),
|
||||||
(adjustmentEntryUuid, membership.uuid, 'ADJUSTMENT', '2022-10-21', 128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some adjustment', lossEntryUuid);
|
(uuid_generate_v4(), membership.uuid, 'ADJUSTMENT', '2022-10-21', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some adjustment', lossEntryUuid);
|
||||||
end; $$;
|
end; $$;
|
||||||
--//
|
--//
|
||||||
|
|
||||||
|
@ -19,10 +19,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.PersistenceContext;
|
import jakarta.persistence.PersistenceContext;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.LOSS;
|
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.DEPOSIT;
|
||||||
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
|
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
|
||||||
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
|
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ -105,15 +106,15 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
|||||||
"comment": "partial disbursal"
|
"comment": "partial disbursal"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"transactionType": "LOSS",
|
"transactionType": "DEPOSIT",
|
||||||
"assetValue": -128.00,
|
"assetValue": 128.00,
|
||||||
"valueDate": "2022-10-20",
|
"valueDate": "2022-10-20",
|
||||||
"reference": "ref 1000202-3",
|
"reference": "ref 1000202-3",
|
||||||
"comment": "some loss"
|
"comment": "some loss"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"transactionType": "ADJUSTMENT",
|
"transactionType": "ADJUSTMENT",
|
||||||
"assetValue": 128.00,
|
"assetValue": -128.00,
|
||||||
"valueDate": "2022-10-21",
|
"valueDate": "2022-10-21",
|
||||||
"reference": "ref 1000202-3",
|
"reference": "ref 1000202-3",
|
||||||
"comment": "some adjustment"
|
"comment": "some adjustment"
|
||||||
@ -196,9 +197,9 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
|||||||
.extract().header("Location"); // @formatter:on
|
.extract().header("Location"); // @formatter:on
|
||||||
|
|
||||||
// finally, the new coopAssetsTransaction can be accessed under the generated UUID
|
// finally, the new coopAssetsTransaction can be accessed under the generated UUID
|
||||||
final var newUserUuid = UUID.fromString(
|
final var newAssetTxUuid = UUID.fromString(
|
||||||
location.substring(location.lastIndexOf('/') + 1));
|
location.substring(location.lastIndexOf('/') + 1));
|
||||||
assertThat(newUserUuid).isNotNull();
|
assertThat(newAssetTxUuid).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -206,10 +207,18 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
|||||||
|
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
|
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
|
||||||
final var givenTransaction = coopAssetsTransactionRepo.findCoopAssetsTransactionByOptionalMembershipUuidAndDateRange(givenMembership.getUuid(), null, null)
|
final var givenTransaction = jpaAttempt.transacted(() -> {
|
||||||
.stream().filter(at -> at.getTransactionType() == LOSS)
|
// TODO.impl: introduce something like transactedAsSuperuser / transactedAs("...", ...)
|
||||||
.findFirst()
|
context.define("superuser-alex@hostsharing.net");
|
||||||
.orElseThrow();
|
return coopAssetsTransactionRepo.save(HsOfficeCoopAssetsTransactionEntity.builder()
|
||||||
|
.transactionType(DEPOSIT)
|
||||||
|
.valueDate(LocalDate.of(2022, 10, 20))
|
||||||
|
.membership(givenMembership)
|
||||||
|
.assetValue(new BigDecimal("256.00"))
|
||||||
|
.reference("test ref")
|
||||||
|
.build());
|
||||||
|
}).assertSuccessful().assertNotNull().returnedValue();
|
||||||
|
toCleanup(HsOfficeCoopAssetsTransactionRawEntity.class, givenTransaction.getUuid());
|
||||||
|
|
||||||
final var location = RestAssured // @formatter:off
|
final var location = RestAssured // @formatter:off
|
||||||
.given()
|
.given()
|
||||||
@ -221,7 +230,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
|||||||
"transactionType": "ADJUSTMENT",
|
"transactionType": "ADJUSTMENT",
|
||||||
"assetValue": %s,
|
"assetValue": %s,
|
||||||
"valueDate": "2022-10-30",
|
"valueDate": "2022-10-30",
|
||||||
"reference": "temp ref A",
|
"reference": "test ref adjustment",
|
||||||
"comment": "some coop assets adjustment transaction",
|
"comment": "some coop assets adjustment transaction",
|
||||||
"reverseEntryUuid": "%s"
|
"reverseEntryUuid": "%s"
|
||||||
}
|
}
|
||||||
@ -239,16 +248,15 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
|||||||
.body("", lenientlyEquals("""
|
.body("", lenientlyEquals("""
|
||||||
{
|
{
|
||||||
"transactionType": "ADJUSTMENT",
|
"transactionType": "ADJUSTMENT",
|
||||||
"assetValue": 128.00,
|
"assetValue": -256.00,
|
||||||
"valueDate": "2022-10-30",
|
"valueDate": "2022-10-30",
|
||||||
"reference": "temp ref A",
|
"reference": "test ref adjustment",
|
||||||
"comment": "some coop assets adjustment transaction",
|
"comment": "some coop assets adjustment transaction",
|
||||||
"reverseEntry": {
|
"adjustedAssetTx": {
|
||||||
"transactionType": "LOSS",
|
"transactionType": "DEPOSIT",
|
||||||
"assetValue": -128.00,
|
"assetValue": 256.00,
|
||||||
"valueDate": "2022-10-20",
|
"valueDate": "2022-10-20",
|
||||||
"reference": "ref 1000101-3",
|
"reference": "test ref"
|
||||||
"comment": "some loss"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".formatted(givenTransaction.getUuid())))
|
""".formatted(givenTransaction.getUuid())))
|
||||||
@ -256,9 +264,10 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
|||||||
.extract().header("Location"); // @formatter:on
|
.extract().header("Location"); // @formatter:on
|
||||||
|
|
||||||
// finally, the new coopAssetsTransaction can be accessed under the generated UUID
|
// finally, the new coopAssetsTransaction can be accessed under the generated UUID
|
||||||
final var newUserUuid = UUID.fromString(
|
final var newAssetTxUuid = UUID.fromString(
|
||||||
location.substring(location.lastIndexOf('/') + 1));
|
location.substring(location.lastIndexOf('/') + 1));
|
||||||
assertThat(newUserUuid).isNotNull();
|
assertThat(newAssetTxUuid).isNotNull();
|
||||||
|
toCleanup(HsOfficeCoopAssetsTransactionRawEntity.class, newAssetTxUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -267,7 +276,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
|||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
|
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
|
||||||
|
|
||||||
final var location = RestAssured // @formatter:off
|
RestAssured // @formatter:off
|
||||||
.given()
|
.given()
|
||||||
.header("current-user", "superuser-alex@hostsharing.net")
|
.header("current-user", "superuser-alex@hostsharing.net")
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
|
@ -27,7 +27,7 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
|
|||||||
.transactionType(HsOfficeCoopAssetsTransactionType.ADJUSTMENT)
|
.transactionType(HsOfficeCoopAssetsTransactionType.ADJUSTMENT)
|
||||||
.assetValue(new BigDecimal("-128.00"))
|
.assetValue(new BigDecimal("-128.00"))
|
||||||
.comment("some comment")
|
.comment("some comment")
|
||||||
.reverseEntry(givenCoopAssetTransaction)
|
.adjustedAssetTx(givenCoopAssetTransaction)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final HsOfficeCoopAssetsTransactionEntity givenEmptyCoopAssetsTransaction = HsOfficeCoopAssetsTransactionEntity.builder().build();
|
final HsOfficeCoopAssetsTransactionEntity givenEmptyCoopAssetsTransaction = HsOfficeCoopAssetsTransactionEntity.builder().build();
|
||||||
@ -41,7 +41,7 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toStringWithReverseEntryContainsReverseEntry() {
|
void toStringWithReverseEntryContainsReverseEntry() {
|
||||||
givenCoopAssetTransaction.setReverseEntry(givenCoopAssetAdjustmentTransaction);
|
givenCoopAssetTransaction.setAdjustedAssetTx(givenCoopAssetAdjustmentTransaction);
|
||||||
|
|
||||||
final var result = givenCoopAssetTransaction.toString();
|
final var result = givenCoopAssetTransaction.toString();
|
||||||
|
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||||
|
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "hs_office_coopassetstransaction")
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class HsOfficeCoopAssetsTransactionRawEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private UUID uuid;
|
||||||
|
}
|
@ -142,18 +142,18 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
|
|||||||
result,
|
result,
|
||||||
"CoopAssetsTransaction(M-1000101: 2010-03-15, DEPOSIT, 320.00, ref 1000101-1, initial deposit)",
|
"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: 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)",
|
||||||
"CoopAssetsTransaction(M-1000101: 2022-10-20, LOSS, -128.00, ref 1000101-3, some loss, M-1000101:+128.00)",
|
"CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss)",
|
||||||
"CoopAssetsTransaction(M-1000101: 2022-10-21, ADJUSTMENT, 128.00, ref 1000101-3, some adjustment, 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: 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: 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)",
|
||||||
"CoopAssetsTransaction(M-1000202: 2022-10-20, LOSS, -128.00, ref 1000202-3, some loss, M-1000202:+128.00)",
|
"CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss)",
|
||||||
"CoopAssetsTransaction(M-1000202: 2022-10-21, ADJUSTMENT, 128.00, ref 1000202-3, some adjustment, 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: 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: 2021-09-01, DISBURSAL, -128.00, ref 1000303-2, partial disbursal)",
|
||||||
"CoopAssetsTransaction(M-1000303: 2022-10-20, LOSS, -128.00, ref 1000303-3, some loss, M-1000303:+128.00)",
|
"CoopAssetsTransaction(M-1000303: 2022-10-20, DEPOSIT, 128.00, ref 1000303-3, some loss)",
|
||||||
"CoopAssetsTransaction(M-1000303: 2022-10-21, ADJUSTMENT, 128.00, ref 1000303-3, some adjustment, M-1000303:-128.00)");
|
"CoopAssetsTransaction(M-1000303: 2022-10-21, ADJUSTMENT, -128.00, ref 1000303-3, some adjustment, M-1000303:+128.00)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -173,8 +173,8 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
|
|||||||
result,
|
result,
|
||||||
"CoopAssetsTransaction(M-1000202: 2010-03-15, DEPOSIT, 320.00, ref 1000202-1, initial deposit)",
|
"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: 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)",
|
||||||
"CoopAssetsTransaction(M-1000202: 2022-10-20, LOSS, -128.00, ref 1000202-3, some loss, M-1000202:+128.00)",
|
"CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss)",
|
||||||
"CoopAssetsTransaction(M-1000202: 2022-10-21, ADJUSTMENT, 128.00, ref 1000202-3, some adjustment, M-1000202:-128.00)");
|
"CoopAssetsTransaction(M-1000202: 2022-10-21, ADJUSTMENT, -128.00, ref 1000202-3, some adjustment, M-1000202:+128.00)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -211,8 +211,8 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
|
|||||||
result,
|
result,
|
||||||
"CoopAssetsTransaction(M-1000101: 2010-03-15, DEPOSIT, 320.00, ref 1000101-1, initial deposit)",
|
"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: 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)",
|
||||||
"CoopAssetsTransaction(M-1000101: 2022-10-20, LOSS, -128.00, ref 1000101-3, some loss, M-1000101:+128.00)",
|
"CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss)",
|
||||||
"CoopAssetsTransaction(M-1000101: 2022-10-21, ADJUSTMENT, 128.00, ref 1000101-3, some adjustment, M-1000101:-128.00)");
|
"CoopAssetsTransaction(M-1000101: 2022-10-21, ADJUSTMENT, -128.00, ref 1000101-3, some adjustment, M-1000101:+128.00)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ public class ImportOfficeData extends ContextBasedTest {
|
|||||||
34001=CoopAssetsTransaction(M-1002000: 2016-12-31, CLEARING, -8.00, legacy data import, for cancellation D),
|
34001=CoopAssetsTransaction(M-1002000: 2016-12-31, CLEARING, -8.00, legacy data import, for cancellation D),
|
||||||
34002=CoopAssetsTransaction(M-1002000: 2016-12-31, DISBURSAL, -100.00, legacy data import, for cancellation D),
|
34002=CoopAssetsTransaction(M-1002000: 2016-12-31, DISBURSAL, -100.00, legacy data import, for cancellation D),
|
||||||
34003=CoopAssetsTransaction(M-1002000: 2016-12-31, LOSS, -20.00, legacy data import, for cancellation D),
|
34003=CoopAssetsTransaction(M-1002000: 2016-12-31, LOSS, -20.00, legacy data import, for cancellation D),
|
||||||
35001=CoopAssetsTransaction(M-1909000: 2024-01-15, DEPOSIT, 128.00, legacy data import, for subscription E, M-1909000:-128.00),
|
35001=CoopAssetsTransaction(M-1909000: 2024-01-15, DEPOSIT, 128.00, legacy data import, for subscription E),
|
||||||
35002=CoopAssetsTransaction(M-1909000: 2024-01-20, ADJUSTMENT, -128.00, legacy data import, chargeback for subscription E, M-1909000:+128.00)
|
35002=CoopAssetsTransaction(M-1909000: 2024-01-20, ADJUSTMENT, -128.00, legacy data import, chargeback for subscription E, M-1909000:+128.00)
|
||||||
}
|
}
|
||||||
""");
|
""");
|
||||||
@ -854,14 +854,13 @@ public class ImportOfficeData extends ContextBasedTest {
|
|||||||
|
|
||||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.ADJUSTMENT) {
|
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.ADJUSTMENT) {
|
||||||
final var negativeValue = assetTransaction.getAssetValue().negate();
|
final var negativeValue = assetTransaction.getAssetValue().negate();
|
||||||
final var reverseEntry = coopAssets.values().stream().filter(a ->
|
final var adjustedAssetTx = coopAssets.values().stream().filter(a ->
|
||||||
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.ADJUSTMENT &&
|
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.ADJUSTMENT &&
|
||||||
a.getMembership() == assetTransaction.getMembership() &&
|
a.getMembership() == assetTransaction.getMembership() &&
|
||||||
a.getAssetValue().equals(negativeValue))
|
a.getAssetValue().equals(negativeValue))
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseThrow(() -> new IllegalStateException("cannot determine asset reverse entry for adjustment " + assetTransaction));
|
.orElseThrow(() -> new IllegalStateException("cannot determine asset reverse entry for adjustment " + assetTransaction));
|
||||||
reverseEntry.setReverseEntry(assetTransaction);
|
assetTransaction.setAdjustedAssetTx(adjustedAssetTx);
|
||||||
assetTransaction.setReverseEntry(reverseEntry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
||||||
|
@ -64,8 +64,10 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
|
|||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID toCleanup(final Class<? extends RbacObject> entityClass, final UUID uuidToCleanup) {
|
// TODO.test: back to `Class<? extends RbacObject> entityClass` but delete on raw table
|
||||||
out.println("toCleanup(" + entityClass.getSimpleName() + ", " + uuidToCleanup);
|
// remove HsOfficeCoopAssetsTransactionRawEntity, which is not needed anymore after this change
|
||||||
|
public UUID toCleanup(final Class entityClass, final UUID uuidToCleanup) {
|
||||||
|
out.println("toCleanup(" + entityClass.getSimpleName() + ", " + uuidToCleanup + ")");
|
||||||
entitiesToCleanup.put(uuidToCleanup, entityClass);
|
entitiesToCleanup.put(uuidToCleanup, entityClass);
|
||||||
return uuidToCleanup;
|
return uuidToCleanup;
|
||||||
}
|
}
|
||||||
@ -120,7 +122,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (initialRbacObjects != null){
|
if (initialRbacObjects != null){
|
||||||
assertNoNewRbackObjectsRolesAndGrantsLeaked();
|
assertNoNewRbacObjectsRolesAndGrantsLeaked();
|
||||||
}
|
}
|
||||||
|
|
||||||
initialTestDataValidated = false;
|
initialTestDataValidated = false;
|
||||||
@ -170,7 +172,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
|
|||||||
out.println(ContextBasedTestWithCleanup.class.getSimpleName() + ".cleanupAndCheckCleanup");
|
out.println(ContextBasedTestWithCleanup.class.getSimpleName() + ".cleanupAndCheckCleanup");
|
||||||
cleanupTemporaryTestData();
|
cleanupTemporaryTestData();
|
||||||
deleteLeakedRbacObjects();
|
deleteLeakedRbacObjects();
|
||||||
long rbacObjectCount = assertNoNewRbackObjectsRolesAndGrantsLeaked();
|
long rbacObjectCount = assertNoNewRbacObjectsRolesAndGrantsLeaked();
|
||||||
|
|
||||||
out.println("TOTAL OBJECT COUNT (after): " + rbacObjectCount);
|
out.println("TOTAL OBJECT COUNT (after): " + rbacObjectCount);
|
||||||
}
|
}
|
||||||
@ -180,7 +182,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
|
|||||||
final var caughtException = jpaAttempt.transacted(() -> {
|
final var caughtException = jpaAttempt.transacted(() -> {
|
||||||
context.define("superuser-alex@hostsharing.net", null);
|
context.define("superuser-alex@hostsharing.net", null);
|
||||||
em.remove(em.getReference(entityClass, uuid));
|
em.remove(em.getReference(entityClass, uuid));
|
||||||
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " successful");
|
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " generated");
|
||||||
}).caughtException();
|
}).caughtException();
|
||||||
if (caughtException != null) {
|
if (caughtException != null) {
|
||||||
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " failed: " + caughtException);
|
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " failed: " + caughtException);
|
||||||
@ -188,7 +190,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private long assertNoNewRbackObjectsRolesAndGrantsLeaked() {
|
private long assertNoNewRbacObjectsRolesAndGrantsLeaked() {
|
||||||
return jpaAttempt.transacted(() -> {
|
return jpaAttempt.transacted(() -> {
|
||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
assertEqual(initialRbacObjects, allRbacObjects());
|
assertEqual(initialRbacObjects, allRbacObjects());
|
||||||
|
@ -6,7 +6,7 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers
|
url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers
|
||||||
url-local: jdbc:postgresql://localhost:5432/postgres
|
url-local: jdbc:postgresql://localhost:5432/postgres
|
||||||
url: ${spring.datasource.url-local}
|
url: ${spring.datasource.url-tc}
|
||||||
username: postgres
|
username: postgres
|
||||||
password: password
|
password: password
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user