add optional alarm-contact to hosting-asset #64
@ -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(),
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -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$);
|
||||
--//
|
||||
|
||||
|
@ -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")
|
||||
|
@ -108,7 +108,6 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
PATCHED_CONTACT_UUID,
|
||||
HsHostingAssetEntity::setAlarmContact,
|
||||
newContact(PATCHED_CONTACT_UUID))
|
||||
.notNullable()
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user