add optional alarm-contact to hosting-asset #64

Merged
hsh-michaelhoennig merged 5 commits from add-alarm-contact-to-hosting-asset into master 2024-06-21 12:02:07 +02:00
5 changed files with 13 additions and 17 deletions
Showing only changes of commit 3a1d883dd9 - Show all commits

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")
hsh-michaelhoennig marked this conversation as resolved Outdated

UUid falsch geschrieben

UUid falsch geschrieben
.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)));
}
}
hsh-michaelhoennig marked this conversation as resolved Outdated

muss raus, darf null sein

muss raus, darf null sein

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",
hsh-michaelhoennig marked this conversation as resolved Outdated

muss wieder raus

muss wieder raus
"..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()
);
}