Browse Source

Minor refactoring

pull/1247/head
Andrew Shvayka 8 years ago
parent
commit
6a779352b9
  1. 12
      dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java
  2. 11
      dao/src/main/java/org/thingsboard/server/dao/service/TimePaginatedRemover.java

12
dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java

@ -214,7 +214,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
if (customer == null) { if (customer == null) {
throw new DataValidationException("Can't unassign dashboards from non-existent customer!"); throw new DataValidationException("Can't unassign dashboards from non-existent customer!");
} }
new CustomerDashboardsUnassigner(customer).removeEntities(customer); new CustomerDashboardsUnassigner(customer).removeEntities(tenantId, customer);
} }
@Override @Override
@ -225,7 +225,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
if (customer == null) { if (customer == null) {
throw new DataValidationException("Can't update dashboards for non-existent customer!"); throw new DataValidationException("Can't update dashboards for non-existent customer!");
} }
new CustomerDashboardsUpdater(customer).removeEntities(customer); new CustomerDashboardsUpdater(customer).removeEntities(tenantId, customer);
} }
private DataValidator<Dashboard> dashboardValidator = private DataValidator<Dashboard> dashboardValidator =
@ -269,7 +269,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
} }
@Override @Override
protected List<DashboardInfo> findEntities(Customer customer, TimePageLink pageLink) { protected List<DashboardInfo> findEntities(TenantId tenantId, Customer customer, TimePageLink pageLink) {
try { try {
return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get(); return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get();
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
@ -279,7 +279,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
} }
@Override @Override
protected void removeEntity(DashboardInfo entity) { protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
unassignDashboardFromCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer.getId()); unassignDashboardFromCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer.getId());
} }
@ -294,7 +294,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
} }
@Override @Override
protected List<DashboardInfo> findEntities(Customer customer, TimePageLink pageLink) { protected List<DashboardInfo> findEntities(TenantId tenantId, Customer customer, TimePageLink pageLink) {
try { try {
return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get(); return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(customer.getTenantId().getId(), customer.getId().getId(), pageLink).get();
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
@ -304,7 +304,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
} }
@Override @Override
protected void removeEntity(DashboardInfo entity) { protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
updateAssignedCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer); updateAssignedCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer);
} }

11
dao/src/main/java/org/thingsboard/server/dao/service/TimePaginatedRemover.java

@ -16,6 +16,7 @@
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import org.thingsboard.server.common.data.id.IdBased; import org.thingsboard.server.common.data.id.IdBased;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TimePageLink; import org.thingsboard.server.common.data.page.TimePageLink;
import java.util.List; import java.util.List;
@ -25,13 +26,13 @@ public abstract class TimePaginatedRemover<I, D extends IdBased<?>> {
private static final int DEFAULT_LIMIT = 100; private static final int DEFAULT_LIMIT = 100;
public void removeEntities(I id) { public void removeEntities(TenantId tenantId, I id) {
TimePageLink pageLink = new TimePageLink(DEFAULT_LIMIT); TimePageLink pageLink = new TimePageLink(DEFAULT_LIMIT);
boolean hasNext = true; boolean hasNext = true;
while (hasNext) { while (hasNext) {
List<D> entities = findEntities(id, pageLink); List<D> entities = findEntities(tenantId, id, pageLink);
for (D entity : entities) { for (D entity : entities) {
removeEntity(entity); removeEntity(tenantId, entity);
} }
hasNext = entities.size() == pageLink.getLimit(); hasNext = entities.size() == pageLink.getLimit();
if (hasNext) { if (hasNext) {
@ -42,8 +43,8 @@ public abstract class TimePaginatedRemover<I, D extends IdBased<?>> {
} }
} }
protected abstract List<D> findEntities(I id, TimePageLink pageLink); protected abstract List<D> findEntities(TenantId tenantId, I id, TimePageLink pageLink);
protected abstract void removeEntity(D entity); protected abstract void removeEntity(TenantId tenantId, D entity);
} }

Loading…
Cancel
Save