add advanced scenario-tests for coop-assets #123
@ -99,7 +99,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE
|
||||
private String comment;
|
||||
|
||||
// Optionally, the UUID of the corresponding transaction for a reversal transaction.
|
||||
@OneToOne
|
||||
@OneToOne(cascade = CascadeType.PERSIST) // TODO.impl: can probably be removed after office data migration
|
||||
@JoinColumn(name = "revertedassettxuuid")
|
||||
private HsOfficeCoopAssetsTransactionEntity revertedAssetTx;
|
||||
|
||||
@ -108,7 +108,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE
|
||||
private HsOfficeCoopAssetsTransactionEntity assetReversalTx;
|
||||
|
||||
// Optionally, the UUID of the corresponding transaction for a transfer transaction.
|
||||
@OneToOne
|
||||
@OneToOne(cascade = CascadeType.PERSIST) // TODO.impl: can probably be removed after office data migration
|
||||
@JoinColumn(name = "assetadoptiontxuuid")
|
||||
private HsOfficeCoopAssetsTransactionEntity assetAdoptionAssetTx;
|
||||
|
||||
|
@ -436,7 +436,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
||||
1094=CoopAssetsTransaction(M-1000300: 2023-10-06, DEPOSIT, 3072, 1000300, Kapitalerhoehung - Ueberweisung),
|
||||
31000=CoopAssetsTransaction(M-1002000: 2000-12-06, DEPOSIT, 128.00, 1002000, for subscription B),
|
||||
32000=CoopAssetsTransaction(M-1000300: 2005-01-10, DEPOSIT, 2560.00, 1000300, for subscription C),
|
||||
33001=CoopAssetsTransaction(M-1000300: 2005-01-10, TRANSFER, -512.00, 1000300, for transfer to 10),
|
||||
33001=CoopAssetsTransaction(M-1000300: 2005-01-10, TRANSFER, -512.00, 1000300, for transfer to 10, M-1002000:ADO:+512.00),
|
||||
33002=CoopAssetsTransaction(M-1002000: 2005-01-10, ADOPTION, 512.00, 1002000, for transfer from 7),
|
||||
34001=CoopAssetsTransaction(M-1002000: 2016-12-31, CLEARING, -8.00, 1002000, for cancellation D),
|
||||
34002=CoopAssetsTransaction(M-1002000: 2016-12-31, DISBURSAL, -100.00, 1002000, for cancellation D),
|
||||
@ -864,21 +864,44 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
||||
.comment(rec.getString("comment"))
|
||||
.reference(member.getMemberNumber().toString())
|
||||
.build();
|
||||
|
||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.REVERSAL) {
|
||||
final var negativeValue = assetTransaction.getAssetValue().negate();
|
||||
final var reversalAssetTx = coopAssets.values().stream().filter(a ->
|
||||
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.REVERSAL &&
|
||||
a.getMembership() == assetTransaction.getMembership() &&
|
||||
a.getAssetValue().equals(negativeValue))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"cannot determine asset reverse entry for reversal " + assetTransaction));
|
||||
assetTransaction.setAssetReversalTx(reversalAssetTx);
|
||||
}
|
||||
|
||||
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
||||
});
|
||||
|
||||
coopAssets.values().forEach(assetTransaction -> {
|
||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.REVERSAL) {
|
||||
connectToRelatedRevertedAssetTx(assetTransaction);
|
||||
}
|
||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.TRANSFER) {
|
||||
connectToRelatedAdoptionAssetTx(assetTransaction);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void connectToRelatedRevertedAssetTx(final HsOfficeCoopAssetsTransactionEntity assetTransaction) {
|
||||
final var negativeValue = assetTransaction.getAssetValue().negate();
|
||||
final var revertedAssetTx = coopAssets.values().stream().filter(a ->
|
||||
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.REVERSAL &&
|
||||
a.getMembership() == assetTransaction.getMembership() &&
|
||||
a.getAssetValue().equals(negativeValue))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"cannot determine asset reverse entry for reversal " + assetTransaction));
|
||||
assetTransaction.setRevertedAssetTx(revertedAssetTx);
|
||||
//revertedAssetTx.setAssetReversalTx(assetTransaction);
|
||||
}
|
||||
|
||||
private static void connectToRelatedAdoptionAssetTx(final HsOfficeCoopAssetsTransactionEntity assetTransaction) {
|
||||
final var negativeValue = assetTransaction.getAssetValue().negate();
|
||||
final var adoptionAssetTx = coopAssets.values().stream().filter(a ->
|
||||
a.getTransactionType() == HsOfficeCoopAssetsTransactionType.ADOPTION &&
|
||||
a.getMembership() != assetTransaction.getMembership() &&
|
||||
a.getValueDate().equals(assetTransaction.getValueDate()) &&
|
||||
a.getAssetValue().equals(negativeValue))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"cannot determine asset adoption entry for reversal " + assetTransaction));
|
||||
assetTransaction.setAssetAdoptionAssetTx(adoptionAssetTx);
|
||||
//adoptionAssetTx.setAssetTransferTx(assetTransaction);
|
||||
}
|
||||
|
||||
private static HsOfficeMembershipEntity createOnDemandMembership(final Integer bpId) {
|
||||
|
@ -172,10 +172,14 @@ public class CsvDataImport extends ContextBasedTest {
|
||||
public <T extends BaseEntity> T persistViaEM(final Integer id, final T entity) {
|
||||
//System.out.println("persisting #" + entity.hashCode() + ": " + entity);
|
||||
em.persist(entity);
|
||||
// uncomment for debugging purposes
|
||||
// em.flush(); // makes it slow, but produces better error messages
|
||||
// System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid());
|
||||
return entity;
|
||||
// uncomment for debugging purposes FIXME
|
||||
try {
|
||||
em.flush(); // makes it slow, but produces better error messages
|
||||
System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid());
|
||||
return entity;
|
||||
} catch (final Exception exc) {
|
||||
throw exc; // for breakpoints
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
||||
import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@ -35,6 +36,9 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
@MockBean
|
||||
HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo;
|
||||
|
||||
@MockBean
|
||||
HsOfficeMembershipRepository membershipRepo;
|
||||
|
||||
static final String VALID_INSERT_REQUEST_BODY = """
|
||||
{
|
||||
"membership.uuid": "%s",
|
||||
|
Loading…
Reference in New Issue
Block a user