Browse Source

Fixes for cases when asset/device deleted but has entity view assigned

pull/1108/head
Volodymyr Babak 8 years ago
parent
commit
aa79557841
  1. 3
      application/src/main/data/upgrade/2.1.1/schema_update.cql
  2. 2
      dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java
  3. 4
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java
  4. 2
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java

3
application/src/main/data/upgrade/2.1.1/schema_update.cql

@ -17,9 +17,10 @@
DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_name;
DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_search_text;
DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_customer;
DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_entity_id;
DROP TABLE IF EXISTS thingsboard.entity_views;
ControllerSqlTestSuite
CREATE TABLE IF NOT EXISTS thingsboard.entity_views (
id timeuuid,
entity_id timeuuid,

2
dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java

@ -115,9 +115,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
throw new IncorrectParameterException("Unable to delete non-existent customer.");
}
dashboardService.unassignCustomerDashboards(customerId);
entityViewService.unassignCustomerEntityViews(customer.getTenantId(), customerId);
assetService.unassignCustomerAssets(customer.getTenantId(), customerId);
deviceService.unassignCustomerDevices(customer.getTenantId(), customerId);
entityViewService.unassignCustomerEntityViews(customer.getTenantId(), customerId);
userService.deleteCustomerUsers(customer.getTenantId(), customerId);
deleteEntityRelations(customerId);
customerDao.removeById(customerId.getId());

4
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -155,8 +155,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
Device device = deviceDao.findById(deviceId.getId());
try {
List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get();
if (entityViews != null && !entityViews.isEmpty()) {
throw new DataValidationException("Can't delete device that is assigned to entity views!");
if (entityViews != null && !entityViews.isEmpty()) {
throw new DataValidationException("Can't delete device that is assigned to entity views!");
}
} catch (Exception e) {
log.error("Exception while finding entity views for deviceId [{}]", deviceId, e);

2
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java

@ -105,9 +105,9 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe
customerService.deleteCustomersByTenantId(tenantId);
widgetsBundleService.deleteWidgetsBundlesByTenantId(tenantId);
dashboardService.deleteDashboardsByTenantId(tenantId);
entityViewService.deleteEntityViewsByTenantId(tenantId);
assetService.deleteAssetsByTenantId(tenantId);
deviceService.deleteDevicesByTenantId(tenantId);
entityViewService.deleteEntityViewsByTenantId(tenantId);
userService.deleteTenantAdmins(tenantId);
ruleChainService.deleteRuleChainsByTenantId(tenantId);
tenantDao.removeById(tenantId.getId());

Loading…
Cancel
Save