combined memberNumber

This commit is contained in:
Michael Hoennig 2024-01-23 17:46:52 +01:00
parent e0d410fd3b
commit bcf8ad2148
15 changed files with 104 additions and 80 deletions

View File

@ -58,7 +58,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, HasUu
private BigDecimal assetValue;
@Column(name = "reference")
private String reference; // TODO: what is this for?
private String reference;
@Column(name = "comment")
private String comment;

View File

@ -53,7 +53,7 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, HasUu
private int shareCount;
@Column(name = "reference")
private String reference; // TODO: what is this for?
private String reference;
@Column(name = "comment")
private String comment;

View File

@ -44,7 +44,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
Integer memberNumber) {
context.define(currentUser, assumedRoles);
final var entities = membershipRepo.findMembershipsByOptionalPartherNumber(partnerUuid);
final var entities = membershipRepo.findMembershipsByOptionalPartnerUuid(partnerUuid);
final var resources = mapper.mapList(entities, HsOfficeMembershipResource.class,
SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER);

View File

@ -15,6 +15,7 @@ import org.hibernate.annotations.Type;
import jakarta.persistence.*;
import java.time.LocalDate;
import java.util.Optional;
import java.util.UUID;
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.*;
@ -30,8 +31,10 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@DisplayName("Membership")
public class HsOfficeMembershipEntity implements HasUuid, Stringifyable {
public static final String MEMBER_NUMBER_TAG = "M-";
private static Stringify<HsOfficeMembershipEntity> stringify = stringify(HsOfficeMembershipEntity.class)
.withProp(HsOfficeMembershipEntity::getMemberNumber)
.withProp(HsOfficeMembershipEntity::getMemberNumberString)
.withProp(e -> e.getPartner().toShortString())
.withProp(e -> e.getMainDebitor().toShortString())
.withProp(e -> e.getValidity().asString())
@ -82,15 +85,33 @@ public class HsOfficeMembershipEntity implements HasUuid, Stringifyable {
return upperInclusiveFromPostgresDateRange(getValidity());
}
public Range<LocalDate> getValidity() {
if (validity == null) {
validity = Range.infinite(LocalDate.class);
}
;
return validity;
}
public String getMemberNumberString() {
return MEMBER_NUMBER_TAG + getMemberNumber();
}
public Integer getMemberNumber() {
// TODO: refactor
String combinedMemberNumber;
if (partner.getPartnerNumber() == null ) {
if (memberNumberSuffix == null) {
combinedMemberNumber = null;
} else {combinedMemberNumber = MEMBER_NUMBER_TAG + memberNumberSuffix;}
} else if (memberNumberSuffix == null) {
combinedMemberNumber = partner.getPartnerNumber() + "??";
} else {
combinedMemberNumber = partner.getPartnerNumber() + memberNumberSuffix;
}
return Optional.ofNullable(combinedMemberNumber).map(Integer::parseInt).orElse(null);
}
@Override
public String toString() {
return stringify.apply(this);
@ -98,7 +119,7 @@ public class HsOfficeMembershipEntity implements HasUuid, Stringifyable {
@Override
public String toShortString() {
return partner.getPartnerNumber() + String.valueOf(memberNumberSuffix);
return "M-" + partner.getPartnerNumber() + String.valueOf(memberNumberSuffix);
}
@PrePersist

View File

@ -21,7 +21,7 @@ public interface HsOfficeMembershipRepository extends Repository<HsOfficeMembers
OR membership.partner.uuid = :partnerUuid )
ORDER BY membership.partner.partnerNumber, membership.memberNumberSuffix
""")
List<HsOfficeMembershipEntity> findMembershipsByOptionalPartherNumber(UUID partnerUuid);
List<HsOfficeMembershipEntity> findMembershipsByOptionalPartnerUuid(UUID partnerUuid);
@Query("""
SELECT membership FROM HsOfficeMembershipEntity membership
WHERE (:partnerNumber = membership.partner.partnerNumber)

View File

@ -92,8 +92,9 @@ execute procedure hsOfficeMembershipRbacRolesTrigger();
--changeset hs-office-membership-rbac-IDENTITY-VIEW:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
call generateRbacIdentityView('hs_office_membership', idNameExpression => $idName$
target.memberNumberSuffix ||
':' ||
'#' ||
(select partnerNumber from hs_office_partner p where p.uuid = target.partnerUuid) ||
memberNumberSuffix ||
':' || (select split_part(idName, ':', 2) from hs_office_partner_iv p where p.uuid = target.partnerUuid)
$idName$);
--//

View File

@ -93,21 +93,21 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
"transactionType": "DEPOSIT",
"assetValue": 320.00,
"valueDate": "2010-03-15",
"reference": "ref 10002-1",
"reference": "ref 1000202-1",
"comment": "initial deposit"
},
{
"transactionType": "DISBURSAL",
"assetValue": -128.00,
"valueDate": "2021-09-01",
"reference": "ref 10002-2",
"reference": "ref 1000202-2",
"comment": "partial disbursal"
},
{
"transactionType": "ADJUSTMENT",
"assetValue": 128.00,
"valueDate": "2022-10-20",
"reference": "ref 10002-3",
"reference": "ref 1000202-3",
"comment": "some adjustment"
}
]
@ -137,7 +137,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
"transactionType": "DISBURSAL",
"assetValue": -128.00,
"valueDate": "2021-09-01",
"reference": "ref 10002-2",
"reference": "ref 1000202-2",
"comment": "partial disbursal"
}
]

View File

@ -23,14 +23,14 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
void toStringContainsAlmostAllPropertiesAccount() {
final var result = givenCoopAssetTransaction.toString();
assertThat(result).isEqualTo("CoopAssetsTransaction(300001, 2020-01-01, DEPOSIT, 128.00, some-ref)");
assertThat(result).isEqualTo("CoopAssetsTransaction(1000101, 2020-01-01, DEPOSIT, 128.00, some-ref)");
}
@Test
void toShortStringContainsOnlyMemberNumberSuffixAndSharesCountOnly() {
final var result = givenCoopAssetTransaction.toShortString();
assertThat(result).isEqualTo("300001+128.00");
assertThat(result).isEqualTo("1000101+128.00");
}
@Test

View File

@ -115,7 +115,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
.map(s -> s.replace("hs_office_", ""))
.containsExactlyInAnyOrder(Array.fromFormatted(
initialGrantNames,
"{ grant perm view on coopassetstransaction#temprefB to role membership#10001:....tenant by system and assume }",
"{ grant perm view on coopassetstransaction#temprefB to role membership#1000101:....tenant by system and assume }",
null));
}
@ -142,17 +142,17 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
// then
allTheseCoopAssetsTransactionsAreReturned(
result,
"CoopAssetsTransaction(10001, 2010-03-15, DEPOSIT, 320.00, ref 10001-1, initial deposit)",
"CoopAssetsTransaction(10001, 2021-09-01, DISBURSAL, -128.00, ref 10001-2, partial disbursal)",
"CoopAssetsTransaction(10001, 2022-10-20, ADJUSTMENT, 128.00, ref 10001-3, some adjustment)",
"CoopAssetsTransaction(1000101, 2010-03-15, DEPOSIT, 320.00, ref 1000101-1, initial deposit)",
"CoopAssetsTransaction(1000101, 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)",
"CoopAssetsTransaction(1000101, 2022-10-20, ADJUSTMENT, 128.00, ref 1000101-3, some adjustment)",
"CoopAssetsTransaction(10002, 2010-03-15, DEPOSIT, 320.00, ref 10002-1, initial deposit)",
"CoopAssetsTransaction(10002, 2021-09-01, DISBURSAL, -128.00, ref 10002-2, partial disbursal)",
"CoopAssetsTransaction(10002, 2022-10-20, ADJUSTMENT, 128.00, ref 10002-3, some adjustment)",
"CoopAssetsTransaction(1000202, 2010-03-15, DEPOSIT, 320.00, ref 1000202-1, initial deposit)",
"CoopAssetsTransaction(1000202, 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)",
"CoopAssetsTransaction(1000202, 2022-10-20, ADJUSTMENT, 128.00, ref 1000202-3, some adjustment)",
"CoopAssetsTransaction(10003, 2010-03-15, DEPOSIT, 320.00, ref 10003-1, initial deposit)",
"CoopAssetsTransaction(10003, 2021-09-01, DISBURSAL, -128.00, ref 10003-2, partial disbursal)",
"CoopAssetsTransaction(10003, 2022-10-20, ADJUSTMENT, 128.00, ref 10003-3, some adjustment)");
"CoopAssetsTransaction(1000303, 2010-03-15, DEPOSIT, 320.00, ref 1000303-1, initial deposit)",
"CoopAssetsTransaction(1000303, 2021-09-01, DISBURSAL, -128.00, ref 1000303-2, partial disbursal)",
"CoopAssetsTransaction(1000303, 2022-10-20, ADJUSTMENT, 128.00, ref 1000303-3, some adjustment)");
}
@Test
@ -170,9 +170,9 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
// then
allTheseCoopAssetsTransactionsAreReturned(
result,
"CoopAssetsTransaction(10002, 2010-03-15, DEPOSIT, 320.00, ref 10002-1, initial deposit)",
"CoopAssetsTransaction(10002, 2021-09-01, DISBURSAL, -128.00, ref 10002-2, partial disbursal)",
"CoopAssetsTransaction(10002, 2022-10-20, ADJUSTMENT, 128.00, ref 10002-3, some adjustment)");
"CoopAssetsTransaction(1000202, 2010-03-15, DEPOSIT, 320.00, ref 1000202-1, initial deposit)",
"CoopAssetsTransaction(1000202, 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)",
"CoopAssetsTransaction(1000202, 2022-10-20, ADJUSTMENT, 128.00, ref 1000202-3, some adjustment)");
}
@Test
@ -191,7 +191,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
// then
allTheseCoopAssetsTransactionsAreReturned(
result,
"CoopAssetsTransaction(10002, 2021-09-01, DISBURSAL, -128.00, ref 10002-2, partial disbursal)");
"CoopAssetsTransaction(1000202, 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)");
}
@Test
@ -208,9 +208,9 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
// then:
exactlyTheseCoopAssetsTransactionsAreReturned(
result,
"CoopAssetsTransaction(10001, 2010-03-15, DEPOSIT, 320.00, ref 10001-1, initial deposit)",
"CoopAssetsTransaction(10001, 2021-09-01, DISBURSAL, -128.00, ref 10001-2, partial disbursal)",
"CoopAssetsTransaction(10001, 2022-10-20, ADJUSTMENT, 128.00, ref 10001-3, some adjustment)");
"CoopAssetsTransaction(1000101, 2010-03-15, DEPOSIT, 320.00, ref 1000101-1, initial deposit)",
"CoopAssetsTransaction(1000101, 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)",
"CoopAssetsTransaction(1000101, 2022-10-20, ADJUSTMENT, 128.00, ref 1000101-3, some adjustment)");
}
}
@ -229,8 +229,8 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
// then
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating coopAssetsTransaction test-data 10001, hs_office_coopassetstransaction, INSERT]",
"[creating coopAssetsTransaction test-data 10002, hs_office_coopassetstransaction, INSERT]");
"[creating coopAssetsTransaction test-data 1000101, hs_office_coopassetstransaction, INSERT]",
"[creating coopAssetsTransaction test-data 1000202, hs_office_coopassetstransaction, INSERT]");
}
@BeforeEach

View File

@ -84,21 +84,21 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest {
"transactionType": "SUBSCRIPTION",
"shareCount": 4,
"valueDate": "2010-03-15",
"reference": "ref 10002-1",
"reference": "ref 1000202-1",
"comment": "initial subscription"
},
{
"transactionType": "CANCELLATION",
"shareCount": -2,
"valueDate": "2021-09-01",
"reference": "ref 10002-2",
"reference": "ref 1000202-2",
"comment": "cancelling some"
},
{
"transactionType": "ADJUSTMENT",
"shareCount": 2,
"valueDate": "2022-10-20",
"reference": "ref 10002-3",
"reference": "ref 1000202-3",
"comment": "some adjustment"
}
]
@ -118,7 +118,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest {
"transactionType": "CANCELLATION",
"shareCount": -2,
"valueDate": "2021-09-01",
"reference": "ref 10002-2",
"reference": "ref 1000202-2",
"comment": "cancelling some"
}
]

View File

@ -22,14 +22,14 @@ class HsOfficeCoopSharesTransactionEntityUnitTest {
void toStringContainsAlmostAllPropertiesAccount() {
final var result = givenCoopSharesTransaction.toString();
assertThat(result).isEqualTo("CoopShareTransaction(300001, 2020-01-01, SUBSCRIPTION, 4, some-ref)");
assertThat(result).isEqualTo("CoopShareTransaction(1000101, 2020-01-01, SUBSCRIPTION, 4, some-ref)");
}
@Test
void toShortStringContainsOnlyMemberNumberAndShareCountOnly() {
final var result = givenCoopSharesTransaction.toShortString();
assertThat(result).isEqualTo("300001+4");
assertThat(result).isEqualTo("1000101+4");
}
@Test

View File

@ -230,8 +230,8 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase
// then
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating coopSharesTransaction test-data 10001, hs_office_coopsharestransaction, INSERT]",
"[creating coopSharesTransaction test-data 10002, hs_office_coopsharestransaction, INSERT]");
"[creating coopSharesTransaction test-data 1000101, hs_office_coopsharestransaction, INSERT]",
"[creating coopSharesTransaction test-data 1000202, hs_office_coopsharestransaction, INSERT]");
}
@BeforeEach

View File

@ -27,14 +27,14 @@ class HsOfficeMembershipEntityUnitTest {
void toStringContainsAllProps() {
final var result = givenMembership.toString();
assertThat(result).isEqualTo("Membership(1000101, LEGAL Test Ltd., 1000100, [2020-01-01,))");
assertThat(result).isEqualTo("Membership(M-1000101, LEGAL Test Ltd., 1000100, [2020-01-01,))");
}
@Test
void toShortStringContainsMemberNumberSuffixOnly() {
final var result = givenMembership.toShortString();
assertThat(result).isEqualTo("1000101");
assertThat(result).isEqualTo("M-1000101");
}
@Test

View File

@ -108,7 +108,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("First").get(0);
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var newMembership = toCleanup(HsOfficeMembershipEntity.builder()
.memberNumberSuffix("02")
.memberNumberSuffix("07")
.partner(givenPartner)
.mainDebitor(givenDebitor)
.validity(Range.closedInfinite(LocalDate.parse("2020-01-01")))
@ -121,11 +121,11 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
final var all = rawRoleRepo.findAll();
assertThat(roleNamesOf(all)).containsExactlyInAnyOrder(Array.from(
initialRoleNames,
"hs_office_membership#20002:FirstGmbH-firstcontact.admin",
"hs_office_membership#20002:FirstGmbH-firstcontact.agent",
"hs_office_membership#20002:FirstGmbH-firstcontact.guest",
"hs_office_membership#20002:FirstGmbH-firstcontact.owner",
"hs_office_membership#20002:FirstGmbH-firstcontact.tenant"));
"hs_office_membership#1000107:FirstGmbH-firstcontact.admin",
"hs_office_membership#1000107:FirstGmbH-firstcontact.agent",
"hs_office_membership#1000107:FirstGmbH-firstcontact.guest",
"hs_office_membership#1000107:FirstGmbH-firstcontact.owner",
"hs_office_membership#1000107:FirstGmbH-firstcontact.tenant"));
assertThat(grantDisplaysOf(rawGrantRepo.findAll()))
.map(s -> s.replace("GmbH-firstcontact", ""))
.map(s -> s.replace("hs_office_", ""))
@ -133,33 +133,33 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
initialGrantNames,
// owner
"{ grant perm * on membership#20002:First to role membership#20002:First.owner by system and assume }",
"{ grant role membership#20002:First.owner to role global#global.admin by system and assume }",
"{ grant perm * on membership#1000107:First to role membership#1000107:First.owner by system and assume }",
"{ grant role membership#1000107:First.owner to role global#global.admin by system and assume }",
// admin
"{ grant perm edit on membership#20002:First to role membership#20002:First.admin by system and assume }",
"{ grant role membership#20002:First.admin to role membership#20002:First.owner by system and assume }",
"{ grant perm edit on membership#1000107:First to role membership#1000107:First.admin by system and assume }",
"{ grant role membership#1000107:First.admin to role membership#1000107:First.owner by system and assume }",
// agent
"{ grant role membership#20002:First.agent to role membership#20002:First.admin by system and assume }",
"{ grant role partner#10001:First.tenant to role membership#20002:First.agent by system and assume }",
"{ grant role membership#20002:First.agent to role debitor#1000111:First.admin by system and assume }",
"{ grant role membership#20002:First.agent to role partner#10001:First.admin by system and assume }",
"{ grant role debitor#1000111:First.tenant to role membership#20002:First.agent by system and assume }",
"{ grant role membership#1000107:First.agent to role membership#1000107:First.admin by system and assume }",
"{ grant role partner#10001:First.tenant to role membership#1000107:First.agent by system and assume }",
"{ grant role membership#1000107:First.agent to role debitor#1000111:First.admin by system and assume }",
"{ grant role membership#1000107:First.agent to role partner#10001:First.admin by system and assume }",
"{ grant role debitor#1000111:First.tenant to role membership#1000107:First.agent by system and assume }",
// tenant
"{ grant role membership#20002:First.tenant to role membership#20002:First.agent by system and assume }",
"{ grant role partner#10001:First.guest to role membership#20002:First.tenant by system and assume }",
"{ grant role debitor#1000111:First.guest to role membership#20002:First.tenant by system and assume }",
"{ grant role membership#20002:First.tenant to role debitor#1000111:First.agent by system and assume }",
"{ grant role membership#1000107:First.tenant to role membership#1000107:First.agent by system and assume }",
"{ grant role partner#10001:First.guest to role membership#1000107:First.tenant by system and assume }",
"{ grant role debitor#1000111:First.guest to role membership#1000107:First.tenant by system and assume }",
"{ grant role membership#1000107:First.tenant to role debitor#1000111:First.agent by system and assume }",
"{ grant role membership#20002:First.tenant to role partner#10001:First.agent by system and assume }",
"{ grant role membership#1000107:First.tenant to role partner#10001:First.agent by system and assume }",
// guest
"{ grant perm view on membership#20002:First to role membership#20002:First.guest by system and assume }",
"{ grant role membership#20002:First.guest to role membership#20002:First.tenant by system and assume }",
"{ grant role membership#20002:First.guest to role partner#10001:First.tenant by system and assume }",
"{ grant role membership#20002:First.guest to role debitor#1000111:First.tenant by system and assume }",
"{ grant perm view on membership#1000107:First to role membership#1000107:First.guest by system and assume }",
"{ grant role membership#1000107:First.guest to role membership#1000107:First.tenant by system and assume }",
"{ grant role membership#1000107:First.guest to role partner#10001:First.tenant by system and assume }",
"{ grant role membership#1000107:First.guest to role debitor#1000111:First.tenant by system and assume }",
null));
}
@ -179,14 +179,14 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
context("superuser-alex@hostsharing.net");
// when
final var result = membershipRepo.findMembershipsByOptionalPartherNumber(null);
final var result = membershipRepo.findMembershipsByOptionalPartnerUuid(null);
// then
exactlyTheseMembershipsAreReturned(
result,
"Membership(10001, LEGAL First GmbH, 1000111, [2022-10-01,), NONE)",
"Membership(10002, LEGAL Second e.K., 1000212, [2022-10-01,), NONE)",
"Membership(10003, SOLE_REPRESENTATION Third OHG, 1000313, [2022-10-01,), NONE)");
"Membership(M-1000101, LEGAL First GmbH, 1000111, [2022-10-01,), NONE)",
"Membership(M-1000202, LEGAL Second e.K., 1000212, [2022-10-01,), NONE)",
"Membership(M-1000303, SOLE_REPRESENTATION Third OHG, 1000313, [2022-10-01,), NONE)");
}
@Test
@ -196,10 +196,11 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("First").get(0);
// when
final var result = membershipRepo.findMembershipsByOptionalPartherNumber(givenPartner.getUuid());
final var result = membershipRepo.findMembershipsByOptionalPartnerUuid(givenPartner.getUuid());
// then
exactlyTheseMembershipsAreReturned(result, "Membership(10001, LEGAL First GmbH, 1000111, [2022-10-01,), NONE)");
exactlyTheseMembershipsAreReturned(result,
"Membership(M-1000101, LEGAL First GmbH, 1000111, [2022-10-01,), NONE)");
}
@Test
@ -208,10 +209,11 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
context("superuser-alex@hostsharing.net");
// when
final var result = membershipRepo.findMembershipsByOptionalPartherNumber(null);
final var result = membershipRepo.findMembershipsByMemberNumber(1000202);
// then
exactlyTheseMembershipsAreReturned(result, "Membership(10002, LEGAL Second e.K., 1000212, [2022-10-01,), NONE)");
exactlyTheseMembershipsAreReturned(result,
"Membership(M-1000202, LEGAL Second e.K., 1000212, [2022-10-01,), NONE)");
}
}

View File

@ -182,9 +182,9 @@ public class ImportOfficeData extends ContextBasedTest {
""");
assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace("""
{
17=Membership(10017, null null, null, 1001700, [2000-12-06,), NONE),
20=Membership(10020, null null, null, 1002000, [2000-12-06,2016-01-01), UNKNOWN),
22=Membership(11022, null null, null, 1102200, [2021-04-01,), NONE)
17=Membership(1001700, null null, null, 1001700, [2000-12-06,), NONE),
20=Membership(1002000, null null, null, 1002000, [2000-12-06,2016-01-01), UNKNOWN),
22=Membership(1102200, null null, null, 1102200, [2021-04-01,), NONE)
}
""");
}