amendmends according to Code-Review

This commit is contained in:
Michael Hoennig 2024-06-21 12:00:28 +02:00
parent 1ba760e9a9
commit 3a1d883dd9
5 changed files with 13 additions and 17 deletions

View File

@ -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(),

View File

@ -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<HsHostingAssetPatchResource> {
@ -26,15 +25,11 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher<HsHostingAsset
.ifPresent(entity::setCaption);
Optional.ofNullable(resource.getConfig())
.ifPresent(r -> 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)));
}
}

View File

@ -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$);
--//

View File

@ -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")

View File

@ -108,7 +108,6 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
PATCHED_CONTACT_UUID,
HsHostingAssetEntity::setAlarmContact,
newContact(PATCHED_CONTACT_UUID))
.notNullable()
);
}