Commit 9728478b0df75e442eb3c39898b56aab56ec05dc
Committed by
GitHub
1 parent
5865dd28
Stub for querying entities after deleting dashboard (#4107)
* Code cleaning after review * Code cleaning * Refactoring * Clean solution improved * Imports standartization * Correct if statement improved
Showing
4 changed files
with
48 additions
and
6 deletions
@@ -27,7 +27,22 @@ import org.springframework.beans.factory.annotation.Value; | @@ -27,7 +27,22 @@ import org.springframework.beans.factory.annotation.Value; | ||
27 | import org.springframework.security.core.Authentication; | 27 | import org.springframework.security.core.Authentication; |
28 | import org.springframework.security.core.context.SecurityContextHolder; | 28 | import org.springframework.security.core.context.SecurityContextHolder; |
29 | import org.springframework.web.bind.annotation.ExceptionHandler; | 29 | import org.springframework.web.bind.annotation.ExceptionHandler; |
30 | -import org.thingsboard.server.common.data.*; | 30 | +import org.thingsboard.server.common.data.Customer; |
31 | +import org.thingsboard.server.common.data.Dashboard; | ||
32 | +import org.thingsboard.server.common.data.DashboardInfo; | ||
33 | +import org.thingsboard.server.common.data.DataConstants; | ||
34 | +import org.thingsboard.server.common.data.Device; | ||
35 | +import org.thingsboard.server.common.data.DeviceInfo; | ||
36 | +import org.thingsboard.server.common.data.DeviceProfile; | ||
37 | +import org.thingsboard.server.common.data.EntityType; | ||
38 | +import org.thingsboard.server.common.data.EntityView; | ||
39 | +import org.thingsboard.server.common.data.EntityViewInfo; | ||
40 | +import org.thingsboard.server.common.data.HasName; | ||
41 | +import org.thingsboard.server.common.data.HasTenantId; | ||
42 | +import org.thingsboard.server.common.data.Tenant; | ||
43 | +import org.thingsboard.server.common.data.TenantInfo; | ||
44 | +import org.thingsboard.server.common.data.TenantProfile; | ||
45 | +import org.thingsboard.server.common.data.User; | ||
31 | import org.thingsboard.server.common.data.alarm.Alarm; | 46 | import org.thingsboard.server.common.data.alarm.Alarm; |
32 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 47 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
33 | import org.thingsboard.server.common.data.asset.Asset; | 48 | import org.thingsboard.server.common.data.asset.Asset; |
@@ -84,6 +99,7 @@ import org.thingsboard.server.dao.oauth2.OAuth2ConfigTemplateService; | @@ -84,6 +99,7 @@ import org.thingsboard.server.dao.oauth2.OAuth2ConfigTemplateService; | ||
84 | import org.thingsboard.server.dao.oauth2.OAuth2Service; | 99 | import org.thingsboard.server.dao.oauth2.OAuth2Service; |
85 | import org.thingsboard.server.dao.relation.RelationService; | 100 | import org.thingsboard.server.dao.relation.RelationService; |
86 | import org.thingsboard.server.dao.rule.RuleChainService; | 101 | import org.thingsboard.server.dao.rule.RuleChainService; |
102 | +import org.thingsboard.server.dao.tenant.TbTenantProfileCache; | ||
87 | import org.thingsboard.server.dao.tenant.TenantProfileService; | 103 | import org.thingsboard.server.dao.tenant.TenantProfileService; |
88 | import org.thingsboard.server.dao.tenant.TenantService; | 104 | import org.thingsboard.server.dao.tenant.TenantService; |
89 | import org.thingsboard.server.dao.user.UserService; | 105 | import org.thingsboard.server.dao.user.UserService; |
@@ -95,7 +111,6 @@ import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | @@ -95,7 +111,6 @@ import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | ||
95 | import org.thingsboard.server.queue.util.TbCoreComponent; | 111 | import org.thingsboard.server.queue.util.TbCoreComponent; |
96 | import org.thingsboard.server.service.component.ComponentDiscoveryService; | 112 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
97 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 113 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
98 | -import org.thingsboard.server.dao.tenant.TbTenantProfileCache; | ||
99 | import org.thingsboard.server.service.queue.TbClusterService; | 114 | import org.thingsboard.server.service.queue.TbClusterService; |
100 | import org.thingsboard.server.service.security.model.SecurityUser; | 115 | import org.thingsboard.server.service.security.model.SecurityUser; |
101 | import org.thingsboard.server.service.security.permission.AccessControlService; | 116 | import org.thingsboard.server.service.security.permission.AccessControlService; |
@@ -123,6 +138,9 @@ public abstract class BaseController { | @@ -123,6 +138,9 @@ public abstract class BaseController { | ||
123 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; | 138 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
124 | public static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "You don't have permission to perform this operation!"; | 139 | public static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "You don't have permission to perform this operation!"; |
125 | 140 | ||
141 | + protected static final String DEFAULT_DASHBOARD = "defaultDashboardId"; | ||
142 | + protected static final String HOME_DASHBOARD = "homeDashboardId"; | ||
143 | + | ||
126 | private static final ObjectMapper json = new ObjectMapper(); | 144 | private static final ObjectMapper json = new ObjectMapper(); |
127 | 145 | ||
128 | @Autowired | 146 | @Autowired |
@@ -858,4 +876,14 @@ public abstract class BaseController { | @@ -858,4 +876,14 @@ public abstract class BaseController { | ||
858 | } | 876 | } |
859 | } | 877 | } |
860 | } | 878 | } |
879 | + | ||
880 | + protected void processDashboardIdFromAdditionalInfo(ObjectNode additionalInfo, String requiredFields) throws ThingsboardException { | ||
881 | + String dashboardId = additionalInfo.has(requiredFields) ? additionalInfo.get(requiredFields).asText() : null; | ||
882 | + if(dashboardId != null && !dashboardId.equals("null")) { | ||
883 | + if(dashboardService.findDashboardById(getTenantId(), new DashboardId(UUID.fromString(dashboardId))) == null) { | ||
884 | + additionalInfo.remove(requiredFields); | ||
885 | + } | ||
886 | + } | ||
887 | + } | ||
888 | + | ||
861 | } | 889 | } |
@@ -55,7 +55,11 @@ public class CustomerController extends BaseController { | @@ -55,7 +55,11 @@ public class CustomerController extends BaseController { | ||
55 | checkParameter(CUSTOMER_ID, strCustomerId); | 55 | checkParameter(CUSTOMER_ID, strCustomerId); |
56 | try { | 56 | try { |
57 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); | 57 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); |
58 | - return checkCustomerId(customerId, Operation.READ); | 58 | + Customer customer = checkCustomerId(customerId, Operation.READ); |
59 | + if(!customer.getAdditionalInfo().isNull()) { | ||
60 | + processDashboardIdFromAdditionalInfo((ObjectNode) customer.getAdditionalInfo(), HOME_DASHBOARD); | ||
61 | + } | ||
62 | + return customer; | ||
59 | } catch (Exception e) { | 63 | } catch (Exception e) { |
60 | throw handleException(e); | 64 | throw handleException(e); |
61 | } | 65 | } |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller; | 16 | package org.thingsboard.server.controller; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
18 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
19 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.http.HttpStatus; | 21 | import org.springframework.http.HttpStatus; |
@@ -59,7 +60,11 @@ public class TenantController extends BaseController { | @@ -59,7 +60,11 @@ public class TenantController extends BaseController { | ||
59 | checkParameter("tenantId", strTenantId); | 60 | checkParameter("tenantId", strTenantId); |
60 | try { | 61 | try { |
61 | TenantId tenantId = new TenantId(toUUID(strTenantId)); | 62 | TenantId tenantId = new TenantId(toUUID(strTenantId)); |
62 | - return checkTenantId(tenantId, Operation.READ); | 63 | + Tenant tenant = checkTenantId(tenantId, Operation.READ); |
64 | + if(!tenant.getAdditionalInfo().isNull()) { | ||
65 | + processDashboardIdFromAdditionalInfo((ObjectNode) tenant.getAdditionalInfo(), HOME_DASHBOARD); | ||
66 | + } | ||
67 | + return tenant; | ||
63 | } catch (Exception e) { | 68 | } catch (Exception e) { |
64 | throw handleException(e); | 69 | throw handleException(e); |
65 | } | 70 | } |
@@ -53,7 +53,6 @@ import org.thingsboard.server.service.security.model.token.JwtTokenFactory; | @@ -53,7 +53,6 @@ import org.thingsboard.server.service.security.model.token.JwtTokenFactory; | ||
53 | import org.thingsboard.server.service.security.permission.Operation; | 53 | import org.thingsboard.server.service.security.permission.Operation; |
54 | import org.thingsboard.server.service.security.permission.Resource; | 54 | import org.thingsboard.server.service.security.permission.Resource; |
55 | import org.thingsboard.server.service.security.system.SystemSecurityService; | 55 | import org.thingsboard.server.service.security.system.SystemSecurityService; |
56 | -import org.thingsboard.server.utils.MiscUtils; | ||
57 | 56 | ||
58 | import javax.servlet.http.HttpServletRequest; | 57 | import javax.servlet.http.HttpServletRequest; |
59 | 58 | ||
@@ -90,7 +89,12 @@ public class UserController extends BaseController { | @@ -90,7 +89,12 @@ public class UserController extends BaseController { | ||
90 | checkParameter(USER_ID, strUserId); | 89 | checkParameter(USER_ID, strUserId); |
91 | try { | 90 | try { |
92 | UserId userId = new UserId(toUUID(strUserId)); | 91 | UserId userId = new UserId(toUUID(strUserId)); |
93 | - return checkUserId(userId, Operation.READ); | 92 | + User user = checkUserId(userId, Operation.READ); |
93 | + if(!user.getAdditionalInfo().isNull()) { | ||
94 | + processDashboardIdFromAdditionalInfo((ObjectNode) user.getAdditionalInfo(), DEFAULT_DASHBOARD); | ||
95 | + processDashboardIdFromAdditionalInfo((ObjectNode) user.getAdditionalInfo(), HOME_DASHBOARD); | ||
96 | + } | ||
97 | + return user; | ||
94 | } catch (Exception e) { | 98 | } catch (Exception e) { |
95 | throw handleException(e); | 99 | throw handleException(e); |
96 | } | 100 | } |
@@ -329,4 +333,5 @@ public class UserController extends BaseController { | @@ -329,4 +333,5 @@ public class UserController extends BaseController { | ||
329 | throw handleException(e); | 333 | throw handleException(e); |
330 | } | 334 | } |
331 | } | 335 | } |
336 | + | ||
332 | } | 337 | } |