Browse Source

refactoring: - dashboard commits

pull/6551/head
nickAS21 4 years ago
parent
commit
1e973825b7
  1. 4
      application/src/main/java/org/thingsboard/server/controller/AssetController.java
  2. 2
      application/src/main/java/org/thingsboard/server/controller/CustomerController.java
  3. 2
      application/src/main/java/org/thingsboard/server/controller/DashboardController.java
  4. 2
      application/src/main/java/org/thingsboard/server/service/asset/AssetBulkImportService.java
  5. 10
      application/src/main/java/org/thingsboard/server/service/entitiy/DefaultTbNotificationEntityService.java
  6. 8
      application/src/main/java/org/thingsboard/server/service/entitiy/SimpleTbEntityService.java
  7. 2
      application/src/main/java/org/thingsboard/server/service/entitiy/TbNotificationEntityService.java
  8. 7
      application/src/main/java/org/thingsboard/server/service/entitiy/alarm/DefaultTbAlarmService.java
  9. 11
      application/src/main/java/org/thingsboard/server/service/entitiy/asset/DefaultTbAssetService.java
  10. 7
      application/src/main/java/org/thingsboard/server/service/entitiy/asset/TbAssetService.java
  11. 12
      application/src/main/java/org/thingsboard/server/service/entitiy/customer/DefaultTbCustomerService.java
  12. 3
      application/src/main/java/org/thingsboard/server/service/entitiy/customer/TbCustomerService.java
  13. 14
      application/src/main/java/org/thingsboard/server/service/entitiy/dashboard/DefaultTbDashboardService.java
  14. 2
      application/src/main/java/org/thingsboard/server/service/entitiy/dashboard/TbDashboardService.java

4
application/src/main/java/org/thingsboard/server/controller/AssetController.java

@ -149,7 +149,7 @@ public class AssetController extends BaseController {
}
asset.setTenantId(getCurrentUser().getTenantId());
checkEntity(asset.getId(), asset, Resource.ASSET);
return tbAssetService.save(asset, getCurrentUser());
return tbAssetService.saveAsset(asset, getCurrentUser());
}
@ApiOperation(value = "Delete asset (deleteAsset)",
@ -162,7 +162,7 @@ public class AssetController extends BaseController {
try {
AssetId assetId = new AssetId(toUUID(strAssetId));
Asset asset = checkAssetId(assetId, Operation.DELETE);
tbAssetService.delete(asset, getCurrentUser()).get();
tbAssetService.deleteAsset(asset, getCurrentUser()).get();
} catch (Exception e) {
throw handleException(e);
}

2
application/src/main/java/org/thingsboard/server/controller/CustomerController.java

@ -161,7 +161,7 @@ public class CustomerController extends BaseController {
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
Customer customer = checkCustomerId(customerId, Operation.DELETE);
try {
tbCustomerService.delete(customer, customerId, getCurrentUser());
tbCustomerService.delete(customer, getCurrentUser());
} catch (Exception e) {
throw handleException(e);
}

2
application/src/main/java/org/thingsboard/server/controller/DashboardController.java

@ -194,7 +194,7 @@ public class DashboardController extends BaseController {
checkParameter(DASHBOARD_ID, strDashboardId);
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
Dashboard dashboard = checkDashboardId(dashboardId, Operation.DELETE);
tbDashboardService.delete(dashboard, dashboardId, getCurrentUser());
tbDashboardService.delete(dashboard, getCurrentUser());
}
@ApiOperation(value = "Assign the Dashboard (assignDashboardToCustomer)",

2
application/src/main/java/org/thingsboard/server/service/asset/AssetBulkImportService.java

@ -66,7 +66,7 @@ public class AssetBulkImportService extends AbstractBulkImportService<Asset> {
@Override
@SneakyThrows
protected Asset saveEntity(SecurityUser user, Asset entity, Map<BulkImportColumnType, String> fields) {
return tbAssetService.save(entity, user);
return tbAssetService.saveAsset(entity, user);
}
@Override

10
application/src/main/java/org/thingsboard/server/service/entitiy/DefaultTbNotificationEntityService.java

@ -22,7 +22,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg;
import org.thingsboard.server.cluster.TbClusterService;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.HasName;
@ -68,17 +67,14 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
}
@Override
public <E extends HasName, I extends EntityId> void notifyDeleteEntity(TenantId tenantId, I entityId, E entity,
public <E extends HasName, I extends EntityId> void notifyDeleteEntity(TenantId tenantId, I entityId, E entity, EntityId originatorId,
CustomerId customerId, ActionType actionType,
List<EdgeId> relatedEdgeIds,
SecurityUser user,
String body, Object... additionalInfo) {
EntityId entityIdForLogEntityAction = entity instanceof Alarm ? ((Alarm)entity).getOriginator() : entityId;
EntityId entityIdForLogEntityAction = originatorId != null ? originatorId : entityId;
logEntityAction(tenantId, entityIdForLogEntityAction, entity, customerId, actionType, user, additionalInfo);
sendDeleteNotificationMsg(tenantId, entityId, entity, relatedEdgeIds, body);
if (entity instanceof Customer) {
tbClusterService.broadcastEntityStateChangeEvent(tenantId, customerId, ComponentLifecycleEvent.DELETED);
}
}
@Override
@ -131,7 +127,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
gatewayNotificationsService.onDeviceDeleted(device);
tbClusterService.onDeviceDeleted(device, null);
notifyDeleteEntity(tenantId, deviceId, device, customerId, ActionType.DELETED, relatedEdgeIds, user,null, additionalInfo);
notifyDeleteEntity(tenantId, deviceId, device, customerId, null, ActionType.DELETED, relatedEdgeIds, user,null, additionalInfo);
}
@Override

8
application/src/main/java/org/thingsboard/server/service/entitiy/SimpleTbEntityService.java

@ -15,15 +15,13 @@
*/
package org.thingsboard.server.service.entitiy;
import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.service.security.model.SecurityUser;
public interface SimpleTbEntityService<E extends HasName, I extends EntityId> {
public interface SimpleTbEntityService<T> {
E save(E entity, SecurityUser user) throws ThingsboardException;
T save(T entity, SecurityUser user) throws ThingsboardException;
void delete (E entity, I entityId, SecurityUser user) throws ThingsboardException;
void delete (T entity, SecurityUser user) throws ThingsboardException;
}

2
application/src/main/java/org/thingsboard/server/service/entitiy/TbNotificationEntityService.java

@ -43,7 +43,7 @@ public interface TbNotificationEntityService {
CustomerId customerId, ActionType actionType,
SecurityUser user, Object... additionalInfo);
<E extends HasName, I extends EntityId> void notifyDeleteEntity(TenantId tenantId, I entityId, E entity, CustomerId customerId,
<E extends HasName, I extends EntityId> void notifyDeleteEntity(TenantId tenantId, I entityId, E entity, EntityId originatorId, CustomerId customerId,
ActionType actionType, List<EdgeId> relatedEdgeIds, SecurityUser user,
String body, Object... additionalInfo);

7
application/src/main/java/org/thingsboard/server/service/entitiy/alarm/DefaultTbAlarmService.java

@ -15,9 +15,9 @@
*/
package org.thingsboard.server.service.entitiy.alarm;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmStatus;
@ -35,7 +35,6 @@ import java.util.List;
@TbCoreComponent
@AllArgsConstructor
public class DefaultTbAlarmService extends AbstractTbEntityService implements TbAlarmService {
private static final ObjectMapper json = new ObjectMapper();
@Override
public Alarm save(Alarm alarm, SecurityUser user) throws ThingsboardException {
@ -81,8 +80,8 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
public Boolean deleteAlarm(Alarm alarm, SecurityUser user) throws ThingsboardException {
try {
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(user.getTenantId(), alarm.getOriginator());
notificationEntityService.notifyDeleteEntity(user.getTenantId(), alarm.getId(), alarm, user.getCustomerId(),
ActionType.DELETED, relatedEdgeIds, user, json.writeValueAsString(alarm));
notificationEntityService.notifyDeleteEntity(user.getTenantId(), alarm.getId(), alarm, alarm.getOriginator(), user.getCustomerId(),
ActionType.DELETED, relatedEdgeIds, user, JacksonUtil.OBJECT_MAPPER.writeValueAsString(alarm));
return alarmService.deleteAlarm(user.getTenantId(), alarm.getId()).isSuccessful();
} catch (Exception e) {
throw handleException(e);

11
application/src/main/java/org/thingsboard/server/service/entitiy/asset/DefaultTbAssetService.java

@ -39,8 +39,9 @@ import java.util.List;
@TbCoreComponent
@AllArgsConstructor
public class DefaultTbAssetService extends AbstractTbEntityService implements TbAssetService {
@Override
public Asset save(Asset asset, SecurityUser user) throws ThingsboardException {
public Asset saveAsset(Asset asset, SecurityUser user) throws ThingsboardException {
ActionType actionType = asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
TenantId tenantId = asset.getTenantId();
try {
@ -54,13 +55,13 @@ public class DefaultTbAssetService extends AbstractTbEntityService implements Tb
}
@Override
public ListenableFuture<Void> delete(Asset asset, SecurityUser user) throws ThingsboardException {
public ListenableFuture<Void> deleteAsset(Asset asset, SecurityUser user) throws ThingsboardException {
TenantId tenantId = asset.getTenantId();
AssetId assetId = asset.getId();
try {
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, assetId);
assetService.deleteAsset(tenantId, assetId);
notificationEntityService.notifyDeleteEntity(tenantId, assetId, asset, asset.getCustomerId(), ActionType.DELETED,
notificationEntityService.notifyDeleteEntity(tenantId, assetId, asset, null, asset.getCustomerId(), ActionType.DELETED,
relatedEdgeIds, user, null, asset.toString());
return removeAlarmsByEntityId(tenantId, assetId);
@ -71,10 +72,6 @@ public class DefaultTbAssetService extends AbstractTbEntityService implements Tb
}
}
@Override
public void delete(Asset entity, AssetId entityId, SecurityUser user) throws ThingsboardException {}
@Override
public Asset assignAssetToCustomer(TenantId tenantId, AssetId assetId, Customer customer, SecurityUser user) throws ThingsboardException {
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;

7
application/src/main/java/org/thingsboard/server/service/entitiy/asset/TbAssetService.java

@ -22,12 +22,13 @@ import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
import org.thingsboard.server.service.security.model.SecurityUser;
public interface TbAssetService extends SimpleTbEntityService<Asset, AssetId> {
public interface TbAssetService {
ListenableFuture<Void> delete(Asset asset, SecurityUser user) throws ThingsboardException;
Asset saveAsset(Asset asset, SecurityUser user) throws ThingsboardException;
ListenableFuture<Void> deleteAsset (Asset asset, SecurityUser user) throws ThingsboardException;
Asset assignAssetToCustomer(TenantId tenantId, AssetId assetId, Customer customer, SecurityUser user) throws ThingsboardException;

12
application/src/main/java/org/thingsboard/server/service/entitiy/customer/DefaultTbCustomerService.java

@ -17,6 +17,7 @@ package org.thingsboard.server.service.entitiy.customer;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.cluster.TbClusterService;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.audit.ActionType;
@ -24,6 +25,7 @@ import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.entitiy.AbstractTbEntityService;
import org.thingsboard.server.service.security.model.SecurityUser;
@ -35,6 +37,8 @@ import java.util.List;
@AllArgsConstructor
public class DefaultTbCustomerService extends AbstractTbEntityService implements TbCustomerService {
private final TbClusterService tbClusterService;
@Override
public Customer save(Customer customer, SecurityUser user) throws ThingsboardException {
ActionType actionType = customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
@ -51,13 +55,15 @@ public class DefaultTbCustomerService extends AbstractTbEntityService implements
@Override
public void delete(Customer customer, CustomerId customerId, SecurityUser user) throws ThingsboardException {
TenantId tenantId = user.getTenantId();
public void delete(Customer customer, SecurityUser user) throws ThingsboardException {
TenantId tenantId = customer.getTenantId();
CustomerId customerId = customer.getId();
try {
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, customerId);
customerService.deleteCustomer(tenantId, customerId);
notificationEntityService.notifyDeleteEntity(tenantId, customerId, customer, user.getCustomerId(),
notificationEntityService.notifyDeleteEntity(tenantId, customerId, customer, null, customerId,
ActionType.DELETED, relatedEdgeIds, user, null);
tbClusterService.broadcastEntityStateChangeEvent(tenantId, customerId, ComponentLifecycleEvent.DELETED);
} catch (Exception e) {
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.CUSTOMER), null, null, ActionType.DELETED, user, e);
throw handleException(e);

3
application/src/main/java/org/thingsboard/server/service/entitiy/customer/TbCustomerService.java

@ -16,9 +16,8 @@
package org.thingsboard.server.service.entitiy.customer;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
public interface TbCustomerService extends SimpleTbEntityService<Customer, CustomerId> {
public interface TbCustomerService extends SimpleTbEntityService<Customer> {
}

14
application/src/main/java/org/thingsboard/server/service/entitiy/dashboard/DefaultTbDashboardService.java

@ -59,12 +59,13 @@ public class DefaultTbDashboardService extends AbstractTbEntityService implement
}
@Override
public void delete(Dashboard dashboard, DashboardId dashboardId, SecurityUser user) throws ThingsboardException {
TenantId tenantId = user.getTenantId();
public void delete(Dashboard dashboard, SecurityUser user) throws ThingsboardException {
TenantId tenantId = dashboard.getTenantId();
DashboardId dashboardId = dashboard.getId();
try {
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(tenantId, dashboardId);
dashboardService.deleteDashboard(tenantId, (DashboardId) dashboardId);
notificationEntityService.notifyDeleteEntity(tenantId, dashboardId, dashboard, user.getCustomerId(),
dashboardService.deleteDashboard(tenantId, dashboardId);
notificationEntityService.notifyDeleteEntity(tenantId, dashboardId, dashboard, null, user.getCustomerId(),
ActionType.DELETED, relatedEdgeIds, user, null);
} catch (Exception e) {
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
@ -104,7 +105,6 @@ public class DefaultTbDashboardService extends AbstractTbEntityService implement
actionType, user, e, dashboardId.toString());
throw handleException(e);
}
}
@Override
@ -128,8 +128,6 @@ public class DefaultTbDashboardService extends AbstractTbEntityService implement
public Dashboard updateDashboardCustomers(TenantId tenantId, Dashboard dashboard, String[] strCustomerIds, SecurityUser user) throws ThingsboardException {
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;
try {
Set<CustomerId> customerIds = new HashSet<>();
if (strCustomerIds != null) {
for (String strCustomerId : strCustomerIds) {
@ -216,8 +214,6 @@ public class DefaultTbDashboardService extends AbstractTbEntityService implement
public Dashboard removeDashboardCustomers(TenantId tenantId, Dashboard dashboard, String[] strCustomerIds, SecurityUser user) throws ThingsboardException {
ActionType actionType = ActionType.UNASSIGNED_FROM_CUSTOMER;
try {
Set<CustomerId> customerIds = new HashSet<>();
if (strCustomerIds != null) {
for (String strCustomerId : strCustomerIds) {

2
application/src/main/java/org/thingsboard/server/service/entitiy/dashboard/TbDashboardService.java

@ -24,7 +24,7 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
import org.thingsboard.server.service.security.model.SecurityUser;
public interface TbDashboardService extends SimpleTbEntityService<Dashboard, DashboardId> {
public interface TbDashboardService extends SimpleTbEntityService<Dashboard> {
Dashboard assignDashboardToCustomer(DashboardId dashboardId, Customer customer, SecurityUser user) throws ThingsboardException;

Loading…
Cancel
Save