100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Fixes for JPA entity persistence errors after Hibernate upgrade (#1867)
Rich Turner6003202dc4bc
diff --git a/container/src/main/java/org/openremote/container/web/WebServiceExceptions.java b/container/src/main/java/org/openremote/container/web/WebServiceExceptions.javaindex fd8492a07..bd002c943 100644--- a/container/src/main/java/org/openremote/container/web/WebServiceExceptions.java+++ b/container/src/main/java/org/openremote/container/web/WebServiceExceptions.java@@ -24,9 +24,11 @@ import io.undertow.server.HttpServerExchange;import io.undertow.servlet.api.ExceptionHandler;import io.undertow.util.HttpString;+import jakarta.persistence.OptimisticLockException;import jakarta.servlet.ServletRequest;import jakarta.servlet.ServletResponse;import jakarta.ws.rs.ForbiddenException;+import jakarta.ws.rs.NotAllowedException;import jakarta.ws.rs.WebApplicationException;import jakarta.ws.rs.core.*;import jakarta.ws.rs.ext.ExceptionMapper;@@ -150,6 +152,13 @@ public class WebServiceExceptions {logException(throwable, origin, request.getMethod() + " " + uriInfo.getRequestUri());int statusCode = 500;++ if (throwable instanceof OptimisticLockException) {+ // We get here if JPA entity id is set on merge but it doesn't already exist (unless ID generator is configured to allow ID to be assigned)+ // Or we get here is JPA entity version doesn't match what's in the DB+ throwable = new NotAllowedException(throwable);+ }+if (throwable instanceof WebApplicationException) {Response response = ((WebApplicationException) throwable).getResponse();switch (response.getStatusInfo().getFamily()) {diff --git a/manager/src/main/java/org/openremote/manager/dashboard/DashboardResourceImpl.java b/manager/src/main/java/org/openremote/manager/dashboard/DashboardResourceImpl.javaindex 87e790e0d..b22e3eab7 100644--- a/manager/src/main/java/org/openremote/manager/dashboard/DashboardResourceImpl.java+++ b/manager/src/main/java/org/openremote/manager/dashboard/DashboardResourceImpl.java@@ -74,13 +74,10 @@ public class DashboardResourceImpl extends ManagerWebResource implements Dashboathis.createDashboardQuery(realm).ids(dashboardId).limit(1),getUserId());- // If no dashboards were returned, check whether it existed, and return a different response.++ // Don't return a different response if dashboard exists, expensive and of limited use it only gives attackers more info than we shouldif(dashboards.length == 0) {- if(this.dashboardStorageService.exists(dashboardId, realm)) {- throw new WebApplicationException(FORBIDDEN);- } else {- throw new WebApplicationException(NOT_FOUND);- }+ throw new WebApplicationException(NOT_FOUND);}return dashboards[0];@@ -111,7 +108,6 @@ public class DashboardResourceImpl extends ManagerWebResource implements Dashboadashboard.setAccess(DashboardAccess.SHARED);return this.dashboardStorageService.createNew(ValueUtil.clone(dashboard));} catch (IllegalStateException ex) {- ex.printStackTrace();throw new WebApplicationException(ex, INTERNAL_SERVER_ERROR);}}@@ -130,7 +126,6 @@ public class DashboardResourceImpl extends ManagerWebResource implements Dashboa} catch (IllegalArgumentException ex) {throw new WebApplicationException(ex, NOT_FOUND);} catch (IllegalStateException ex) {- ex.printStackTrace();throw new WebApplicationException(ex, INTERNAL_SERVER_ERROR);}}@@ -148,7 +143,6 @@ public class DashboardResourceImpl extends ManagerWebResource implements Dashboa} catch (IllegalArgumentException ex) {throw new WebApplicationException(ex, NOT_FOUND);} catch (IllegalStateException ex) {- ex.printStackTrace();throw new WebApplicationException(ex, INTERNAL_SERVER_ERROR);}}diff --git a/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.java b/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.javaindex 8a215d1c7..857101bc5 100644--- a/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.java+++ b/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.java@@ -19,6 +19,7 @@*/package org.openremote.manager.dashboard;+import jakarta.persistence.NoResultException;import jakarta.persistence.Query;import org.apache.camel.builder.RouteBuilder;import org.openremote.container.message.MessageBrokerService;@@ -35,6 +36,7 @@ import org.openremote.model.dashboard.DashboardAccess;import org.openremote.model.query.DashboardQuery;import org.openremote.model.query.filter.RealmPredicate;import org.openremote.model.query.filter.StringPredicate;+import org.openremote.model.util.TextUtil;import java.util.*;import java.util.logging.Logger;@@ -244,23 +246,6 @@ public class DashboardStorageService extends RouteBuilder implements ContainerSereturn sqlBuilder;}- // Method to check if a dashboardId actually exists in the database- // Useful for when query() does not return any accessible dashboard for that user, and check if it does however exist.- public boolean exists(String dashboardId, String realm) {- if(dashboardId == null) {- throw new IllegalArgumentException("No dashboardId is specified.");- }- if(realm == null) {- throw new IllegalArgumentException("No realm is specified.");- }- return this.query(new DashboardQuery()- .realm(new RealmPredicate(realm))- .ids(dashboardId),- null- ).length > 0;- }--// Creation of initial dashboard (so no updating!)public Dashboard createNew(Dashboard dashboard) {if(dashboard == null) {@@ -279,7 +264,7 @@ public class DashboardStorageService extends RouteBuilder implements ContainerSe// Update of an existing dashboardpublic Dashboard update(Dashboard dashboard, String realm, String userId) throws IllegalArgumentException {- if(dashboard == null) {+ if(dashboard == null || TextUtil.isNullOrEmpty(dashboard.getId())) {throw new IllegalArgumentException("No dashboard is specified.");}if(realm == null) {@@ -288,21 +273,25 @@ public class DashboardStorageService extends RouteBuilder implements ContainerSeif(userId == null) {throw new IllegalArgumentException("No userId is specified.");}- // Query the dashboards with the same ID (which is only 1)- var query = new DashboardQuery()- .ids(dashboard.getId())- .realm(new RealmPredicate(realm))- .limit(1);- Dashboard[] dashboards = this.query(query, userId);- if(dashboards != null && dashboards.length > 0) {- Dashboard d = dashboards[0];- return persistenceService.doReturningTransaction(em -> {- dashboard.setVersion(d.getVersion()); // TODO: Investigate why versioning is not correct for Dashboard model+ return persistenceService.doReturningTransaction(em -> {+ // Check it exists and is associated with the specified user if private+ StringBuilder sb = new StringBuilder("SELECT d.id FROM Dashboard d where id = :id AND (access <> ")+ .append(DashboardAccess.PRIVATE.ordinal())+ .append(" OR ownerId = :userId)")+ .append(" AND realm = :realm");++ try {+ em.createQuery(sb.toString(), String.class)+ .setParameter("id", dashboard.getId())+ .setParameter("userId", userId)+ .setParameter("realm", realm)+ .getSingleResult();+return em.merge(dashboard);- });- } else {- throw new IllegalArgumentException("This dashboard does not exist!");- }+ } catch (NoResultException e) {+ throw new IllegalArgumentException("Dashboard does not exist or is inaccessible.");+ }+ });}public boolean delete(String dashboardId, String realm, String userId) throws IllegalArgumentException {diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.javaindex 5b8e1eda8..688dec3f1 100644--- a/model/src/main/java/org/openremote/model/asset/Asset.java+++ b/model/src/main/java/org/openremote/model/asset/Asset.java@@ -47,7 +47,7 @@ import org.openremote.model.attribute.MetaMap;import org.openremote.model.geo.GeoJSONPoint;import org.openremote.model.jackson.AssetTypeIdResolver;import org.openremote.model.persistence.LTreeType;-import org.openremote.model.util.HibernateUniqueIdentifierType;+import org.openremote.model.util.HibernateUniqueIdentifierTypeAssignable;import org.openremote.model.util.TsIgnoreTypeParams;import org.openremote.model.util.ValueUtil;import org.openremote.model.validation.AssetValid;@@ -78,6 +78,11 @@ import static jakarta.persistence.DiscriminatorType.STRING;* {@link AssetDescriptor} registered within the running instance. If the corresponding {@link AssetDescriptor} cannot* be found then the fallback generic {@link ThingAsset#DESCRIPTOR} will be assumed.* <p>+ * The {@link #id} is BASE-62 encoded UUID (22 characters long) and can be supplied or auto generated; by allowing it+ * to be supplied services have a predictable way to find a given asset and can use the+ * {@link org.openremote.model.util.UniqueIdentifierGenerator#generateId( String)} to generate a constant ID from a+ * given input string.+ * <p>* The {@link #path} is a list of parent asset identifiers, starting with the identifier of this asset, followed by* parent asset identifiers, and ending with the identifier of the root asset in the tree. This is a transient property* and only resolved and usable when the asset is loaded from storage and as calculating it is costly, might be empty@@ -277,7 +282,7 @@ public abstract class Asset<T extends Asset<?>> implements IdentifiableEntity<T>public static final AttributeDescriptor<String> MANUFACTURER = new AttributeDescriptor<>("manufacturer", ValueType.TEXT).withOptional(true);public static final AttributeDescriptor<String> MODEL = new AttributeDescriptor<>("model", ValueType.TEXT).withOptional(true);- @Id @HibernateUniqueIdentifierType+ @Id @HibernateUniqueIdentifierTypeAssignable@Column(name = "ID", length = 22, columnDefinition = "char(22)")@Pattern(regexp = Constants.ASSET_ID_REGEXP, message = "{Asset.id.Pattern}")protected String id;diff --git a/model/src/main/java/org/openremote/model/dashboard/Dashboard.java b/model/src/main/java/org/openremote/model/dashboard/Dashboard.javaindex f0b910db1..32c4ff22a 100644--- a/model/src/main/java/org/openremote/model/dashboard/Dashboard.java+++ b/model/src/main/java/org/openremote/model/dashboard/Dashboard.java@@ -10,6 +10,7 @@ import org.hibernate.type.SqlTypes;import org.openremote.model.util.HibernateUniqueIdentifierType;import java.util.Date;+import java.util.Objects;@Entity@Table(name = "DASHBOARD")@@ -31,7 +32,7 @@ public class Dashboard {@Version@Column(name = "VERSION", nullable = false)- protected long version;+ protected Long version;@Column(name = "OWNER_ID", nullable = false)protected String ownerId;@@ -103,7 +104,6 @@ public class Dashboard {return this;}-public String getId() {return this.id;}@@ -116,7 +116,7 @@ public class Dashboard {return this.realm;}- public long getVersion() {+ public Long getVersion() {return this.version;}@@ -135,4 +135,16 @@ public class Dashboard {public DashboardTemplate getTemplate() {return this.template;}++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof Dashboard dashboard)) return false;+ return Objects.equals(id, dashboard.id) && Objects.equals(createdOn, dashboard.createdOn) && Objects.equals(realm, dashboard.realm) && Objects.equals(version, dashboard.version) && Objects.equals(ownerId, dashboard.ownerId) && access == dashboard.access && Objects.equals(displayName, dashboard.displayName) && Objects.equals(template, dashboard.template);+ }++ @Override+ public int hashCode() {+ return Objects.hash(id, createdOn, realm, version, ownerId, access, displayName, template);+ }}diff --git a/model/src/main/java/org/openremote/model/dashboard/DashboardScreenPreset.java b/model/src/main/java/org/openremote/model/dashboard/DashboardScreenPreset.javaindex 87fd99007..7f8b23d42 100644--- a/model/src/main/java/org/openremote/model/dashboard/DashboardScreenPreset.java+++ b/model/src/main/java/org/openremote/model/dashboard/DashboardScreenPreset.java@@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotEmpty;import jakarta.validation.constraints.NotNull;import jakarta.ws.rs.WebApplicationException;+import java.util.Objects;+import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST;public class DashboardScreenPreset {@@ -29,6 +31,7 @@ public class DashboardScreenPreset {public DashboardScreenPreset() {}+public DashboardScreenPreset(String displayName, DashboardScalingPreset scalingPreset) {this.displayName = displayName;this.breakpoint = 1;@@ -51,4 +54,16 @@ public class DashboardScreenPreset {public int getBreakpoint() { return breakpoint; }public DashboardScalingPreset getScalingPreset() { return scalingPreset; }public String getRedirectDashboardId() { return redirectDashboardId; }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof DashboardScreenPreset that)) return false;+ return breakpoint == that.breakpoint && Objects.equals(id, that.id) && Objects.equals(displayName, that.displayName) && scalingPreset == that.scalingPreset && Objects.equals(redirectDashboardId, that.redirectDashboardId);+ }++ @Override+ public int hashCode() {+ return Objects.hash(id, displayName, breakpoint, scalingPreset, redirectDashboardId);+ }}diff --git a/model/src/main/java/org/openremote/model/dashboard/DashboardTemplate.java b/model/src/main/java/org/openremote/model/dashboard/DashboardTemplate.javaindex 711dbaf76..5d7ab65ea 100644--- a/model/src/main/java/org/openremote/model/dashboard/DashboardTemplate.java+++ b/model/src/main/java/org/openremote/model/dashboard/DashboardTemplate.java@@ -4,6 +4,9 @@ import jakarta.validation.Valid;import jakarta.validation.constraints.Min;import jakarta.validation.constraints.NotNull;+import java.util.Arrays;+import java.util.Objects;+public class DashboardTemplate {// Fields@@ -93,4 +96,16 @@ public class DashboardTemplate {public DashboardWidget[] getWidgets() {return widgets;}++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof DashboardTemplate that)) return false;+ return columns == that.columns && maxScreenWidth == that.maxScreenWidth && Objects.equals(id, that.id) && refreshInterval == that.refreshInterval && Objects.deepEquals(screenPresets, that.screenPresets) && Objects.deepEquals(widgets, that.widgets);+ }++ @Override+ public int hashCode() {+ return Objects.hash(id, columns, maxScreenWidth, refreshInterval, Arrays.hashCode(screenPresets), Arrays.hashCode(widgets));+ }}diff --git a/model/src/main/java/org/openremote/model/dashboard/DashboardWidget.java b/model/src/main/java/org/openremote/model/dashboard/DashboardWidget.javaindex 3038cc31b..2f8b175f0 100644--- a/model/src/main/java/org/openremote/model/dashboard/DashboardWidget.java+++ b/model/src/main/java/org/openremote/model/dashboard/DashboardWidget.java@@ -4,6 +4,8 @@ import jakarta.validation.Valid;import jakarta.validation.constraints.NotEmpty;import jakarta.validation.constraints.NotNull;+import java.util.Objects;+public class DashboardWidget {// Fields@@ -68,4 +70,16 @@ public class DashboardWidget {public Object getWidgetConfig() {return widgetConfig;}++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof DashboardWidget that)) return false;+ return Objects.equals(id, that.id) && Objects.equals(displayName, that.displayName) && Objects.equals(gridItem, that.gridItem) && Objects.equals(widgetTypeId, that.widgetTypeId) && Objects.equals(widgetConfig, that.widgetConfig);+ }++ @Override+ public int hashCode() {+ return Objects.hash(id, displayName, gridItem, widgetTypeId, widgetConfig);+ }}diff --git a/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierGenerator.java b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierGenerator.javaindex ac6040743..37011e535 100644--- a/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierGenerator.java+++ b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierGenerator.java@@ -38,9 +38,4 @@ public class HibernateUniqueIdentifierGenerator implements IdentifierGenerator {}return UniqueIdentifierGenerator.generateId();}-- @Override- public boolean allowAssignedIdentifiers() {- return true;- }}diff --git a/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierGeneratorAssignable.java b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierGeneratorAssignable.javanew file mode 100644index 000000000..06bd1c68b--- /dev/null+++ b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierGeneratorAssignable.java@@ -0,0 +1,46 @@+/*+ * Copyright 2025, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.util;++import org.hibernate.HibernateException;+import org.hibernate.engine.spi.SharedSessionContractImplementor;+import org.hibernate.id.IdentifierGenerator;+import org.openremote.model.IdentifiableEntity;++import java.io.Serializable;++public class HibernateUniqueIdentifierGeneratorAssignable implements IdentifierGenerator {++ @Override+ public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {+ if (object instanceof IdentifiableEntity) {+ IdentifiableEntity<?> identifiableEntity = (IdentifiableEntity<?>) object;+ if (identifiableEntity.getId() != null)+ return identifiableEntity.getId();+ }+ return UniqueIdentifierGenerator.generateId();+ }++ @Override+ public boolean allowAssignedIdentifiers() {+ return true;+ }+}diff --git a/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierType.java b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierType.javaindex 1e0193e08..407de06aa 100644--- a/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierType.java+++ b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierType.java@@ -1,3 +1,23 @@+/*+ * Copyright 2025, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.model.util;import org.hibernate.annotations.IdGeneratorType;diff --git a/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierTypeAssignable.java b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierTypeAssignable.javanew file mode 100644index 000000000..fd937c358--- /dev/null+++ b/model/src/main/java/org/openremote/model/util/HibernateUniqueIdentifierTypeAssignable.java@@ -0,0 +1,37 @@+/*+ * Copyright 2025, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.util;++import org.hibernate.annotations.IdGeneratorType;++import java.lang.annotation.Retention;+import java.lang.annotation.Target;++import static java.lang.annotation.ElementType.FIELD;+import static java.lang.annotation.ElementType.METHOD;+import static java.lang.annotation.RetentionPolicy.RUNTIME;++@IdGeneratorType(HibernateUniqueIdentifierGeneratorAssignable.class)+@Retention(RUNTIME) @Target({METHOD,FIELD})+public @interface HibernateUniqueIdentifierTypeAssignable {+++}diff --git a/setup/src/demo/java/org/openremote/setup/demo/ManagerDemoSetup.java b/setup/src/demo/java/org/openremote/setup/demo/ManagerDemoSetup.javaindex 75f8decc3..cd54c8707 100644--- a/setup/src/demo/java/org/openremote/setup/demo/ManagerDemoSetup.java+++ b/setup/src/demo/java/org/openremote/setup/demo/ManagerDemoSetup.java@@ -114,7 +114,7 @@ public class ManagerDemoSetup extends ManagerSetup {new MetaItem<>(RULE_STATE), new MetaItem<>(READ_ONLY));harvestRobotAsset.getAttributes().getOrCreate(HarvestRobotAsset.HARVESTED_TOTAL).addMeta(new MetaItem<>(RULE_STATE), new MetaItem<>(READ_ONLY))- .setValue(harvestedTotal);;+ .setValue(harvestedTotal);return harvestRobotAsset;}diff --git a/setup/src/demo/resources/demo/dashboards/manufacturer/harvesting.json b/setup/src/demo/resources/demo/dashboards/manufacturer/harvesting.jsonindex f5f93cd50..efa675897 100644--- a/setup/src/demo/resources/demo/dashboards/manufacturer/harvesting.json+++ b/setup/src/demo/resources/demo/dashboards/manufacturer/harvesting.json@@ -1,8 +1,6 @@{- "id": "3k0JH2gePMKy3BnLoRqLp5","createdOn": 1711029945937,"realm": "manufacturer",- "version": 11,"ownerId": "e5ca8a39-5193-478d-ba86-57e7095679cf","access": "SHARED","displayName": "Harvesting dashboard",diff --git a/setup/src/demo/resources/demo/dashboards/smartcity/parking.json b/setup/src/demo/resources/demo/dashboards/smartcity/parking.jsonindex 487cd4b07..a817a5820 100644--- a/setup/src/demo/resources/demo/dashboards/smartcity/parking.json+++ b/setup/src/demo/resources/demo/dashboards/smartcity/parking.json@@ -1,8 +1,6 @@{- "id": "5o0KL29L50Q7hSoVyvAI2y","createdOn": 1711029229921,"realm": "smartcity",- "version": 8,"ownerId": "e5ca8a39-5193-478d-ba86-57e7095679cf","access": "SHARED","displayName": "Parking dashboard",diff --git a/test/src/test/groovy/org/openremote/test/dashboard/DashboardTest.groovy b/test/src/test/groovy/org/openremote/test/dashboard/DashboardTest.groovyindex 4c2c0ec31..47505754a 100644--- a/test/src/test/groovy/org/openremote/test/dashboard/DashboardTest.groovy+++ b/test/src/test/groovy/org/openremote/test/dashboard/DashboardTest.groovy@@ -123,10 +123,10 @@ class DashboardTest extends Specification implements ManagerContainerTrait {assert adminDashboard.id == userDashboards[0].idassert privateUser1Dashboard.id == userDashboards[1].id- when: "a user without READ_INSIGHTS tries to fetch a dashboard"+ when: "a user without READ_INSIGHTS tries to fetch all realm dashboards"def readonlyDashboards = noAccessDashboardResource.getAllRealmDashboards(null, MASTER_REALM)- then: "an exception is thrown that reflects their lack of READ permissions"+ then: "none are returned"assert readonlyDashboards.length == 0/* ----------------------- */@@ -145,7 +145,7 @@ class DashboardTest extends Specification implements ManagerContainerTrait {when: "a user without READ_INSIGHTS tries to query dashboard by display name"dashboards = noAccessDashboardResource.query(null, displayNameQuery)- then: "no dashboards with the display name could be found"+ then: "no dashboards are returned"assert dashboards.length == 0when: "an unauthenticated user tries to query dashboard by display name"@@ -158,28 +158,38 @@ class DashboardTest extends Specification implements ManagerContainerTrait {// Test to verify access logic- when: "dashboard1 is shared, and updated from a different realm"+ when: "a dashboard is updated from a different realm"privateUser1Dashboard.setDisplayName("New displayname")- smartcityDashboardResource.update(null, privateUser1Dashboard)+ privateUser1Dashboard = smartcityDashboardResource.update(null, privateUser1Dashboard)then: "an forbidden exception is thrown for not having cross-realm access"thrown ForbiddenException- when: "dashboard1 is shared, and updated by a different user"- alternativeUserDashboardResource.update(null, privateUser1Dashboard)+ when: "a shared dashboard is updated by a different user"+ privateUser1Dashboard = alternativeUserDashboardResource.update(null, privateUser1Dashboard)- then: "updating the dashboard succeeds as it is shared across the realm"+ then: "the update succeeds as it is shared across the realm"def alternativeUpdatedDashboard = alternativeUserDashboardResource.get(null, MASTER_REALM, privateUser1Dashboard.id)assert alternativeUpdatedDashboard.setDisplayName("New displayname 2")/* ----------- */+ when: "the user without READ_INSIGHTS and WRITE_INSIGHTS tries to retrieve the shared dashboard"+ noAccessDashboardResource.get(null, MASTER_REALM, privateUser1Dashboard.id)++ then: "a not found exception should be thrown"+ thrown NotFoundException++ /* ----------- */+when: "dashboard1 is made 'private' by its original owner"privateUser1Dashboard.setAccess(DashboardAccess.PRIVATE)privateUser1Dashboard = privateUser1DashboardResource.update(null, privateUser1Dashboard)- assert privateUser1Dashboard != null- and: "all dashboards of the original owner are retrieved"+ then: "the dashboard should have been updated"+ privateUser1Dashboard != null++ when: "all dashboards of the original owner are retrieved"dashboards = privateUser1DashboardResource.getAllRealmDashboards(null, MASTER_REALM)then: "dashboard1 is actually private"@@ -188,31 +198,19 @@ class DashboardTest extends Specification implements ManagerContainerTrait {/* ----------- */- when: "the original owner of dashboard1 has been changed to a user without READ_INSIGHTS and WRITE_INSIGHTS role"- privateUser1Dashboard.setOwnerId(noAccessUser.id)- privateUser1Dashboard = adminUserDashboardResource.update(null, privateUser1Dashboard)-- and: "the user without READ_INSIGHTS and WRITE_INSIGHTS tries to retrieve their personal dashboard"- noAccessDashboardResource.get(null, MASTER_REALM, privateUser1Dashboard.id)-- then: "a NOT_FOUND exception is thrown as no READ_INSIGHTS role is assigned"- thrown NotFoundException-- /* ----------- */-- when: "the first dashboard cannot be edited by a different user, even if its admin user"+ when: "a user tries to update another user's private dashboard"privateUser1Dashboard.setDisplayName("another displayname")privateUser1Dashboard = adminUserDashboardResource.update(null, privateUser1Dashboard)- then: "it should throw exception"+ then: "it should throw an exception"thrown NotFoundException/* ----------- */- when: "the first dashboard cannot be read by a different user, even if its admin user"+ when: "a user makes a dashboard query for a name that matches a another user's private dashboard"def adminDisplaynameDashboards = adminUserDashboardResource.query(null, new DashboardQuery().names(privateUser1Dashboard.displayName))- then: "the dashboard could not be found, since it's made 'private' by its original owner"+ then: "the dashboard should not be returned"assert adminDisplaynameDashboards.length == 0/* ----------------------- */@@ -222,8 +220,8 @@ class DashboardTest extends Specification implements ManagerContainerTrait {when: "when a public user specifically fetches a private dashboard"publicUserDashboardResource.get(null, MASTER_REALM, adminDashboard.id)- then: "it should throw exception"- thrown ForbiddenException+ then: "a not found exception should be thrown"+ thrown NotFoundException/* ----------------------- */@@ -231,7 +229,7 @@ class DashboardTest extends Specification implements ManagerContainerTrait {when: "admin user updates his dashboard to be private"adminDashboard.setAccess(DashboardAccess.PRIVATE)- adminUserDashboardResource.update(null, adminDashboard)+ adminDashboard = adminUserDashboardResource.update(null, adminDashboard)and: "a different user tries to delete a dashboard he doesn't own"privateUser1DashboardResource.delete(null, MASTER_REALM, adminDashboard.id)@@ -241,7 +239,7 @@ class DashboardTest extends Specification implements ManagerContainerTrait {when: "admin user makes his dashboard SHARED again"adminDashboard.setAccess(DashboardAccess.SHARED)- adminUserDashboardResource.update(null, adminDashboard)+ adminDashboard = adminUserDashboardResource.update(null, adminDashboard)and: "a different user tries to delete the dashboard again"privateUser1DashboardResource.delete(null, MASTER_REALM, adminDashboard.id)@@ -266,9 +264,9 @@ class DashboardTest extends Specification implements ManagerContainerTrait {when: "dashboard1 is made 'public' by its original owner"privateUser1Dashboard.setAccess(DashboardAccess.PUBLIC)privateUser1Dashboard.setDisplayName("Public dashboard")- assert privateUser1DashboardResource.update(null, privateUser1Dashboard) != null+ privateUser1Dashboard = privateUser1DashboardResource.update(null, privateUser1Dashboard) != null- then: "when a public user fetches all dashboards, it should only return that dashboard"+ then: "the now public dashboard should be available to anonymous users"def publicDashboards2 = publicUserDashboardResource.getAllRealmDashboards(null, MASTER_REALM)assert publicDashboards2.length == 1assert publicDashboards2[0].access == DashboardAccess.PUBLICdiff --git a/ui/app/insights/src/pages/page-view.ts b/ui/app/insights/src/pages/page-view.tsindex 4bc58c1df..22c60b35d 100644--- a/ui/app/insights/src/pages/page-view.ts+++ b/ui/app/insights/src/pages/page-view.ts@@ -192,13 +192,8 @@ export class PageView extends Page<AppStateKeyed> {const response = await promise;return response.data;} catch (ex) {- if(isAxiosError(ex)) {- if(ex.response.status === 404 && manager.isSuperUser()) {- return undefined;- }- if(!manager.authenticated && ex.response.status === 403 && loginRedirect) {- manager.login();- }+ if(isAxiosError(ex) && !manager.authenticated && loginRedirect) {+ manager.login();}return undefined;}diff --git a/ui/component/or-dashboard-builder/src/index.ts b/ui/component/or-dashboard-builder/src/index.tsindex 88663df49..278338dda 100644--- a/ui/component/or-dashboard-builder/src/index.ts+++ b/ui/component/or-dashboard-builder/src/index.ts@@ -523,14 +523,16 @@ export class OrDashboardBuilder extends LitElement {this.isLoading = true;// Saving object into the database- manager.rest.api.DashboardResource.update(this.selectedDashboard).then(() => {- if(this.dashboards != null && this.selectedDashboard != null) {- this.initialDashboardJSON = JSON.stringify(this.selectedDashboard);- this.initialTemplateJSON = JSON.stringify(this.selectedDashboard.template);- this.dashboards[this.dashboards?.indexOf(this.selectedDashboard)] = this.selectedDashboard;- this.currentTemplate = Object.assign({}, this.selectedDashboard.template);- showSnackbar(undefined, "dashboard.saveSuccessful");- }+ manager.rest.api.DashboardResource.update(this.selectedDashboard).then((response) => {+ // Need to update the selected dashboard with what was persisted but due to code structure we also need to update+ // the dashboards array otherwise the old version gets loaded+ this.selectedDashboard = response.data;+ this.dashboards = [this.selectedDashboard,...this.dashboards?.filter(d => d.id !== this.selectedDashboard!.id)!];+ this.initialDashboardJSON = JSON.stringify(this.selectedDashboard);+ this.initialTemplateJSON = JSON.stringify(this.selectedDashboard.template);+ this.dashboards[this.dashboards?.indexOf(this.selectedDashboard)] = this.selectedDashboard;+ this.currentTemplate = Object.assign({}, this.selectedDashboard.template);+ showSnackbar(undefined, "dashboard.saveSuccessful");}).catch((reason) => {console.error(reason);showSnackbar(undefined, "errorOccurred");diff --git a/ui/component/or-rules/src/or-rule-tree.ts b/ui/component/or-rules/src/or-rule-tree.tsindex 1a393727a..0f3cc882c 100644--- a/ui/component/or-rules/src/or-rule-tree.ts+++ b/ui/component/or-rules/src/or-rule-tree.ts@@ -459,7 +459,6 @@ export class OrRuleTree extends OrTreeMenu {const type = global ? "global" : "realm";const realm = manager.isSuperUser() ? manager.displayRealm : manager.config.realm;const ruleset: RulesetUnion = {- id: 0,type: type,name: OrRules.DEFAULT_RULESET_NAME,lang: lang,