From abd6a48b5e07237fe97f444c902790edf413e867 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 12 Jan 2025 20:12:44 +0100 Subject: [PATCH] fix all remaining tests except the RBAC problem --- .../hs/hosting/asset/HsHostingAsset.java | 2 +- .../debitor/HsOfficeDebitorController.java | 19 ++++++++++++++++++- ...HsBookingItemControllerAcceptanceTest.java | 1 - ...ookingProjectControllerAcceptanceTest.java | 1 - 4 files changed, 19 insertions(+), 4 deletions(-) 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 d327f354..f8a1d0c3 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 @@ -89,7 +89,7 @@ public abstract class HsHostingAsset implements Stringifyable, BaseEntity subHostingAssets; 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 089d85b2..adcf4235 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 @@ -3,10 +3,12 @@ package net.hostsharing.hsadminng.hs.office.debitor; import io.micrometer.core.annotation.Timed; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeDebitorsApi; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorInsertResource; 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.person.HsOfficePersonRealRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository; import net.hostsharing.hsadminng.mapper.StrictMapper; @@ -45,6 +47,12 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { @Autowired private HsOfficeRelationRealRepository realRelRepo; + @Autowired + private HsOfficePersonRealRepository realPersonRepo; + + @Autowired + private HsOfficeContactRealRepository realContactRepo; + @Autowired private HsOfficeBankAccountRepository bankAccountRepo; @@ -94,7 +102,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); if (body.getDebitorRel() != null) { // FIXME: move this into RESOURCE_TO_ENTITY_POSTMAPPER - final var debitorRel = mapper.map("debitorRel.", body.getDebitorRel(), HsOfficeRelationRealEntity.class); + final var debitorRel = entityToSave.getDebitorRel(); debitorRel.setType(DEBITOR); entityValidator.validateEntityExists("debitorRel.anchorUuid", debitorRel.getAnchor()); entityValidator.validateEntityExists("debitorRel.holderUuid", debitorRel.getHolder()); @@ -196,6 +204,15 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { } final BiConsumer RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { + if (resource.getDebitorRel() != null) { + final var debitorRel = realRelRepo.save(HsOfficeRelationRealEntity.builder() + .type(DEBITOR) + .anchor(realPersonRepo.findByUuid(resource.getDebitorRel().getAnchorUuid()).orElseThrow() ) // FIXME + .holder(realPersonRepo.findByUuid(resource.getDebitorRel().getHolderUuid()).orElseThrow() ) // FIXME + .contact(realContactRepo.findByUuid(resource.getDebitorRel().getContactUuid()).orElseThrow() ) // FIXME + .build()); + entity.setDebitorRel(debitorRel); + } if (resource.getRefundBankAccountUuid() != null) { final var bankAccountEntity = bankAccountRepo.findByUuid(resource.getRefundBankAccountUuid()) .orElseThrow(() -> new ValidationException()); // FIXME diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java index 4715ad72..ab3b3d08 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java @@ -643,7 +643,6 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup final var givenProject = realProjectRepo.findByCaption(projectCaption).stream() .findAny().orElseThrow(); final var newBookingItem = HsBookingItemRealEntity.builder() - .uuid(UUID.randomUUID()) .project(givenProject) .type(hsBookingItemType) .caption("some test-booking") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java index 05313c56..37b54e7e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java @@ -270,7 +270,6 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean context.define("superuser-alex@hostsharing.net"); final var givenDebitor = debitorRepo.findByDebitorNumber(debitorNumber).stream().findAny().orElseThrow(); final var newBookingProject = HsBookingProjectRealEntity.builder() - .uuid(UUID.randomUUID()) .debitor(givenDebitor) .caption(caption) .build();