memberNumber as partnerNumber+memberNumberSuffix #13

Merged
hsh-michaelhoennig merged 78 commits from memberNumberSuffix-and-partnerNumber into master 2024-01-24 15:57:16 +01:00
47 changed files with 789 additions and 423 deletions

View File

@ -80,3 +80,4 @@ alias fp='grep -r '@Accepts' src | sed -e 's/^.*@/@/g' | sort -u | wc -l'
alias gw-spotless='./gradlew spotlessApply -x pitest -x test -x :processResources'
alias gw-test='. .aliases; ./gradlew test'
alias gw-check='. .aliases; gw check -x pitest -x :dependencyCheckAnalyze'

View File

@ -53,12 +53,25 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, HasUu
@Column(name = "valuedate")
private LocalDate valueDate;
/**
* The signed value which directly affects the booking balance.
*
* <p>This means, that a DEPOSIT is always positive, a DISBURSAL is always negative,
* but an ADJUSTMENT can bei either positive or negative.
* See {@link HsOfficeCoopAssetsTransactionType} for</p> more information.
*/
@Column(name = "assetvalue")
private BigDecimal assetValue;
/**
* The booking reference.
*/
@Column(name = "reference")
private String reference; // TODO: what is this for?
private String reference;
/**
* An optional arbitrary comment.
*/
@Column(name = "comment")
private String comment;

View File

@ -17,7 +17,7 @@ public interface HsOfficeCoopAssetsTransactionRepository extends Repository<HsOf
WHERE ( CAST(:membershipUuid AS org.hibernate.type.UUIDCharType) IS NULL OR at.membership.uuid = :membershipUuid)
AND ( CAST(:fromValueDate AS java.time.LocalDate) IS NULL OR (at.valueDate >= :fromValueDate))
AND ( CAST(:toValueDate AS java.time.LocalDate)IS NULL OR (at.valueDate <= :toValueDate))
ORDER BY at.membership.memberNumber, at.valueDate
ORDER BY at.membership.memberNumberSuffix, at.valueDate
""")
List<HsOfficeCoopAssetsTransactionEntity> findCoopAssetsTransactionByOptionalMembershipUuidAndDateRange(
UUID membershipUuid, LocalDate fromValueDate, LocalDate toValueDate);

View File

@ -1,12 +1,43 @@
package net.hostsharing.hsadminng.hs.office.coopassets;
public enum HsOfficeCoopAssetsTransactionType {
ADJUSTMENT, // correction of wrong bookings
DEPOSIT, // payment received from member after signing shares, >0
DISBURSAL, // payment send to member after cancellation of shares, <0
TRANSFER, // transferring shares to another member, <0
ADOPTION, // receiving shares from another member, >0
CLEARING, // settlement with members dept, <0
LOSS, // assignment of balance sheet loss in case of cancellation of shares, <0
LIMITATION // limitation period was reached after impossible disbursal, <0
/**
* correction of wrong bookings, value can be positive or negative
*/
ADJUSTMENT,
/**
* payment received from member after signing shares, value >0
*/
DEPOSIT,
/**
* payment send to member after cancellation of shares, value <0
*/
DISBURSAL,
/**
* transferring shares to another member, value <0
*/
TRANSFER,
/**
* receiving shares from another member, value >0
*/
ADOPTION,
/**
* settlement with members dept, value <0
*/
CLEARING,
/**
* assignment of balance sheet loss in case of cancellation of shares, value <0
*/
LOSS,
/**
* limitation period was reached after impossible disbursal, value <0
*/
LIMITATION
}

View File

@ -46,15 +46,28 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, HasUu
@Enumerated(EnumType.STRING)
private HsOfficeCoopSharesTransactionType transactionType;
/**
* The signed value which directly affects the booking balance.
*
* <p>This means, that a SUBSCRIPTION is always positive, a CANCELLATION is always negative,
* but an ADJUSTMENT can bei either positive or negative.
* See {@link HsOfficeCoopSharesTransactionType} for</p> more information.
*/
@Column(name = "valuedate")
private LocalDate valueDate;
@Column(name = "sharecount")
private int shareCount;
/**
* The Booking reference.
hsh-michaelhoennig marked this conversation as resolved Outdated
*/
@Column(name = "reference")
private String reference; // TODO: what is this for?
private String reference;
/**
* An optional arbitrary comment.
*/
@Column(name = "comment")
private String comment;
@ -69,6 +82,6 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, HasUu
@Override
public String toShortString() {
return "%s%+d".formatted(getMemberNumber(), shareCount);
return "M-%s%+d".formatted(getMemberNumber(), shareCount);
}
}

View File

@ -17,7 +17,7 @@ public interface HsOfficeCoopSharesTransactionRepository extends Repository<HsOf
WHERE ( CAST(:membershipUuid AS org.hibernate.type.UUIDCharType) IS NULL OR st.membership.uuid = :membershipUuid)
AND ( CAST(:fromValueDate AS java.time.LocalDate) IS NULL OR (st.valueDate >= :fromValueDate))
AND ( CAST(:toValueDate AS java.time.LocalDate)IS NULL OR (st.valueDate <= :toValueDate))
ORDER BY st.membership.memberNumber, st.valueDate
ORDER BY st.membership.memberNumberSuffix, st.valueDate
""")
List<HsOfficeCoopSharesTransactionEntity> findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(
UUID membershipUuid, LocalDate fromValueDate, LocalDate toValueDate);

View File

@ -1,7 +1,18 @@
package net.hostsharing.hsadminng.hs.office.coopshares;
public enum HsOfficeCoopSharesTransactionType {
ADJUSTMENT, // correction of wrong bookings
SUBSCRIPTION, // shares signed, e.g. with the declaration of accession, >0
CANCELLATION; // shares terminated, e.g. when a membership is resigned, <0
/**
* correction of wrong bookings, with either positive or negative value
*/
ADJUSTMENT,
/**
* shares signed, e.g. with the declaration of accession, value >0
*/
SUBSCRIPTION,
/**
* shares terminated, e.g. when a membership is resigned, value <0
*/
CANCELLATION;
}

View File

@ -26,12 +26,14 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@DisplayName("Debitor")
public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
public static final String DEBITOR_NUMBER_TAG = "D-";
// TODO: I would rather like to generate something matching this example:
// debitor(1234500: Test AG, tes)
// maybe remove withSepararator (always use ', ') and add withBusinessIdProp (with ': ' afterwards)?
private static Stringify<HsOfficeDebitorEntity> stringify =
stringify(HsOfficeDebitorEntity.class, "debitor")
.withProp(HsOfficeDebitorEntity::getDebitorNumber)
.withProp(e -> DEBITOR_NUMBER_TAG + e.getDebitorNumber())
.withProp(HsOfficeDebitorEntity::getPartner)
.withProp(HsOfficeDebitorEntity::getDefaultPrefix)
.withSeparator(": ")
@ -75,18 +77,11 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
@Column(name = "defaultprefix", columnDefinition = "char(3) not null")
private String defaultPrefix;
public String getDebitorNumberString() {
// TODO: refactor
if (partner.getDebitorNumberPrefix() == null ) {
if (debitorNumberSuffix == null) {
return null;
}
return String.format("%02d", debitorNumberSuffix);
private String getDebitorNumberString() {
if (partner == null || partner.getPartnerNumber() == null || debitorNumberSuffix == null ) {
return null;
}
if (debitorNumberSuffix == null) {
return partner.getDebitorNumberPrefix() + "??";
}
return partner.getDebitorNumberPrefix() + String.format("%02d", debitorNumberSuffix);
return partner.getPartnerNumber() + String.format("%02d", debitorNumberSuffix);
}
public Integer getDebitorNumber() {
@ -100,6 +95,6 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
@Override
public String toShortString() {
return getDebitorNumberString();
return DEBITOR_NUMBER_TAG + getDebitorNumberString();
}
}

View File

@ -13,10 +13,10 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
@Query("""
SELECT debitor FROM HsOfficeDebitorEntity debitor
WHERE cast(debitor.partner.debitorNumberPrefix as integer) = :debitorNumberPrefix
WHERE cast(debitor.partner.partnerNumber as integer) = :partnerNumber
AND cast(debitor.debitorNumberSuffix as integer) = :debitorNumberSuffix
""")
List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int debitorNumberPrefix, byte debitorNumberSuffix);
List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int partnerNumber, byte debitorNumberSuffix);
default List<HsOfficeDebitorEntity> findDebitorByDebitorNumber(int debitorNumber) {
return findDebitorByDebitorNumber( debitorNumber/100, (byte) (debitorNumber%100));

View File

@ -44,8 +44,9 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
Integer memberNumber) {
context.define(currentUser, assumedRoles);
final var entities =
membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(partnerUuid, memberNumber);
final var entities = ( memberNumber != null)
? List.of(membershipRepo.findMembershipByMemberNumber(memberNumber))
: membershipRepo.findMembershipsByOptionalPartnerUuid(partnerUuid);
final var resources = mapper.mapList(entities, HsOfficeMembershipResource.class,
SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER);

View File

@ -30,8 +30,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(e -> MEMBER_NUMBER_TAG + e.getMemberNumber())
.withProp(e -> e.getPartner().toShortString())
.withProp(e -> e.getMainDebitor().toShortString())
.withProp(e -> e.getValidity().asString())
@ -52,8 +54,8 @@ public class HsOfficeMembershipEntity implements HasUuid, Stringifyable {
@JoinColumn(name = "maindebitoruuid")
private HsOfficeDebitorEntity mainDebitor;
@Column(name = "membernumber")
private int memberNumber; // TODO: migrate to suffix, like debitorNumberSuffix
@Column(name = "membernumbersuffix", length = 2)
private String memberNumberSuffix;
@Column(name = "validity", columnDefinition = "daterange")
@Type(PostgreSQLRangeType.class)
@ -82,14 +84,19 @@ public class HsOfficeMembershipEntity implements HasUuid, Stringifyable {
return upperInclusiveFromPostgresDateRange(getValidity());
}
public Range<LocalDate> getValidity() {
if (validity == null) {
validity = Range.infinite(LocalDate.class);
}
;
return validity;
}
public Integer getMemberNumber() {
if (partner == null || partner.getPartnerNumber() == null || memberNumberSuffix == null ) {
return null;
}
return getPartner().getPartnerNumber() * 100 + Integer.parseInt(memberNumberSuffix, 10);
}
@Override
public String toString() {
@ -98,7 +105,7 @@ public class HsOfficeMembershipEntity implements HasUuid, Stringifyable {
@Override
public String toShortString() {
return String.valueOf(memberNumber);
return "M-" + getMemberNumber();
}
@PrePersist

View File

@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.office.membership;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@ -11,16 +12,30 @@ public interface HsOfficeMembershipRepository extends Repository<HsOfficeMembers
Optional<HsOfficeMembershipEntity> findByUuid(UUID id);
HsOfficeMembershipEntity save(final HsOfficeMembershipEntity entity);
@Query("""
SELECT membership FROM HsOfficeMembershipEntity membership
WHERE (:memberNumber is null OR membership.memberNumber = :memberNumber)
AND ( CAST(:partnerUuid as org.hibernate.type.UUIDCharType) IS NULL
OR membership.partner.uuid = :partnerUuid )
ORDER BY membership.memberNumber
WHERE ( CAST(:partnerUuid as org.hibernate.type.UUIDCharType) IS NULL
OR membership.partner.uuid = :partnerUuid )
ORDER BY membership.partner.partnerNumber, membership.memberNumberSuffix
""")
List<HsOfficeMembershipEntity> findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(UUID partnerUuid, Integer memberNumber);
HsOfficeMembershipEntity save(final HsOfficeMembershipEntity entity);
List<HsOfficeMembershipEntity> findMembershipsByOptionalPartnerUuid(UUID partnerUuid);
@Query("""
SELECT membership FROM HsOfficeMembershipEntity membership
WHERE (:partnerNumber = membership.partner.partnerNumber)
AND (membership.memberNumberSuffix = :suffix)
ORDER BY membership.memberNumberSuffix
""")
HsOfficeMembershipEntity findMembershipByPartnerNumberAndSuffix(
@NotNull Integer partnerNumber,
@NotNull String suffix);
default HsOfficeMembershipEntity findMembershipByMemberNumber(Integer memberNumber) {
final var partnerNumber = memberNumber / 100;
final var suffix = memberNumber % 100;
return findMembershipByPartnerNumberAndSuffix(partnerNumber, String.format("%02d", suffix));
}
long count();

View File

@ -36,8 +36,8 @@ public class HsOfficePartnerEntity implements Stringifyable, HasUuid {
@GeneratedValue
private UUID uuid;
@Column(name = "debitornumberprefix", columnDefinition = "numeric(5) not null")
private Integer debitorNumberPrefix;
@Column(name = "partnernumber", columnDefinition = "numeric(5) not null")
private Integer partnerNumber;
@ManyToOne
@JoinColumn(name = "personuuid", nullable = false)

View File

@ -23,6 +23,7 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
OR person.familyName like concat(cast(:name as text), '%')
""")
List<HsOfficePartnerEntity> findPartnerByOptionalNameLike(String name);
HsOfficePartnerEntity findPartnerByPartnerNumber(Integer partnerNumber);
HsOfficePartnerEntity save(final HsOfficePartnerEntity entity);

View File

@ -25,6 +25,13 @@ components:
$ref: './hs-office-debitor-schemas.yaml#/components/schemas/HsOfficeDebitor'
memberNumber:
type: integer
minimum: 1000000
maximum: 9999999
memberNumberSuffix:
type: string
minLength: 2
maxLength: 2
pattern: '[0-9]+'
validFrom:
type: string
format: date
@ -66,8 +73,11 @@ components:
type: string
format: uuid
nullable: false
memberNumber:
type: integer
memberNumberSuffix:
type: string
minLength: 2
maxLength: 2
pattern: '[0-9]+'
nullable: false
validFrom:
type: string
@ -84,6 +94,7 @@ components:
type: boolean
required:
- partnerUuid
- memberNumberSuffix
- mainDebitorUuid
- validFrom
- membershipFeeBillable

View File

@ -1,6 +1,7 @@
get:
summary: Returns a list of (optionally filtered) memberships.
description: Returns the list of (optionally filtered) memberships which are visible to the current user or any of it's assumed roles.
description: Returns the list of memberships which are visible to the current user or any of it's assumed roles.
The list can optionally be filtered by either the `partnerUuid` or the `memberNumber` - not both at the same time.
tags:
- hs-office-memberships
operationId: listMemberships
@ -13,13 +14,13 @@ get:
schema:
type: string
format: uuid
description: UUID of the business partner.
description: UUID of the business partner, exclusive to `memberNumber`.
- name: memberNumber
in: query
required: false
schema:
type: integer
description: Member number.
description: Member number, exclusive to `partnerUuid`.
responses:
"200":
description: OK

View File

@ -9,7 +9,7 @@ components:
uuid:
type: string
format: uuid
debitorNumberPrefix:
partnerNumber:
type: integer
format: int8
minimum: 10000
@ -91,7 +91,7 @@ components:
HsOfficePartnerInsert:
type: object
properties:
debitorNumberPrefix:
partnerNumber:
type: integer
format: int8
minimum: 10000
@ -105,7 +105,7 @@ components:
details:
$ref: '#/components/schemas/HsOfficePartnerDetailsInsert'
required:
- debitorNumberPrefix
- partnerNumber
- personUuid
- contactUuid
- details

View File

@ -32,7 +32,7 @@ call create_journal('hs_office_partner_details');
create table hs_office_partner
(
uuid uuid unique references RbacObject (uuid) initially deferred,
debitorNumberPrefix varchar(5),
partnerNumber numeric(5),
personUuid uuid not null references hs_office_person(uuid),
contactUuid uuid not null references hs_office_contact(uuid),
detailsUuid uuid not null references hs_office_partner_details(uuid) on delete cascade

View File

@ -165,8 +165,7 @@ execute procedure hsOfficePartnerRbacRolesTrigger();
--changeset hs-office-partner-rbac-IDENTITY-VIEW:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
call generateRbacIdentityView('hs_office_partner', $idName$
-- TODO: simplify by using just debitorNumberPrefix for the essential part
debitorNumberPrefix || ':' ||
partnerNumber || ':' ||
(select idName from hs_office_person_iv p where p.uuid = target.personuuid)
|| '-' ||
(select idName from hs_office_contact_iv c where c.uuid = target.contactuuid)
@ -180,7 +179,6 @@ call generateRbacIdentityView('hs_office_partner', $idName$
call generateRbacRestrictedView('hs_office_partner',
'(select idName from hs_office_person_iv p where p.uuid = target.personUuid)',
$updates$
debitorNumberPrefix = new.debitorNumberPrefix,
personUuid = new.personUuid,
hsh-michaelhoennig marked this conversation as resolved Outdated

entfernen, nicht sinnvoll

entfernen, nicht sinnvoll
contactUuid = new.contactUuid
$updates$);

View File

@ -9,7 +9,7 @@
Creates a single partner test record.
*/
create or replace procedure createHsOfficePartnerTestData(
debitorNumberPrefix numeric(5),
partnerNumber numeric(5),
personTradeOrFamilyName varchar,
contactLabel varchar )
language plpgsql as $$
@ -49,8 +49,8 @@ begin
end if;
insert
into hs_office_partner (uuid, debitorNumberPrefix, personuuid, contactuuid, detailsUuid)
values (uuid_generate_v4(), debitorNumberPrefix, relatedPerson.uuid, relatedContact.uuid, relatedDetailsUuid);
into hs_office_partner (uuid, partnerNumber, personuuid, contactuuid, detailsUuid)
values (uuid_generate_v4(), partnerNumber, relatedPerson.uuid, relatedContact.uuid, relatedDetailsUuid);
end; $$;
--//

View File

@ -173,7 +173,7 @@ execute procedure hsOfficeDebitorRbacRolesTrigger();
-- ----------------------------------------------------------------------------
call generateRbacIdentityView('hs_office_debitor', $idName$
'#' ||
(select debitornumberprefix from hs_office_partner p where p.uuid = target.partnerUuid) ||
(select partnerNumber from hs_office_partner p where p.uuid = target.partnerUuid) ||
to_char(debitorNumberSuffix, 'fm00') ||
':' || (select split_part(idName, ':', 2) from hs_office_partner_iv pi where pi.uuid = target.partnerUuid)
$idName$);

View File

@ -13,10 +13,13 @@ create table if not exists hs_office_membership
uuid uuid unique references RbacObject (uuid) initially deferred,
partnerUuid uuid not null references hs_office_partner(uuid),
mainDebitorUuid uuid not null references hs_office_debitor(uuid),
memberNumber numeric(5) not null unique,
memberNumberSuffix char(2) not null check (
hsh-michaelhoennig marked this conversation as resolved

add unique constraint mit partnerNumber

add unique constraint mit partnerNumber
memberNumberSuffix::text ~ '^[0-9][0-9]$'),
validity daterange not null,
reasonForTermination HsOfficeReasonForTermination not null default 'NONE',
membershipFeeBillable boolean not null default true
membershipFeeBillable boolean not null default true,
UNIQUE(partnerUuid, memberNumberSuffix)
);
--//

View File

@ -92,7 +92,9 @@ execute procedure hsOfficeMembershipRbacRolesTrigger();
--changeset hs-office-membership-rbac-IDENTITY-VIEW:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
call generateRbacIdentityView('hs_office_membership', idNameExpression => $idName$
target.memberNumber ||
'#' ||
(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$);
--//
@ -102,7 +104,7 @@ call generateRbacIdentityView('hs_office_membership', idNameExpression => $idNam
--changeset hs-office-membership-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
call generateRbacRestrictedView('hs_office_membership',
orderby => 'target.memberNumber',
orderby => 'target.memberNumberSuffix',
columnUpdates => $updates$
validity = new.validity,
reasonForTermination = new.reasonForTermination,

View File

@ -8,16 +8,18 @@
/*
Creates a single membership test record.
*/
create or replace procedure createHsOfficeMembershipTestData( forPartnerTradeName varchar, forMainDebitorNumber numeric )
create or replace procedure createHsOfficeMembershipTestData(
forPartnerTradeName varchar,
forMainDebitorNumberSuffix numeric,
newMemberNumberSuffix char(2) )
language plpgsql as $$
declare
currentTask varchar;
idName varchar;
relatedPartner hs_office_partner;
relatedDebitor hs_office_debitor;
newMemberNumber numeric;
currentTask varchar;
idName varchar;
relatedPartner hs_office_partner;
relatedDebitor hs_office_debitor;
begin
idName := cleanIdentifier( forPartnerTradeName || '#' || forMainDebitorNumber);
idName := cleanIdentifier( forPartnerTradeName || '#' || forMainDebitorNumberSuffix);
currentTask := 'creating Membership test-data ' || idName;
call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global.admin');
execute format('set local hsadminng.currentTask to %L', currentTask);
@ -25,15 +27,17 @@ begin
select partner.* from hs_office_partner partner
join hs_office_person person on person.uuid = partner.personUuid
where person.tradeName = forPartnerTradeName into relatedPartner;
select d.* from hs_office_debitor d where d.debitorNumberSuffix = forMainDebitorNumber into relatedDebitor;
select coalesce(max(memberNumber)+1, 10001) from hs_office_membership into newMemberNumber;
select d.* from hs_office_debitor d
where d.partneruuid = relatedPartner.uuid
and d.debitorNumberSuffix = forMainDebitorNumberSuffix
into relatedDebitor;
raise notice 'creating test Membership: %', idName;
raise notice '- using partner (%): %', relatedPartner.uuid, relatedPartner;
raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor;
insert
into hs_office_membership (uuid, partneruuid, maindebitoruuid, membernumber, validity, reasonfortermination)
values (uuid_generate_v4(), relatedPartner.uuid, relatedDebitor.uuid, newMemberNumber, daterange('20221001' , null, '[]'), 'NONE');
into hs_office_membership (uuid, partneruuid, maindebitoruuid, memberNumberSuffix, validity, reasonfortermination)
values (uuid_generate_v4(), relatedPartner.uuid, relatedDebitor.uuid, newMemberNumberSuffix, daterange('20221001' , null, '[]'), 'NONE');
end; $$;
--//
@ -44,9 +48,9 @@ end; $$;
do language plpgsql $$
begin
call createHsOfficeMembershipTestData('First GmbH', 11);
call createHsOfficeMembershipTestData('Second e.K.', 12);
call createHsOfficeMembershipTestData('Third OHG', 13);
call createHsOfficeMembershipTestData('First GmbH', 11, '01');
call createHsOfficeMembershipTestData('Second e.K.', 12, '02');
call createHsOfficeMembershipTestData('Third OHG', 13, '03');
end;
$$;
--//

View File

@ -8,25 +8,33 @@
/*
Creates a single coopSharesTransaction test record.
*/
create or replace procedure createHsOfficeCoopSharesTransactionTestData(givenMembershipNumber numeric)
create or replace procedure createHsOfficeCoopSharesTransactionTestData(
givenPartnerNumber numeric,
givenMemberNumberSuffix char(2)
)
language plpgsql as $$
declare
currentTask varchar;
membership hs_office_membership;
begin
currentTask = 'creating coopSharesTransaction test-data ' || givenMembershipNumber;
currentTask = 'creating coopSharesTransaction test-data ' || givenPartnerNumber::text || givenMemberNumberSuffix;
execute format('set local hsadminng.currentTask to %L', currentTask);
call defineContext(currentTask);
select m.uuid from hs_office_membership m where m.memberNumber = givenMembershipNumber into membership;
select m.uuid
from hs_office_membership m
join hs_office_partner p on p.uuid = m.partneruuid
where p.partnerNumber = givenPartnerNumber
and m.memberNumberSuffix = givenMemberNumberSuffix
into membership;
raise notice 'creating test coopSharesTransaction: %', givenMembershipNumber;
raise notice 'creating test coopSharesTransaction: %', givenPartnerNumber::text || givenMemberNumberSuffix;
insert
into hs_office_coopsharestransaction(uuid, membershipuuid, transactiontype, valuedate, sharecount, reference, comment)
values
(uuid_generate_v4(), membership.uuid, 'SUBSCRIPTION', '2010-03-15', 4, 'ref '||givenMembershipNumber||'-1', 'initial subscription'),
(uuid_generate_v4(), membership.uuid, 'CANCELLATION', '2021-09-01', -2, 'ref '||givenMembershipNumber||'-2', 'cancelling some'),
(uuid_generate_v4(), membership.uuid, 'ADJUSTMENT', '2022-10-20', 2, 'ref '||givenMembershipNumber||'-3', 'some adjustment');
(uuid_generate_v4(), membership.uuid, 'SUBSCRIPTION', '2010-03-15', 4, 'ref '||givenPartnerNumber::text || givenMemberNumberSuffix||'-1', 'initial subscription'),
(uuid_generate_v4(), membership.uuid, 'CANCELLATION', '2021-09-01', -2, 'ref '||givenPartnerNumber::text || givenMemberNumberSuffix||'-2', 'cancelling some'),
(uuid_generate_v4(), membership.uuid, 'ADJUSTMENT', '2022-10-20', 2, 'ref '||givenPartnerNumber::text || givenMemberNumberSuffix||'-3', 'some adjustment');
end; $$;
--//
@ -37,8 +45,8 @@ end; $$;
do language plpgsql $$
begin
call createHsOfficeCoopSharesTransactionTestData(10001);
call createHsOfficeCoopSharesTransactionTestData(10002);
call createHsOfficeCoopSharesTransactionTestData(10003);
call createHsOfficeCoopSharesTransactionTestData(10001, '01');
call createHsOfficeCoopSharesTransactionTestData(10002, '02');
call createHsOfficeCoopSharesTransactionTestData(10003, '03');
end;
$$;

View File

@ -8,25 +8,33 @@
/*
Creates a single coopAssetsTransaction test record.
*/
create or replace procedure createHsOfficeCoopAssetsTransactionTestData(givenMembershipNumber numeric)
create or replace procedure createHsOfficeCoopAssetsTransactionTestData(
givenPartnerNumber numeric,
givenMemberNumberSuffix char(2)
)
language plpgsql as $$
declare
currentTask varchar;
membership hs_office_membership;
begin
currentTask = 'creating coopAssetsTransaction test-data ' || givenMembershipNumber;
currentTask = 'creating coopAssetsTransaction test-data ' || givenPartnerNumber || givenMemberNumberSuffix;
execute format('set local hsadminng.currentTask to %L', currentTask);
call defineContext(currentTask);
select m.uuid from hs_office_membership m where m.memberNumber = givenMembershipNumber into membership;
select m.uuid
from hs_office_membership m
join hs_office_partner p on p.uuid = m.partneruuid
where p.partnerNumber = givenPartnerNumber
and m.memberNumberSuffix = givenMemberNumberSuffix
into membership;
raise notice 'creating test coopAssetsTransaction: %', givenMembershipNumber;
raise notice 'creating test coopAssetsTransaction: %', givenPartnerNumber || givenMemberNumberSuffix;
insert
into hs_office_coopassetstransaction(uuid, membershipuuid, transactiontype, valuedate, assetvalue, reference, comment)
values
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenMembershipNumber||'-1', 'initial deposit'),
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenMembershipNumber||'-2', 'partial disbursal'),
(uuid_generate_v4(), membership.uuid, 'ADJUSTMENT', '2022-10-20', 128.00, 'ref '||givenMembershipNumber||'-3', 'some adjustment');
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit'),
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal'),
(uuid_generate_v4(), membership.uuid, 'ADJUSTMENT', '2022-10-20', 128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some adjustment');
end; $$;
--//
@ -37,8 +45,8 @@ end; $$;
do language plpgsql $$
begin
call createHsOfficeCoopAssetsTransactionTestData(10001);
call createHsOfficeCoopAssetsTransactionTestData(10002);
call createHsOfficeCoopAssetsTransactionTestData(10003);
call createHsOfficeCoopAssetsTransactionTestData(10001, '01');
call createHsOfficeCoopAssetsTransactionTestData(10002, '02');
call createHsOfficeCoopAssetsTransactionTestData(10003, '03');
end;
$$;

View File

@ -75,8 +75,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
void globalAdmin_canFindCoopAssetsTransactionsByMemberNumber() {
hsh-michaelhoennig marked this conversation as resolved Outdated

ohne "Suffix" im Namen

ohne "Suffix" im Namen
context.define("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10002)
.get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000202);
RestAssured // @formatter:off
.given()
@ -93,21 +92,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"
}
]
@ -115,11 +114,10 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
}
@Test
void globalAdmin_canFindCoopAssetsTransactionsByMemberNumberAndDateRange() {
void globalAdmin_canFindCoopAssetsTransactionsByMembershipUuidAndDateRange() {
hsh-michaelhoennig marked this conversation as resolved Outdated

ohne "Suffix" im Namen

ohne "Suffix" im Namen
context.define("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10002)
.get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000202);
RestAssured // @formatter:off
.given()
@ -137,7 +135,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
"transactionType": "DISBURSAL",
"assetValue": -128.00,
"valueDate": "2021-09-01",
"reference": "ref 10002-2",
"reference": "ref 1000202-2",
"comment": "partial disbursal"
}
]
@ -153,8 +151,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
void globalAdmin_canAddCoopAssetsTransaction() {
context.define("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10001)
.get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
final var location = RestAssured // @formatter:off
.given()
@ -199,8 +196,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
void globalAdmin_canNotCancelMoreAssetsThanCurrentlySubscribed() {
context.define("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10001)
.get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
final var location = RestAssured // @formatter:off
.given()

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 toShortStringContainsOnlyMemberNumberAndSharesCountOnly() {
void toShortStringContainsOnlyMemberNumberSuffixAndSharesCountOnly() {
final var result = givenCoopAssetTransaction.toShortString();
assertThat(result).isEqualTo("300001+128.00");
assertThat(result).isEqualTo("1000101+128.00");
}
@Test

View File

@ -62,8 +62,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
// given
context("superuser-alex@hostsharing.net");
final var count = coopAssetsTransactionRepo.count();
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10001)
.get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
// when
final var result = attempt(em, () -> {
@ -96,9 +95,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
// when
attempt(em, () -> {
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(
null,
10001).get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000101);
final var newCoopAssetsTransaction = HsOfficeCoopAssetsTransactionEntity.builder()
.membership(givenMembership)
.transactionType(HsOfficeCoopAssetsTransactionType.DEPOSIT)
@ -117,7 +114,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));
}
@ -144,25 +141,24 @@ 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
public void globalAdmin_canViewCoopAssetsTransactions_filteredByMembershipUuid() {
// given
context("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10002)
.get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000202);
// when
final var result = coopAssetsTransactionRepo.findCoopAssetsTransactionByOptionalMembershipUuidAndDateRange(
@ -173,17 +169,16 @@ 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
public void globalAdmin_canViewCoopAssetsTransactions_filteredByMembershipUuidAndValueDateRange() {
// given
context("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10002)
.get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000202);
// when
final var result = coopAssetsTransactionRepo.findCoopAssetsTransactionByOptionalMembershipUuidAndDateRange(
@ -194,7 +189,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
@ -211,9 +206,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)");
}
}
@ -232,8 +227,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

@ -75,7 +75,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest {
void globalAdmin_canFindCoopSharesTransactionsByMemberNumber() {
hsh-michaelhoennig marked this conversation as resolved Outdated

ohne "Suffix" im Namen

ohne "Suffix" im Namen
context.define("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10002).get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000202);
RestAssured // @formatter:off
.given().header("current-user", "superuser-alex@hostsharing.net").port(port).when().get("http://localhost/api/hs/office/coopsharestransactions?membershipUuid=" + givenMembership.getUuid()).then().log().all().assertThat().statusCode(200).contentType("application/json").body("", lenientlyEquals("""
@ -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"
}
]
@ -106,19 +106,20 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest {
}
@Test
void globalAdmin_canFindCoopSharesTransactionsByMemberNumberAndDateRange() {
void globalAdmin_canFindCoopSharesTransactionsByMembershipUuidAndDateRange() {
context.define("superuser-alex@hostsharing.net");
final var givenMembership = membershipRepo.findMembershipsByOptionalPartnerUuidAndOptionalMemberNumber(null, 10002).get(0);
final var givenMembership = membershipRepo.findMembershipByMemberNumber(1000202);
RestAssured // @formatter:off
.given().header("current-user", "superuser-alex@hostsharing.net").port(port).when().get("http://localhost/api/hs/office/coopsharestransactions?membershipUuid=" + givenMembership.getUuid() + "&fromValueDate=2020-01-01&toValueDate=2021-12-31").then().log().all().assertThat().statusCode(200).contentType("application/json").body("", lenientlyEquals("""
.given().header("current-user", "superuser-alex@hostsharing.net").port(port).when()
.get("http://localhost/api/hs/office/coopsharestransactions?membershipUuid=" + givenMembership.getUuid() + "&fromValueDate=2020-01-01&toValueDate=2021-12-31").then().log().all().assertThat().statusCode(200).contentType("application/json").body("", lenientlyEquals("""
[