From d644e9aef206ac483ea969cc6c380063d5298dce Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 15 Nov 2024 13:46:42 +0100 Subject: [PATCH] add P- tag to partnerNumber in API --- doc/hs-office-data-structure.md | 2 +- .../debitor/HsBookingDebitorEntity.java | 6 ++--- .../hs/booking/item/HsBookingItem.java | 6 ++--- .../hs/booking/project/HsBookingProject.java | 6 ++--- .../hs/hosting/asset/HsHostingAsset.java | 6 ++--- .../HsOfficeBankAccountEntity.java | 6 ++--- .../hs/office/contact/HsOfficeContact.java | 6 ++--- .../HsOfficeCoopAssetsTransactionEntity.java | 6 ++--- .../HsOfficeCoopSharesTransactionEntity.java | 6 ++--- .../office/debitor/HsOfficeDebitorEntity.java | 6 ++--- .../membership/HsOfficeMembershipEntity.java | 6 ++--- .../partner/HsOfficePartnerController.java | 3 ++- .../partner/HsOfficePartnerDetailsEntity.java | 6 ++--- .../office/partner/HsOfficePartnerEntity.java | 6 ++--- .../office/person/HsOfficePersonEntity.java | 6 ++--- .../hs/office/relation/HsOfficeRelation.java | 6 ++--- .../HsOfficeSepaMandateEntity.java | 6 ++--- .../{stringify => repr}/Stringify.java | 2 +- .../{stringify => repr}/Stringifyable.java | 2 +- .../hsadminng/repr/TaggedNumber.java | 15 ++++++++++++ .../hs-office/hs-office-partner-schemas.yaml | 16 ++++++------- ...OfficePartnerControllerAcceptanceTest.java | 24 +++++++++---------- .../HsOfficePartnerControllerRestTest.java | 4 ++-- .../scenarios/HsOfficeScenarioTests.java | 6 ++--- .../rbac/test/StringifyUnitTest.java | 6 ++--- .../hsadminng/repr/TaggedNumberUnitTest.java | 22 +++++++++++++++++ 26 files changed, 115 insertions(+), 77 deletions(-) rename src/main/java/net/hostsharing/hsadminng/{stringify => repr}/Stringify.java (99%) rename src/main/java/net/hostsharing/hsadminng/{stringify => repr}/Stringifyable.java (59%) create mode 100644 src/main/java/net/hostsharing/hsadminng/repr/TaggedNumber.java create mode 100644 src/test/java/net/hostsharing/hsadminng/repr/TaggedNumberUnitTest.java diff --git a/doc/hs-office-data-structure.md b/doc/hs-office-data-structure.md index b84264d0..cce17510 100644 --- a/doc/hs-office-data-structure.md +++ b/doc/hs-office-data-structure.md @@ -64,7 +64,7 @@ classDiagram } class partner-MeierGmbH { - +Numeric partnerNumber: 12345 + +Numeric partnerNumber: P-12345 +Relation partnerRel } partner-MeierGmbH *-- rel-MeierGmbH diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java index 69932d5b..a09a33bc 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java @@ -5,8 +5,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import net.hostsharing.hsadminng.errors.DisplayAs; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -14,7 +14,7 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import java.util.UUID; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; // a partial HsOfficeDebitorEntity to reduce the number of SQL queries to load the entity @Entity diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java index 07d85007..2d63df74 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java @@ -15,8 +15,8 @@ import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.CascadeType; @@ -45,7 +45,7 @@ import static java.util.Optional.ofNullable; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.lowerInclusiveFromPostgresDateRange; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.upperInclusiveFromPostgresDateRange; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java index 742cf88f..90235732 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java @@ -4,14 +4,14 @@ import lombok.*; import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import java.util.UUID; import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java index e89e962f..d327f354 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java @@ -15,8 +15,8 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.CascadeType; @@ -42,7 +42,7 @@ import java.util.Optional; import java.util.UUID; import static java.util.Collections.emptyMap; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java index 5be09962..edc26010 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java @@ -5,8 +5,8 @@ import lombok.experimental.FieldNameConstants; import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import java.io.IOException; @@ -16,7 +16,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Permission.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectReference.UserRole.CREATOR; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "bankaccount_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java index a4267f53..dc5bca3e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java @@ -12,8 +12,8 @@ import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Type; @@ -27,7 +27,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java index 18e12a11..cc2e504b 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java @@ -10,8 +10,8 @@ import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; @@ -31,7 +31,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.ADMIN; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.AGENT; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "coopassettx_rv") 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 54787ad7..b5329cea 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 @@ -10,8 +10,8 @@ import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import java.io.IOException; @@ -29,7 +29,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.ADMIN; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.AGENT; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "coopsharetx_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java index 2c339605..e7e25ea9 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java @@ -14,8 +14,8 @@ import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.JoinFormula; import org.hibernate.annotations.NotFound; @@ -51,7 +51,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.fetchedBySql; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "debitor_rv") 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 893623d7..a0740b8b 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 @@ -13,8 +13,8 @@ import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.Column; @@ -53,7 +53,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.OWNER; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.TENANT; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.fetchedBySql; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "membership_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java index 1aefafa2..c39dcd49 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.UUID; import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.EX_PARTNER; +import static net.hostsharing.hsadminng.repr.TaggedNumber.cropTag; @RestController @@ -150,7 +151,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi { private HsOfficePartnerEntity createPartnerEntity(final HsOfficePartnerInsertResource body) { final var entityToSave = new HsOfficePartnerEntity(); - entityToSave.setPartnerNumber(body.getPartnerNumber()); + entityToSave.setPartnerNumber(cropTag(HsOfficePartnerEntity.PARTNER_NUMBER_TAG, body.getPartnerNumber())); entityToSave.setPartnerRel(persistPartnerRel(body.getPartnerRel())); entityToSave.setDetails(mapper.map(body.getDetails(), HsOfficePartnerDetailsEntity.class)); return entityToSave; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java index e6e43996..ca8c391b 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntity.java @@ -5,8 +5,8 @@ import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import java.io.IOException; @@ -17,7 +17,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.GLOBAL; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Permission.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "partner_details_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java index b91f3ab1..f7de08c8 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java @@ -14,8 +14,8 @@ import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; @@ -33,7 +33,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "partner_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java index f28bd4ab..da14e1c4 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonEntity.java @@ -6,8 +6,8 @@ import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.apache.commons.lang3.StringUtils; import jakarta.persistence.*; @@ -19,7 +19,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Permission.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectReference.UserRole.CREATOR; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; // TODO.refa: split HsOfficePersonEntity into Real+Rbac-Entity @Entity diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelation.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelation.java index 2a4fbd42..c1b4ad8c 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelation.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelation.java @@ -6,14 +6,14 @@ import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import jakarta.persistence.Column; import java.util.UUID; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java index f781212e..94ac21e2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java @@ -9,8 +9,8 @@ import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.*; @@ -30,7 +30,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectRefer import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "sepamandate_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java b/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java similarity index 99% rename from src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java rename to src/main/java/net/hostsharing/hsadminng/repr/Stringify.java index 269b0c69..aaa3ea73 100644 --- a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java +++ b/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.stringify; +package net.hostsharing.hsadminng.repr; import net.hostsharing.hsadminng.errors.DisplayAs; diff --git a/src/main/java/net/hostsharing/hsadminng/stringify/Stringifyable.java b/src/main/java/net/hostsharing/hsadminng/repr/Stringifyable.java similarity index 59% rename from src/main/java/net/hostsharing/hsadminng/stringify/Stringifyable.java rename to src/main/java/net/hostsharing/hsadminng/repr/Stringifyable.java index 70877dc9..397a6c2b 100644 --- a/src/main/java/net/hostsharing/hsadminng/stringify/Stringifyable.java +++ b/src/main/java/net/hostsharing/hsadminng/repr/Stringifyable.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.stringify; +package net.hostsharing.hsadminng.repr; public interface Stringifyable { diff --git a/src/main/java/net/hostsharing/hsadminng/repr/TaggedNumber.java b/src/main/java/net/hostsharing/hsadminng/repr/TaggedNumber.java new file mode 100644 index 00000000..ab445ec0 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/repr/TaggedNumber.java @@ -0,0 +1,15 @@ +package net.hostsharing.hsadminng.repr; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class TaggedNumber { + + public static Integer cropTag(final String tag, final String taggedNumber) { + return taggedNumber.startsWith(tag) ? Integer.valueOf(taggedNumber.substring(tag.length())) : invalidTag(tag, taggedNumber); + } + + private static Integer invalidTag(final String tag, final String taggedNumber) { + throw new IllegalArgumentException("Expected " + tag + "... but got: " + taggedNumber); + } +} diff --git a/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml index bd327e10..2fd3d39b 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml @@ -10,10 +10,10 @@ components: type: string format: uuid partnerNumber: - type: integer - format: int8 - minimum: 10000 - maximum: 99999 + type: string + minLength: 7 + maxLength: 7 + pattern: 'P-[0-9]{5}' partnerRel: $ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation' details: @@ -86,10 +86,10 @@ components: type: object properties: partnerNumber: - type: integer - format: int8 - minimum: 10000 - maximum: 99999 + type: string + minLength: 7 + maxLength: 7 + pattern: 'P-[0-9]{5}' partnerRel: $ref: '#/components/schemas/HsOfficePartnerRelInsert' details: diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java index c2ec1271..9f2f3318 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java @@ -71,11 +71,11 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType("application/json") .body("", lenientlyEquals(""" [ - { partnerNumber: 10001 }, - { partnerNumber: 10002 }, - { partnerNumber: 10003 }, - { partnerNumber: 10004 }, - { partnerNumber: 10010 } + { partnerNumber: "P-10001" }, + { partnerNumber: "P-10002" }, + { partnerNumber: "P-10003" }, + { partnerNumber: "P-10004" }, + { partnerNumber: "P-10010" } ] """)); // @formatter:on @@ -100,7 +100,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20002", + "partnerNumber": "P-20002", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -123,7 +123,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body("", lenientlyEquals(""" { - "partnerNumber": 20002, + "partnerNumber": "P-20002", "partnerRel": { "anchor": { "tradeName": "Hostsharing eG" }, "holder": { "tradeName": "Third OHG" }, @@ -159,7 +159,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20003", + "partnerNumber": "P-20003", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -197,7 +197,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20004", + "partnerNumber": "P-20004", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -247,7 +247,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType("application/json") .body("", lenientlyEquals(""" { - "partnerNumber": 10001, + "partnerNumber": "P-10001", "partnerRel": { "anchor": { "tradeName": "Hostsharing eG" }, "holder": { "tradeName": "First GmbH" }, @@ -320,7 +320,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20011", + "partnerNumber": "P-20011", "partnerRel.uuid": "%s", "details": { "registrationOffice": "Temp Registergericht Aurich", @@ -339,7 +339,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body("", lenientlyEquals(""" { - "partnerNumber": 20011, + "partnerNumber": "P-20011", "partnerRel": { "anchor": { "tradeName": "Hostsharing eG" }, "holder": { "tradeName": "Third OHG" }, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java index 889e776f..74270f69 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java @@ -99,7 +99,7 @@ class HsOfficePartnerControllerRestTest { .contentType(MediaType.APPLICATION_JSON) .content(""" { - "partnerNumber": "20002", + "partnerNumber": "P-20002", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -136,7 +136,7 @@ class HsOfficePartnerControllerRestTest { .contentType(MediaType.APPLICATION_JSON) .content(""" { - "partnerNumber": "20002", + "partnerNumber": "P-20002", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java index 13af695b..ab5419ae 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java @@ -58,7 +58,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Produces(explicitly = "Partner: P-31010 - Test AG", implicitly = {"Person: Test AG", "Contact: Test AG - Hamburg"}) void shouldCreateLegalPersonAsPartner() { new CreatePartner(this) - .given("partnerNumber", 31010) + .given("partnerNumber", "P-31010") .given("personType", "LEGAL_PERSON") .given("tradeName", "Test AG") .given("contactCaption", "Test AG - Hamburg") @@ -80,7 +80,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Produces(explicitly = "Partner: P-31011 - Michelle Matthieu", implicitly = {"Person: Michelle Matthieu", "Contact: Michelle Matthieu"}) void shouldCreateNaturalPersonAsPartner() { new CreatePartner(this) - .given("partnerNumber", 31011) + .given("partnerNumber", "P-31011") .given("personType", "NATURAL_PERSON") .given("givenName", "Michelle") .given("familyName", "Matthieu") @@ -148,7 +148,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Order(1090) void shouldDeletePartner() { new DeletePartner(this) - .given("partnerNumber", 31020) + .given("partnerNumber", "P-31020") .doRun(); } diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java b/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java index 0267871f..1d22056d 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java @@ -2,13 +2,13 @@ package net.hostsharing.hsadminng.rbac.test; import lombok.*; import lombok.experimental.FieldNameConstants; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.junit.jupiter.api.Test; import java.util.UUID; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; import static org.assertj.core.api.Assertions.assertThat; class StringifyUnitTest { diff --git a/src/test/java/net/hostsharing/hsadminng/repr/TaggedNumberUnitTest.java b/src/test/java/net/hostsharing/hsadminng/repr/TaggedNumberUnitTest.java new file mode 100644 index 00000000..ca373f38 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/repr/TaggedNumberUnitTest.java @@ -0,0 +1,22 @@ +package net.hostsharing.hsadminng.repr; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +class TaggedNumberUnitTest { + + @Test + void cropsProperTag() { + assertThat(TaggedNumber.cropTag("P-", "P-12345")).isEqualTo(12345); + } + + @Test + void throwsExceptionForImproperTag() { + final var exception = catchThrowable(() -> TaggedNumber.cropTag("P-", "X-12345")); + assertThat(exception).isInstanceOf(IllegalArgumentException.class); + assertThat(exception.getMessage()).isEqualTo("Expected P-... but got: X-12345"); + } + +}