import coop assets
This commit is contained in:
parent
1833d98b67
commit
412ed6fdc4
@ -8,6 +8,7 @@ import net.hostsharing.hsadminng.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType;
|
||||
import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionType;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
@ -38,12 +39,11 @@ import jakarta.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
|
||||
@ -65,15 +65,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class ImportOfficeTables extends ContextBasedTest {
|
||||
|
||||
private static Map<Integer, HsOfficeContactEntity> contacts = new HashMap<>();
|
||||
private static Map<Integer, HsOfficePersonEntity> persons = new HashMap<>();
|
||||
private static Map<Integer, HsOfficePartnerEntity> partners = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeDebitorEntity> debitors = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeMembershipEntity> memberships = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeSepaMandateEntity> sepaMandates = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeBankAccountEntity> bankAccounts = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeCoopSharesTransactionEntity> coopShares = new HashMap<>();
|
||||
private static Map<Integer, HsOfficeCoopAssetsTransactionEntity> assetTransactions = new HashMap<>();
|
||||
private static NavigableMap<Integer, HsOfficeContactEntity> contacts = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficePersonEntity> persons = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficePartnerEntity> partners = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficeDebitorEntity> debitors = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficeMembershipEntity> memberships = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficeSepaMandateEntity> sepaMandates = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficeBankAccountEntity> bankAccounts = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficeCoopSharesTransactionEntity> coopShares = new TreeMap<>();
|
||||
private static NavigableMap<Integer, HsOfficeCoopAssetsTransactionEntity> coopAssets = new TreeMap<>();
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
@ -142,9 +142,9 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
""");
|
||||
assertThat(contacts.toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
71=contact(label='Herr Michael Mellies ', emailAddresses='mih@example.org'),
|
||||
101=contact(label='Frau Dr. Jenny Meyer , JM e.K.', emailAddresses='jm@example.org'),
|
||||
102=contact(label='Herr Andrew Meyer , JM e.K.', emailAddresses='am@example.org'),
|
||||
71=contact(label='Herr Michael Mellies ', emailAddresses='mih@example.org'),
|
||||
121=contact(label='Paule Schmidt , Test PS', emailAddresses='ps@example.com')
|
||||
}
|
||||
""");
|
||||
@ -209,10 +209,37 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
|
||||
assertThat(coopShares.toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
33810=CoopShareTransaction(10010, 2016-12-31, CANCELLATION, 22, membership ended),
|
||||
33443=CoopShareTransaction(10007, 2000-12-06, SUBSCRIPTION, 20, initial share subscription),
|
||||
33451=CoopShareTransaction(10010, 2000-12-06, SUBSCRIPTION, 2, initial share subscription),
|
||||
33701=CoopShareTransaction(10007, 2005-01-10, SUBSCRIPTION, 40, increase),
|
||||
33451=CoopShareTransaction(10010, 2000-12-06, SUBSCRIPTION, 2, initial share subscription)
|
||||
33810=CoopShareTransaction(10010, 2016-12-31, CANCELLATION, 22, membership ended)
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void importCoopAssets() {
|
||||
|
||||
try (Reader reader = resourceReader("migration/asset-transactions.csv")) {
|
||||
final var lines = readAllLines(reader);
|
||||
importCoopAssets(justHeader(lines), withoutHeader(lines));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
assertThat(coopAssets.toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
30000=CoopAssetsTransaction(10007, 2000-12-06, DEPOSIT, 1280.00, for subscription A),
|
||||
31001=CoopAssetsTransaction(10010, 2000-12-06, DEPOSIT, 18.00, for subscription B),
|
||||
31002=CoopAssetsTransaction(10010, 2000-12-06, -18.00, for subscription B),
|
||||
31003=CoopAssetsTransaction(10010, 2000-12-06, DEPOSIT, 128.00, for subscription B),
|
||||
32000=CoopAssetsTransaction(10007, 2005-01-10, DEPOSIT, 2560.00, for subscription C),
|
||||
33001=CoopAssetsTransaction(10007, 2005-01-10, -512.00, for transfer to 10),
|
||||
33002=CoopAssetsTransaction(10010, 2005-01-10, ADOPTION, 512.00, for transfer from 7),
|
||||
34001=CoopAssetsTransaction(10010, 2016-12-31, CLEARING, -8.00, for cancellation D),
|
||||
34002=CoopAssetsTransaction(10010, 2016-12-31, DISBURSAL, -100.00, for cancellation D),
|
||||
34003=CoopAssetsTransaction(10010, 2016-12-31, LOSS, -20.00, for cancellation D)
|
||||
}
|
||||
""");
|
||||
}
|
||||
@ -355,6 +382,38 @@ public class ImportOfficeTables extends ContextBasedTest {
|
||||
});
|
||||
}
|
||||
|
||||
private void importCoopAssets(final String[] header, final List<String[]> records) {
|
||||
|
||||
final var columns = new Columns(header);
|
||||
|
||||
records.stream()
|
||||
.map(this::trimAll)
|
||||
.map(row -> new Record(columns, row))
|
||||
.forEach(rec -> {
|
||||
final var member = memberships.get(rec.getInteger("bp_id"));
|
||||
|
||||
final var assetTypeMapping = new HashMap<String, HsOfficeCoopAssetsTransactionType>() {{
|
||||
put("HANDOVER", HsOfficeCoopAssetsTransactionType.TRANSFER);
|
||||
put("ADOPTION", HsOfficeCoopAssetsTransactionType.ADOPTION);
|
||||
put("LOSS", HsOfficeCoopAssetsTransactionType.LOSS);
|
||||
put("CLEARING", HsOfficeCoopAssetsTransactionType.CLEARING);
|
||||
put("PRESCRIPTION", HsOfficeCoopAssetsTransactionType.LIMITATION);
|
||||
put("PAYBACK", HsOfficeCoopAssetsTransactionType.DISBURSAL);
|
||||
put("PAYMENT", HsOfficeCoopAssetsTransactionType.DEPOSIT);
|
||||
}};
|
||||
|
||||
final var assetTransaction = HsOfficeCoopAssetsTransactionEntity.builder()
|
||||
.membership(member)
|
||||
.valueDate(rec.getLocalDate("date"))
|
||||
.transactionType(assetTypeMapping.get(rec.getString("action")))
|
||||
.assetValue(rec.getBigDecimal("amount"))
|
||||
.reference(rec.getString("comment"))
|
||||
.build();
|
||||
|
||||
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
||||
});
|
||||
}
|
||||
|
||||
private void importSepaMandates(final String[] header, final List<String[]> records) {
|
||||
|
||||
final var columns = new Columns(header);
|
||||
@ -549,18 +608,20 @@ class Record {
|
||||
}
|
||||
|
||||
Integer getInteger(final String columnName) {
|
||||
return toInt(getString(columnName));
|
||||
}
|
||||
|
||||
LocalDate getLocalDate(final String columnName) {
|
||||
return toLocalDate(getString(columnName));
|
||||
}
|
||||
|
||||
private static Integer toInt(final String value) {
|
||||
final String value = getString(columnName);
|
||||
return isNotBlank(value) ? Integer.parseInt(value.trim()) : 0;
|
||||
}
|
||||
|
||||
private LocalDate toLocalDate(final String dateString) {
|
||||
BigDecimal getBigDecimal(final String columnName) {
|
||||
final String value = getString(columnName);
|
||||
if (isNotBlank(value)) {
|
||||
return new BigDecimal(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
LocalDate getLocalDate(final String columnName) {
|
||||
final String dateString = getString(columnName);
|
||||
if (isNotBlank(dateString)) {
|
||||
return LocalDate.parse(dateString);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user