From c70705a2e6e914822ee76b9233e88b75dfa4b241 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 24 Jan 2024 13:23:21 +0100 Subject: [PATCH] TODO cleanup --- .../HsOfficeCoopSharesTransactionEntity.java | 3 +- .../membership/HsOfficeMembershipEntity.java | 1 - .../changelog/223-hs-office-partner-rbac.sql | 1 - .../318-hs-office-coopshares-test-data.sql | 2 +- ...ceCoopSharesTransactionEntityUnitTest.java | 4 +-- ...iceMembershipControllerAcceptanceTest.java | 26 ++++++--------- .../hs/office/migration/ImportOfficeData.java | 32 +++++++++---------- 7 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java index 22cecc55..e2ac5e6f 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java @@ -2,7 +2,6 @@ package net.hostsharing.hsadminng.hs.office.coopshares; import lombok.*; import net.hostsharing.hsadminng.errors.DisplayName; -import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.hs.office.migration.HasUuid; import net.hostsharing.hsadminng.stringify.Stringify; @@ -77,6 +76,6 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, HasUu @Override public String toShortString() { - return "%s%+d".formatted(getMemberNumber(), shareCount); + return "M-%s%+d".formatted(getMemberNumber(), shareCount); } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java index 25bb412a..355b79a9 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java @@ -15,7 +15,6 @@ 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.*; diff --git a/src/main/resources/db/changelog/223-hs-office-partner-rbac.sql b/src/main/resources/db/changelog/223-hs-office-partner-rbac.sql index 852ed8ad..97079877 100644 --- a/src/main/resources/db/changelog/223-hs-office-partner-rbac.sql +++ b/src/main/resources/db/changelog/223-hs-office-partner-rbac.sql @@ -165,7 +165,6 @@ execute procedure hsOfficePartnerRbacRolesTrigger(); --changeset hs-office-partner-rbac-IDENTITY-VIEW:1 endDelimiter:--// -- ---------------------------------------------------------------------------- call generateRbacIdentityView('hs_office_partner', $idName$ - -- TODO: simplify by using just partnerNumber for the essential part partnerNumber || ':' || (select idName from hs_office_person_iv p where p.uuid = target.personuuid) || '-' || diff --git a/src/main/resources/db/changelog/318-hs-office-coopshares-test-data.sql b/src/main/resources/db/changelog/318-hs-office-coopshares-test-data.sql index 2bef88af..c3d2bf98 100644 --- a/src/main/resources/db/changelog/318-hs-office-coopshares-test-data.sql +++ b/src/main/resources/db/changelog/318-hs-office-coopshares-test-data.sql @@ -10,7 +10,7 @@ */ create or replace procedure createHsOfficeCoopSharesTransactionTestData( givenPartnerNumber numeric, - givenMemberNumberSuffix varchar -- TODO char(2)? + givenMemberNumberSuffix char(2) ) language plpgsql as $$ declare diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java index 862c593e..0170e1d8 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java @@ -29,7 +29,7 @@ class HsOfficeCoopSharesTransactionEntityUnitTest { void toShortStringContainsOnlyMemberNumberAndShareCountOnly() { final var result = givenCoopSharesTransaction.toShortString(); - assertThat(result).isEqualTo("1000101+4"); + assertThat(result).isEqualTo("M-1000101+4"); } @Test @@ -43,6 +43,6 @@ class HsOfficeCoopSharesTransactionEntityUnitTest { void toShortStringEmptyTransactionDoesNotThrowException() { final var result = givenEmptyCoopSharesTransaction.toShortString(); - assertThat(result).isEqualTo("null+0"); + assertThat(result).isEqualTo("M-null+0"); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java index 0a96b732..c46fe77e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java @@ -11,7 +11,6 @@ import net.hostsharing.test.Accepts; import net.hostsharing.test.JpaAttempt; import org.json.JSONException; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -37,6 +36,8 @@ import static org.hamcrest.Matchers.*; @Transactional class HsOfficeMembershipControllerAcceptanceTest { + private static String TEMP_MEMBER_NUMBER_SUFFIX = "90"; + @LocalServerPort private Integer port; @@ -61,8 +62,6 @@ class HsOfficeMembershipControllerAcceptanceTest { @PersistenceContext EntityManager em; - private static int tempMemberNumberSuffix = 90; // TODO: check if we even need multiple distinct values - @Nested @Accepts({ "Membership:F(Find)" }) class ListMemberships { @@ -185,9 +184,8 @@ class HsOfficeMembershipControllerAcceptanceTest { context.define("superuser-alex@hostsharing.net"); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); - final var givenMemberSuffixNumber = ++tempMemberNumberSuffix; - final var givenMemberSuffix = toPaddedSuffix(givenMemberSuffixNumber); - final var expectedMemberNumber = givenPartner.getPartnerNumber()*100+givenMemberSuffixNumber; + final var givenMemberSuffix = TEMP_MEMBER_NUMBER_SUFFIX; + final var expectedMemberNumber = Integer.parseInt(givenPartner.getPartnerNumber() + TEMP_MEMBER_NUMBER_SUFFIX); final var location = RestAssured // @formatter:off .given() @@ -503,7 +501,7 @@ class HsOfficeMembershipControllerAcceptanceTest { .uuid(UUID.randomUUID()) .partner(givenPartner) .mainDebitor(givenDebitor) - .memberNumberSuffix(toPaddedSuffix(++tempMemberNumberSuffix)) + .memberNumberSuffix(TEMP_MEMBER_NUMBER_SUFFIX) .validity(Range.closedInfinite(LocalDate.parse("2022-11-01"))) .reasonForTermination(NONE) .membershipFeeBillable(true) @@ -513,19 +511,15 @@ class HsOfficeMembershipControllerAcceptanceTest { }).assertSuccessful().returnedValue(); } - private String toPaddedSuffix(final int numericSuffix) { - return String.format("%02d", numericSuffix); - } - - @BeforeEach @AfterEach void cleanup() { jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net", null); - final var query = em.createQuery("DELETE FROM HsOfficeMembershipEntity m WHERE m.memberNumberSuffix >= '90'"); - if ( query.executeUpdate() > 0 ) { - query.toString(); - } + final var query = em.createQuery( + "DELETE FROM HsOfficeMembershipEntity m WHERE m.memberNumberSuffix >= '%s'" + .formatted(TEMP_MEMBER_NUMBER_SUFFIX) + ); + query.executeUpdate(); }).assertSuccessful(); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java index 473807eb..78f3c95e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java @@ -176,15 +176,15 @@ public class ImportOfficeData extends ContextBasedTest { assertThat(toFormattedString(contacts)).isEqualTo("{}"); assertThat(toFormattedString(debitors)).isEqualToIgnoringWhitespace(""" { - 17=debitor(1001700: null null, null: mih), - 20=debitor(1002000: null null, null: xyz), - 22=debitor(1102200: null null, null: xxx)} + 17=debitor(D-1001700: null null, null: mih), + 20=debitor(D-1002000: null null, null: xyz), + 22=debitor(D-1102200: null null, null: xxx)} """); assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace(""" { - 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) + 17=Membership(M-1001700, null null, null, D-1001700, [2000-12-06,), NONE), + 20=Membership(M-1002000, null null, null, D-1002000, [2000-12-06,2016-01-01), UNKNOWN), + 22=Membership(M-1102200, null null, null, D-1102200, [2021-04-01,), NONE) } """); } @@ -235,16 +235,16 @@ public class ImportOfficeData extends ContextBasedTest { """); assertThat(toFormattedString(debitors)).isEqualToIgnoringWhitespace(""" { - 17=debitor(1001700: NATURAL Mellies, Michael: mih), - 20=debitor(1002000: LEGAL JM GmbH: xyz), - 22=debitor(1102200: LEGAL Test PS: xxx) + 17=debitor(D-1001700: NATURAL Mellies, Michael: mih), + 20=debitor(D-1002000: LEGAL JM GmbH: xyz), + 22=debitor(D-1102200: LEGAL Test PS: xxx) } """); assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace(""" { - 17=Membership(10017, NATURAL Mellies, Michael, 1001700, [2000-12-06,), NONE), - 20=Membership(10020, LEGAL JM GmbH, 1002000, [2000-12-06,2016-01-01), UNKNOWN), - 22=Membership(11022, LEGAL Test PS, 1102200, [2021-04-01,), NONE) + 17=Membership(M-1001700, NATURAL Mellies, Michael, D-1001700, [2000-12-06,), NONE), + 20=Membership(M-1002000, LEGAL JM GmbH, D-1002000, [2000-12-06,2016-01-01), UNKNOWN), + 22=Membership(M-1102200, LEGAL Test PS, D-1102200, [2021-04-01,), NONE) } """); assertThat(toFormattedString(relationships)).isEqualToIgnoringWhitespace(""" @@ -312,10 +312,10 @@ public class ImportOfficeData extends ContextBasedTest { assertThat(toFormattedString(coopShares)).isEqualToIgnoringWhitespace(""" { - 33443=CoopShareTransaction(10017, 2000-12-06, SUBSCRIPTION, 20, initial share subscription), - 33451=CoopShareTransaction(10020, 2000-12-06, SUBSCRIPTION, 2, initial share subscription), - 33701=CoopShareTransaction(10017, 2005-01-10, SUBSCRIPTION, 40, increase), - 33810=CoopShareTransaction(10020, 2016-12-31, CANCELLATION, 22, membership ended) + 33443=CoopShareTransaction(M-1001700, 2000-12-06, SUBSCRIPTION, 20, initial share subscription), + 33451=CoopShareTransaction(M-1002000, 2000-12-06, SUBSCRIPTION, 2, initial share subscription), + 33701=CoopShareTransaction(M-1001700, 2005-01-10, SUBSCRIPTION, 40, increase), + 33810=CoopShareTransaction(M-1002000, 2016-12-31, CANCELLATION, 22, membership ended) } """); }