Commit 6a779352b98eba5974b9dfa026b8290014e988d9

Authored by Andrew Shvayka
1 parent 56c6ad50

Minor refactoring

@@ -214,7 +214,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -214,7 +214,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
214 if (customer == null) { 214 if (customer == null) {
215 throw new DataValidationException("Can't unassign dashboards from non-existent customer!"); 215 throw new DataValidationException("Can't unassign dashboards from non-existent customer!");
216 } 216 }
217 - new CustomerDashboardsUnassigner(customer).removeEntities(customer); 217 + new CustomerDashboardsUnassigner(customer).removeEntities(tenantId, customer);
218 } 218 }
219 219
220 @Override 220 @Override
@@ -225,7 +225,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -225,7 +225,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
225 if (customer == null) { 225 if (customer == null) {
226 throw new DataValidationException("Can't update dashboards for non-existent customer!"); 226 throw new DataValidationException("Can't update dashboards for non-existent customer!");
227 } 227 }
228 - new CustomerDashboardsUpdater(customer).removeEntities(customer); 228 + new CustomerDashboardsUpdater(customer).removeEntities(tenantId, customer);
229 } 229 }
230 230
231 private DataValidator<Dashboard> dashboardValidator = 231 private DataValidator<Dashboard> dashboardValidator =
@@ -269,7 +269,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -269,7 +269,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
269 } 269 }
270 270
271 @Override 271 @Override
272 - protected List<DashboardInfo> findEntities(Customer customer, TimePageLink pageLink) { 272 + protected List<DashboardInfo> findEntities(TenantId tenantId, Customer customer, TimePageLink pageLink) {
273 try { 273 try {
274 return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get(); 274 return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get();
275 } catch (InterruptedException | ExecutionException e) { 275 } catch (InterruptedException | ExecutionException e) {
@@ -279,7 +279,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -279,7 +279,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
279 } 279 }
280 280
281 @Override 281 @Override
282 - protected void removeEntity(DashboardInfo entity) { 282 + protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
283 unassignDashboardFromCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer.getId()); 283 unassignDashboardFromCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer.getId());
284 } 284 }
285 285
@@ -294,7 +294,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -294,7 +294,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
294 } 294 }
295 295
296 @Override 296 @Override
297 - protected List<DashboardInfo> findEntities(Customer customer, TimePageLink pageLink) { 297 + protected List<DashboardInfo> findEntities(TenantId tenantId, Customer customer, TimePageLink pageLink) {
298 try { 298 try {
299 return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get(); 299 return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get();
300 } catch (InterruptedException | ExecutionException e) { 300 } catch (InterruptedException | ExecutionException e) {
@@ -304,7 +304,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -304,7 +304,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
304 } 304 }
305 305
306 @Override 306 @Override
307 - protected void removeEntity(DashboardInfo entity) { 307 + protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
308 updateAssignedCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer); 308 updateAssignedCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer);
309 } 309 }
310 310
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 package org.thingsboard.server.dao.service; 16 package org.thingsboard.server.dao.service;
17 17
18 import org.thingsboard.server.common.data.id.IdBased; 18 import org.thingsboard.server.common.data.id.IdBased;
  19 +import org.thingsboard.server.common.data.id.TenantId;
19 import org.thingsboard.server.common.data.page.TimePageLink; 20 import org.thingsboard.server.common.data.page.TimePageLink;
20 21
21 import java.util.List; 22 import java.util.List;
@@ -25,13 +26,13 @@ public abstract class TimePaginatedRemover<I, D extends IdBased<?>> { @@ -25,13 +26,13 @@ public abstract class TimePaginatedRemover<I, D extends IdBased<?>> {
25 26
26 private static final int DEFAULT_LIMIT = 100; 27 private static final int DEFAULT_LIMIT = 100;
27 28
28 - public void removeEntities(I id) { 29 + public void removeEntities(TenantId tenantId, I id) {
29 TimePageLink pageLink = new TimePageLink(DEFAULT_LIMIT); 30 TimePageLink pageLink = new TimePageLink(DEFAULT_LIMIT);
30 boolean hasNext = true; 31 boolean hasNext = true;
31 while (hasNext) { 32 while (hasNext) {
32 - List<D> entities = findEntities(id, pageLink); 33 + List<D> entities = findEntities(tenantId, id, pageLink);
33 for (D entity : entities) { 34 for (D entity : entities) {
34 - removeEntity(entity); 35 + removeEntity(tenantId, entity);
35 } 36 }
36 hasNext = entities.size() == pageLink.getLimit(); 37 hasNext = entities.size() == pageLink.getLimit();
37 if (hasNext) { 38 if (hasNext) {
@@ -42,8 +43,8 @@ public abstract class TimePaginatedRemover<I, D extends IdBased<?>> { @@ -42,8 +43,8 @@ public abstract class TimePaginatedRemover<I, D extends IdBased<?>> {
42 } 43 }
43 } 44 }
44 45
45 - protected abstract List<D> findEntities(I id, TimePageLink pageLink); 46 + protected abstract List<D> findEntities(TenantId tenantId, I id, TimePageLink pageLink);
46 47
47 - protected abstract void removeEntity(D entity); 48 + protected abstract void removeEntity(TenantId tenantId, D entity);
48 49
49 } 50 }