From 3a1d883dd988f4d2aef68bb4ba5f4310d04028ca Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 21 Jun 2024 12:00:28 +0200 Subject: [PATCH] amendmends according to Code-Review --- .../hs/hosting/asset/HsHostingAssetEntity.java | 2 +- .../asset/HsHostingAssetEntityPatcher.java | 17 ++++++----------- .../7013-hs-hosting-asset-rbac.sql | 5 +++-- .../hsadminng/arch/ArchitectureTest.java | 5 +++-- .../HsHostingAssetEntityPatcherUnitTest.java | 1 - 5 files changed, 13 insertions(+), 17 deletions(-) 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 4891258f..76bcd40d 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 @@ -142,7 +142,7 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject { return rbacViewFor("asset", HsHostingAssetEntity.class) .withIdentityView(SQL.projection("identifier")) .withRestrictedViewOrderBy(SQL.expression("identifier")) - .withUpdatableColumns("version", "caption", "config", "assignedToAssetUuid", "alarmContactUUid") + .withUpdatableColumns("version", "caption", "config", "assignedToAssetUuid", "alarmContactUuid") .toRole(GLOBAL, ADMIN).grantPermission(INSERT) // TODO.impl: Why is this necessary to insert test data? .importEntityAlias("bookingItem", HsBookingItemEntity.class, usingDefaultCase(), 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 753dc8fa..f1cff713 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 @@ -8,7 +8,6 @@ import net.hostsharing.hsadminng.mapper.OptionalFromJson; import jakarta.persistence.EntityManager; import java.util.Optional; -import java.util.UUID; public class HsHostingAssetEntityPatcher implements EntityPatcher { @@ -26,15 +25,11 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher entity.getConfig().patch(KeyValueMap.from(resource.getConfig()))); - OptionalFromJson.of(resource.getAlarmContactUuid()).ifPresent(newValue -> { - verifyNotNull(newValue, "alarmContact"); - entity.setAlarmContact(em.getReference(HsOfficeContactEntity.class, newValue)); - }); - } - - private void verifyNotNull(final UUID newValue, final String propertyName) { - if (newValue == null) { - throw new IllegalArgumentException("property '" + propertyName + "' must not be null"); - } + OptionalFromJson.of(resource.getAlarmContactUuid()) + // HOWTO: patch nullable JSON resource uuid to an ntity reference + .ifPresent(newValue -> entity.setAlarmContact( + Optional.ofNullable(newValue) + .map(uuid -> em.getReference(HsOfficeContactEntity.class, newValue)) + .orElse(null))); } } diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql index 8a8b8c42..cbaffa47 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql @@ -120,7 +120,8 @@ create or replace procedure updateRbacRulesForHsHostingAsset( language plpgsql as $$ begin - if NEW.assignedToAssetUuid is distinct from OLD.assignedToAssetUuid then + if NEW.assignedToAssetUuid is distinct from OLD.assignedToAssetUuid + or NEW.alarmContactUuid is distinct from OLD.alarmContactUuid then delete from rbacgrants g where g.grantedbytriggerof = OLD.uuid; call buildRbacSystemForHsHostingAsset(NEW); end if; @@ -277,7 +278,7 @@ call generateRbacRestrictedView('hs_hosting_asset', caption = new.caption, config = new.config, assignedToAssetUuid = new.assignedToAssetUuid, - alarmContactUUid = new.alarmContactUUid + alarmContactUuid = new.alarmContactUuid $updates$); --// diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java index 9c73c9b9..f626a3ed 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java @@ -58,7 +58,6 @@ public class ArchitectureTest { "..hs.booking.project", "..hs.booking.item", "..hs.booking.item.validators", - "..hs.hosting.contact", "..hs.hosting.asset", "..hs.hosting.asset.validators", "..errors", @@ -197,7 +196,9 @@ public class ArchitectureTest { "..hs.office.partner..", "..hs.office.debitor..", "..hs.office.membership..", - "..hs.office.migration.."); + "..hs.office.migration..", + "..hs.hosting.asset.." + ); @ArchTest @SuppressWarnings("unused") 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 0514d2b7..890932b4 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 @@ -108,7 +108,6 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< PATCHED_CONTACT_UUID, HsHostingAssetEntity::setAlarmContact, newContact(PATCHED_CONTACT_UUID)) - .notNullable() ); }