Commit aa795578415a62b0ab129e57df0bdd09ace8e430
1 parent
b1f9ffb3
Fixes for cases when asset/device deleted but has entity view assigned
Showing
4 changed files
with
6 additions
and
5 deletions
@@ -17,9 +17,10 @@ | @@ -17,9 +17,10 @@ | ||
17 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_name; | 17 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_name; |
18 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_search_text; | 18 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_search_text; |
19 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_customer; | 19 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_customer; |
20 | +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_entity_id; | ||
20 | 21 | ||
21 | DROP TABLE IF EXISTS thingsboard.entity_views; | 22 | DROP TABLE IF EXISTS thingsboard.entity_views; |
22 | - | 23 | +ControllerSqlTestSuite |
23 | CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | 24 | CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( |
24 | id timeuuid, | 25 | id timeuuid, |
25 | entity_id timeuuid, | 26 | entity_id timeuuid, |
@@ -115,9 +115,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom | @@ -115,9 +115,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom | ||
115 | throw new IncorrectParameterException("Unable to delete non-existent customer."); | 115 | throw new IncorrectParameterException("Unable to delete non-existent customer."); |
116 | } | 116 | } |
117 | dashboardService.unassignCustomerDashboards(customerId); | 117 | dashboardService.unassignCustomerDashboards(customerId); |
118 | + entityViewService.unassignCustomerEntityViews(customer.getTenantId(), customerId); | ||
118 | assetService.unassignCustomerAssets(customer.getTenantId(), customerId); | 119 | assetService.unassignCustomerAssets(customer.getTenantId(), customerId); |
119 | deviceService.unassignCustomerDevices(customer.getTenantId(), customerId); | 120 | deviceService.unassignCustomerDevices(customer.getTenantId(), customerId); |
120 | - entityViewService.unassignCustomerEntityViews(customer.getTenantId(), customerId); | ||
121 | userService.deleteCustomerUsers(customer.getTenantId(), customerId); | 121 | userService.deleteCustomerUsers(customer.getTenantId(), customerId); |
122 | deleteEntityRelations(customerId); | 122 | deleteEntityRelations(customerId); |
123 | customerDao.removeById(customerId.getId()); | 123 | customerDao.removeById(customerId.getId()); |
@@ -155,8 +155,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -155,8 +155,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
155 | Device device = deviceDao.findById(deviceId.getId()); | 155 | Device device = deviceDao.findById(deviceId.getId()); |
156 | try { | 156 | try { |
157 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get(); | 157 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get(); |
158 | - if (entityViews != null && !entityViews.isEmpty()) { | ||
159 | - throw new DataValidationException("Can't delete device that is assigned to entity views!"); | 158 | + if (entityViews != null && !entityViews.isEmpty()) { |
159 | + throw new DataValidationException("Can't delete device that is assigned to entity views!"); | ||
160 | } | 160 | } |
161 | } catch (Exception e) { | 161 | } catch (Exception e) { |
162 | log.error("Exception while finding entity views for deviceId [{}]", deviceId, e); | 162 | log.error("Exception while finding entity views for deviceId [{}]", deviceId, e); |
@@ -105,9 +105,9 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe | @@ -105,9 +105,9 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe | ||
105 | customerService.deleteCustomersByTenantId(tenantId); | 105 | customerService.deleteCustomersByTenantId(tenantId); |
106 | widgetsBundleService.deleteWidgetsBundlesByTenantId(tenantId); | 106 | widgetsBundleService.deleteWidgetsBundlesByTenantId(tenantId); |
107 | dashboardService.deleteDashboardsByTenantId(tenantId); | 107 | dashboardService.deleteDashboardsByTenantId(tenantId); |
108 | + entityViewService.deleteEntityViewsByTenantId(tenantId); | ||
108 | assetService.deleteAssetsByTenantId(tenantId); | 109 | assetService.deleteAssetsByTenantId(tenantId); |
109 | deviceService.deleteDevicesByTenantId(tenantId); | 110 | deviceService.deleteDevicesByTenantId(tenantId); |
110 | - entityViewService.deleteEntityViewsByTenantId(tenantId); | ||
111 | userService.deleteTenantAdmins(tenantId); | 111 | userService.deleteTenantAdmins(tenantId); |
112 | ruleChainService.deleteRuleChainsByTenantId(tenantId); | 112 | ruleChainService.deleteRuleChainsByTenantId(tenantId); |
113 | tenantDao.removeById(tenantId.getId()); | 113 | tenantDao.removeById(tenantId.getId()); |