From 457fe37306dc182dc0cc7b79d3db75d6d5c55b3f Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 2 Aug 2024 13:19:11 +0200 Subject: [PATCH 01/12] introduce HsOfficeRelationRawEntity (WIP) Import working, but not normal tests --- .../partner/HsOfficePartnerController.java | 3 +- .../relation/HsOfficeRelationController.java | 2 +- .../relation/HsOfficeRelationEntity.java | 10 +- .../relation/HsOfficeRelationRawEntity.java | 25 ++++ .../relation/HsOfficeRelationRbacEntity.java | 126 ++++++++++++++++++ .../hsadminng/stringify/Stringify.java | 13 +- .../hs/migration/ImportOfficeData.java | 3 +- ...OfficeDebitorControllerAcceptanceTest.java | 6 +- .../HsOfficeDebitorEntityPatcherUnitTest.java | 7 +- .../HsOfficeDebitorEntityUnitTest.java | 3 +- ...fficeDebitorRepositoryIntegrationTest.java | 11 +- .../office/debitor/TestHsOfficeDebitor.java | 4 +- ...OfficePartnerControllerAcceptanceTest.java | 3 +- .../HsOfficePartnerControllerRestTest.java | 4 +- .../HsOfficePartnerEntityPatcherUnitTest.java | 7 +- .../HsOfficePartnerEntityUnitTest.java | 4 +- ...fficePartnerRepositoryIntegrationTest.java | 5 +- .../office/partner/TestHsOfficePartner.java | 4 +- ...fficeRelationControllerAcceptanceTest.java | 2 +- ...HsOfficeRelationEntityPatcherUnitTest.java | 2 +- .../HsOfficeRelationEntityUnitTest.java | 4 +- ...ficeRelationRepositoryIntegrationTest.java | 6 +- 22 files changed, 210 insertions(+), 44 deletions(-) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRawEntity.java create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java 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 1b9707f7..656a959c 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 @@ -10,6 +10,7 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartne import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRelInsertResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.mapper.Mapper; @@ -156,7 +157,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi { } private HsOfficeRelationEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) { - final var entity = new HsOfficeRelationEntity(); + final var entity = new HsOfficeRelationRbacEntity(); entity.setType(HsOfficeRelationType.PARTNER); entity.setAnchor(ref(HsOfficePersonEntity.class, resource.getAnchorUuid())); entity.setHolder(ref(HsOfficePersonEntity.class, resource.getHolderUuid())); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java index e1f80148..8fc6a0df 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java @@ -68,7 +68,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { context.define(currentUser, assumedRoles); - final var entityToSave = new HsOfficeRelationEntity(); + final var entityToSave = new HsOfficeRelationRbacEntity(); entityToSave.setType(HsOfficeRelationType.valueOf(body.getType())); entityToSave.setMark(body.getMark()); entityToSave.setAnchor(holderRepo.findByUuid(body.getAnchorUuid()).orElseThrow( diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java index e7ab353b..fe8144c6 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java @@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.hs.office.relation; import lombok.*; import lombok.experimental.FieldNameConstants; +import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; @@ -15,6 +16,7 @@ import jakarta.persistence.Column; import java.io.IOException; import java.util.UUID; +import static jakarta.persistence.InheritanceType.TABLE_PER_CLASS; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.*; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inOtherCases; @@ -28,14 +30,14 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetche import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Entity -@Table(name = "hs_office_relation_rv") +@Inheritance(strategy = TABLE_PER_CLASS) @Getter @Setter -@Builder(toBuilder = true) +@SuperBuilder @NoArgsConstructor @AllArgsConstructor @FieldNameConstants -public class HsOfficeRelationEntity implements RbacObject, Stringifyable { +public abstract class HsOfficeRelationEntity implements RbacObject, Stringifyable { private static Stringify toString = stringify(HsOfficeRelationEntity.class, "rel") .withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor) @@ -94,6 +96,8 @@ public class HsOfficeRelationEntity implements RbacObject, Stringifyable { return toShortString.apply(this); } + public abstract HsOfficeRelationEntityBuilder toBuilder(); + public static RbacView rbac() { return rbacViewFor("relation", HsOfficeRelationEntity.class) .withIdentityView(SQL.projection(""" diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRawEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRawEntity.java new file mode 100644 index 00000000..26ca463b --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRawEntity.java @@ -0,0 +1,25 @@ +package net.hostsharing.hsadminng.hs.office.relation; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + + +@Entity +@Table(name = "hs_office_relation") +//@DiscriminatorValue("0") +@SuperBuilder +@NoArgsConstructor +@Getter +@Setter +public class HsOfficeRelationRawEntity extends HsOfficeRelationEntity { + + @Override + public HsOfficeRelationEntityBuilder toBuilder() { + return null; + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java new file mode 100644 index 00000000..1df7b92c --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java @@ -0,0 +1,126 @@ +package net.hostsharing.hsadminng.hs.office.relation; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; +import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; +import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import java.io.IOException; + +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inOtherCases; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingDefaultCase; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Nullable.NOT_NULL; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.DELETE; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.INSERT; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.SELECT; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.UPDATE; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.ADMIN; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.AGENT; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.OWNER; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.REFERRER; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.TENANT; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetchedByDependsOnColumn; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; + +@Entity +@Table(name = "hs_office_relation_rv") +@SuperBuilder +@NoArgsConstructor +@Getter +@Setter +public class HsOfficeRelationRbacEntity extends HsOfficeRelationEntity { + + @Override + public HsOfficeRelationRbacEntityBuilder toBuilder() { + return null; + } + + public static RbacView rbac() { + return rbacViewFor("relation", HsOfficeRelationRbacEntity.class) + .withIdentityView(SQL.projection(""" + (select idName from hs_office_person_iv p where p.uuid = anchorUuid) + || '-with-' || target.type || '-' + || (select idName from hs_office_person_iv p where p.uuid = holderUuid) + """)) + .withRestrictedViewOrderBy(SQL.expression( + "(select idName from hs_office_person_iv p where p.uuid = target.holderUuid)")) + .withUpdatableColumns("contactUuid") + .importEntityAlias("anchorPerson", HsOfficePersonEntity.class, usingDefaultCase(), + dependsOnColumn("anchorUuid"), + directlyFetchedByDependsOnColumn(), + NOT_NULL) + .importEntityAlias("holderPerson", HsOfficePersonEntity.class, usingDefaultCase(), + dependsOnColumn("holderUuid"), + directlyFetchedByDependsOnColumn(), + NOT_NULL) + .importEntityAlias("contact", HsOfficeContactEntity.class, usingDefaultCase(), + dependsOnColumn("contactUuid"), + directlyFetchedByDependsOnColumn(), + NOT_NULL) + .switchOnColumn( + "type", + inCaseOf("REPRESENTATIVE", then -> { + then.createRole(OWNER, (with) -> { + with.owningUser(CREATOR); + with.incomingSuperRole(GLOBAL, ADMIN); + with.incomingSuperRole("holderPerson", ADMIN); + with.permission(DELETE); + }) + .createSubRole(ADMIN, (with) -> { + with.outgoingSubRole("anchorPerson", OWNER); + with.permission(UPDATE); + }) + .createSubRole(AGENT, (with) -> { + with.incomingSuperRole("anchorPerson", ADMIN); + }) + .createSubRole(TENANT, (with) -> { + with.incomingSuperRole("contact", ADMIN); + with.outgoingSubRole("anchorPerson", REFERRER); + with.outgoingSubRole("holderPerson", REFERRER); + with.outgoingSubRole("contact", REFERRER); + with.permission(SELECT); + }); + }), + // inCaseOf("DEBITOR", then -> {}), TODO.spec: needs to be defined + inOtherCases(then -> { + then.createRole(OWNER, (with) -> { + with.owningUser(CREATOR); + with.incomingSuperRole(GLOBAL, ADMIN); + with.incomingSuperRole("anchorPerson", ADMIN); + with.permission(DELETE); + }) + .createSubRole(ADMIN, (with) -> { + with.permission(UPDATE); + }) + .createSubRole(AGENT, (with) -> { + // TODO.rbac: we need relation:PROXY, to allow changing the relation contact. + // the alternative would be to move this to the relation:ADMIN role, + // but then the partner holder person could update the partner relation itself, + // see partner entity. + with.incomingSuperRole("holderPerson", ADMIN); + }) + .createSubRole(TENANT, (with) -> { + with.incomingSuperRole("contact", ADMIN); + with.outgoingSubRole("anchorPerson", REFERRER); + with.outgoingSubRole("holderPerson", REFERRER); + with.outgoingSubRole("contact", REFERRER); + with.permission(SELECT); + }); + })) + .toRole("anchorPerson", ADMIN).grantPermission(INSERT); + } + + public static void main(String[] args) throws IOException { + rbac().generateWithBaseFileName("5-hs-office/503-relation/5033-hs-office-relation-rbac"); + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java b/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java index b410465f..3ad80cde 100644 --- a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java +++ b/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java @@ -8,11 +8,11 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import static java.lang.Boolean.TRUE; +import static java.util.Optional.ofNullable; public final class Stringify { @@ -32,11 +32,14 @@ public final class Stringify { public Stringify using(final Class subClass) { //noinspection unchecked - return (Stringify) new Stringify(subClass, null) + final var stringify = new Stringify(subClass, null) .withIdProp(cast(idProp)) .withProps(cast(props)) - .withSeparator(separator) - .quotedValues(quotedValues); + .withSeparator(separator); + if (quotedValues != null) { + stringify.quotedValues(quotedValues); + } + return stringify; } private Stringify(final Class clazz, final String name) { @@ -96,7 +99,7 @@ public final class Stringify { } private String propName(final PropertyValue propVal, final String delimiter) { - return Optional.ofNullable(propVal.prop.name).map(v -> v + delimiter).orElse(""); + return ofNullable(propVal.prop.name).map(v -> v + delimiter).orElse(""); } private String optionallyQuoted(final PropertyValue propVal) { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java index dd1f7d2b..0846d6bd 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java @@ -15,6 +15,7 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRawEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; @@ -1057,7 +1058,7 @@ public class ImportOfficeData extends CsvDataImport { final HsOfficePersonEntity anchor, final HsOfficePersonEntity holder, final HsOfficeContactEntity contact) { - final var rel = HsOfficeRelationEntity.builder() + final var rel = HsOfficeRelationRawEntity.builder() .anchor(anchor) .holder(holder) .contact(contact) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java index 2fee9a31..564f1d37 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java @@ -8,7 +8,7 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; @@ -274,7 +274,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu final var givenDebitorRelUUid = jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); - return relRepo.save(HsOfficeRelationEntity.builder() + return relRepo.save(HsOfficeRelationRbacEntity.builder() .type(DEBITOR) .anchor(givenPartner.getPartnerRel().getHolder()) .holder(givenBillingPerson) @@ -726,7 +726,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu .debitorNumberSuffix(nextDebitorSuffix()) .billable(true) .debitorRel( - HsOfficeRelationEntity.builder() + HsOfficeRelationRbacEntity.builder() .type(DEBITOR) .anchor(givenPartner.getPartnerRel().getHolder()) .holder(givenPartner.getPartnerRel().getHolder()) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java index 82e4d303..cbc3a2f1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java @@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.office.debitor; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInstance; @@ -44,7 +45,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); - private final HsOfficeRelationEntity givenInitialDebitorRel = HsOfficeRelationEntity.builder() + private final HsOfficeRelationEntity givenInitialDebitorRel = HsOfficeRelationRbacEntity.builder() .uuid(INITIAL_DEBITOR_REL_UUID) .build(); @@ -57,7 +58,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< @BeforeEach void initMocks() { lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> - HsOfficeRelationEntity.builder().uuid(invocation.getArgument(1)).build()); + HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation -> HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build()); } @@ -142,7 +143,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< } private HsOfficeRelationEntity newDebitorRel(final UUID uuid) { - return HsOfficeRelationEntity.builder() + return HsOfficeRelationRbacEntity.builder() .uuid(uuid) .build(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java index e1250775..1f645d33 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java @@ -5,13 +5,14 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; class HsOfficeDebitorEntityUnitTest { - private HsOfficeRelationEntity givenDebitorRel = HsOfficeRelationEntity.builder() + private HsOfficeRelationEntity givenDebitorRel = HsOfficeRelationRbacEntity.builder() .anchor(HsOfficePersonEntity.builder() .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("some partner trade name") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java index fabc93e7..2e1f7d39 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java @@ -6,6 +6,7 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; @@ -91,7 +92,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var newDebitor = HsOfficeDebitorEntity.builder() .partner(givenPartner) .debitorNumberSuffix("21") - .debitorRel(HsOfficeRelationEntity.builder() + .debitorRel(HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenPartnerPerson) @@ -124,7 +125,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var result = attempt(em, () -> { final var newDebitor = HsOfficeDebitorEntity.builder() .debitorNumberSuffix("21") - .debitorRel(HsOfficeRelationEntity.builder() + .debitorRel(HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenPartnerPerson) @@ -159,7 +160,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("fourth contact")); final var newDebitor = HsOfficeDebitorEntity.builder() .debitorNumberSuffix("22") - .debitorRel(HsOfficeRelationEntity.builder() + .debitorRel(HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenDebitorPerson) @@ -331,7 +332,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean // when final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - givenDebitor.setDebitorRel(HsOfficeRelationEntity.builder() + givenDebitor.setDebitorRel(HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenNewPartnerPerson) .holder(givenNewBillingPerson) @@ -616,7 +617,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var newDebitor = HsOfficeDebitorEntity.builder() .partner(givenPartner) .debitorNumberSuffix("20") - .debitorRel(HsOfficeRelationEntity.builder() + .debitorRel(HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenPartnerPerson) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java index b8ddf8b5..febb5c8e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor; import lombok.experimental.UtilityClass; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT; import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER; @@ -14,7 +14,7 @@ public class TestHsOfficeDebitor { public static final HsOfficeDebitorEntity TEST_DEBITOR = HsOfficeDebitorEntity.builder() .debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX) - .debitorRel(HsOfficeRelationEntity.builder() + .debitorRel(HsOfficeRelationRbacEntity.builder() .holder(HsOfficePersonEntity.builder().build()) .anchor(HsOfficePersonEntity.builder().build()) .contact(TEST_CONTACT) 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 1bf30d14..3a4eaf1b 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 @@ -8,6 +8,7 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; @@ -525,7 +526,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow(); final var givenContact = contactRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow(); - final var partnerRel = new HsOfficeRelationEntity(); + final var partnerRel = new HsOfficeRelationRbacEntity(); partnerRel.setType(HsOfficeRelationType.PARTNER); partnerRel.setAnchor(givenMandantPerson); partnerRel.setHolder(givenPerson); 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 e6e7fb7e..a55695e4 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 @@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.mapper.Mapper; import org.junit.jupiter.api.BeforeEach; @@ -176,7 +176,7 @@ class HsOfficePartnerControllerRestTest { when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0); final UUID givenRelationUuid = UUID.randomUUID(); - when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationEntity.builder() + when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationRbacEntity.builder() .uuid(givenRelationUuid) .build()); when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java index 6cc072b3..878a9302 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java @@ -4,6 +4,7 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInstance; @@ -49,7 +50,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< @BeforeEach void initMocks() { lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> - HsOfficeRelationEntity.builder().uuid(invocation.getArgument(1)).build()); + HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); } @Override @@ -57,7 +58,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< final var entity = HsOfficePartnerEntity.builder() .uuid(INITIAL_PARTNER_UUID) .partnerNumber(12345) - .partnerRel(HsOfficeRelationEntity.builder() + .partnerRel(HsOfficeRelationRbacEntity.builder() .holder(givenInitialPerson) .contact(givenInitialContact) .build()) @@ -90,7 +91,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< } private static HsOfficeRelationEntity newPartnerRel(final UUID uuid) { - final var newPartnerRel = HsOfficeRelationEntity.builder() + final var newPartnerRel = HsOfficeRelationRbacEntity.builder() .uuid(uuid) .build(); return newPartnerRel; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java index dd373e98..54ad1b20 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java @@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import org.junit.jupiter.api.Test; @@ -13,7 +13,7 @@ class HsOfficePartnerEntityUnitTest { private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder() .partnerNumber(12345) - .partnerRel(HsOfficeRelationEntity.builder() + .partnerRel(HsOfficeRelationRbacEntity.builder() .anchor(HsOfficePersonEntity.builder() .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("Hostsharing eG") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java index ecf645d7..5b712087 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java @@ -4,6 +4,7 @@ import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; @@ -112,7 +113,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); - final var newRelation = HsOfficeRelationEntity.builder() + final var newRelation = HsOfficeRelationRbacEntity.builder() .holder(givenPartnerPerson) .type(HsOfficeRelationType.PARTNER) .anchor(givenMandantPerson) @@ -467,7 +468,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike(contact).get(0); - final var partnerRel = HsOfficeRelationEntity.builder() + final var partnerRel = HsOfficeRelationRbacEntity.builder() .holder(givenPartnerPerson) .type(HsOfficeRelationType.PARTNER) .anchor(givenMandantorPerson) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java index 5fa6c156..a9bd0a64 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON; @@ -15,7 +15,7 @@ public class TestHsOfficePartner { return HsOfficePartnerEntity.builder() .partnerNumber(10001) .partnerRel( - HsOfficeRelationEntity.builder() + HsOfficeRelationRbacEntity.builder() .holder(HsOfficePersonEntity.builder() .personType(LEGAL_PERSON) .tradeName("Hostsharing eG") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java index 636975eb..a7909c3a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java @@ -456,7 +456,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike("seventh contact").get(0); - final var newRelation = HsOfficeRelationEntity.builder() + final var newRelation = HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.REPRESENTATIVE) .anchor(givenAnchorPerson) .holder(givenHolderPerson) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java index 823d1c61..fe90e0f1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java @@ -50,7 +50,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< @Override protected HsOfficeRelationEntity newInitialEntity() { - final var entity = new HsOfficeRelationEntity(); + final var entity = new HsOfficeRelationRbacEntity(); entity.setUuid(INITIAL_RELATION_UUID); entity.setType(HsOfficeRelationType.REPRESENTATIVE); entity.setAnchor(givenInitialAnchorPerson); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityUnitTest.java index bf2a7ed3..072d42ef 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityUnitTest.java @@ -20,7 +20,7 @@ class HsOfficeRelationEntityUnitTest { @Test void toStringReturnsAllProperties() { - final var given = HsOfficeRelationEntity.builder() + final var given = HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.SUBSCRIBER) .mark("members-announce") .anchor(anchor) @@ -32,7 +32,7 @@ class HsOfficeRelationEntityUnitTest { @Test void toShortString() { - final var given = HsOfficeRelationEntity.builder() + final var given = HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.REPRESENTATIVE) .anchor(anchor) .holder(holder) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java index f6807b34..7bf9112c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java @@ -76,7 +76,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea // when final var result = attempt(em, () -> { - final var newRelation = HsOfficeRelationEntity.builder() + final var newRelation = HsOfficeRelationRbacEntity.builder() .anchor(givenAnchorPerson) .holder(givenHolderPerson) .type(HsOfficeRelationType.SUBSCRIBER) @@ -113,7 +113,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea .findFirst().orElseThrow(); final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").stream() .findFirst().orElseThrow(); - final var newRelation = HsOfficeRelationEntity.builder() + final var newRelation = HsOfficeRelationRbacEntity.builder() .anchor(givenAnchorPerson) .holder(givenHolderPerson) .type(HsOfficeRelationType.REPRESENTATIVE) @@ -414,7 +414,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike(holderPerson).get(0); final var givenContact = contactRepo.findContactByOptionalCaptionLike(contact).get(0); - final var newRelation = HsOfficeRelationEntity.builder() + final var newRelation = HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.REPRESENTATIVE) .anchor(givenAnchorPerson) .holder(givenHolderPerson) -- 2.39.5 From ab3365941be172823fe1a5148657edd682ffbdf3 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 2 Aug 2024 14:02:42 +0200 Subject: [PATCH 02/12] introduce HsOfficeContactRbacEntity (WIP) Import working, but not normal tests --- .../hs/hosting/asset/HsHostingAsset.java | 4 +- .../hosting/asset/HsHostingAssetEntity.java | 6 +- .../asset/HsHostingAssetEntityPatcher.java | 4 +- .../HostingAssetEntityValidator.java | 4 +- .../contact/HsOfficeContactController.java | 4 +- .../office/contact/HsOfficeContactEntity.java | 39 ++++++++++--- .../contact/HsOfficeContactEntityPatcher.java | 4 +- .../contact/HsOfficeContactRbacEntity.java | 56 +++++++++++++++++++ .../contact/HsOfficeContactRepository.java | 10 ++-- .../partner/HsOfficePartnerController.java | 1 + .../office/partner/HsOfficePartnerEntity.java | 1 + ...y.java => HsOfficeRelationBareEntity.java} | 5 +- .../relation/HsOfficeRelationEntity.java | 4 +- .../HsOfficeRelationEntityPatcher.java | 4 +- .../relation/HsOfficeRelationRbacEntity.java | 4 +- ...sHostingAssetControllerAcceptanceTest.java | 4 +- .../HsHostingAssetEntityPatcherUnitTest.java | 12 ++-- ...ity.java => HsHostingAssetBareEntity.java} | 14 ++--- .../hs/migration/ImportHostingAssets.java | 28 +++++----- .../hs/migration/ImportOfficeData.java | 14 ++--- ...OfficeContactControllerAcceptanceTest.java | 6 +- .../HsOfficeContactEntityPatcherUnitTest.java | 16 +++--- .../HsOfficeContactEntityUnitTest.java | 4 +- ...fficeContactRepositoryIntegrationTest.java | 20 +++---- .../office/contact/TestHsOfficeContact.java | 6 +- .../HsOfficeDebitorEntityUnitTest.java | 4 +- ...OfficePartnerControllerAcceptanceTest.java | 4 +- .../HsOfficePartnerControllerRestTest.java | 6 +- ...cePartnerDetailsEntityPatcherUnitTest.java | 6 +- .../HsOfficePartnerEntityPatcherUnitTest.java | 4 +- .../HsOfficePartnerEntityUnitTest.java | 4 +- .../office/partner/TestHsOfficePartner.java | 4 +- ...HsOfficeRelationEntityPatcherUnitTest.java | 12 ++-- 33 files changed, 201 insertions(+), 117 deletions(-) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java rename src/main/java/net/hostsharing/hsadminng/hs/office/relation/{HsOfficeRelationRawEntity.java => HsOfficeRelationBareEntity.java} (75%) rename src/test/java/net/hostsharing/hsadminng/hs/migration/{HsHostingAssetRawEntity.java => HsHostingAssetBareEntity.java} (89%) 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 637e19cb..20a14ca9 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 @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.stringify.Stringify; @@ -36,7 +36,7 @@ public interface HsHostingAsset extends Stringifyable, RbacObject getSubHostingAssets(); String getCaption(); Map getConfig(); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java index ceb27238..ce4ef38c 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java @@ -8,7 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; @@ -90,7 +90,7 @@ public class HsHostingAssetEntity implements HsHostingAsset { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "alarmcontactuuid") - private HsOfficeContactEntity alarmContact; + private HsOfficeContactRbacEntity alarmContact; @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") @@ -160,7 +160,7 @@ public class HsHostingAssetEntity implements HsHostingAsset { directlyFetchedByDependsOnColumn(), NULLABLE) - .importEntityAlias("alarmContact", HsOfficeContactEntity.class, usingDefaultCase(), + .importEntityAlias("alarmContact", HsOfficeContactRbacEntity.class, usingDefaultCase(), dependsOnColumn("alarmContactUuid"), directlyFetchedByDependsOnColumn(), NULLABLE) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java index f1cff713..b0b924bb 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.KeyValueMap; import net.hostsharing.hsadminng.mapper.OptionalFromJson; @@ -29,7 +29,7 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher entity.setAlarmContact( Optional.ofNullable(newValue) - .map(uuid -> em.getReference(HsOfficeContactEntity.class, newValue)) + .map(uuid -> em.getReference(HsOfficeContactRbacEntity.class, newValue)) .orElse(null))); } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java index b6747ff8..1cf4074e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java @@ -5,7 +5,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; import net.hostsharing.hsadminng.hs.validation.ValidatableProperty; @@ -213,7 +213,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator> { + static class AlarmContact extends ReferenceValidator> { AlarmContact(final HsHostingAssetType.RelationPolicy policy) { super(policy, HsHostingAsset::getAlarmContact); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java index 83f182a3..6139f399 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java @@ -54,7 +54,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi { context.define(currentUser, assumedRoles); - final var entityToSave = mapper.map(body, HsOfficeContactEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); + final var entityToSave = mapper.map(body, HsOfficeContactRbacEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); final var saved = contactRepo.save(entityToSave); @@ -119,7 +119,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi { } @SuppressWarnings("unchecked") - final BiConsumer RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { + final BiConsumer RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { entity.putEmailAddresses(from(resource.getEmailAddresses())); entity.putPhoneNumbers(from(resource.getPhoneNumbers())); }; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java index 3bcaf140..0ce2eeb9 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java @@ -1,36 +1,58 @@ package net.hostsharing.hsadminng.hs.office.contact; import io.hypersistence.utils.hibernate.type.json.JsonType; -import lombok.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.experimental.FieldNameConstants; +import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.errors.DisplayName; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; +import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Type; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; +import jakarta.persistence.Version; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import static jakarta.persistence.InheritanceType.TABLE_PER_CLASS; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.*; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.DELETE; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.INSERT; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.SELECT; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.UPDATE; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.*; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.ADMIN; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.GUEST; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.OWNER; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.REFERRER; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Entity -@Table(name = "hs_office_contact_rv") +@Table(name = "hs_office_contact") +@Inheritance(strategy = TABLE_PER_CLASS) @Getter @Setter -@Builder +@SuperBuilder @NoArgsConstructor @AllArgsConstructor @FieldNameConstants @@ -99,6 +121,9 @@ public class HsOfficeContactEntity implements Stringifyable, RbacObject toBuilder() { + return null; + } public static RbacView rbac() { return rbacViewFor("contact", HsOfficeContactEntity.class) .withIdentityView(SQL.projection("caption")) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java index ddc4f982..e08e6bae 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcher.java @@ -9,9 +9,9 @@ import java.util.Optional; class HsOfficeContactEntityPatcher implements EntityPatcher { - private final HsOfficeContactEntity entity; + private final HsOfficeContactRbacEntity entity; - HsOfficeContactEntityPatcher(final HsOfficeContactEntity entity) { + HsOfficeContactEntityPatcher(final HsOfficeContactRbacEntity entity) { this.entity = entity; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java new file mode 100644 index 00000000..54f069c9 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java @@ -0,0 +1,56 @@ +package net.hostsharing.hsadminng.hs.office.contact; + +import lombok.*; +import lombok.experimental.FieldNameConstants; +import lombok.experimental.SuperBuilder; +import net.hostsharing.hsadminng.errors.DisplayName; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; +import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; + +import jakarta.persistence.*; +import java.io.IOException; + +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.*; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.*; +import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; + +@Entity +@Table(name = "hs_office_contact_rv") +@Getter +@Setter +@SuperBuilder +@NoArgsConstructor +@FieldNameConstants +@DisplayName("Contact") +public class HsOfficeContactRbacEntity extends HsOfficeContactEntity { + + @Override + public HsOfficeRelationEntity.HsOfficeRelationEntityBuilder toBuilder() { + return null; + } + + public static RbacView rbac() { + return rbacViewFor("contact", HsOfficeContactRbacEntity.class) + .withIdentityView(SQL.projection("caption")) + .withUpdatableColumns("caption", "postalAddress", "emailAddresses", "phoneNumbers") + .createRole(OWNER, (with) -> { + with.owningUser(CREATOR); + with.incomingSuperRole(GLOBAL, ADMIN); + with.permission(DELETE); + }) + .createSubRole(ADMIN, (with) -> { + with.permission(UPDATE); + }) + .createSubRole(REFERRER, (with) -> { + with.permission(SELECT); + }) + .toRole(GLOBAL, GUEST).grantPermission(INSERT); + } + + public static void main(String[] args) throws IOException { + rbac().generateWithBaseFileName("5-hs-office/501-contact/5013-hs-office-contact-rbac"); + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepository.java index 22a285ab..bb3519c3 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepository.java @@ -7,18 +7,18 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -public interface HsOfficeContactRepository extends Repository { +public interface HsOfficeContactRepository extends Repository { - Optional findByUuid(UUID id); + Optional findByUuid(UUID id); @Query(""" - SELECT c FROM HsOfficeContactEntity c + SELECT c FROM HsOfficeContactRbacEntity c WHERE :caption is null OR c.caption like concat(cast(:caption as text), '%') """) - List findContactByOptionalCaptionLike(String caption); + List findContactByOptionalCaptionLike(String caption); - HsOfficeContactEntity save(final HsOfficeContactEntity entity); + HsOfficeContactRbacEntity save(final HsOfficeContactRbacEntity entity); int deleteByUuid(final UUID uuid); 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 656a959c..7d41b078 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 @@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.errors.ReferenceNotFoundException; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePartnersApi; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; 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 2ec637be..5802552f 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 @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRawEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareEntity.java similarity index 75% rename from src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRawEntity.java rename to src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareEntity.java index 26ca463b..d5e056df 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRawEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareEntity.java @@ -11,15 +11,14 @@ import jakarta.persistence.Table; @Entity @Table(name = "hs_office_relation") -//@DiscriminatorValue("0") @SuperBuilder @NoArgsConstructor @Getter @Setter -public class HsOfficeRelationRawEntity extends HsOfficeRelationEntity { +public class HsOfficeRelationBareEntity extends HsOfficeRelationEntity { @Override public HsOfficeRelationEntityBuilder toBuilder() { - return null; + return null; // FIXME: also the ugly generics, if possible } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java index fe8144c6..783c9634 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java @@ -4,6 +4,8 @@ import lombok.*; import lombok.experimental.FieldNameConstants; import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; @@ -116,7 +118,7 @@ public abstract class HsOfficeRelationEntity implements RbacObject { verifyNotNull(newValue, "contact"); - entity.setContact(em.getReference(HsOfficeContactEntity.class, newValue)); + entity.setContact(em.getReference(HsOfficeContactRbacEntity.class, newValue)); }); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java index 1df7b92c..a7ab3b13 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java @@ -4,7 +4,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.SuperBuilder; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; @@ -63,7 +63,7 @@ public class HsOfficeRelationRbacEntity extends HsOfficeRelationEntity { dependsOnColumn("holderUuid"), directlyFetchedByDependsOnColumn(), NOT_NULL) - .importEntityAlias("contact", HsOfficeContactEntity.class, usingDefaultCase(), + .importEntityAlias("contact", HsOfficeContactRbacEntity.class, usingDefaultCase(), dependsOnColumn("contactUuid"), directlyFetchedByDependsOnColumn(), NOT_NULL) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java index 54edc9ef..94d27f6d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java @@ -8,7 +8,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; @@ -732,7 +732,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup }).assertSuccessful().returnedValue(); } - private HsOfficeContactEntity givenContact() { + private HsOfficeContactRbacEntity givenContact() { return jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); return contactRepo.findContactByOptionalCaptionLike("second").stream().findFirst().orElseThrow(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java index 96728cca..b75e401d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.mapper.KeyValueMap; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import org.junit.jupiter.api.BeforeEach; @@ -48,7 +48,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< entry("SSD", 256), entry("MEM", 64) ); - final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder() + final HsOfficeContactRbacEntity givenInitialContact = HsOfficeContactRbacEntity.builder() .uuid(UUID.randomUUID()) .build(); @@ -62,8 +62,8 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< void initMocks() { lenient().when(em.getReference(eq(HsHostingAssetEntity.class), any())).thenAnswer(invocation -> HsHostingAssetEntity.builder().uuid(invocation.getArgument(1)).build()); - lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation -> - HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> + HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); } @Override @@ -111,7 +111,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< ); } - static HsOfficeContactEntity newContact(final UUID uuid) { - return HsOfficeContactEntity.builder().uuid(uuid).build(); + static HsOfficeContactRbacEntity newContact(final UUID uuid) { + return HsOfficeContactRbacEntity.builder().uuid(uuid).build(); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRawEntity.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetBareEntity.java similarity index 89% rename from src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRawEntity.java rename to src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetBareEntity.java index 33e632d5..235d3c6d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRawEntity.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetBareEntity.java @@ -10,7 +10,7 @@ import lombok.Setter; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import org.hibernate.annotations.Type; @@ -42,7 +42,7 @@ import java.util.UUID; @Setter @NoArgsConstructor @AllArgsConstructor -public class HsHostingAssetRawEntity implements HsHostingAsset { +public class HsHostingAssetBareEntity implements HsHostingAsset { @Id @GeneratedValue @@ -57,11 +57,11 @@ public class HsHostingAssetRawEntity implements HsHostingAsset { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parentassetuuid") - private HsHostingAssetRawEntity parentAsset; + private HsHostingAssetBareEntity parentAsset; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "assignedtoassetuuid") - private HsHostingAssetRawEntity assignedToAsset; + private HsHostingAssetBareEntity assignedToAsset; @Column(name = "type") @Enumerated(EnumType.STRING) @@ -69,11 +69,11 @@ public class HsHostingAssetRawEntity implements HsHostingAsset { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "alarmcontactuuid") - private HsOfficeContactEntity alarmContact; + private HsOfficeContactRbacEntity alarmContact; @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") - private List subHostingAssets; + private List subHostingAssets; @Column(name = "identifier") private String identifier; // e.g. vm1234, xyz00, example.org, xyz00_abc @@ -109,6 +109,6 @@ public class HsHostingAssetRawEntity implements HsHostingAsset { @Override public String toString() { - return stringify.using(HsHostingAssetRawEntity.class).apply(this); + return stringify.using(HsHostingAssetBareEntity.class).apply(this); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java index 288261e7..d2e1d83c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java @@ -113,13 +113,13 @@ public class ImportHostingAssets extends ImportOfficeData { static final Integer DBUSER_ID_OFFSET = 7000000; static final Integer DB_ID_OFFSET = 8000000; - record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference serverRef) {} + record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference serverRef) {} static Map bookingProjects = new WriteOnceMap<>(); static Map bookingItems = new WriteOnceMap<>(); static Map hives = new WriteOnceMap<>(); - static Map hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type? - static Map dbUsersByEngineAndName = new WriteOnceMap<>(); + static Map hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type? + static Map dbUsersByEngineAndName = new WriteOnceMap<>(); @Test @Order(11010) @@ -670,7 +670,7 @@ public class ImportHostingAssets extends ImportOfficeData { .map(this::trimAll) .map(row -> new Record(columns, row)) .forEach(rec -> { - final var ipNumber = HsHostingAssetRawEntity.builder() + final var ipNumber = HsHostingAssetBareEntity.builder() .type(IPV4_NUMBER) .identifier(rec.getString("inet_addr")) .caption(rec.getString("description")) @@ -734,7 +734,7 @@ public class ImportHostingAssets extends ImportOfficeData { + packet_name) .isTrue()); - final var asset = HsHostingAssetRawEntity.builder() + final var asset = HsHostingAssetBareEntity.builder() // this turns off identifier validation to accept former default prefixes .isLoaded(haType == MANAGED_WEBSPACE) .type(haType) @@ -874,7 +874,7 @@ public class ImportHostingAssets extends ImportOfficeData { .forEach(rec -> { final var unixuser_id = rec.getInteger("unixuser_id"); final var packet_id = rec.getInteger("packet_id"); - final var unixUserAsset = HsHostingAssetRawEntity.builder() + final var unixUserAsset = HsHostingAssetBareEntity.builder() .type(UNIX_USER) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .identifier(rec.getString("name")) @@ -931,7 +931,7 @@ public class ImportHostingAssets extends ImportOfficeData { final var unixuser_id = rec.getInteger("emailalias_id"); final var packet_id = rec.getInteger("pac_id"); final var targets = parseCsvLine(rec.getString("target")); - final var unixUserAsset = HsHostingAssetRawEntity.builder() + final var unixUserAsset = HsHostingAssetBareEntity.builder() .type(EMAIL_ALIAS) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .identifier(rec.getString("name")) @@ -944,14 +944,14 @@ public class ImportHostingAssets extends ImportOfficeData { }); } - private void createDatabaseInstances(final List parentAssets) { + private void createDatabaseInstances(final List parentAssets) { final var idRef = new AtomicInteger(0); parentAssets.forEach(pa -> { if (pa.getSubHostingAssets() == null) { pa.setSubHostingAssets(new ArrayList<>()); } - final var pgSqlInstanceAsset = HsHostingAssetRawEntity.builder() + final var pgSqlInstanceAsset = HsHostingAssetBareEntity.builder() .type(PGSQL_INSTANCE) .parentAsset(pa) .identifier(pa.getIdentifier() + "|PgSql.default") @@ -960,7 +960,7 @@ public class ImportHostingAssets extends ImportOfficeData { pa.getSubHostingAssets().add(pgSqlInstanceAsset); hostingAssets.put(DBINSTANCE_ID_OFFSET + idRef.getAndIncrement(), pgSqlInstanceAsset); - final var mariaDbInstanceAsset = HsHostingAssetRawEntity.builder() + final var mariaDbInstanceAsset = HsHostingAssetBareEntity.builder() .type(MARIADB_INSTANCE) .parentAsset(pa) .identifier(pa.getIdentifier() + "|MariaDB.default") @@ -996,7 +996,7 @@ public class ImportHostingAssets extends ImportOfficeData { .filter(ha -> ha.getType() == dbInstanceAssetType) .findAny().orElseThrow(); // there is exactly one: the default instance for the given type - final var dbUserAsset = HsHostingAssetRawEntity.builder() + final var dbUserAsset = HsHostingAssetBareEntity.builder() .type(dbUserAssetType) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .assignedToAsset(dbInstanceAsset) @@ -1027,7 +1027,7 @@ public class ImportHostingAssets extends ImportOfficeData { : failWith("unknown DB engine " + engine); final var name = rec.getString("name"); final var encoding = rec.getString("encoding").replaceAll("[-_]+", ""); - final var dbAsset = HsHostingAssetRawEntity.builder() + final var dbAsset = HsHostingAssetBareEntity.builder() .type(type) .parentAsset(owningDbUserHA) .identifier(type.name().substring(0, 2) + "D|" + name) @@ -1069,7 +1069,7 @@ public class ImportHostingAssets extends ImportOfficeData { }; } - private static HsHostingAssetRawEntity ipNumber(final Integer inet_addr_id) { + private static HsHostingAssetBareEntity ipNumber(final Integer inet_addr_id) { return inet_addr_id != null ? hostingAssets.get(IP_NUMBER_ID_OFFSET + inet_addr_id) : null; } @@ -1077,7 +1077,7 @@ public class ImportHostingAssets extends ImportOfficeData { return hive_id != null ? hives.get(HIVE_ID_OFFSET + hive_id) : null; } - private static HsHostingAssetRawEntity pac(final Integer packet_id) { + private static HsHostingAssetBareEntity pac(final Integer packet_id) { return packet_id != null ? hostingAssets.get(PACKET_ID_OFFSET + packet_id) : null; } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java index 0846d6bd..1fc3761f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.migration; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionEntity; import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType; import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionEntity; @@ -15,7 +15,7 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRawEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; @@ -121,7 +121,7 @@ public class ImportOfficeData extends CsvDataImport { -1 ); - static Map contacts = new WriteOnceMap<>(); + static Map contacts = new WriteOnceMap<>(); static Map persons = new WriteOnceMap<>(); static Map partners = new WriteOnceMap<>(); static Map debitors = new WriteOnceMap<>(); @@ -979,7 +979,7 @@ public class ImportOfficeData extends CsvDataImport { contactPerson = addPerson(HsOfficePersonEntity.builder().build(), rec); } - final var contact = HsOfficeContactEntity.builder().build(); + final var contact = HsOfficeContactRbacEntity.builder().build(); initContact(contact, rec); if (containsPartnerRel(rec)) { @@ -1057,8 +1057,8 @@ public class ImportOfficeData extends CsvDataImport { final HsOfficeRelationType type, final HsOfficePersonEntity anchor, final HsOfficePersonEntity holder, - final HsOfficeContactEntity contact) { - final var rel = HsOfficeRelationRawEntity.builder() + final HsOfficeContactRbacEntity contact) { + final var rel = HsOfficeRelationBareEntity.builder() .anchor(anchor) .holder(holder) .contact(contact) @@ -1118,7 +1118,7 @@ public class ImportOfficeData extends CsvDataImport { assertThat(unexpectedRolesSet).isEmpty(); } - private HsOfficeContactEntity initContact(final HsOfficeContactEntity contact, final Record contactRecord) { + private HsOfficeContactRbacEntity initContact(final HsOfficeContactRbacEntity contact, final Record contactRecord) { contact.setCaption(toCaption( contactRecord.getString("salut"), diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java index 2d171fcc..d7a77e56 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java @@ -355,10 +355,10 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu } } - private HsOfficeContactEntity givenSomeTemporaryContactCreatedBy(final String creatingUser) { + private HsOfficeContactRbacEntity givenSomeTemporaryContactCreatedBy(final String creatingUser) { return jpaAttempt.transacted(() -> { context.define(creatingUser); - final var newContact = HsOfficeContactEntity.builder() + final var newContact = HsOfficeContactRbacEntity.builder() .uuid(UUID.randomUUID()) .caption("Temp from " + Context.getCallerMethodNameFromStackFrame(1) ) .emailAddresses(Map.of("main", RandomStringUtils.randomAlphabetic(10) + "@example.org")) @@ -375,7 +375,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu void cleanup() { jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net", null); - em.createQuery("DELETE FROM HsOfficeContactEntity c WHERE c.caption LIKE 'Temp %'").executeUpdate(); + em.createQuery("DELETE FROM HsOfficeContactRbacEntity c WHERE c.caption LIKE 'Temp %'").executeUpdate(); }).assertSuccessful(); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcherUnitTest.java index a4c7cd38..e1f00a98 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcherUnitTest.java @@ -15,7 +15,7 @@ import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @TestInstance(PER_CLASS) class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase< HsOfficeContactPatchResource, - HsOfficeContactEntity + HsOfficeContactRbacEntity > { private static final UUID INITIAL_CONTACT_UUID = UUID.randomUUID(); @@ -42,8 +42,8 @@ class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase< ); @Override - protected HsOfficeContactEntity newInitialEntity() { - final var entity = new HsOfficeContactEntity(); + protected HsOfficeContactRbacEntity newInitialEntity() { + final var entity = new HsOfficeContactRbacEntity(); entity.setUuid(INITIAL_CONTACT_UUID); entity.setCaption("initial caption"); entity.putEmailAddresses(Map.ofEntries( @@ -64,7 +64,7 @@ class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase< } @Override - protected HsOfficeContactEntityPatcher createPatcher(final HsOfficeContactEntity entity) { + protected HsOfficeContactEntityPatcher createPatcher(final HsOfficeContactRbacEntity entity) { return new HsOfficeContactEntityPatcher(entity); } @@ -75,26 +75,26 @@ class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase< "caption", HsOfficeContactPatchResource::setCaption, "patched caption", - HsOfficeContactEntity::setCaption), + HsOfficeContactRbacEntity::setCaption), new SimpleProperty<>( "resources", HsOfficeContactPatchResource::setEmailAddresses, PATCH_EMAIL_ADDRESSES, - HsOfficeContactEntity::putEmailAddresses, + HsOfficeContactRbacEntity::putEmailAddresses, PATCHED_EMAIL_ADDRESSES) .notNullable(), new SimpleProperty<>( "resources", HsOfficeContactPatchResource::setPhoneNumbers, PATCH_PHONE_NUMBERS, - HsOfficeContactEntity::putPhoneNumbers, + HsOfficeContactRbacEntity::putPhoneNumbers, PATCHED_PHONE_NUMBERS) .notNullable(), new JsonNullableProperty<>( "patched given name", HsOfficeContactPatchResource::setPostalAddress, "patched given name", - HsOfficeContactEntity::setPostalAddress) + HsOfficeContactRbacEntity::setPostalAddress) ); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityUnitTest.java index 43747418..7b290ecc 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityUnitTest.java @@ -8,13 +8,13 @@ class HsOfficeContactEntityUnitTest { @Test void toStringReturnsNullForNullContact() { - final HsOfficeContactEntity givenContact = null; + final HsOfficeContactRbacEntity givenContact = null; assertThat("" + givenContact).isEqualTo("null"); } @Test void toStringReturnsCaption() { - final var givenContact = HsOfficeContactEntity.builder().caption("given caption").build(); + final var givenContact = HsOfficeContactRbacEntity.builder().caption("given caption").build(); assertThat("" + givenContact).isEqualTo("contact(caption='given caption')"); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java index 89a03f67..87a236fb 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java @@ -65,7 +65,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean // then result.assertSuccessful(); - assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactEntity::getUuid).isNotNull(); + assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactRbacEntity::getUuid).isNotNull(); assertThatContactIsPersisted(result.returnedValue()); assertThat(contactRepo.count()).isEqualTo(count + 1); } @@ -82,7 +82,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean // then result.assertSuccessful(); - assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactEntity::getUuid).isNotNull(); + assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactRbacEntity::getUuid).isNotNull(); assertThatContactIsPersisted(result.returnedValue()); assertThat(contactRepo.count()).isEqualTo(count + 1); } @@ -120,7 +120,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean )); } - private void assertThatContactIsPersisted(final HsOfficeContactEntity saved) { + private void assertThatContactIsPersisted(final HsOfficeContactRbacEntity saved) { final var found = contactRepo.findByUuid(saved.getUuid()); assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString()); } @@ -270,16 +270,16 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean "[creating contact test-data second contact, hs_office_contact, INSERT]"); } - private HsOfficeContactEntity givenSomeTemporaryContact( + private HsOfficeContactRbacEntity givenSomeTemporaryContact( final String createdByUser, - Supplier entitySupplier) { + Supplier entitySupplier) { return jpaAttempt.transacted(() -> { context(createdByUser); return toCleanup(contactRepo.save(entitySupplier.get())); }).assumeSuccessful().returnedValue(); } - private HsOfficeContactEntity givenSomeTemporaryContact(final String createdByUser) { + private HsOfficeContactRbacEntity givenSomeTemporaryContact(final String createdByUser) { final var random = RandomStringUtils.randomAlphabetic(12); return givenSomeTemporaryContact(createdByUser, () -> hsOfficeContact( @@ -287,15 +287,15 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean "some-temporary-contact" + random + "@example.com")); } - void exactlyTheseContactsAreReturned(final List actualResult, final String... contactCaptions) { + void exactlyTheseContactsAreReturned(final List actualResult, final String... contactCaptions) { assertThat(actualResult) - .extracting(HsOfficeContactEntity::getCaption) + .extracting(HsOfficeContactRbacEntity::getCaption) .containsExactlyInAnyOrder(contactCaptions); } - void allTheseContactsAreReturned(final List actualResult, final String... contactCaptions) { + void allTheseContactsAreReturned(final List actualResult, final String... contactCaptions) { assertThat(actualResult) - .extracting(HsOfficeContactEntity::getCaption) + .extracting(HsOfficeContactRbacEntity::getCaption) .contains(contactCaptions); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/TestHsOfficeContact.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/TestHsOfficeContact.java index c104be32..cf20b8f4 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/TestHsOfficeContact.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/TestHsOfficeContact.java @@ -4,10 +4,10 @@ import java.util.Map; public class TestHsOfficeContact { - public static final HsOfficeContactEntity TEST_CONTACT = hsOfficeContact("some contact", "some-contact@example.com"); + public static final HsOfficeContactRbacEntity TEST_CONTACT = hsOfficeContact("some contact", "some-contact@example.com"); - static public HsOfficeContactEntity hsOfficeContact(final String caption, final String emailAddr) { - return HsOfficeContactEntity.builder() + static public HsOfficeContactRbacEntity hsOfficeContact(final String caption, final String emailAddr) { + return HsOfficeContactRbacEntity.builder() .caption(caption) .postalAddress("address of " + caption) .emailAddresses(Map.of("main", emailAddr)) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java index 1f645d33..dfa94e6a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.debitor; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; @@ -21,7 +21,7 @@ class HsOfficeDebitorEntityUnitTest { .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("some billing trade name") .build()) - .contact(HsOfficeContactEntity.builder().caption("some caption").build()) + .contact(HsOfficeContactRbacEntity.builder().caption("some caption").build()) .build(); @Test 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 3a4eaf1b..25e0ee8e 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 @@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import io.restassured.RestAssured; import io.restassured.http.ContentType; import net.hostsharing.hsadminng.HsadminNgApplication; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; @@ -180,7 +180,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .post("http://localhost/api/hs/office/partners") .then().log().all().assertThat() .statusCode(400) - .body("message", is("Unable to find " + HsOfficeContactEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID)); + .body("message", is("Unable to find " + HsOfficeContactRbacEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID)); // @formatter:on } 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 a55695e4..a14f2cbd 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 @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.context.Context; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; @@ -69,7 +69,7 @@ class HsOfficePartnerControllerRestTest { HsOfficePersonEntity personMock; @Mock - HsOfficeContactEntity contactMock; + HsOfficeContactRbacEntity contactMock; @Mock HsOfficePartnerEntity partnerMock; @@ -83,7 +83,7 @@ class HsOfficePartnerControllerRestTest { lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_MANDANTE_UUID)).thenReturn(mandateMock); lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_PERSON_UUID)).thenReturn(personMock); - lenient().when(em.getReference(HsOfficeContactEntity.class, GIVEN_CONTACT_UUID)).thenReturn(contactMock); + lenient().when(em.getReference(HsOfficeContactRbacEntity.class, GIVEN_CONTACT_UUID)).thenReturn(contactMock); lenient().when(em.getReference(any(), eq(GIVEN_INVALID_UUID))).thenThrow(EntityNotFoundException.class); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntityPatcherUnitTest.java index 10cb6016..8a3c0084 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerDetailsEntityPatcherUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.partner; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerDetailsPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; @@ -43,8 +43,8 @@ class HsOfficePartnerDetailsEntityPatcherUnitTest extends PatchUnitTestBase< @BeforeEach void initMocks() { - lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation -> - HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> + HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); lenient().when(em.getReference(eq(HsOfficePersonEntity.class), any())).thenAnswer(invocation -> HsOfficePersonEntity.builder().uuid(invocation.getArgument(1)).build()); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java index 878a9302..9a5d42e1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.partner; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; @@ -37,7 +37,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< private final HsOfficePersonEntity givenInitialPerson = HsOfficePersonEntity.builder() .uuid(INITIAL_PERSON_UUID) .build(); - private final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder() + private final HsOfficeContactRbacEntity givenInitialContact = HsOfficeContactRbacEntity.builder() .uuid(INITIAL_CONTACT_UUID) .build(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java index 54ad1b20..b0a396ee 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.partner; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; @@ -23,7 +23,7 @@ class HsOfficePartnerEntityUnitTest { .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("some trade name") .build()) - .contact(HsOfficeContactEntity.builder().caption("some caption").build()) + .contact(HsOfficeContactRbacEntity.builder().caption("some caption").build()) .build()) .build(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java index a9bd0a64..25cbc082 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.partner; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; @@ -25,7 +25,7 @@ public class TestHsOfficePartner { .personType(LEGAL_PERSON) .tradeName(tradeName) .build()) - .contact(HsOfficeContactEntity.builder() + .contact(HsOfficeContactRbacEntity.builder() .caption(tradeName) .build()) .build() diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java index fe90e0f1..5bfd4690 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.relation; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; @@ -34,8 +34,8 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< @BeforeEach void initMocks() { - lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation -> - HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> + HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); } final HsOfficePersonEntity givenInitialAnchorPerson = HsOfficePersonEntity.builder() @@ -44,7 +44,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< final HsOfficePersonEntity givenInitialHolderPerson = HsOfficePersonEntity.builder() .uuid(UUID.randomUUID()) .build(); - final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder() + final HsOfficeContactRbacEntity givenInitialContact = HsOfficeContactRbacEntity.builder() .uuid(UUID.randomUUID()) .build(); @@ -82,8 +82,8 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< ); } - static HsOfficeContactEntity newContact(final UUID uuid) { - final var newContact = new HsOfficeContactEntity(); + static HsOfficeContactRbacEntity newContact(final UUID uuid) { + final var newContact = new HsOfficeContactRbacEntity(); newContact.setUuid(uuid); return newContact; } -- 2.39.5 From cdd35ef4b8683506f30db26d77dc06471303d516 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sat, 3 Aug 2024 17:33:30 +0200 Subject: [PATCH 03/12] switch to HsOfficeContactRbacEntity + HsOfficeContactBaseEntity as subclasses of HsOfficeContact --- .run/ImportHostingAssets.run.xml | 36 +++++ .run/ImportOfficeData.run.xml | 36 +++++ .../hs/hosting/asset/HsHostingAsset.java | 4 +- .../hosting/asset/HsHostingAssetEntity.java | 3 +- .../asset/HsHostingAssetEntityPatcher.java | 4 +- .../HostingAssetEntityValidator.java | 4 +- .../hs/office/contact/HsOfficeContact.java | 106 +++++++++++++ .../contact/HsOfficeContactBareEntity.java | 23 +++ .../HsOfficeContactBareRepository.java | 26 +++ .../contact/HsOfficeContactController.java | 2 +- .../office/contact/HsOfficeContactEntity.java | 148 ------------------ .../contact/HsOfficeContactRbacEntity.java | 11 +- ...ava => HsOfficeContactRbacRepository.java} | 2 +- .../debitor/HsOfficeDebitorRepository.java | 2 +- .../partner/HsOfficePartnerController.java | 5 +- .../office/partner/HsOfficePartnerEntity.java | 5 +- .../partner/HsOfficePartnerRepository.java | 2 +- .../relation/HsOfficeRelationController.java | 6 +- .../relation/HsOfficeRelationEntity.java | 5 +- .../HsOfficeRelationEntityPatcher.java | 4 +- ...sHostingAssetControllerAcceptanceTest.java | 4 +- .../HsHostingAssetControllerRestTest.java | 6 +- .../HsHostingAssetEntityPatcherUnitTest.java | 7 +- .../migration/HsHostingAssetBareEntity.java | 4 +- .../hs/migration/ImportOfficeData.java | 10 +- .../HsOfficeContactBareTestEntity.java | 16 ++ ...OfficeContactControllerAcceptanceTest.java | 2 +- ...va => HsOfficeContactPatcherUnitTest.java} | 2 +- ...ContactRbacRepositoryIntegrationTest.java} | 6 +- ...ava => HsOfficeContactRbacTestEntity.java} | 4 +- ...Test.java => HsOfficeContactUnitTest.java} | 2 +- ...OfficeDebitorControllerAcceptanceTest.java | 14 +- .../HsOfficeDebitorEntityUnitTest.java | 4 +- ...fficeDebitorRepositoryIntegrationTest.java | 14 +- .../office/debitor/TestHsOfficeDebitor.java | 4 +- ...OfficePartnerControllerAcceptanceTest.java | 10 +- .../HsOfficePartnerEntityPatcherUnitTest.java | 4 +- .../HsOfficePartnerEntityUnitTest.java | 4 +- ...fficePartnerRepositoryIntegrationTest.java | 8 +- .../office/partner/TestHsOfficePartner.java | 4 +- ...fficeRelationControllerAcceptanceTest.java | 14 +- ...HsOfficeRelationEntityPatcherUnitTest.java | 9 +- ...ficeRelationRepositoryIntegrationTest.java | 12 +- 43 files changed, 343 insertions(+), 255 deletions(-) create mode 100644 .run/ImportHostingAssets.run.xml create mode 100644 .run/ImportOfficeData.run.xml create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareRepository.java delete mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java rename src/main/java/net/hostsharing/hsadminng/hs/office/contact/{HsOfficeContactRepository.java => HsOfficeContactRbacRepository.java} (87%) create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareTestEntity.java rename src/test/java/net/hostsharing/hsadminng/hs/office/contact/{HsOfficeContactEntityPatcherUnitTest.java => HsOfficeContactPatcherUnitTest.java} (98%) rename src/test/java/net/hostsharing/hsadminng/hs/office/contact/{HsOfficeContactRepositoryIntegrationTest.java => HsOfficeContactRbacRepositoryIntegrationTest.java} (98%) rename src/test/java/net/hostsharing/hsadminng/hs/office/contact/{TestHsOfficeContact.java => HsOfficeContactRbacTestEntity.java} (70%) rename src/test/java/net/hostsharing/hsadminng/hs/office/contact/{HsOfficeContactEntityUnitTest.java => HsOfficeContactUnitTest.java} (93%) diff --git a/.run/ImportHostingAssets.run.xml b/.run/ImportHostingAssets.run.xml new file mode 100644 index 00000000..233ef548 --- /dev/null +++ b/.run/ImportHostingAssets.run.xml @@ -0,0 +1,36 @@ + + + + + + + + false + true + + + + false + true + + + \ No newline at end of file diff --git a/.run/ImportOfficeData.run.xml b/.run/ImportOfficeData.run.xml new file mode 100644 index 00000000..80b17552 --- /dev/null +++ b/.run/ImportOfficeData.run.xml @@ -0,0 +1,36 @@ + + + + + + + + false + true + + + + false + true + + + \ No newline at end of file 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 20a14ca9..81fd6f98 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 @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.stringify.Stringify; @@ -36,7 +36,7 @@ public interface HsHostingAsset extends Stringifyable, RbacObject getSubHostingAssets(); String getCaption(); Map getConfig(); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java index ce4ef38c..52a05a64 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; @@ -90,7 +91,7 @@ public class HsHostingAssetEntity implements HsHostingAsset { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "alarmcontactuuid") - private HsOfficeContactRbacEntity alarmContact; + private HsOfficeContactBareEntity alarmContact; @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java index b0b924bb..585375d5 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.KeyValueMap; import net.hostsharing.hsadminng.mapper.OptionalFromJson; @@ -29,7 +29,7 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher entity.setAlarmContact( Optional.ofNullable(newValue) - .map(uuid -> em.getReference(HsOfficeContactRbacEntity.class, newValue)) + .map(uuid -> em.getReference(HsOfficeContactBareEntity.class, newValue)) .orElse(null))); } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java index 1cf4074e..6a95448d 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java @@ -5,7 +5,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; import net.hostsharing.hsadminng.hs.validation.ValidatableProperty; @@ -213,7 +213,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator> { + static class AlarmContact extends ReferenceValidator> { AlarmContact(final HsHostingAssetType.RelationPolicy policy) { super(policy, HsHostingAsset::getAlarmContact); 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 new file mode 100644 index 00000000..922800e1 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java @@ -0,0 +1,106 @@ +package net.hostsharing.hsadminng.hs.office.contact; + +import io.hypersistence.utils.hibernate.type.json.JsonType; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.FieldNameConstants; +import lombok.experimental.SuperBuilder; +import net.hostsharing.hsadminng.errors.DisplayName; +import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; +import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.stringify.Stringify; +import net.hostsharing.hsadminng.stringify.Stringifyable; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Type; + +import jakarta.persistence.Column; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import jakarta.persistence.Transient; +import jakarta.persistence.Version; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static net.hostsharing.hsadminng.stringify.Stringify.stringify; + +@MappedSuperclass +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder(toBuilder = true) +@FieldNameConstants +@DisplayName("Contact") +public class HsOfficeContact implements Stringifyable, RbacObject { + + private static Stringify toString = stringify(HsOfficeContact.class, "contact") + .withProp(Fields.caption, HsOfficeContact::getCaption) + .withProp(Fields.emailAddresses, HsOfficeContact::getEmailAddresses); + + @Id + @GeneratedValue(generator = "UUID") + @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") + private UUID uuid; + + @Version + private int version; + + @Column(name = "caption") + private String caption; + + @Column(name = "postaladdress") + private String postalAddress; // multiline free-format text + + @Builder.Default + @Setter(AccessLevel.NONE) + @Type(JsonType.class) + @Column(name = "emailaddresses") + private Map emailAddresses = new HashMap<>(); + + @Transient + private PatchableMapWrapper emailAddressesWrapper; + + @Builder.Default + @Setter(AccessLevel.NONE) + @Type(JsonType.class) + @Column(name = "phonenumbers") + private Map phoneNumbers = new HashMap<>(); + + @Transient + private PatchableMapWrapper phoneNumbersWrapper; + + public PatchableMapWrapper getEmailAddresses() { + return PatchableMapWrapper.of( + emailAddressesWrapper, + (newWrapper) -> {emailAddressesWrapper = newWrapper;}, + emailAddresses); + } + + public void putEmailAddresses(Map newEmailAddresses) { + getEmailAddresses().assign(newEmailAddresses); + } + + public PatchableMapWrapper getPhoneNumbers() { + return PatchableMapWrapper.of(phoneNumbersWrapper, (newWrapper) -> {phoneNumbersWrapper = newWrapper;}, phoneNumbers); + } + + public void putPhoneNumbers(Map newPhoneNumbers) { + getPhoneNumbers().assign(newPhoneNumbers); + } + + @Override + public String toString() { + return toString.apply(this); + } + + @Override + public String toShortString() { + return caption; + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java new file mode 100644 index 00000000..958883ab --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java @@ -0,0 +1,23 @@ +package net.hostsharing.hsadminng.hs.office.contact; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.FieldNameConstants; +import lombok.experimental.SuperBuilder; +import net.hostsharing.hsadminng.errors.DisplayName; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "hs_office_contact") +@Getter +@Setter +@NoArgsConstructor +@SuperBuilder(toBuilder = true) +@FieldNameConstants +@DisplayName("BareContact") +public class HsOfficeContactBareEntity extends HsOfficeContact { + +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareRepository.java new file mode 100644 index 00000000..baa1e1e1 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareRepository.java @@ -0,0 +1,26 @@ +package net.hostsharing.hsadminng.hs.office.contact; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface HsOfficeContactBareRepository extends Repository { + + Optional findByUuid(UUID id); + + @Query(""" + SELECT c FROM HsOfficeContactBareEntity c + WHERE :caption is null + OR c.caption like concat(cast(:caption as text), '%') + """) + List findContactByOptionalCaptionLike(String caption); + + HsOfficeContactBareEntity save(final HsOfficeContactBareEntity entity); + + int deleteByUuid(final UUID uuid); + + long count(); +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java index 6139f399..cee7e28a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java @@ -29,7 +29,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi { private Mapper mapper; @Autowired - private HsOfficeContactRepository contactRepo; + private HsOfficeContactRbacRepository contactRepo; @Override @Transactional(readOnly = true) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java deleted file mode 100644 index 0ce2eeb9..00000000 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java +++ /dev/null @@ -1,148 +0,0 @@ -package net.hostsharing.hsadminng.hs.office.contact; - -import io.hypersistence.utils.hibernate.type.json.JsonType; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.experimental.FieldNameConstants; -import lombok.experimental.SuperBuilder; -import net.hostsharing.hsadminng.errors.DisplayName; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; -import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; -import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.Table; -import jakarta.persistence.Transient; -import jakarta.persistence.Version; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import static jakarta.persistence.InheritanceType.TABLE_PER_CLASS; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.DELETE; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.INSERT; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.SELECT; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.UPDATE; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.ADMIN; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.GUEST; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.OWNER; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.REFERRER; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; - -@Entity -@Table(name = "hs_office_contact") -@Inheritance(strategy = TABLE_PER_CLASS) -@Getter -@Setter -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -@FieldNameConstants -@DisplayName("Contact") -public class HsOfficeContactEntity implements Stringifyable, RbacObject { - - private static Stringify toString = stringify(HsOfficeContactEntity.class, "contact") - .withProp(Fields.caption, HsOfficeContactEntity::getCaption) - .withProp(Fields.emailAddresses, HsOfficeContactEntity::getEmailAddresses); - - @Id - @GeneratedValue(generator = "UUID") - @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") - private UUID uuid; - - @Version - private int version; - - @Column(name = "caption") - private String caption; - - @Column(name = "postaladdress") - private String postalAddress; // multiline free-format text - - @Builder.Default - @Setter(AccessLevel.NONE) - @Type(JsonType.class) - @Column(name = "emailaddresses") - private Map emailAddresses = new HashMap<>(); - - @Transient - private PatchableMapWrapper emailAddressesWrapper; - - @Builder.Default - @Setter(AccessLevel.NONE) - @Type(JsonType.class) - @Column(name = "phonenumbers") - private Map phoneNumbers = new HashMap<>(); - - @Transient - private PatchableMapWrapper phoneNumbersWrapper; - - public PatchableMapWrapper getEmailAddresses() { - return PatchableMapWrapper.of(emailAddressesWrapper, (newWrapper) -> {emailAddressesWrapper = newWrapper; }, emailAddresses ); - } - - public void putEmailAddresses(Map newEmailAddresses) { - getEmailAddresses().assign(newEmailAddresses); - } - - public PatchableMapWrapper getPhoneNumbers() { - return PatchableMapWrapper.of(phoneNumbersWrapper, (newWrapper) -> {phoneNumbersWrapper = newWrapper; }, phoneNumbers ); - } - - public void putPhoneNumbers(Map newPhoneNumbers) { - getPhoneNumbers().assign(newPhoneNumbers); - } - - @Override - public String toString() { - return toString.apply(this); - } - - @Override - public String toShortString() { - return caption; - } - - public HsOfficeRelationEntity.HsOfficeRelationEntityBuilder toBuilder() { - return null; - } - public static RbacView rbac() { - return rbacViewFor("contact", HsOfficeContactEntity.class) - .withIdentityView(SQL.projection("caption")) - .withUpdatableColumns("caption", "postalAddress", "emailAddresses", "phoneNumbers") - .createRole(OWNER, (with) -> { - with.owningUser(CREATOR); - with.incomingSuperRole(GLOBAL, ADMIN); - with.permission(DELETE); - }) - .createSubRole(ADMIN, (with) -> { - with.permission(UPDATE); - }) - .createSubRole(REFERRER, (with) -> { - with.permission(SELECT); - }) - .toRole(GLOBAL, GUEST).grantPermission(INSERT); - } - - public static void main(String[] args) throws IOException { - rbac().generateWithBaseFileName("5-hs-office/501-contact/5013-hs-office-contact-rbac"); - } -} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java index 54f069c9..5a474066 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java @@ -4,7 +4,6 @@ import lombok.*; import lombok.experimental.FieldNameConstants; import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.errors.DisplayName; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; @@ -21,16 +20,12 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; @Table(name = "hs_office_contact_rv") @Getter @Setter -@SuperBuilder @NoArgsConstructor +@SuperBuilder(toBuilder = true) @FieldNameConstants -@DisplayName("Contact") -public class HsOfficeContactRbacEntity extends HsOfficeContactEntity { +@DisplayName("RbacContact") +public class HsOfficeContactRbacEntity extends HsOfficeContact { - @Override - public HsOfficeRelationEntity.HsOfficeRelationEntityBuilder toBuilder() { - return null; - } public static RbacView rbac() { return rbacViewFor("contact", HsOfficeContactRbacEntity.class) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java similarity index 87% rename from src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepository.java rename to src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java index bb3519c3..e893bced 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -public interface HsOfficeContactRepository extends Repository { +public interface HsOfficeContactRbacRepository extends Repository { Optional findByUuid(UUID id); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java index 1e0b8f60..bc794f6c 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java @@ -33,7 +33,7 @@ public interface HsOfficeDebitorRepository extends Repository ofNullable(p.getPartnerRel()) .map(HsOfficeRelationEntity::getContact) - .map(HsOfficeContactEntity::toShortString) + .map(HsOfficeContact::toShortString) .orElse(null)) .quotedValues(false); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java index 2ae260bd..f63bf469 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java @@ -16,7 +16,7 @@ public interface HsOfficePartnerRepository extends Repository new NoSuchElementException("cannot find holderUuid " + body.getHolderUuid()) )); - entityToSave.setContact(contactRepo.findByUuid(body.getContactUuid()).orElseThrow( + entityToSave.setContact(contactBareRepo.findByUuid(body.getContactUuid()).orElseThrow( () -> new NoSuchElementException("cannot find contactUuid " + body.getContactUuid()) )); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java index 783c9634..60464ee8 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java @@ -3,8 +3,7 @@ package net.hostsharing.hsadminng.hs.office.relation; import lombok.*; import lombok.experimental.FieldNameConstants; import lombok.experimental.SuperBuilder; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; @@ -70,7 +69,7 @@ public abstract class HsOfficeRelationEntity implements RbacObject { verifyNotNull(newValue, "contact"); - entity.setContact(em.getReference(HsOfficeContactRbacEntity.class, newValue)); + entity.setContact(em.getReference(HsOfficeContactBareEntity.class, newValue)); }); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java index 94d27f6d..b6a6d263 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java @@ -9,7 +9,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; @@ -62,7 +62,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup HsOfficeDebitorRepository debitorRepo; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactRbacRepository contactRepo; @Autowired JpaAttempt jpaAttempt; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java index f20006c2..62d319ea 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java @@ -32,7 +32,7 @@ import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_C import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; -import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT; +import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareTestEntity.TEST_BARE_CONTACT; import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -75,7 +75,7 @@ public class HsHostingAssetControllerRestTest { .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) .identifier("vm1234") .caption("some fake cloud-server") - .alarmContact(TEST_CONTACT) + .alarmContact(TEST_BARE_CONTACT) .build()), """ [ @@ -101,7 +101,7 @@ public class HsHostingAssetControllerRestTest { .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) .identifier("vm1234") .caption("some fake managed-server") - .alarmContact(TEST_CONTACT) + .alarmContact(TEST_BARE_CONTACT) .config(Map.ofEntries( entry("monit_max_ssd_usage", 70), entry("monit_max_cpu_usage", 80), diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java index b75e401d..7a8c2f76 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java @@ -1,6 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.mapper.KeyValueMap; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; @@ -48,7 +49,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< entry("SSD", 256), entry("MEM", 64) ); - final HsOfficeContactRbacEntity givenInitialContact = HsOfficeContactRbacEntity.builder() + final HsOfficeContactBareEntity givenInitialContact = HsOfficeContactBareEntity.builder() .uuid(UUID.randomUUID()) .build(); @@ -111,7 +112,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< ); } - static HsOfficeContactRbacEntity newContact(final UUID uuid) { - return HsOfficeContactRbacEntity.builder().uuid(uuid).build(); + static HsOfficeContactBareEntity newContact(final UUID uuid) { + return HsOfficeContactBareEntity.builder().uuid(uuid).build(); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetBareEntity.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetBareEntity.java index 235d3c6d..34e6721f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetBareEntity.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetBareEntity.java @@ -10,7 +10,7 @@ import lombok.Setter; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import org.hibernate.annotations.Type; @@ -69,7 +69,7 @@ public class HsHostingAssetBareEntity implements HsHostingAsset { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "alarmcontactuuid") - private HsOfficeContactRbacEntity alarmContact; + private HsOfficeContactBareEntity alarmContact; @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java index 1fc3761f..af65a204 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.migration; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionEntity; import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType; import net.hostsharing.hsadminng.hs.office.coopshares.HsOfficeCoopSharesTransactionEntity; @@ -121,7 +121,7 @@ public class ImportOfficeData extends CsvDataImport { -1 ); - static Map contacts = new WriteOnceMap<>(); + static Map contacts = new WriteOnceMap<>(); static Map persons = new WriteOnceMap<>(); static Map partners = new WriteOnceMap<>(); static Map debitors = new WriteOnceMap<>(); @@ -979,7 +979,7 @@ public class ImportOfficeData extends CsvDataImport { contactPerson = addPerson(HsOfficePersonEntity.builder().build(), rec); } - final var contact = HsOfficeContactRbacEntity.builder().build(); + final var contact = HsOfficeContactBareEntity.builder().build(); initContact(contact, rec); if (containsPartnerRel(rec)) { @@ -1057,7 +1057,7 @@ public class ImportOfficeData extends CsvDataImport { final HsOfficeRelationType type, final HsOfficePersonEntity anchor, final HsOfficePersonEntity holder, - final HsOfficeContactRbacEntity contact) { + final HsOfficeContactBareEntity contact) { final var rel = HsOfficeRelationBareEntity.builder() .anchor(anchor) .holder(holder) @@ -1118,7 +1118,7 @@ public class ImportOfficeData extends CsvDataImport { assertThat(unexpectedRolesSet).isEmpty(); } - private HsOfficeContactRbacEntity initContact(final HsOfficeContactRbacEntity contact, final Record contactRecord) { + private HsOfficeContactBareEntity initContact(final HsOfficeContactBareEntity contact, final Record contactRecord) { contact.setCaption(toCaption( contactRecord.getString("salut"), diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareTestEntity.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareTestEntity.java new file mode 100644 index 00000000..bb50a609 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareTestEntity.java @@ -0,0 +1,16 @@ +package net.hostsharing.hsadminng.hs.office.contact; + +import java.util.Map; + +public class HsOfficeContactBareTestEntity { + + public static final HsOfficeContactBareEntity TEST_BARE_CONTACT = hsOfficeContact("some contact", "some-contact@example.com"); + + static public HsOfficeContactBareEntity hsOfficeContact(final String caption, final String emailAddr) { + return HsOfficeContactBareEntity.builder() + .caption(caption) + .postalAddress("address of " + caption) + .emailAddresses(Map.of("main", emailAddr)) + .build(); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java index d7a77e56..4bd2a4be 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactControllerAcceptanceTest.java @@ -45,7 +45,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu Context contextMock; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactRbacRepository contactRepo; @Autowired JpaAttempt jpaAttempt; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java similarity index 98% rename from src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcherUnitTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java index e1f00a98..95b4eb94 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactPatcherUnitTest.java @@ -13,7 +13,7 @@ import static net.hostsharing.hsadminng.mapper.PatchMap.patchMap; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @TestInstance(PER_CLASS) -class HsOfficeContactEntityPatcherUnitTest extends PatchUnitTestBase< +class HsOfficeContactPatcherUnitTest extends PatchUnitTestBase< HsOfficeContactPatchResource, HsOfficeContactRbacEntity > { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepositoryIntegrationTest.java similarity index 98% rename from src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepositoryIntegrationTest.java index 87a236fb..5f5e6190 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepositoryIntegrationTest.java @@ -21,7 +21,7 @@ import java.util.Arrays; import java.util.List; import java.util.function.Supplier; -import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.hsOfficeContact; +import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacTestEntity.hsOfficeContact; import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf; import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.distinctRoleNamesOf; import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt; @@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest @Import( { Context.class, JpaAttempt.class }) -class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithCleanup { +class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithCleanup { @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactRbacRepository contactRepo; @Autowired RawRbacRoleRepository rawRoleRepo; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/TestHsOfficeContact.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacTestEntity.java similarity index 70% rename from src/test/java/net/hostsharing/hsadminng/hs/office/contact/TestHsOfficeContact.java rename to src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacTestEntity.java index cf20b8f4..ba96f31b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/TestHsOfficeContact.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacTestEntity.java @@ -2,9 +2,9 @@ package net.hostsharing.hsadminng.hs.office.contact; import java.util.Map; -public class TestHsOfficeContact { +public class HsOfficeContactRbacTestEntity { - public static final HsOfficeContactRbacEntity TEST_CONTACT = hsOfficeContact("some contact", "some-contact@example.com"); + public static final HsOfficeContactRbacEntity TEST_RBAC_CONTACT = hsOfficeContact("some contact", "some-contact@example.com"); static public HsOfficeContactRbacEntity hsOfficeContact(final String caption, final String emailAddr) { return HsOfficeContactRbacEntity.builder() diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactUnitTest.java similarity index 93% rename from src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityUnitTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactUnitTest.java index 7b290ecc..94f8e0b8 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactUnitTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -class HsOfficeContactEntityUnitTest { +class HsOfficeContactUnitTest { @Test void toStringReturnsNullForNullContact() { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java index 564f1d37..15e23122 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java @@ -5,7 +5,7 @@ import io.restassured.http.ContentType; import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; @@ -55,7 +55,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu HsOfficePartnerRepository partnerRepo; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactBareRepository contactBareRepo; @Autowired HsOfficeBankAccountRepository bankAccountRepo; @@ -268,7 +268,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu context.define("superuser-alex@hostsharing.net"); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0); final var givenBillingPerson = personRepo.findPersonByOptionalNameLike("Fourth").get(0); @@ -325,7 +325,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu context.define("superuser-alex@hostsharing.net"); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -414,7 +414,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu context.define("superuser-alex@hostsharing.net"); final var givenDebitorRelUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -551,7 +551,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu context.define("superuser-alex@hostsharing.net"); final var givenDebitor = givenSomeTemporaryDebitor(); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -721,7 +721,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu return jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0).load(); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var newDebitor = HsOfficeDebitorEntity.builder() .debitorNumberSuffix(nextDebitorSuffix()) .billable(true) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java index dfa94e6a..9ff0f6e5 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.debitor; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; @@ -21,7 +21,7 @@ class HsOfficeDebitorEntityUnitTest { .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("some billing trade name") .build()) - .contact(HsOfficeContactRbacEntity.builder().caption("some caption").build()) + .contact(HsOfficeContactBareEntity.builder().caption("some caption").build()) .build(); @Test diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java index 2e1f7d39..499a0b63 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; @@ -50,7 +50,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean HsOfficePartnerRepository partnerRepo; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactBareRepository contactBareRepo; @Autowired HsOfficePersonRepository personRepo; @@ -85,7 +85,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var count = debitorRepo.count(); final var givenPartner = partnerRepo.findPartnerByPartnerNumber(10001); final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH")); - final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("first contact")); + final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("first contact")); // when final var result = attempt(em, () -> { @@ -119,7 +119,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean // given context("superuser-alex@hostsharing.net"); final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH")); - final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("first contact")); + final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("first contact")); // when final var result = attempt(em, () -> { @@ -157,7 +157,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean attempt(em, () -> { final var givenPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First GmbH")); final var givenDebitorPerson = one(personRepo.findPersonByOptionalNameLike("Fourth eG")); - final var givenContact = one(contactRepo.findContactByOptionalCaptionLike("fourth contact")); + final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("fourth contact")); final var newDebitor = HsOfficeDebitorEntity.builder() .debitorNumberSuffix("22") .debitorRel(HsOfficeRelationRbacEntity.builder() @@ -323,7 +323,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean "hs_office_relation#FourtheG-with-DEBITOR-FourtheG:ADMIN", true); final var givenNewPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First")); final var givenNewBillingPerson = one(personRepo.findPersonByOptionalNameLike("Firby")); - final var givenNewContact = one(contactRepo.findContactByOptionalCaptionLike("sixth contact")); + final var givenNewContact = one(contactBareRepo.findContactByOptionalCaptionLike("sixth contact")); final var givenNewBankAccount = one(bankAccountRepo.findByOptionalHolderLike("first")); final String givenNewVatId = "NEW-VAT-ID"; final String givenNewVatCountryCode = "NC"; @@ -611,7 +611,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean context("superuser-alex@hostsharing.net"); final var givenPartner = one(partnerRepo.findPartnerByOptionalNameLike(partnerName)); final var givenPartnerPerson = givenPartner.getPartnerRel().getHolder(); - final var givenContact = one(contactRepo.findContactByOptionalCaptionLike(contactCaption)); + final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike(contactCaption)); final var givenBankAccount = bankAccountHolder != null ? one(bankAccountRepo.findByOptionalHolderLike(bankAccountHolder)) : null; final var newDebitor = HsOfficeDebitorEntity.builder() diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java index febb5c8e..fea82b79 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java @@ -4,7 +4,7 @@ import lombok.experimental.UtilityClass; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; -import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT; +import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareTestEntity.TEST_BARE_CONTACT; import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER; @UtilityClass @@ -17,7 +17,7 @@ public class TestHsOfficeDebitor { .debitorRel(HsOfficeRelationRbacEntity.builder() .holder(HsOfficePersonEntity.builder().build()) .anchor(HsOfficePersonEntity.builder().build()) - .contact(TEST_CONTACT) + .contact(TEST_BARE_CONTACT) .build()) .partner(TEST_PARTNER) .defaultPrefix("abc") 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 25e0ee8e..fc661c89 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 @@ -3,8 +3,8 @@ package net.hostsharing.hsadminng.hs.office.partner; import io.restassured.RestAssured; import io.restassured.http.ContentType; import net.hostsharing.hsadminng.HsadminNgApplication; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; @@ -48,7 +48,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu HsOfficePersonRepository personRepo; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactBareRepository contactBareRepo; @Autowired JpaAttempt jpaAttempt; @@ -92,7 +92,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu context.define("superuser-alex@hostsharing.net"); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow(); final var givenPerson = personRepo.findPersonByOptionalNameLike("Third").stream().findFirst().orElseThrow(); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").stream().findFirst().orElseThrow(); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").stream().findFirst().orElseThrow(); final var location = RestAssured // @formatter:off .given() @@ -189,7 +189,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu context.define("superuser-alex@hostsharing.net"); final var mandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -524,7 +524,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu context.define("superuser-alex@hostsharing.net"); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow(); final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow(); - final var givenContact = contactRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow(); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow(); final var partnerRel = new HsOfficeRelationRbacEntity(); partnerRel.setType(HsOfficeRelationType.PARTNER); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java index 9a5d42e1..a8928fb0 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.partner; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; @@ -37,7 +37,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< private final HsOfficePersonEntity givenInitialPerson = HsOfficePersonEntity.builder() .uuid(INITIAL_PERSON_UUID) .build(); - private final HsOfficeContactRbacEntity givenInitialContact = HsOfficeContactRbacEntity.builder() + private final HsOfficeContactBareEntity givenInitialContact = HsOfficeContactBareEntity.builder() .uuid(INITIAL_CONTACT_UUID) .build(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java index b0a396ee..f1c9ad2c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.partner; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; @@ -23,7 +23,7 @@ class HsOfficePartnerEntityUnitTest { .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("some trade name") .build()) - .contact(HsOfficeContactRbacEntity.builder().caption("some caption").build()) + .contact(HsOfficeContactBareEntity.builder().caption("some caption").build()) .build()) .build(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java index 5b712087..b74e4036 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.context.Context; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; @@ -49,7 +49,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean HsOfficePersonRepository personRepo; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactBareRepository contactBareRepo; @Autowired RawRbacObjectRepository rawObjectRepo; @@ -110,7 +110,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean // when attempt(em, () -> { final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var newRelation = HsOfficeRelationRbacEntity.builder() @@ -466,7 +466,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean private HsOfficeRelationEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) { final var givenMandantorPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike(contact).get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contact).get(0); final var partnerRel = HsOfficeRelationRbacEntity.builder() .holder(givenPartnerPerson) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java index 25cbc082..a62b8910 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.office.partner; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; @@ -25,7 +25,7 @@ public class TestHsOfficePartner { .personType(LEGAL_PERSON) .tradeName(tradeName) .build()) - .contact(HsOfficeContactRbacEntity.builder() + .contact(HsOfficeContactBareEntity.builder() .caption(tradeName) .build()) .build() diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java index a7909c3a..87a015b5 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java @@ -2,10 +2,10 @@ package net.hostsharing.hsadminng.hs.office.relation; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.context.Context; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; @@ -49,7 +49,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean HsOfficePersonRepository personRepo; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactBareRepository contactBareRepo; @Autowired JpaAttempt jpaAttempt; @@ -125,7 +125,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean context.define("superuser-alex@hostsharing.net"); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("second").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("second").get(0); final var location = RestAssured // @formatter:off .given() @@ -172,7 +172,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean context.define("superuser-alex@hostsharing.net"); final var givenAnchorPersonUuid = GIVEN_NON_EXISTING_HOLDER_PERSON_UUID; final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Smith").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -204,7 +204,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean context.define("superuser-alex@hostsharing.net"); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -353,7 +353,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean context.define("superuser-alex@hostsharing.net"); final var givenRelation = givenSomeTemporaryRelationBessler(); assertThat(givenRelation.getContact().getCaption()).isEqualTo("seventh contact"); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth").get(0); RestAssured // @formatter:off .given() @@ -455,7 +455,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean context.define("superuser-alex@hostsharing.net"); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("seventh contact").get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("seventh contact").get(0); final var newRelation = HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.REPRESENTATIVE) .anchor(givenAnchorPerson) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java index 5bfd4690..ca1dfa8d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.relation; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; @@ -44,7 +45,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< final HsOfficePersonEntity givenInitialHolderPerson = HsOfficePersonEntity.builder() .uuid(UUID.randomUUID()) .build(); - final HsOfficeContactRbacEntity givenInitialContact = HsOfficeContactRbacEntity.builder() + final HsOfficeContactBareEntity givenInitialContact = HsOfficeContactBareEntity.builder() .uuid(UUID.randomUUID()) .build(); @@ -82,9 +83,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< ); } - static HsOfficeContactRbacEntity newContact(final UUID uuid) { - final var newContact = new HsOfficeContactRbacEntity(); - newContact.setUuid(uuid); - return newContact; + static HsOfficeContactBareEntity newContact(final UUID uuid) { + return HsOfficeContactBareEntity.builder().uuid(uuid).build(); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java index 7bf9112c..329e97c6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.office.relation; import net.hostsharing.hsadminng.context.Context; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; @@ -40,7 +40,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea HsOfficePersonRepository personRepo; @Autowired - HsOfficeContactRepository contactRepo; + HsOfficeContactBareRepository contactBareRepo; @Autowired RawRbacRoleRepository rawRoleRepo; @@ -71,7 +71,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").stream() .filter(p -> p.getPersonType() == NATURAL_PERSON) .findFirst().orElseThrow(); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").stream() + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").stream() .findFirst().orElseThrow(); // when @@ -111,7 +111,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Bert").stream() .filter(p -> p.getPersonType() == NATURAL_PERSON) .findFirst().orElseThrow(); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("fourth contact").stream() + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").stream() .findFirst().orElseThrow(); final var newRelation = HsOfficeRelationRbacEntity.builder() .anchor(givenAnchorPerson) @@ -219,7 +219,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea givenRelation, "hs_office_person#ErbenBesslerMelBessler:ADMIN"); context("superuser-alex@hostsharing.net"); - final var givenContact = contactRepo.findContactByOptionalCaptionLike("sixth contact").stream().findFirst().orElseThrow(); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("sixth contact").stream().findFirst().orElseThrow(); // when final var result = jpaAttempt.transacted(() -> { @@ -413,7 +413,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea context("superuser-alex@hostsharing.net"); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike(holderPerson).get(0); - final var givenContact = contactRepo.findContactByOptionalCaptionLike(contact).get(0); + final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contact).get(0); final var newRelation = HsOfficeRelationRbacEntity.builder() .type(HsOfficeRelationType.REPRESENTATIVE) .anchor(givenAnchorPerson) -- 2.39.5 From b41dce5c6c8939290862179563c7dfddea2dc371 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sat, 3 Aug 2024 18:53:19 +0200 Subject: [PATCH 04/12] switch to HsOfficeRelationRbacEntity + HsOfficeRelationBaseEntity as subclasses of HsOfficeRelation, now tests pass --- .../project/HsBookingProjectEntity.java | 4 +- .../hs/office/contact/HsOfficeContact.java | 4 +- .../debitor/HsOfficeDebitorController.java | 14 +- .../office/debitor/HsOfficeDebitorEntity.java | 11 +- .../debitor/HsOfficeDebitorEntityPatcher.java | 4 +- .../membership/HsOfficeMembershipEntity.java | 4 +- .../partner/HsOfficePartnerController.java | 14 +- .../office/partner/HsOfficePartnerEntity.java | 11 +- .../partner/HsOfficePartnerEntityPatcher.java | 4 +- .../partner/HsOfficePartnerRepository.java | 2 +- .../hs/office/relation/HsOfficeRelation.java | 83 ++++++++ .../relation/HsOfficeRelationBareEntity.java | 9 +- ...va => HsOfficeRelationBareRepository.java} | 12 +- .../relation/HsOfficeRelationController.java | 16 +- .../relation/HsOfficeRelationEntity.java | 179 ------------------ .../HsOfficeRelationEntityPatcher.java | 4 +- .../relation/HsOfficeRelationRbacEntity.java | 9 +- .../HsOfficeRelationRbacRepository.java | 37 ++++ .../HsOfficeSepaMandateEntity.java | 4 +- .../hs/migration/ImportOfficeData.java | 6 +- ...OfficeDebitorControllerAcceptanceTest.java | 7 +- .../HsOfficeDebitorEntityPatcherUnitTest.java | 19 +- .../HsOfficeDebitorEntityUnitTest.java | 5 +- ...fficeDebitorRepositoryIntegrationTest.java | 17 +- .../office/debitor/TestHsOfficeDebitor.java | 4 +- ...OfficePartnerControllerAcceptanceTest.java | 20 +- .../HsOfficePartnerControllerRestTest.java | 8 +- .../HsOfficePartnerEntityPatcherUnitTest.java | 14 +- .../HsOfficePartnerEntityUnitTest.java | 4 +- ...fficePartnerRepositoryIntegrationTest.java | 13 +- .../office/partner/TestHsOfficePartner.java | 4 +- ...fficeRelationControllerAcceptanceTest.java | 22 +-- ...a => HsOfficeRelationPatcherUnitTest.java} | 15 +- ...ficeRelationRepositoryIntegrationTest.java | 68 +++---- ...est.java => HsOfficeRelationUnitTest.java} | 2 +- 35 files changed, 290 insertions(+), 363 deletions(-) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelation.java rename src/main/java/net/hostsharing/hsadminng/hs/office/relation/{HsOfficeRelationRepository.java => HsOfficeRelationBareRepository.java} (60%) delete mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java rename src/test/java/net/hostsharing/hsadminng/hs/office/relation/{HsOfficeRelationEntityPatcherUnitTest.java => HsOfficeRelationPatcherUnitTest.java} (86%) rename src/test/java/net/hostsharing/hsadminng/hs/office/relation/{HsOfficeRelationEntityUnitTest.java => HsOfficeRelationUnitTest.java} (97%) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java index 8f5d1397..4408e7b3 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java @@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.booking.project; import lombok.*; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; @@ -81,7 +81,7 @@ public class HsBookingProjectEntity implements Stringifyable, RbacObject {entityToSave.setDebitorRel(relRepo.save(debitorRel));}, + debitorRel -> {entityToSave.setDebitorRel(relBareRepo.save(debitorRel));}, () -> { throw new EntityNotFoundException("ERROR: [400] debitorRelUuid not found: " + body.getDebitorRelUuid());}); } 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 04ebd03b..4f9d7c71 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 @@ -8,7 +8,8 @@ import lombok.Setter; import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; @@ -66,7 +67,7 @@ public class HsOfficeDebitorEntity implements RbacObject, private static Stringify stringify = stringify(HsOfficeDebitorEntity.class, "debitor") .withIdProp(HsOfficeDebitorEntity::toShortString) - .withProp(e -> ofNullable(e.getDebitorRel()).map(HsOfficeRelationEntity::toShortString).orElse(null)) + .withProp(e -> ofNullable(e.getDebitorRel()).map(HsOfficeRelation::toShortString).orElse(null)) .withProp(HsOfficeDebitorEntity::getDefaultPrefix) .quotedValues(false); @@ -101,7 +102,7 @@ public class HsOfficeDebitorEntity implements RbacObject, @ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }, optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "debitorreluuid", nullable = false) - private HsOfficeRelationEntity debitorRel; + private HsOfficeRelationBareEntity debitorRel; @Column(name = "billable", nullable = false) private Boolean billable; // not a primitive because otherwise the default would be false @@ -188,7 +189,7 @@ public class HsOfficeDebitorEntity implements RbacObject, "defaultPrefix") .toRole("global", ADMIN).grantPermission(INSERT) - .importRootEntityAliasProxy("debitorRel", HsOfficeRelationEntity.class, usingCase(DEBITOR), + .importRootEntityAliasProxy("debitorRel", HsOfficeRelation.class, usingCase(DEBITOR), directlyFetchedByDependsOnColumn(), dependsOnColumn("debitorRelUuid")) .createPermission(DELETE).grantedTo("debitorRel", OWNER) @@ -202,7 +203,7 @@ public class HsOfficeDebitorEntity implements RbacObject, .toRole("refundBankAccount", ADMIN).grantRole("debitorRel", AGENT) .toRole("debitorRel", AGENT).grantRole("refundBankAccount", REFERRER) - .importEntityAlias("partnerRel", HsOfficeRelationEntity.class, usingDefaultCase(), + .importEntityAlias("partnerRel", HsOfficeRelation.class, usingDefaultCase(), dependsOnColumn("debitorRelUuid"), fetchedBySql(""" SELECT ${columns} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java index cd50abf8..2acaf1eb 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.OptionalFromJson; @@ -25,7 +25,7 @@ class HsOfficeDebitorEntityPatcher implements EntityPatcher { verifyNotNull(newValue, "debitorRel"); - entity.setDebitorRel(em.getReference(HsOfficeRelationEntity.class, newValue)); + entity.setDebitorRel(em.getReference(HsOfficeRelationBareEntity.class, newValue)); }); Optional.ofNullable(resource.getBillable()).ifPresent(entity::setBillable); OptionalFromJson.of(resource.getVatId()).ifPresent(entity::setVatId); 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 20dac5c7..eb1523ec 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 @@ -8,7 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.errors.DisplayName; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; @@ -165,7 +165,7 @@ public class HsOfficeMembershipEntity implements RbacObject stringify = stringify(HsOfficePartnerEntity.class, "partner") .withIdProp(HsOfficePartnerEntity::toShortString) .withProp(p -> ofNullable(p.getPartnerRel()) - .map(HsOfficeRelationEntity::getHolder) + .map(HsOfficeRelation::getHolder) .map(HsOfficePersonEntity::toShortString) .orElse(null)) .withProp(p -> ofNullable(p.getPartnerRel()) - .map(HsOfficeRelationEntity::getContact) + .map(HsOfficeRelation::getContact) .map(HsOfficeContact::toShortString) .orElse(null)) .quotedValues(false); @@ -68,7 +69,7 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject { verifyNotNull(newValue, "partnerRel"); - entity.setPartnerRel(em.getReference(HsOfficeRelationEntity.class, newValue)); + entity.setPartnerRel(em.getReference(HsOfficeRelationBareEntity.class, newValue)); }); new HsOfficePartnerDetailsEntityPatcher(em, entity.getDetails()).apply(resource.getDetails()); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java index f63bf469..be9463bd 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepository.java @@ -15,7 +15,7 @@ public interface HsOfficePartnerRepository extends Repository, Stringifyable { + + private static Stringify toString = stringify(HsOfficeRelation.class, "rel") + .withProp(Fields.anchor, HsOfficeRelation::getAnchor) + .withProp(Fields.type, HsOfficeRelation::getType) + .withProp(Fields.mark, HsOfficeRelation::getMark) + .withProp(Fields.holder, HsOfficeRelation::getHolder) + .withProp(Fields.contact, HsOfficeRelation::getContact); + + private static Stringify toShortString = stringify(HsOfficeRelation.class, "rel") + .withProp(Fields.anchor, HsOfficeRelation::getAnchor) + .withProp(Fields.type, HsOfficeRelation::getType) + .withProp(Fields.holder, HsOfficeRelation::getHolder); + + @Id + @GeneratedValue + private UUID uuid; + + @Version + private int version; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "anchoruuid") + private HsOfficePersonEntity anchor; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "holderuuid") + private HsOfficePersonEntity holder; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "contactuuid") + private HsOfficeContactBareEntity contact; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private HsOfficeRelationType type; + + @Column(name = "mark") + private String mark; + + @Override + public HsOfficeRelation load() { + RbacObject.super.load(); + anchor.load(); + holder.load(); + contact.load(); + return this; + } + + @Override + public String toString() { + return toString.apply(this); + } + + @Override + public String toShortString() { + return toShortString.apply(this); + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareEntity.java index d5e056df..55a5668f 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareEntity.java @@ -11,14 +11,9 @@ import jakarta.persistence.Table; @Entity @Table(name = "hs_office_relation") -@SuperBuilder @NoArgsConstructor @Getter @Setter -public class HsOfficeRelationBareEntity extends HsOfficeRelationEntity { - - @Override - public HsOfficeRelationEntityBuilder toBuilder() { - return null; // FIXME: also the ugly generics, if possible - } +@SuperBuilder(toBuilder = true) +public class HsOfficeRelationBareEntity extends HsOfficeRelation { } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareRepository.java similarity index 60% rename from src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepository.java rename to src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareRepository.java index 95bac3a2..4ecadbe1 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareRepository.java @@ -8,11 +8,11 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -public interface HsOfficeRelationRepository extends Repository { +public interface HsOfficeRelationBareRepository extends Repository { - Optional findByUuid(UUID id); + Optional findByUuid(UUID id); - default List findRelationRelatedToPersonUuidAndRelationType(@NotNull UUID personUuid, HsOfficeRelationType relationType) { + default List findRelationRelatedToPersonUuidAndRelationType(@NotNull UUID personUuid, HsOfficeRelationType relationType) { return findRelationRelatedToPersonUuidAndRelationTypeString(personUuid, relationType.toString()); } @@ -20,16 +20,16 @@ public interface HsOfficeRelationRepository extends Repository findRelationRelatedToPersonUuid(@NotNull UUID personUuid); + List findRelationRelatedToPersonUuid(@NotNull UUID personUuid); @Query(value = """ SELECT p.* FROM hs_office_relation_rv AS p WHERE (:relationType IS NULL OR p.type = cast(:relationType AS HsOfficeRelationType)) AND ( p.anchorUuid = :personUuid OR p.holderUuid = :personUuid) """, nativeQuery = true) - List findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); + List findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); - HsOfficeRelationEntity save(final HsOfficeRelationEntity entity); + HsOfficeRelationBareEntity save(final HsOfficeRelation entity); long count(); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java index 29381ee3..77e5d7a6 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java @@ -31,7 +31,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { private Mapper mapper; @Autowired - private HsOfficeRelationRepository relationRepo; + private HsOfficeRelationRbacRepository relationRbacRepo; @Autowired private HsOfficePersonRepository holderRepo; @@ -51,7 +51,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { final HsOfficeRelationTypeResource relationType) { context.define(currentUser, assumedRoles); - final var entities = relationRepo.findRelationRelatedToPersonUuidAndRelationType(personUuid, + final var entities = relationRbacRepo.findRelationRelatedToPersonUuidAndRelationType(personUuid, mapper.map(relationType, HsOfficeRelationType.class)); final var resources = mapper.mapList(entities, HsOfficeRelationResource.class, @@ -81,7 +81,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { () -> new NoSuchElementException("cannot find contactUuid " + body.getContactUuid()) )); - final var saved = relationRepo.save(entityToSave); + final var saved = relationRbacRepo.save(entityToSave); final var uri = MvcUriComponentsBuilder.fromController(getClass()) @@ -102,7 +102,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { context.define(currentUser, assumedRoles); - final var result = relationRepo.findByUuid(relationUuid); + final var result = relationRbacRepo.findByUuid(relationUuid); if (result.isEmpty()) { return ResponseEntity.notFound().build(); } @@ -117,7 +117,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { final UUID relationUuid) { context.define(currentUser, assumedRoles); - final var result = relationRepo.deleteByUuid(relationUuid); + final var result = relationRbacRepo.deleteByUuid(relationUuid); if (result == 0) { return ResponseEntity.notFound().build(); } @@ -135,17 +135,17 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { context.define(currentUser, assumedRoles); - final var current = relationRepo.findByUuid(relationUuid).orElseThrow(); + final var current = relationRbacRepo.findByUuid(relationUuid).orElseThrow(); new HsOfficeRelationEntityPatcher(em, current).apply(body); - final var saved = relationRepo.save(current); + final var saved = relationRbacRepo.save(current); final var mapped = mapper.map(saved, HsOfficeRelationResource.class); return ResponseEntity.ok(mapped); } - final BiConsumer RELATION_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { + final BiConsumer RELATION_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { resource.setAnchor(mapper.map(entity.getAnchor(), HsOfficePersonResource.class)); resource.setHolder(mapper.map(entity.getHolder(), HsOfficePersonResource.class)); resource.setContact(mapper.map(entity.getContact(), HsOfficeContactResource.class)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java deleted file mode 100644 index 60464ee8..00000000 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntity.java +++ /dev/null @@ -1,179 +0,0 @@ -package net.hostsharing.hsadminng.hs.office.relation; - -import lombok.*; -import lombok.experimental.FieldNameConstants; -import lombok.experimental.SuperBuilder; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; -import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; -import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; -import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; - -import jakarta.persistence.*; -import jakarta.persistence.Column; -import java.io.IOException; -import java.util.UUID; - -import static jakarta.persistence.InheritanceType.TABLE_PER_CLASS; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.*; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inOtherCases; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingDefaultCase; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Nullable.NOT_NULL; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.*; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.*; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetchedByDependsOnColumn; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; - -@Entity -@Inheritance(strategy = TABLE_PER_CLASS) -@Getter -@Setter -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -@FieldNameConstants -public abstract class HsOfficeRelationEntity implements RbacObject, Stringifyable { - - private static Stringify toString = stringify(HsOfficeRelationEntity.class, "rel") - .withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor) - .withProp(Fields.type, HsOfficeRelationEntity::getType) - .withProp(Fields.mark, HsOfficeRelationEntity::getMark) - .withProp(Fields.holder, HsOfficeRelationEntity::getHolder) - .withProp(Fields.contact, HsOfficeRelationEntity::getContact); - - private static Stringify toShortString = stringify(HsOfficeRelationEntity.class, "rel") - .withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor) - .withProp(Fields.type, HsOfficeRelationEntity::getType) - .withProp(Fields.holder, HsOfficeRelationEntity::getHolder); - - @Id - @GeneratedValue - private UUID uuid; - - @Version - private int version; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "anchoruuid") - private HsOfficePersonEntity anchor; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "holderuuid") - private HsOfficePersonEntity holder; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "contactuuid") - private HsOfficeContactBareEntity contact; - - @Column(name = "type") - @Enumerated(EnumType.STRING) - private HsOfficeRelationType type; - - @Column(name = "mark") - private String mark; - - @Override - public HsOfficeRelationEntity load() { - RbacObject.super.load(); - anchor.load(); - holder.load(); - contact.load(); - return this; - } - - @Override - public String toString() { - return toString.apply(this); - } - - @Override - public String toShortString() { - return toShortString.apply(this); - } - - public abstract HsOfficeRelationEntityBuilder toBuilder(); - - public static RbacView rbac() { - return rbacViewFor("relation", HsOfficeRelationEntity.class) - .withIdentityView(SQL.projection(""" - (select idName from hs_office_person_iv p where p.uuid = anchorUuid) - || '-with-' || target.type || '-' - || (select idName from hs_office_person_iv p where p.uuid = holderUuid) - """)) - .withRestrictedViewOrderBy(SQL.expression( - "(select idName from hs_office_person_iv p where p.uuid = target.holderUuid)")) - .withUpdatableColumns("contactUuid") - .importEntityAlias("anchorPerson", HsOfficePersonEntity.class, usingDefaultCase(), - dependsOnColumn("anchorUuid"), - directlyFetchedByDependsOnColumn(), - NOT_NULL) - .importEntityAlias("holderPerson", HsOfficePersonEntity.class, usingDefaultCase(), - dependsOnColumn("holderUuid"), - directlyFetchedByDependsOnColumn(), - NOT_NULL) - .importEntityAlias("contact", HsOfficeContactRbacEntity.class, usingDefaultCase(), - dependsOnColumn("contactUuid"), - directlyFetchedByDependsOnColumn(), - NOT_NULL) - .switchOnColumn("type", - inCaseOf("REPRESENTATIVE", then -> { - then.createRole(OWNER, (with) -> { - with.owningUser(CREATOR); - with.incomingSuperRole(GLOBAL, ADMIN); - with.incomingSuperRole("holderPerson", ADMIN); - with.permission(DELETE); - }) - .createSubRole(ADMIN, (with) -> { - with.outgoingSubRole("anchorPerson", OWNER); - with.permission(UPDATE); - }) - .createSubRole(AGENT, (with) -> { - with.incomingSuperRole("anchorPerson", ADMIN); - }) - .createSubRole(TENANT, (with) -> { - with.incomingSuperRole("contact", ADMIN); - with.outgoingSubRole("anchorPerson", REFERRER); - with.outgoingSubRole("holderPerson", REFERRER); - with.outgoingSubRole("contact", REFERRER); - with.permission(SELECT); - }); - }), - // inCaseOf("DEBITOR", then -> {}), TODO.spec: needs to be defined - inOtherCases(then -> { - then.createRole(OWNER, (with) -> { - with.owningUser(CREATOR); - with.incomingSuperRole(GLOBAL, ADMIN); - with.incomingSuperRole("anchorPerson", ADMIN); - with.permission(DELETE); - }) - .createSubRole(ADMIN, (with) -> { - with.permission(UPDATE); - }) - .createSubRole(AGENT, (with) -> { - // TODO.rbac: we need relation:PROXY, to allow changing the relation contact. - // the alternative would be to move this to the relation:ADMIN role, - // but then the partner holder person could update the partner relation itself, - // see partner entity. - with.incomingSuperRole("holderPerson", ADMIN); - }) - .createSubRole(TENANT, (with) -> { - with.incomingSuperRole("contact", ADMIN); - with.outgoingSubRole("anchorPerson", REFERRER); - with.outgoingSubRole("holderPerson", REFERRER); - with.outgoingSubRole("contact", REFERRER); - with.permission(SELECT); - }); - })) - .toRole("anchorPerson", ADMIN).grantPermission(INSERT); - } - - public static void main(String[] args) throws IOException { - rbac().generateWithBaseFileName("5-hs-office/503-relation/5033-hs-office-relation-rbac"); - } -} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcher.java index f1def161..2888e3c0 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcher.java @@ -11,9 +11,9 @@ import java.util.UUID; class HsOfficeRelationEntityPatcher implements EntityPatcher { private final EntityManager em; - private final HsOfficeRelationEntity entity; + private final HsOfficeRelation entity; - HsOfficeRelationEntityPatcher(final EntityManager em, final HsOfficeRelationEntity entity) { + HsOfficeRelationEntityPatcher(final EntityManager em, final HsOfficeRelation entity) { this.em = em; this.entity = entity; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java index a7ab3b13..4f7eb0fb 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacEntity.java @@ -34,16 +34,11 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; @Entity @Table(name = "hs_office_relation_rv") -@SuperBuilder @NoArgsConstructor @Getter @Setter -public class HsOfficeRelationRbacEntity extends HsOfficeRelationEntity { - - @Override - public HsOfficeRelationRbacEntityBuilder toBuilder() { - return null; - } +@SuperBuilder(toBuilder = true) +public class HsOfficeRelationRbacEntity extends HsOfficeRelation { public static RbacView rbac() { return rbacViewFor("relation", HsOfficeRelationRbacEntity.class) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java new file mode 100644 index 00000000..e8187bb7 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java @@ -0,0 +1,37 @@ +package net.hostsharing.hsadminng.hs.office.relation; + +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; + +public interface HsOfficeRelationRbacRepository extends Repository { + + Optional findByUuid(UUID id); + + default List findRelationRelatedToPersonUuidAndRelationType(@NotNull UUID personUuid, HsOfficeRelationType relationType) { + return findRelationRelatedToPersonUuidAndRelationTypeString(personUuid, relationType.toString()); + } + + @Query(value = """ + SELECT p.* FROM hs_office_relation_rv AS p + WHERE p.anchorUuid = :personUuid OR p.holderUuid = :personUuid + """, nativeQuery = true) + List findRelationRelatedToPersonUuid(@NotNull UUID personUuid); + + @Query(value = """ + SELECT p.* FROM hs_office_relation_rv AS p + WHERE (:relationType IS NULL OR p.type = cast(:relationType AS HsOfficeRelationType)) + AND ( p.anchorUuid = :personUuid OR p.holderUuid = :personUuid) + """, nativeQuery = true) + List findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); + + HsOfficeRelationRbacEntity save(final HsOfficeRelationRbacEntity entity); + + long count(); + + int deleteByUuid(UUID uuid); +} 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 7b0f9121..6529b3cd 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 @@ -6,7 +6,7 @@ import lombok.*; import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.stringify.Stringify; @@ -110,7 +110,7 @@ public class HsOfficeSepaMandateEntity implements Stringifyable, RbacObject debitors = new WriteOnceMap<>(); static Map memberships = new WriteOnceMap<>(); - static Map relations = new WriteOnceMap<>(); + static Map relations = new WriteOnceMap<>(); static Map sepaMandates = new WriteOnceMap<>(); static Map bankAccounts = new WriteOnceMap<>(); static Map coopShares = new WriteOnceMap<>(); @@ -1053,7 +1053,7 @@ public class ImportOfficeData extends CsvDataImport { return containsRole(rec, "partner"); } - private static HsOfficeRelationEntity addRelation( + private static HsOfficeRelationBareEntity addRelation( final HsOfficeRelationType type, final HsOfficePersonEntity anchor, final HsOfficePersonEntity holder, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java index 15e23122..1ee1645e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java @@ -8,8 +8,9 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import org.json.JSONException; @@ -64,7 +65,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu HsOfficePersonRepository personRepo; @Autowired - HsOfficeRelationRepository relRepo; + HsOfficeRelationBareRepository relRepo; @Autowired JpaAttempt jpaAttempt; @@ -726,7 +727,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu .debitorNumberSuffix(nextDebitorSuffix()) .billable(true) .debitorRel( - HsOfficeRelationRbacEntity.builder() + HsOfficeRelationBareEntity.builder() .type(DEBITOR) .anchor(givenPartner.getPartnerRel().getHolder()) .holder(givenPartner.getPartnerRel().getHolder()) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java index cbc3a2f1..e46fedf9 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java @@ -2,8 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInstance; @@ -22,10 +21,7 @@ import static org.mockito.Mockito.lenient; @TestInstance(PER_CLASS) @ExtendWith(MockitoExtension.class) -class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< - HsOfficeDebitorPatchResource, - HsOfficeDebitorEntity - > { +class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase { private static final UUID INITIAL_DEBITOR_UUID = UUID.randomUUID(); private static final UUID INITIAL_DEBITOR_REL_UUID = UUID.randomUUID(); @@ -45,20 +41,21 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); - private final HsOfficeRelationEntity givenInitialDebitorRel = HsOfficeRelationRbacEntity.builder() + private final HsOfficeRelationBareEntity givenInitialDebitorRel = HsOfficeRelationBareEntity.builder() .uuid(INITIAL_DEBITOR_REL_UUID) .build(); private final HsOfficeBankAccountEntity givenInitialBankAccount = HsOfficeBankAccountEntity.builder() .uuid(INITIAL_REFUND_BANK_ACCOUNT_UUID) .build(); + @Mock private EntityManager em; @BeforeEach void initMocks() { - lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> - HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsOfficeRelationBareEntity.class), any())).thenAnswer(invocation -> + HsOfficeRelationBareEntity.builder().uuid(invocation.getArgument(1)).build()); lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation -> HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build()); } @@ -142,8 +139,8 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< ); } - private HsOfficeRelationEntity newDebitorRel(final UUID uuid) { - return HsOfficeRelationRbacEntity.builder() + private HsOfficeRelationBareEntity newDebitorRel(final UUID uuid) { + return HsOfficeRelationBareEntity.builder() .uuid(uuid) .build(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java index 9ff0f6e5..2e063e92 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java @@ -4,15 +4,14 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; class HsOfficeDebitorEntityUnitTest { - private HsOfficeRelationEntity givenDebitorRel = HsOfficeRelationRbacEntity.builder() + private HsOfficeRelationBareEntity givenDebitorRel = HsOfficeRelationBareEntity.builder() .anchor(HsOfficePersonEntity.builder() .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("some partner trade name") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java index 499a0b63..ba466014 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java @@ -5,8 +5,9 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; @@ -92,7 +93,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var newDebitor = HsOfficeDebitorEntity.builder() .partner(givenPartner) .debitorNumberSuffix("21") - .debitorRel(HsOfficeRelationRbacEntity.builder() + .debitorRel(HsOfficeRelationBareEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenPartnerPerson) @@ -125,7 +126,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var result = attempt(em, () -> { final var newDebitor = HsOfficeDebitorEntity.builder() .debitorNumberSuffix("21") - .debitorRel(HsOfficeRelationRbacEntity.builder() + .debitorRel(HsOfficeRelationBareEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenPartnerPerson) @@ -160,7 +161,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var givenContact = one(contactBareRepo.findContactByOptionalCaptionLike("fourth contact")); final var newDebitor = HsOfficeDebitorEntity.builder() .debitorNumberSuffix("22") - .debitorRel(HsOfficeRelationRbacEntity.builder() + .debitorRel(HsOfficeRelationBareEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenDebitorPerson) @@ -332,7 +333,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean // when final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - givenDebitor.setDebitorRel(HsOfficeRelationRbacEntity.builder() + givenDebitor.setDebitorRel(HsOfficeRelationBareEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenNewPartnerPerson) .holder(givenNewBillingPerson) @@ -489,7 +490,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean if (withPartner) { assertThat(foundEntity.getPartner()).isNotNull(); } - assertThat(foundEntity.getDebitorRel()).extracting(HsOfficeRelationEntity::toString) + assertThat(foundEntity.getDebitorRel()).extracting(HsOfficeRelation::toString) .isEqualTo(saved.getDebitorRel().toString()); }); } @@ -617,7 +618,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean final var newDebitor = HsOfficeDebitorEntity.builder() .partner(givenPartner) .debitorNumberSuffix("20") - .debitorRel(HsOfficeRelationRbacEntity.builder() + .debitorRel(HsOfficeRelationBareEntity.builder() .type(HsOfficeRelationType.DEBITOR) .anchor(givenPartnerPerson) .holder(givenPartnerPerson) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java index fea82b79..3d03a856 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/TestHsOfficeDebitor.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor; import lombok.experimental.UtilityClass; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareTestEntity.TEST_BARE_CONTACT; import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER; @@ -14,7 +14,7 @@ public class TestHsOfficeDebitor { public static final HsOfficeDebitorEntity TEST_DEBITOR = HsOfficeDebitorEntity.builder() .debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX) - .debitorRel(HsOfficeRelationRbacEntity.builder() + .debitorRel(HsOfficeRelationBareEntity.builder() .holder(HsOfficePersonEntity.builder().build()) .anchor(HsOfficePersonEntity.builder().build()) .contact(TEST_BARE_CONTACT) 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 fc661c89..31c6e806 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 @@ -3,13 +3,13 @@ package net.hostsharing.hsadminng.hs.office.partner; import io.restassured.RestAssured; import io.restassured.http.ContentType; import net.hostsharing.hsadminng.HsadminNgApplication; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; @@ -42,7 +42,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu HsOfficePartnerRepository partnerRepo; @Autowired - HsOfficeRelationRepository relationRepo; + HsOfficeRelationBareRepository relationRepo; @Autowired HsOfficePersonRepository personRepo; @@ -180,7 +180,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .post("http://localhost/api/hs/office/partners") .then().log().all().assertThat() .statusCode(400) - .body("message", is("Unable to find " + HsOfficeContactRbacEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID)); + .body("message", is("Unable to find " + HsOfficeContactBareEntity.class.getName() + " with id " + GIVEN_NON_EXISTING_UUID)); // @formatter:on } @@ -406,7 +406,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu // and an ex-partner-relation got created final var anchorpartnerPersonUUid = givenPartner.getPartnerRel().getAnchor().getUuid(); assertThat(relationRepo.findRelationRelatedToPersonUuidAndRelationType(anchorpartnerPersonUUid, EX_PARTNER)) - .map(HsOfficeRelationEntity::toShortString) + .map(HsOfficeRelation::toShortString) .contains("rel(anchor='LP Hostsharing eG', type='EX_PARTNER', holder='UF Erben Bessler')"); } @@ -517,7 +517,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu } } - private HsOfficeRelationEntity givenSomeTemporaryPartnerRel( + private HsOfficeRelationBareEntity givenSomeTemporaryPartnerRel( final String partnerHolderName, final String contactName) { return jpaAttempt.transacted(() -> { @@ -526,7 +526,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow(); final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow(); - final var partnerRel = new HsOfficeRelationRbacEntity(); + final var partnerRel = new HsOfficeRelationBareEntity(); partnerRel.setType(HsOfficeRelationType.PARTNER); partnerRel.setAnchor(givenMandantPerson); partnerRel.setHolder(givenPerson); @@ -558,6 +558,6 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu cleanupAllNew(HsOfficePartnerEntity.class); // TODO: should not be necessary anymore, once it's deleted via after delete trigger - cleanupAllNew(HsOfficeRelationEntity.class); + cleanupAllNew(HsOfficeRelationBareEntity.class); } } 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 a14f2cbd..40d08e59 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 @@ -3,8 +3,8 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository; import net.hostsharing.hsadminng.mapper.Mapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -54,7 +54,7 @@ class HsOfficePartnerControllerRestTest { HsOfficePartnerRepository partnerRepo; @MockBean - HsOfficeRelationRepository relationRepo; + HsOfficeRelationBareRepository relationRepo; @MockBean EntityManager em; @@ -176,7 +176,7 @@ class HsOfficePartnerControllerRestTest { when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0); final UUID givenRelationUuid = UUID.randomUUID(); - when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationRbacEntity.builder() + when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationBareEntity.builder() .uuid(givenRelationUuid) .build()); when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java index a8928fb0..9392d60a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityPatcherUnitTest.java @@ -3,8 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInstance; @@ -49,8 +48,8 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< @BeforeEach void initMocks() { - lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation -> - HsOfficeRelationRbacEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsOfficeRelationBareEntity.class), any())).thenAnswer(invocation -> + HsOfficeRelationBareEntity.builder().uuid(invocation.getArgument(1)).build()); } @Override @@ -58,7 +57,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< final var entity = HsOfficePartnerEntity.builder() .uuid(INITIAL_PARTNER_UUID) .partnerNumber(12345) - .partnerRel(HsOfficeRelationRbacEntity.builder() + .partnerRel(HsOfficeRelationBareEntity.builder() .holder(givenInitialPerson) .contact(givenInitialContact) .build()) @@ -90,10 +89,9 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase< ); } - private static HsOfficeRelationEntity newPartnerRel(final UUID uuid) { - final var newPartnerRel = HsOfficeRelationRbacEntity.builder() + private static HsOfficeRelationBareEntity newPartnerRel(final UUID uuid) { + return HsOfficeRelationBareEntity.builder() .uuid(uuid) .build(); - return newPartnerRel; } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java index f1c9ad2c..ac644186 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntityUnitTest.java @@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import org.junit.jupiter.api.Test; @@ -13,7 +13,7 @@ class HsOfficePartnerEntityUnitTest { private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder() .partnerNumber(12345) - .partnerRel(HsOfficeRelationRbacEntity.builder() + .partnerRel(HsOfficeRelationBareEntity.builder() .anchor(HsOfficePersonEntity.builder() .personType(HsOfficePersonType.LEGAL_PERSON) .tradeName("Hostsharing eG") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java index b74e4036..63cf3d94 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java @@ -3,9 +3,8 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; @@ -43,7 +42,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean HsOfficePartnerRepository partnerRepo; @Autowired - HsOfficeRelationRepository relationRepo; + HsOfficeRelationBareRepository relationRepo; @Autowired HsOfficePersonRepository personRepo; @@ -113,7 +112,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("fourth contact").get(0); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); - final var newRelation = HsOfficeRelationRbacEntity.builder() + final var newRelation = HsOfficeRelationBareEntity.builder() .holder(givenPartnerPerson) .type(HsOfficeRelationType.PARTNER) .anchor(givenMandantPerson) @@ -463,12 +462,12 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean }).assertSuccessful().returnedValue(); } - private HsOfficeRelationEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) { + private HsOfficeRelationBareEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) { final var givenMandantorPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0); final var givenContact = contactBareRepo.findContactByOptionalCaptionLike(contact).get(0); - final var partnerRel = HsOfficeRelationRbacEntity.builder() + final var partnerRel = HsOfficeRelationBareEntity.builder() .holder(givenPartnerPerson) .type(HsOfficeRelationType.PARTNER) .anchor(givenMandantorPerson) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java index a62b8910..6deb7be4 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/TestHsOfficePartner.java @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON; @@ -15,7 +15,7 @@ public class TestHsOfficePartner { return HsOfficePartnerEntity.builder() .partnerNumber(10001) .partnerRel( - HsOfficeRelationRbacEntity.builder() + HsOfficeRelationBareEntity.builder() .holder(HsOfficePersonEntity.builder() .personType(LEGAL_PERSON) .tradeName("Hostsharing eG") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java index 87a015b5..5f52c1cf 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java @@ -43,7 +43,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean Context contextMock; @Autowired - HsOfficeRelationRepository relationRepo; + HsOfficeRelationBareRepository relationBareRepo; @Autowired HsOfficePersonRepository personRepo; @@ -161,7 +161,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean .extract().header("Location"); // @formatter:on // finally, the new relation can be accessed under the generated UUID - final var newUserUuid = toCleanup(HsOfficeRelationEntity.class, UUID.fromString( + final var newUserUuid = toCleanup(HsOfficeRelation.class, UUID.fromString( location.substring(location.lastIndexOf('/') + 1))); assertThat(newUserUuid).isNotNull(); } @@ -331,12 +331,12 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean } } - private HsOfficeRelationEntity findRelation( + private HsOfficeRelation findRelation( final String anchorPersonName, final String holderPersoneName) { final var anchorPersonUuid = personRepo.findPersonByOptionalNameLike(anchorPersonName).get(0).getUuid(); final var holderPersonUuid = personRepo.findPersonByOptionalNameLike(holderPersoneName).get(0).getUuid(); - final var givenRelation = relationRepo + final var givenRelation = relationBareRepo .findRelationRelatedToPersonUuid(anchorPersonUuid) .stream() .filter(r -> r.getHolder().getUuid().equals(holderPersonUuid)) @@ -379,7 +379,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean // finally, the relation is actually updated context.define("superuser-alex@hostsharing.net"); - assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent().get() + assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isPresent().get() .matches(rel -> { assertThat(rel.getAnchor().getTradeName()).contains("Bessler"); assertThat(rel.getHolder().getFamilyName()).contains("Winkler"); @@ -408,7 +408,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean .statusCode(204); // @formatter:on // then the given relation is gone - assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isEmpty(); + assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isEmpty(); } @Test @@ -427,7 +427,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean .statusCode(403); // @formatter:on // then the given relation is still there - assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty(); + assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isNotEmpty(); } @Test @@ -446,24 +446,24 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean .statusCode(404); // @formatter:on // then the given relation is still there - assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty(); + assertThat(relationBareRepo.findByUuid(givenRelation.getUuid())).isNotEmpty(); } } - private HsOfficeRelationEntity givenSomeTemporaryRelationBessler() { + private HsOfficeRelation givenSomeTemporaryRelationBessler() { return jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0); final var givenContact = contactBareRepo.findContactByOptionalCaptionLike("seventh contact").get(0); - final var newRelation = HsOfficeRelationRbacEntity.builder() + final var newRelation = HsOfficeRelationBareEntity.builder() .type(HsOfficeRelationType.REPRESENTATIVE) .anchor(givenAnchorPerson) .holder(givenHolderPerson) .contact(givenContact) .build(); - assertThat(toCleanup(relationRepo.save(newRelation))).isEqualTo(newRelation); + assertThat(toCleanup(relationBareRepo.save(newRelation))).isEqualTo(newRelation); return newRelation; }).assertSuccessful().returnedValue(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationPatcherUnitTest.java similarity index 86% rename from src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationPatcherUnitTest.java index ca1dfa8d..05ff2b07 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationPatcherUnitTest.java @@ -1,7 +1,6 @@ package net.hostsharing.hsadminng.hs.office.relation; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; @@ -22,9 +21,9 @@ import static org.mockito.Mockito.lenient; @TestInstance(PER_CLASS) @ExtendWith(MockitoExtension.class) -class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< +class HsOfficeRelationPatcherUnitTest extends PatchUnitTestBase< HsOfficeRelationPatchResource, - HsOfficeRelationEntity + HsOfficeRelation > { static final UUID INITIAL_RELATION_UUID = UUID.randomUUID(); @@ -35,8 +34,8 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< @BeforeEach void initMocks() { - lenient().when(em.getReference(eq(HsOfficeContactRbacEntity.class), any())).thenAnswer(invocation -> - HsOfficeContactRbacEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsOfficeContactBareEntity.class), any())).thenAnswer(invocation -> + HsOfficeContactBareEntity.builder().uuid(invocation.getArgument(1)).build()); } final HsOfficePersonEntity givenInitialAnchorPerson = HsOfficePersonEntity.builder() @@ -50,7 +49,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< .build(); @Override - protected HsOfficeRelationEntity newInitialEntity() { + protected HsOfficeRelation newInitialEntity() { final var entity = new HsOfficeRelationRbacEntity(); entity.setUuid(INITIAL_RELATION_UUID); entity.setType(HsOfficeRelationType.REPRESENTATIVE); @@ -66,7 +65,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< } @Override - protected HsOfficeRelationEntityPatcher createPatcher(final HsOfficeRelationEntity relation) { + protected HsOfficeRelationEntityPatcher createPatcher(final HsOfficeRelation relation) { return new HsOfficeRelationEntityPatcher(em, relation); } @@ -77,7 +76,7 @@ class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase< "contact", HsOfficeRelationPatchResource::setContactUuid, PATCHED_CONTACT_UUID, - HsOfficeRelationEntity::setContact, + HsOfficeRelation::setContact, newContact(PATCHED_CONTACT_UUID)) .notNullable() ); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java index 329e97c6..2b99d1b2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java @@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithCleanup { @Autowired - HsOfficeRelationRepository relationRepo; + HsOfficeRelationRbacRepository relationRbacRepo; @Autowired HsOfficePersonRepository personRepo; @@ -64,7 +64,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea public void testHostsharingAdmin_withoutAssumedRole_canCreateNewRelation() { // given context("superuser-alex@hostsharing.net"); - final var count = relationRepo.count(); + final var count = relationRbacRepo.count(); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").stream() .filter(p -> p.getPersonType() == UNINCORPORATED_FIRM) .findFirst().orElseThrow(); @@ -83,16 +83,16 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea .mark("operations-announce") .contact(givenContact) .build(); - return toCleanup(relationRepo.save(newRelation)); + return toCleanup(relationRbacRepo.save(newRelation)); }); // then result.assertSuccessful(); - assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelationEntity::getUuid).isNotNull(); + assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelation::getUuid).isNotNull(); assertThatRelationIsPersisted(result.returnedValue()); - assertThat(relationRepo.count()).isEqualTo(count + 1); - final var stored = relationRepo.findByUuid(result.returnedValue().getUuid()); - assertThat(stored).isNotEmpty().map(HsOfficeRelationEntity::toString).get() + assertThat(relationRbacRepo.count()).isEqualTo(count + 1); + final var stored = relationRbacRepo.findByUuid(result.returnedValue().getUuid()); + assertThat(stored).isNotEmpty().map(HsOfficeRelation::toString).get() .isEqualTo("rel(anchor='UF Erben Bessler', type='SUBSCRIBER', mark='operations-announce', holder='NP Winkler, Paul', contact='fourth contact')"); } @@ -119,7 +119,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea .type(HsOfficeRelationType.REPRESENTATIVE) .contact(givenContact) .build(); - return toCleanup(relationRepo.save(newRelation)); + return toCleanup(relationRbacRepo.save(newRelation)); }); // then @@ -156,8 +156,8 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea ); } - private void assertThatRelationIsPersisted(final HsOfficeRelationEntity saved) { - final var found = relationRepo.findByUuid(saved.getUuid()); + private void assertThatRelationIsPersisted(final HsOfficeRelation saved) { + final var found = relationRbacRepo.findByUuid(saved.getUuid()); assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString()); } } @@ -174,7 +174,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea .findFirst().orElseThrow(); // when - final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid()); + final var result = relationRbacRepo.findRelationRelatedToPersonUuid(person.getUuid()); // then allTheseRelationsAreReturned( @@ -193,7 +193,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea .findFirst().orElseThrow(); // when: - final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid()); + final var result = relationRbacRepo.findRelationRelatedToPersonUuid(person.getUuid()); // then: exactlyTheseRelationsAreReturned( @@ -225,7 +225,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); givenRelation.setContact(givenContact); - return toCleanup(relationRepo.save(givenRelation).load()); + return toCleanup(relationRbacRepo.save(givenRelation).load()); }); // then @@ -242,7 +242,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea result.returnedValue(), "hs_office_contact#fifthcontact:ADMIN"); - relationRepo.deleteByUuid(givenRelation.getUuid()); + relationRbacRepo.deleteByUuid(givenRelation.getUuid()); } @Test @@ -260,7 +260,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net", "hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerAnita:AGENT"); givenRelation.setContact(null); - return relationRepo.save(givenRelation); + return relationRbacRepo.save(givenRelation); }); // then @@ -283,7 +283,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact:ADMIN"); givenRelation.setContact(null); // TODO - return relationRepo.save(givenRelation); + return relationRbacRepo.save(givenRelation); }); // then @@ -291,16 +291,16 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea "[403] Subject ", " is not allowed to update hs_office_relation uuid"); } - private void assertThatRelationActuallyInDatabase(final HsOfficeRelationEntity saved) { - final var found = relationRepo.findByUuid(saved.getUuid()); + private void assertThatRelationActuallyInDatabase(final HsOfficeRelation saved) { + final var found = relationRbacRepo.findByUuid(saved.getUuid()); assertThat(found).isNotEmpty().get() .isNotSameAs(saved) - .extracting(HsOfficeRelationEntity::toString) + .extracting(HsOfficeRelation::toString) .isEqualTo(saved.toString()); } private void assertThatRelationIsVisibleForUserWithRole( - final HsOfficeRelationEntity entity, + final HsOfficeRelation entity, final String assumedRoles) { jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net", assumedRoles); @@ -309,11 +309,11 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea } private void assertThatRelationIsNotVisibleForUserWithRole( - final HsOfficeRelationEntity entity, + final HsOfficeRelation entity, final String assumedRoles) { jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net", assumedRoles); - final var found = relationRepo.findByUuid(entity.getUuid()); + final var found = relationRbacRepo.findByUuid(entity.getUuid()); assertThat(found).isEmpty(); }).assertSuccessful(); } @@ -332,14 +332,14 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea // when final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - relationRepo.deleteByUuid(givenRelation.getUuid()); + relationRbacRepo.deleteByUuid(givenRelation.getUuid()); }); // then result.assertSuccessful(); assertThat(jpaAttempt.transacted(() -> { context("superuser-fran@hostsharing.net", null); - return relationRepo.findByUuid(givenRelation.getUuid()); + return relationRbacRepo.findByUuid(givenRelation.getUuid()); }).assertSuccessful().returnedValue()).isEmpty(); } @@ -353,8 +353,8 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea // when final var result = jpaAttempt.transacted(() -> { context("contact-admin@eleventhcontact.example.com"); - assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent(); - relationRepo.deleteByUuid(givenRelation.getUuid()); + assertThat(relationRbacRepo.findByUuid(givenRelation.getUuid())).isPresent(); + relationRbacRepo.deleteByUuid(givenRelation.getUuid()); }); // then @@ -363,7 +363,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea "[403] Subject ", " not allowed to delete hs_office_relation"); assertThat(jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - return relationRepo.findByUuid(givenRelation.getUuid()); + return relationRbacRepo.findByUuid(givenRelation.getUuid()); }).assertSuccessful().returnedValue()).isPresent(); // still there } @@ -379,7 +379,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea // when final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - return relationRepo.deleteByUuid(givenRelation.getUuid()); + return relationRbacRepo.deleteByUuid(givenRelation.getUuid()); }); // then @@ -408,7 +408,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea "[creating relation test-data FirstGmbH-Firby, hs_office_relation, INSERT]"); } - private HsOfficeRelationEntity givenSomeTemporaryRelationBessler(final String holderPerson, final String contact) { + private HsOfficeRelationRbacEntity givenSomeTemporaryRelationBessler(final String holderPerson, final String contact) { return jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); @@ -421,23 +421,23 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea .contact(givenContact) .build(); - return toCleanup(relationRepo.save(newRelation)); + return toCleanup(relationRbacRepo.save(newRelation)); }).assertSuccessful().returnedValue(); } void exactlyTheseRelationsAreReturned( - final List actualResult, + final List actualResult, final String... relationNames) { assertThat(actualResult) - .extracting(HsOfficeRelationEntity::toString) + .extracting(HsOfficeRelation::toString) .containsExactlyInAnyOrder(relationNames); } void allTheseRelationsAreReturned( - final List actualResult, + final List actualResult, final String... relationNames) { assertThat(actualResult) - .extracting(HsOfficeRelationEntity::toString) + .extracting(HsOfficeRelation::toString) .contains(relationNames); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationUnitTest.java similarity index 97% rename from src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityUnitTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationUnitTest.java index 072d42ef..a422a8b6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationUnitTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -class HsOfficeRelationEntityUnitTest { +class HsOfficeRelationUnitTest { private HsOfficePersonEntity anchor = HsOfficePersonEntity.builder() .personType(HsOfficePersonType.LEGAL_PERSON) -- 2.39.5 From cebba7fe2403ad9e03222895a7b5325dbcf12530 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sat, 3 Aug 2024 19:13:41 +0200 Subject: [PATCH 05/12] add @test verifyMembershipsActuallyPersisted --- .../hsadminng/hs/migration/ImportOfficeData.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java index ef30add4..64d7e4cb 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java @@ -693,6 +693,13 @@ public class ImportOfficeData extends CsvDataImport { } + @Test + @Order(9190) + void verifyMembershipsActuallyPersisted() { + final var biCount = (Integer) em.createNativeQuery("SELECT count(*) FROM hs_office_membership", Integer.class).getSingleResult(); + assertThat(biCount).isGreaterThan(isImportingControlledTestData() ? 5 : 300); + } + protected void assumeThatWeAreExplicitlyImportingOfficeData() { // not throwing AssumptionException } -- 2.39.5 From d179842730b98dae4f39d60acbd50a097dd690f0 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 4 Aug 2024 09:13:04 +0200 Subject: [PATCH 06/12] cleanup after self-review --- .run/ImportOfficeData.run.xml | 2 +- .run/README.txt | 1 + README.md | 2 +- .../hs/migration/ImportHostingAssets.java | 5 ----- .../hsadminng/hs/migration/ImportOfficeData.java | 14 -------------- 5 files changed, 3 insertions(+), 21 deletions(-) create mode 100644 .run/README.txt diff --git a/.run/ImportOfficeData.run.xml b/.run/ImportOfficeData.run.xml index 80b17552..92ce7bd5 100644 --- a/.run/ImportOfficeData.run.xml +++ b/.run/ImportOfficeData.run.xml @@ -33,4 +33,4 @@ true - \ No newline at end of file + diff --git a/.run/README.txt b/.run/README.txt new file mode 100644 index 00000000..96094ded --- /dev/null +++ b/.run/README.txt @@ -0,0 +1 @@ +Stored run-Configurations for IntelliJ IDEA. diff --git a/README.md b/README.md index 4d03a6d3..17bb37b2 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ To generate the TOC (Table of Contents), a little bash script from a Given this is in PATH as `md-toc`, use: ```shell -md-toc Date: Sun, 4 Aug 2024 13:18:45 +0200 Subject: [PATCH 07/12] fix RBAC-generation (naming problem) --- doc/rbac-performance-analysis.md | 4 +- .../hs/booking/item/HsBookingItemEntity.java | 4 +- .../project/HsBookingProjectEntity.java | 8 +-- .../hs/hosting/asset/HsHostingAsset.java | 4 +- .../HsOfficeBankAccountEntity.java | 4 +- .../hs/office/contact/HsOfficeContact.java | 4 +- .../contact/HsOfficeContactBareEntity.java | 1 - .../contact/HsOfficeContactRbacEntity.java | 2 - .../HsOfficeCoopAssetsTransactionEntity.java | 6 +- .../HsOfficeCoopSharesTransactionEntity.java | 6 +- .../debitor/HsOfficeDebitorController.java | 3 +- .../office/debitor/HsOfficeDebitorEntity.java | 11 ++-- .../membership/HsOfficeMembershipEntity.java | 10 ++-- .../partner/HsOfficePartnerController.java | 6 +- .../partner/HsOfficePartnerDetailsEntity.java | 4 +- .../office/partner/HsOfficePartnerEntity.java | 9 +-- .../office/person/HsOfficePersonEntity.java | 4 +- .../hs/office/relation/HsOfficeRelation.java | 6 +- .../HsOfficeRelationBareRepository.java | 6 +- .../HsOfficeSepaMandateEntity.java | 8 +-- .../hsadminng/rbac/rbacdef/RbacView.java | 58 ++++++++++++------- .../{RbacObject.java => BaseEntity.java} | 3 +- .../rbac/test/cust/TestCustomerEntity.java | 4 +- .../rbac/test/dom/TestDomainEntity.java | 4 +- .../rbac/test/pac/TestPackageEntity.java | 4 +- .../changelog/1-rbac/1058-rbac-generators.sql | 3 +- .../2013-test-customer-rbac.sql | 4 +- .../2023-test-package-rbac.sql | 4 +- .../203-test-domain/2033-test-domain-rbac.sql | 4 +- .../5043-hs-office-partner-rbac.sql | 4 +- .../5044-hs-office-partner-details-rbac.sql | 4 +- .../5063-hs-office-debitor-rbac.sql | 4 +- .../5073-hs-office-sepamandate-rbac.sql | 4 +- .../5103-hs-office-membership-rbac.sql | 4 +- .../5113-hs-office-coopshares-rbac.sql | 4 +- .../5123-hs-office-coopassets-rbac.sql | 4 +- .../hsadminng/arch/ArchitectureTest.java | 4 +- .../hsadminng/hs/migration/CsvDataImport.java | 16 ++--- .../hs/migration/ImportOfficeData.java | 4 +- ...OfficeDebitorControllerAcceptanceTest.java | 6 +- .../HsOfficePartnerControllerRestTest.java | 2 +- ...fficePartnerRepositoryIntegrationTest.java | 3 +- .../test/ContextBasedTestWithCleanup.java | 12 ++-- .../hsadminng/rbac/test/EntityList.java | 4 +- .../rbac/test/PatchUnitTestBase.java | 4 +- 45 files changed, 150 insertions(+), 131 deletions(-) rename src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/{RbacObject.java => BaseEntity.java} (64%) diff --git a/doc/rbac-performance-analysis.md b/doc/rbac-performance-analysis.md index 43f47ec6..3e43a090 100644 --- a/doc/rbac-performance-analysis.md +++ b/doc/rbac-performance-analysis.md @@ -121,8 +121,8 @@ WITH statements AS ( SELECT * FROM pg_stat_statements pss ) SELECT calls, - total_exec_time::int/(60*1000) as total_exec_time_mins, - mean_exec_time::int as mean_exec_time_millis, + total_exec_time::int/(60*1000) as total_mins, + mean_exec_time::int as mean_millis, query FROM statements WHERE calls > 100 AND shared_blks_hit > 0 diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java index a9a9c879..a7b9db66 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java @@ -15,7 +15,7 @@ import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; import org.hibernate.annotations.Type; @@ -71,7 +71,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Setter @NoArgsConstructor @AllArgsConstructor -public class HsBookingItemEntity implements Stringifyable, RbacObject, PropertiesProvider { +public class HsBookingItemEntity implements Stringifyable, BaseEntity, PropertiesProvider { private static Stringify stringify = stringify(HsBookingItemEntity.class) .withProp(HsBookingItemEntity::getProject) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java index 4408e7b3..c44d43f5 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java @@ -3,10 +3,10 @@ package net.hostsharing.hsadminng.hs.booking.project; import lombok.*; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; @@ -34,7 +34,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Setter @NoArgsConstructor @AllArgsConstructor -public class HsBookingProjectEntity implements Stringifyable, RbacObject { +public class HsBookingProjectEntity implements Stringifyable, BaseEntity { private static Stringify stringify = stringify(HsBookingProjectEntity.class) .withProp(HsBookingProjectEntity::getDebitor) @@ -81,7 +81,7 @@ public class HsBookingProjectEntity implements Stringifyable, RbacObject, PropertiesProvider { +public interface HsHostingAsset extends Stringifyable, BaseEntity, PropertiesProvider { Stringify stringify = stringify(HsHostingAsset.class) .withProp(HsHostingAsset::getType) 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 0e9ca079..be040d83 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 @@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.bankaccount; import lombok.*; import lombok.experimental.FieldNameConstants; import net.hostsharing.hsadminng.errors.DisplayName; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; @@ -27,7 +27,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @AllArgsConstructor @FieldNameConstants @DisplayName("BankAccount") -public class HsOfficeBankAccountEntity implements RbacObject, Stringifyable { +public class HsOfficeBankAccountEntity implements BaseEntity, Stringifyable { private static Stringify toString = stringify(HsOfficeBankAccountEntity.class, "bankAccount") .withIdProp(HsOfficeBankAccountEntity::getIban) 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 39319464..c1ecb1f9 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 @@ -11,7 +11,7 @@ import lombok.experimental.FieldNameConstants; import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; import org.hibernate.annotations.GenericGenerator; @@ -37,7 +37,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @SuperBuilder(toBuilder = true) @FieldNameConstants @DisplayName("Contact") -public class HsOfficeContact implements Stringifyable, RbacObject { +public class HsOfficeContact implements Stringifyable, BaseEntity { private static Stringify toString = stringify(HsOfficeContact.class, "contact") .withProp(Fields.caption, HsOfficeContact::getCaption) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java index 958883ab..a759bc24 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactBareEntity.java @@ -16,7 +16,6 @@ import jakarta.persistence.Table; @Setter @NoArgsConstructor @SuperBuilder(toBuilder = true) -@FieldNameConstants @DisplayName("BareContact") public class HsOfficeContactBareEntity extends HsOfficeContact { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java index 5a474066..cb819c06 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacEntity.java @@ -22,11 +22,9 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; @Setter @NoArgsConstructor @SuperBuilder(toBuilder = true) -@FieldNameConstants @DisplayName("RbacContact") public class HsOfficeContactRbacEntity extends HsOfficeContact { - public static RbacView rbac() { return rbacViewFor("contact", HsOfficeContactRbacEntity.class) .withIdentityView(SQL.projection("caption")) 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 35e0bda9..4820db10 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 @@ -8,7 +8,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; @@ -41,7 +41,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @NoArgsConstructor @AllArgsConstructor @DisplayName("CoopAssetsTransaction") -public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacObject { +public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseEntity { private static Stringify stringify = stringify(HsOfficeCoopAssetsTransactionEntity.class) .withIdProp(HsOfficeCoopAssetsTransactionEntity::getTaggedMemberNumber) @@ -107,7 +107,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO @Override public HsOfficeCoopAssetsTransactionEntity load() { - RbacObject.super.load(); + BaseEntity.super.load(); membership.load(); return this; } 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 cbab7e4f..03409edc 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 @@ -8,7 +8,7 @@ import lombok.Setter; import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; @@ -39,7 +39,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @NoArgsConstructor @AllArgsConstructor @DisplayName("CoopShareTransaction") -public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, RbacObject { +public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, BaseEntity { private static Stringify stringify = stringify(HsOfficeCoopSharesTransactionEntity.class) .withIdProp(HsOfficeCoopSharesTransactionEntity::getMemberNumberTagged) @@ -104,7 +104,7 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, RbacO @Override public HsOfficeCoopSharesTransactionEntity load() { - RbacObject.super.load(); + BaseEntity.super.load(); membership.load(); return this; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java index 328e93e8..ed31bcd4 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java @@ -6,6 +6,7 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebito import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorResource; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareRepository; import net.hostsharing.hsadminng.mapper.Mapper; import org.apache.commons.lang3.Validate; @@ -82,7 +83,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class); if ( body.getDebitorRel() != null ) { body.getDebitorRel().setType(DEBITOR.name()); - final var debitorRel = mapper.map(body.getDebitorRel(), HsOfficeRelation.class); + final var debitorRel = mapper.map(body.getDebitorRel(), HsOfficeRelationBareEntity.class); entityToSave.setDebitorRel(relBareRepo.save(debitorRel)); } else { final var debitorRelOptional = relBareRepo.findByUuid(body.getDebitorRelUuid()); 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 4f9d7c71..44a83871 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 @@ -10,7 +10,8 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.stringify.Stringify; @@ -59,7 +60,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @NoArgsConstructor @AllArgsConstructor @DisplayName("Debitor") -public class HsOfficeDebitorEntity implements RbacObject, Stringifyable { +public class HsOfficeDebitorEntity implements BaseEntity, Stringifyable { public static final String DEBITOR_NUMBER_TAG = "D-"; public static final String TWO_DECIMAL_DIGITS = "^([0-9]{2})$"; @@ -129,7 +130,7 @@ public class HsOfficeDebitorEntity implements RbacObject, @Override public HsOfficeDebitorEntity load() { - RbacObject.super.load(); + BaseEntity.super.load(); if (partner != null) { partner.load(); } @@ -189,7 +190,7 @@ public class HsOfficeDebitorEntity implements RbacObject, "defaultPrefix") .toRole("global", ADMIN).grantPermission(INSERT) - .importRootEntityAliasProxy("debitorRel", HsOfficeRelation.class, usingCase(DEBITOR), + .importRootEntityAliasProxy("debitorRel", HsOfficeRelationRbacEntity.class, usingCase(DEBITOR), directlyFetchedByDependsOnColumn(), dependsOnColumn("debitorRelUuid")) .createPermission(DELETE).grantedTo("debitorRel", OWNER) @@ -203,7 +204,7 @@ public class HsOfficeDebitorEntity implements RbacObject, .toRole("refundBankAccount", ADMIN).grantRole("debitorRel", AGENT) .toRole("debitorRel", AGENT).grantRole("refundBankAccount", REFERRER) - .importEntityAlias("partnerRel", HsOfficeRelation.class, usingDefaultCase(), + .importEntityAlias("partnerRel", HsOfficeRelationRbacEntity.class, usingDefaultCase(), dependsOnColumn("debitorRelUuid"), fetchedBySql(""" SELECT ${columns} 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 eb1523ec..399ebef2 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 @@ -8,8 +8,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.errors.DisplayName; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; @@ -62,7 +62,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @NoArgsConstructor @AllArgsConstructor @DisplayName("Membership") -public class HsOfficeMembershipEntity implements RbacObject, Stringifyable { +public class HsOfficeMembershipEntity implements BaseEntity, Stringifyable { public static final String MEMBER_NUMBER_TAG = "M-"; public static final String TWO_DECIMAL_DIGITS = "^([0-9]{2})$"; @@ -102,7 +102,7 @@ public class HsOfficeMembershipEntity implements RbacObject E ref(final Class entityClass, final UUID uuid) { + private E ref(final Class entityClass, final UUID uuid) { try { return em.getReference(entityClass, uuid); } catch (final Throwable exc) { 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 4935f591..fbe17465 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 @@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner; import lombok.*; import net.hostsharing.hsadminng.errors.DisplayName; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.stringify.Stringify; @@ -26,7 +26,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @NoArgsConstructor @AllArgsConstructor @DisplayName("PartnerDetails") -public class HsOfficePartnerDetailsEntity implements RbacObject, Stringifyable { +public class HsOfficePartnerDetailsEntity implements BaseEntity, Stringifyable { private static Stringify stringify = stringify( HsOfficePartnerDetailsEntity.class, 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 1454efe2..932bf38b 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 @@ -9,7 +9,8 @@ import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContact; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; @@ -41,7 +42,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @NoArgsConstructor @AllArgsConstructor @DisplayName("Partner") -public class HsOfficePartnerEntity implements Stringifyable, RbacObject { +public class HsOfficePartnerEntity implements Stringifyable, BaseEntity { public static final String PARTNER_NUMBER_TAG = "P-"; @@ -78,7 +79,7 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject, Stringifyable { +public class HsOfficePersonEntity implements BaseEntity, Stringifyable { private static Stringify toString = stringify(HsOfficePersonEntity.class, "person") .withProp(Fields.personType, HsOfficePersonEntity::getPersonType) 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 d836f04c..f685878a 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 @@ -5,7 +5,7 @@ import lombok.experimental.FieldNameConstants; import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactBareEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; @@ -22,7 +22,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Setter @SuperBuilder(toBuilder = true) @FieldNameConstants -public class HsOfficeRelation implements RbacObject, Stringifyable { +public class HsOfficeRelation implements BaseEntity, Stringifyable { private static Stringify toString = stringify(HsOfficeRelation.class, "rel") .withProp(Fields.anchor, HsOfficeRelation::getAnchor) @@ -64,7 +64,7 @@ public class HsOfficeRelation implements RbacObject, Stringify @Override public HsOfficeRelation load() { - RbacObject.super.load(); + BaseEntity.super.load(); anchor.load(); holder.load(); contact.load(); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareRepository.java index 4ecadbe1..e3cdba3d 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationBareRepository.java @@ -17,19 +17,19 @@ public interface HsOfficeRelationBareRepository extends Repository findRelationRelatedToPersonUuid(@NotNull UUID personUuid); @Query(value = """ - SELECT p.* FROM hs_office_relation_rv AS p + SELECT p.* FROM hs_office_relation AS p WHERE (:relationType IS NULL OR p.type = cast(:relationType AS HsOfficeRelationType)) AND ( p.anchorUuid = :personUuid OR p.holderUuid = :personUuid) """, nativeQuery = true) List findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); - HsOfficeRelationBareEntity save(final HsOfficeRelation entity); + HsOfficeRelationBareEntity save(final HsOfficeRelationBareEntity entity); long count(); 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 6529b3cd..3d2af0a5 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 @@ -6,8 +6,8 @@ import lombok.*; import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; -import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; @@ -40,7 +40,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @NoArgsConstructor @AllArgsConstructor @DisplayName("SEPA-Mandate") -public class HsOfficeSepaMandateEntity implements Stringifyable, RbacObject { +public class HsOfficeSepaMandateEntity implements Stringifyable, BaseEntity { private static Stringify stringify = stringify(HsOfficeSepaMandateEntity.class) .withProp(e -> e.getBankAccount().getIban()) @@ -110,7 +110,7 @@ public class HsOfficeSepaMandateEntity implements Stringifyable, RbacObject * a JPA entity class extending RbacObject */ - public static RbacView rbacViewFor(final String alias, final Class entityClass) { + public static RbacView rbacViewFor(final String alias, final Class entityClass) { return new RbacView(alias, entityClass); } - RbacView(final String alias, final Class entityClass) { + RbacView(final String alias, final Class entityClass) { rootEntityAlias = new EntityAlias(alias, entityClass); entityAliases.put(alias, rootEntityAlias); new RbacUserReference(CREATOR); @@ -253,7 +254,7 @@ public class RbacView { .orElseGet(() -> new RbacPermissionDefinition(entityAlias, permission, null, true)); } - public RbacView declarePlaceholderEntityAliases(final String... aliasNames) { + public RbacView declarePlaceholderEntityAliases(final String... aliasNames) { for (String alias : aliasNames) { entityAliases.put(alias, new EntityAlias(alias)); } @@ -286,9 +287,9 @@ public class RbacView { * @param * a JPA entity class extending RbacObject */ - public RbacView importRootEntityAliasProxy( + public RbacView importRootEntityAliasProxy( final String aliasName, - final Class entityClass, + final Class entityClass, final ColumnValue forCase, final SQL fetchSql, final Column dependsOnColum) { @@ -312,7 +313,7 @@ public class RbacView { * a JPA entity class extending RbacObject */ public RbacView importSubEntityAlias( - final String aliasName, final Class entityClass, + final String aliasName, final Class entityClass, final SQL fetchSql, final Column dependsOnColum) { importEntityAliasImpl(aliasName, entityClass, usingDefaultCase(), fetchSql, dependsOnColum, true, NOT_NULL); return this; @@ -349,14 +350,14 @@ public class RbacView { * a JPA entity class extending RbacObject */ public RbacView importEntityAlias( - final String aliasName, final Class entityClass, final ColumnValue usingCase, + final String aliasName, final Class entityClass, final ColumnValue usingCase, final Column dependsOnColum, final SQL fetchSql, final Nullable nullable) { importEntityAliasImpl(aliasName, entityClass, usingCase, fetchSql, dependsOnColum, false, nullable); return this; } private EntityAlias importEntityAliasImpl( - final String aliasName, final Class entityClass, final ColumnValue usingCase, + final String aliasName, final Class entityClass, final ColumnValue usingCase, final SQL fetchSql, final Column dependsOnColum, boolean asSubEntity, final Nullable nullable) { final var entityAlias = ofNullable(entityAliases.get(aliasName)) @@ -378,7 +379,7 @@ public class RbacView { return entityAlias; } - private static RbacView rbacDefinition(final Class entityClass) + private static RbacView rbacDefinition(final Class entityClass) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { return (RbacView) entityClass.getMethod("rbac").invoke(null); } @@ -432,12 +433,22 @@ public class RbacView { } private void verifyVersionColumnExists() { - if (stream(rootEntityAlias.entityClass.getDeclaredFields()) - .noneMatch(f -> f.getAnnotation(Version.class) != null)) { + final var clazz = rootEntityAlias.entityClass; + if (!hasVersionColumn(clazz)) { throw new IllegalArgumentException("@Version field required in updatable entity " + rootEntityAlias.entityClass); } } + private static boolean hasVersionColumn(final Class clazz) { + if (stream(clazz.getDeclaredFields()).anyMatch(f -> f.getAnnotation(Version.class) != null)) { + return true; + } + if (clazz.getSuperclass() != null) { + return hasVersionColumn(clazz.getSuperclass()); + } + return false; + } + /** * Starts declaring a grant to a given role. * @@ -900,13 +911,13 @@ public class RbacView { return distinctGrantDef; } - record EntityAlias(String aliasName, Class entityClass, ColumnValue usingCase, SQL fetchSql, Column dependsOnColum, boolean isSubEntity, Nullable nullable) { + record EntityAlias(String aliasName, Class entityClass, ColumnValue usingCase, SQL fetchSql, Column dependsOnColum, boolean isSubEntity, Nullable nullable) { public EntityAlias(final String aliasName) { this(aliasName, null, null, null, null, false, null); } - public EntityAlias(final String aliasName, final Class entityClass) { + public EntityAlias(final String aliasName, final Class entityClass) { this(aliasName, entityClass, null, null, null, false, null); } @@ -936,6 +947,10 @@ public class RbacView { } private String withoutEntitySuffix(final String simpleEntityName) { + // TODO.impl: maybe introduce an annotation like @RbacObjectName("hsOfficeContact")? + if ( simpleEntityName.endsWith("RbacEntity")) { + return simpleEntityName.substring(0, simpleEntityName.length() - "RbacEntity".length()); + } return simpleEntityName.substring(0, simpleEntityName.length() - "Entity".length()); } @@ -1210,7 +1225,7 @@ public class RbacView { } } - private static void generateRbacView(final Class c) { + private static void generateRbacView(final Class c) { final Method mainMethod = stream(c.getMethods()).filter( m -> isStatic(m.getModifiers()) && m.getName().equals("main") ) @@ -1227,17 +1242,20 @@ public class RbacView { } } - public static Set> findRbacEntityClasses(String packageName) { + public static Set> findRbacEntityClasses(String packageName) { final var reflections = new Reflections(packageName, TypeAnnotationsScanner.class); return reflections.getTypesAnnotatedWith(Entity.class).stream() - .filter(c -> stream(c.getInterfaces()).anyMatch(i -> i==RbacObject.class)) - .map(RbacView::castToSubclassOfRbacObject) + .filter(c -> stream(c.getInterfaces()).anyMatch(i -> i== BaseEntity.class)) + .filter(c -> stream(c.getDeclaredMethods()) + .anyMatch(m -> m.getName().equals("rbac") && Modifier.isStatic(m.getModifiers())) + ) + .map(RbacView::castToSubclassOfBaseEntity) .collect(Collectors.toSet()); } @SuppressWarnings("unchecked") - private static Class castToSubclassOfRbacObject(final Class clazz) { - return (Class) clazz; + private static Class castToSubclassOfBaseEntity(final Class clazz) { + return (Class) clazz; } /** diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/RbacObject.java b/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/BaseEntity.java similarity index 64% rename from src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/RbacObject.java rename to src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/BaseEntity.java index 31e9a85c..d0e7605f 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/RbacObject.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/rbacobject/BaseEntity.java @@ -5,7 +5,8 @@ import org.hibernate.Hibernate; import java.util.UUID; -public interface RbacObject> { +// TODO.impl: this class does not really belong into this package, but there is no right place yet +public interface BaseEntity> { UUID getUuid(); int getVersion(); diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/test/cust/TestCustomerEntity.java b/src/main/java/net/hostsharing/hsadminng/rbac/test/cust/TestCustomerEntity.java index 391a82a6..e9541dd7 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/test/cust/TestCustomerEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/test/cust/TestCustomerEntity.java @@ -4,7 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; @@ -24,7 +24,7 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; @Setter @NoArgsConstructor @AllArgsConstructor -public class TestCustomerEntity implements RbacObject { +public class TestCustomerEntity implements BaseEntity { @Id @GeneratedValue diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/test/dom/TestDomainEntity.java b/src/main/java/net/hostsharing/hsadminng/rbac/test/dom/TestDomainEntity.java index 1dde65d7..5d1369ca 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/test/dom/TestDomainEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/test/dom/TestDomainEntity.java @@ -4,7 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.rbac.test.pac.TestPackageEntity; @@ -27,7 +27,7 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; @Setter @NoArgsConstructor @AllArgsConstructor -public class TestDomainEntity implements RbacObject { +public class TestDomainEntity implements BaseEntity { @Id @GeneratedValue diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/test/pac/TestPackageEntity.java b/src/main/java/net/hostsharing/hsadminng/rbac/test/pac/TestPackageEntity.java index 5de98a64..8f4541d5 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/test/pac/TestPackageEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/test/pac/TestPackageEntity.java @@ -4,7 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; import net.hostsharing.hsadminng.rbac.test.cust.TestCustomerEntity; @@ -27,7 +27,7 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; @Setter @NoArgsConstructor @AllArgsConstructor -public class TestPackageEntity implements RbacObject { +public class TestPackageEntity implements BaseEntity { @Id @GeneratedValue diff --git a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql index 86d9b673..ecea52d1 100644 --- a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql +++ b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql @@ -197,8 +197,7 @@ begin from granted join RbacPermission perm on granted.descendantUuid = perm.uuid join RbacObject obj on obj.uuid = perm.objectUuid - where perm.op = 'SELECT' - and obj.objectTable = '%1$s' + where obj.objectTable = '%1$s' -- 'SELECT' permission is included in all other permissions limit 8001 ) select target.* diff --git a/src/main/resources/db/changelog/2-test/201-test-customer/2013-test-customer-rbac.sql b/src/main/resources/db/changelog/2-test/201-test-customer/2013-test-customer-rbac.sql index 14767c4b..e1540c9a 100644 --- a/src/main/resources/db/changelog/2-test/201-test-customer/2013-test-customer-rbac.sql +++ b/src/main/resources/db/changelog/2-test/201-test-customer/2013-test-customer-rbac.sql @@ -142,8 +142,8 @@ begin return NEW; end if; - raise exception '[403] insert into test_customer not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into test_customer values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger test_customer_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/2-test/202-test-package/2023-test-package-rbac.sql b/src/main/resources/db/changelog/2-test/202-test-package/2023-test-package-rbac.sql index fd832ccf..9ec9c06a 100644 --- a/src/main/resources/db/changelog/2-test/202-test-package/2023-test-package-rbac.sql +++ b/src/main/resources/db/changelog/2-test/202-test-package/2023-test-package-rbac.sql @@ -207,8 +207,8 @@ begin return NEW; end if; - raise exception '[403] insert into test_package not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into test_package values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger test_package_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/2-test/203-test-domain/2033-test-domain-rbac.sql b/src/main/resources/db/changelog/2-test/203-test-domain/2033-test-domain-rbac.sql index d6f32001..042021c9 100644 --- a/src/main/resources/db/changelog/2-test/203-test-domain/2033-test-domain-rbac.sql +++ b/src/main/resources/db/changelog/2-test/203-test-domain/2033-test-domain-rbac.sql @@ -206,8 +206,8 @@ begin return NEW; end if; - raise exception '[403] insert into test_domain not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into test_domain values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger test_domain_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql index 520ef180..bd1c673d 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql @@ -219,8 +219,8 @@ begin return NEW; end if; - raise exception '[403] insert into hs_office_partner not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into hs_office_partner values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger hs_office_partner_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql index bf0fe164..8a7f2725 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql @@ -123,8 +123,8 @@ begin return NEW; end if; - raise exception '[403] insert into hs_office_partner_details not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into hs_office_partner_details values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger hs_office_partner_details_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql index 12f4f09d..8e91d7e7 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql @@ -192,8 +192,8 @@ begin return NEW; end if; - raise exception '[403] insert into hs_office_debitor not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into hs_office_debitor values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger hs_office_debitor_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql index 3fb20baf..6b6595a0 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql @@ -173,8 +173,8 @@ begin return NEW; end if; - raise exception '[403] insert into hs_office_sepamandate not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into hs_office_sepamandate values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger hs_office_sepamandate_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql index bc998fa3..7e628d39 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql @@ -154,8 +154,8 @@ begin return NEW; end if; - raise exception '[403] insert into hs_office_membership not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into hs_office_membership values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger hs_office_membership_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql index 1270fd69..6707bdaa 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql @@ -130,8 +130,8 @@ begin return NEW; end if; - raise exception '[403] insert into hs_office_coopsharestransaction not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into hs_office_coopsharestransaction values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger hs_office_coopsharestransaction_insert_permission_check_tg diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql index ce9926b2..39f5a8fe 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql @@ -130,8 +130,8 @@ begin return NEW; end if; - raise exception '[403] insert into hs_office_coopassetstransaction not allowed for current subjects % (%)', - currentSubjects(), currentSubjectsUuids(); + raise exception '[403] insert into hs_office_coopassetstransaction values(%) not allowed for current subjects % (%)', + NEW, currentSubjects(), currentSubjectsUuids(); end; $$; create trigger hs_office_coopassetstransaction_insert_permission_check_tg diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java index 68a62763..40b9d282 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java @@ -12,7 +12,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; import net.hostsharing.hsadminng.rbac.context.ContextBasedTest; import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantsDiagramService; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import org.springframework.data.repository.Repository; import org.springframework.web.bind.annotation.RestController; @@ -346,7 +346,7 @@ public class ArchitectureTest { static final ArchRule tableNamesOfRbacEntitiesShouldEndWith_rv = classes() .that().areAnnotatedWith(Table.class) - .and().areAssignableTo(RbacObject.class) + .and().areAssignableTo(BaseEntity.class) .should(haveTableNameEndingWith_rv()) .because("it's required that the table names of RBAC entities end with '_rv'"); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java index 2b68e352..a8ad47e1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java @@ -6,7 +6,7 @@ import com.opencsv.CSVReaderBuilder; import lombok.SneakyThrows; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.rbac.context.ContextBasedTest; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; @@ -141,7 +141,7 @@ public class CsvDataImport extends ContextBasedTest { return record; } - public T persist(final Integer id, final T entity) { + public T persist(final Integer id, final T entity) { try { if (entity instanceof HsHostingAsset ha) { //noinspection unchecked @@ -155,7 +155,7 @@ public class CsvDataImport extends ContextBasedTest { return entity; } - public T persistViaEM(final Integer id, final T entity) { + public T persistViaEM(final Integer id, final T entity) { //System.out.println("persisting #" + entity.hashCode() + ": " + entity); em.persist(entity); // uncomment for debugging purposes @@ -165,7 +165,7 @@ public class CsvDataImport extends ContextBasedTest { } @SneakyThrows - public RbacObject persistViaSql(final Integer id, final HsHostingAsset entity) { + public BaseEntity persistViaSql(final Integer id, final HsHostingAsset entity) { if (entity.getUuid() == null) { entity.setUuid(UUID.randomUUID()); } @@ -196,10 +196,10 @@ public class CsvDataImport extends ContextBasedTest { """) .setParameter("uuid", entity.getUuid()) .setParameter("type", entity.getType().name()) - .setParameter("bookingitemuuid", ofNullable(entity.getBookingItem()).map(RbacObject::getUuid).orElse(null)) - .setParameter("parentassetuuid", ofNullable(entity.getParentAsset()).map(RbacObject::getUuid).orElse(null)) - .setParameter("assignedtoassetuuid", ofNullable(entity.getAssignedToAsset()).map(RbacObject::getUuid).orElse(null)) - .setParameter("alarmcontactuuid", ofNullable(entity.getAlarmContact()).map(RbacObject::getUuid).orElse(null)) + .setParameter("bookingitemuuid", ofNullable(entity.getBookingItem()).map(BaseEntity::getUuid).orElse(null)) + .setParameter("parentassetuuid", ofNullable(entity.getParentAsset()).map(BaseEntity::getUuid).orElse(null)) + .setParameter("assignedtoassetuuid", ofNullable(entity.getAssignedToAsset()).map(BaseEntity::getUuid).orElse(null)) + .setParameter("alarmcontactuuid", ofNullable(entity.getAlarmContact()).map(BaseEntity::getUuid).orElse(null)) .setParameter("identifier", entity.getIdentifier()) .setParameter("caption", entity.getCaption()) .setParameter("config", entity.getConfig().toString()) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java index 324a0322..78a2ab0a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java @@ -18,7 +18,7 @@ import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelation; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationBareEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType; import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -698,7 +698,7 @@ public class ImportOfficeData extends CsvDataImport { assumeThat(partners.size()).isLessThanOrEqualTo(MAX_NUMBER_OF_TEST_DATA_PARTNERS); } - private void updateLegacyIds( + private void updateLegacyIds( Map entities, final String legacyIdTable, final String legacyIdColumn) { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java index 1ee1645e..de705020 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java @@ -65,7 +65,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu HsOfficePersonRepository personRepo; @Autowired - HsOfficeRelationBareRepository relRepo; + HsOfficeRelationBareRepository relBareRepo; @Autowired JpaAttempt jpaAttempt; @@ -275,7 +275,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu final var givenDebitorRelUUid = jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); - return relRepo.save(HsOfficeRelationRbacEntity.builder() + return relBareRepo.save(HsOfficeRelationBareEntity.builder() .type(DEBITOR) .anchor(givenPartner.getPartnerRel().getHolder()) .holder(givenBillingPerson) @@ -435,7 +435,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu .post("http://localhost/api/hs/office/debitors") .then().log().all().assertThat() .statusCode(400) - .body("message", is("Unable to find HsOfficeRelationEntity with uuid 00000000-0000-0000-0000-000000000000")); + .body("message", is("Unable to find HsOfficeRelationBareEntity with uuid 00000000-0000-0000-0000-000000000000")); // @formatter:on } } 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 40d08e59..2359f20c 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 @@ -161,7 +161,7 @@ class HsOfficePartnerControllerRestTest { .andExpect(status().is4xxClientError()) .andExpect(jsonPath("statusCode", is(400))) .andExpect(jsonPath("statusPhrase", is("Bad Request"))) - .andExpect(jsonPath("message", startsWith("Cannot resolve HsOfficeContactEntity with uuid "))); + .andExpect(jsonPath("message", startsWith("Cannot resolve HsOfficeContactBareEntity with uuid "))); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java index 63cf3d94..5d325698 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java @@ -329,7 +329,8 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean // then result.assertExceptionWithRootCauseMessage(JpaSystemException.class, - "[403] insert into hs_office_partner_details not allowed for current subjects {hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler:TENANT}"); + "ERROR: [403] insert into hs_office_partner_details ", + " not allowed for current subjects {hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler:TENANT}"); } private void assertThatPartnerActuallyInDatabase(final HsOfficePartnerEntity saved) { diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java b/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java index 5e9d8347..771b7e1f 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.rbac.test; import net.hostsharing.hsadminng.rbac.context.ContextBasedTest; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantEntity; import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantsDiagramService; @@ -50,7 +50,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest { @Autowired JpaAttempt jpaAttempt; - private TreeMap> entitiesToCleanup = new TreeMap<>(); + private TreeMap> entitiesToCleanup = new TreeMap<>(); private static Long latestIntialTestDataSerialId; private static boolean countersInitialized = false; @@ -64,19 +64,19 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest { private TestInfo testInfo; - public T refresh(final T entity) { + public T refresh(final T entity) { final var merged = em.merge(entity); em.refresh(merged); return merged; } - public UUID toCleanup(final Class entityClass, final UUID uuidToCleanup) { + public UUID toCleanup(final Class entityClass, final UUID uuidToCleanup) { out.println("toCleanup(" + entityClass.getSimpleName() + ", " + uuidToCleanup + ")"); entitiesToCleanup.put(uuidToCleanup, entityClass); return uuidToCleanup; } - public E toCleanup(final E entity) { + public E toCleanup(final E entity) { out.println("toCleanup(" + entity.getClass() + ", " + entity.getUuid()); if ( entity.getUuid() == null ) { throw new IllegalArgumentException("only persisted entities with valid uuid allowed"); @@ -85,7 +85,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest { return entity; } - protected void cleanupAllNew(final Class entityClass) { + protected void cleanupAllNew(final Class entityClass) { if (initialRbacObjects == null) { out.println("skipping cleanupAllNew: " + entityClass.getSimpleName()); return; // TODO: seems @AfterEach is called without any @BeforeEach diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/test/EntityList.java b/src/test/java/net/hostsharing/hsadminng/rbac/test/EntityList.java index c504db61..42469ea7 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/test/EntityList.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/test/EntityList.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.rbac.test; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import java.util.List; @@ -8,7 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class EntityList { - public static E one(final List entities) { + public static E one(final List entities) { assertThat(entities).hasSize(1); return entities.stream().findFirst().orElseThrow(); } diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/test/PatchUnitTestBase.java b/src/test/java/net/hostsharing/hsadminng/rbac/test/PatchUnitTestBase.java index f2764386..d446258b 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/test/PatchUnitTestBase.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/test/PatchUnitTestBase.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.rbac.test; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.mapper.EntityPatcher; import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; @@ -233,7 +233,7 @@ public abstract class PatchUnitTestBase { } } - protected static class JsonNullableProperty extends Property { + protected static class JsonNullableProperty extends Property { private final BiConsumer> resourceSetter; public final RV givenPatchValue; -- 2.39.5 From 8128f17821a659172d97f49922b6c1d2b747dda6 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 4 Aug 2024 16:12:02 +0200 Subject: [PATCH 08/12] fix tests and align missing entity error messages --- .run/ImportHostingAssets.run.xml | 2 +- .../debitor/HsOfficeDebitorController.java | 16 +- .../relation/HsOfficeRelationBareEntity.java | 2 + .../relation/HsOfficeRelationRbacEntity.java | 2 + .../hostsharing/hsadminng/mapper/Mapper.java | 4 +- .../HsHostingAssetEntityPatcherUnitTest.java | 5 +- .../hs/migration/ImportHostingAssets.java | 180 +++++++++--------- ...OfficeDebitorControllerAcceptanceTest.java | 8 +- .../HsOfficeMembershipControllerRestTest.java | 2 +- ...ceSepaMandateControllerAcceptanceTest.java | 4 +- 10 files changed, 119 insertions(+), 106 deletions(-) diff --git a/.run/ImportHostingAssets.run.xml b/.run/ImportHostingAssets.run.xml index 233ef548..bedd7143 100644 --- a/.run/ImportHostingAssets.run.xml +++ b/.run/ImportHostingAssets.run.xml @@ -3,7 +3,7 @@