From a9da76621c1be7a11bf292e868a8f7c22f2ea203 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sun, 26 Mar 2023 21:20:42 +0100 Subject: bug(web): Inform user when deleted topology is still used This change fixes #135 which showed that trying to delete a topology used by a scenario would result in nothing happening in the UI and a 500 error being returned by the server. We check whether a scenario still references the topology and show an error to the user if that happens. Fixes #135 --- .../java/org/opendc/web/server/rest/user/TopologyResource.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'opendc-web/opendc-web-server/src/main') diff --git a/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/rest/user/TopologyResource.java b/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/rest/user/TopologyResource.java index 2b66b64b..71491801 100644 --- a/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/rest/user/TopologyResource.java +++ b/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/rest/user/TopologyResource.java @@ -22,10 +22,12 @@ package org.opendc.web.server.rest.user; +import io.quarkus.hibernate.orm.panache.Panache; import io.quarkus.security.identity.SecurityIdentity; import java.time.Instant; import java.util.List; import javax.annotation.security.RolesAllowed; +import javax.persistence.PersistenceException; import javax.transaction.Transactional; import javax.validation.Valid; import javax.ws.rs.Consumes; @@ -193,6 +195,14 @@ public final class TopologyResource { entity.updatedAt = Instant.now(); entity.delete(); + + try { + // Flush the results, so we can check whether the constraints are not violated + Panache.flush(); + } catch (PersistenceException e) { + throw new WebApplicationException("Topology is still in use", 403); + } + return UserProtocol.toDto(entity, auth); } } -- cgit v1.2.3