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) return rbacViewFor("asset", HsHostingAssetEntity.class)
.withIdentityView(SQL.projection("identifier")) .withIdentityView(SQL.projection("identifier"))
.withRestrictedViewOrderBy(SQL.expression("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? .toRole(GLOBAL, ADMIN).grantPermission(INSERT) // TODO.impl: Why is this necessary to insert test data?
.importEntityAlias("bookingItem", HsBookingItemEntity.class, usingDefaultCase(), .importEntityAlias("bookingItem", HsBookingItemEntity.class, usingDefaultCase(),

View File

@ -8,7 +8,6 @@ import net.hostsharing.hsadminng.mapper.OptionalFromJson;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
public class HsHostingAssetEntityPatcher implements EntityPatcher<HsHostingAssetPatchResource> { public class HsHostingAssetEntityPatcher implements EntityPatcher<HsHostingAssetPatchResource> {
@ -26,15 +25,11 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher<HsHostingAsset
.ifPresent(entity::setCaption); .ifPresent(entity::setCaption);
Optional.ofNullable(resource.getConfig()) Optional.ofNullable(resource.getConfig())
.ifPresent(r -> entity.getConfig().patch(KeyValueMap.from(resource.getConfig()))); .ifPresent(r -> entity.getConfig().patch(KeyValueMap.from(resource.getConfig())));
OptionalFromJson.of(resource.getAlarmContactUuid()).ifPresent(newValue -> { OptionalFromJson.of(resource.getAlarmContactUuid())
verifyNotNull(newValue, "alarmContact"); // HOWTO: patch nullable JSON resource uuid to an ntity reference
entity.setAlarmContact(em.getReference(HsOfficeContactEntity.class, newValue)); .ifPresent(newValue -> entity.setAlarmContact(
}); Optional.ofNullable(newValue)
} .map(uuid -> em.getReference(HsOfficeContactEntity.class, newValue))
.orElse(null)));
private void verifyNotNull(final UUID newValue, final String propertyName) {
if (newValue == null) {
throw new IllegalArgumentException("property '" + propertyName + "' must not be null");
}
} }
} }

View File

@ -120,7 +120,8 @@ create or replace procedure updateRbacRulesForHsHostingAsset(
language plpgsql as $$ language plpgsql as $$
begin 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; delete from rbacgrants g where g.grantedbytriggerof = OLD.uuid;
call buildRbacSystemForHsHostingAsset(NEW); call buildRbacSystemForHsHostingAsset(NEW);
end if; end if;
@ -277,7 +278,7 @@ call generateRbacRestrictedView('hs_hosting_asset',
caption = new.caption, caption = new.caption,
config = new.config, config = new.config,
assignedToAssetUuid = new.assignedToAssetUuid, assignedToAssetUuid = new.assignedToAssetUuid,
alarmContactUUid = new.alarmContactUUid alarmContactUuid = new.alarmContactUuid
$updates$); $updates$);
--// --//

View File

@ -58,7 +58,6 @@ public class ArchitectureTest {
"..hs.booking.project", "..hs.booking.project",
"..hs.booking.item", "..hs.booking.item",
"..hs.booking.item.validators", "..hs.booking.item.validators",
"..hs.hosting.contact",
"..hs.hosting.asset", "..hs.hosting.asset",
"..hs.hosting.asset.validators", "..hs.hosting.asset.validators",
"..errors", "..errors",
@ -197,7 +196,9 @@ public class ArchitectureTest {
"..hs.office.partner..", "..hs.office.partner..",
"..hs.office.debitor..", "..hs.office.debitor..",
"..hs.office.membership..", "..hs.office.membership..",
"..hs.office.migration.."); "..hs.office.migration..",
"..hs.hosting.asset.."
);
@ArchTest @ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

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