refactoring: - Dashboard controller
This commit is contained in:
parent
c5a7159499
commit
b85e33bf10
@ -22,6 +22,7 @@ import io.swagger.annotations.ApiParam;
|
|||||||
import io.swagger.annotations.ApiResponse;
|
import io.swagger.annotations.ApiResponse;
|
||||||
import io.swagger.annotations.Example;
|
import io.swagger.annotations.Example;
|
||||||
import io.swagger.annotations.ExampleProperty;
|
import io.swagger.annotations.ExampleProperty;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -41,7 +42,6 @@ import org.thingsboard.server.common.data.DashboardInfo;
|
|||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.HomeDashboard;
|
import org.thingsboard.server.common.data.HomeDashboard;
|
||||||
import org.thingsboard.server.common.data.HomeDashboardInfo;
|
import org.thingsboard.server.common.data.HomeDashboardInfo;
|
||||||
import org.thingsboard.server.common.data.ShortCustomerInfo;
|
|
||||||
import org.thingsboard.server.common.data.Tenant;
|
import org.thingsboard.server.common.data.Tenant;
|
||||||
import org.thingsboard.server.common.data.User;
|
import org.thingsboard.server.common.data.User;
|
||||||
import org.thingsboard.server.common.data.audit.ActionType;
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
@ -55,13 +55,12 @@ import org.thingsboard.server.common.data.id.TenantId;
|
|||||||
import org.thingsboard.server.common.data.page.PageData;
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
import org.thingsboard.server.common.data.page.PageLink;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
|
import org.thingsboard.server.service.entitiy.dashboard.TbDashboardService;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
import org.thingsboard.server.service.security.permission.Operation;
|
import org.thingsboard.server.service.security.permission.Operation;
|
||||||
import org.thingsboard.server.service.security.permission.Resource;
|
import org.thingsboard.server.service.security.permission.Resource;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.thingsboard.server.controller.ControllerConstants.CUSTOMER_ID;
|
import static org.thingsboard.server.controller.ControllerConstants.CUSTOMER_ID;
|
||||||
@ -90,9 +89,11 @@ import static org.thingsboard.server.controller.ControllerConstants.UUID_WIKI_LI
|
|||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@TbCoreComponent
|
@TbCoreComponent
|
||||||
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
public class DashboardController extends BaseController {
|
public class DashboardController extends BaseController {
|
||||||
|
|
||||||
|
private final TbDashboardService tbDashboardService;
|
||||||
public static final String DASHBOARD_ID = "dashboardId";
|
public static final String DASHBOARD_ID = "dashboardId";
|
||||||
|
|
||||||
private static final String HOME_DASHBOARD_ID = "homeDashboardId";
|
private static final String HOME_DASHBOARD_ID = "homeDashboardId";
|
||||||
@ -180,28 +181,9 @@ public class DashboardController extends BaseController {
|
|||||||
public Dashboard saveDashboard(
|
public Dashboard saveDashboard(
|
||||||
@ApiParam(value = "A JSON value representing the dashboard.")
|
@ApiParam(value = "A JSON value representing the dashboard.")
|
||||||
@RequestBody Dashboard dashboard) throws ThingsboardException {
|
@RequestBody Dashboard dashboard) throws ThingsboardException {
|
||||||
try {
|
dashboard.setTenantId(getCurrentUser().getTenantId());
|
||||||
dashboard.setTenantId(getCurrentUser().getTenantId());
|
checkEntity(dashboard.getId(), dashboard, Resource.DASHBOARD);
|
||||||
|
return tbDashboardService.save(dashboard, getCurrentUser());
|
||||||
checkEntity(dashboard.getId(), dashboard, Resource.DASHBOARD);
|
|
||||||
|
|
||||||
Dashboard savedDashboard = checkNotNull(dashboardService.saveDashboard(dashboard));
|
|
||||||
|
|
||||||
logEntityAction(savedDashboard.getId(), savedDashboard,
|
|
||||||
null,
|
|
||||||
dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
|
||||||
|
|
||||||
if (dashboard.getId() != null) {
|
|
||||||
sendEntityNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return savedDashboard;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), dashboard,
|
|
||||||
null, dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e);
|
|
||||||
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Delete the Dashboard (deleteDashboard)",
|
@ApiOperation(value = "Delete the Dashboard (deleteDashboard)",
|
||||||
@ -251,30 +233,13 @@ public class DashboardController extends BaseController {
|
|||||||
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
||||||
checkParameter(CUSTOMER_ID, strCustomerId);
|
checkParameter(CUSTOMER_ID, strCustomerId);
|
||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
try {
|
|
||||||
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
|
||||||
Customer customer = checkCustomerId(customerId, Operation.READ);
|
|
||||||
|
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
||||||
checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
Customer customer = checkCustomerId(customerId, Operation.READ);
|
||||||
|
|
||||||
Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(getCurrentUser().getTenantId(), dashboardId, customerId));
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
|
checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
||||||
logEntityAction(dashboardId, savedDashboard,
|
return tbDashboardService.assignDashboardToCustomer(getTenantId(), dashboardId, customer, getCurrentUser());
|
||||||
customerId,
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName());
|
|
||||||
|
|
||||||
sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
|
|
||||||
|
|
||||||
return savedDashboard;
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
|
||||||
null,
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId, strCustomerId);
|
|
||||||
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Unassign the Dashboard (unassignDashboardFromCustomer)",
|
@ApiOperation(value = "Unassign the Dashboard (unassignDashboardFromCustomer)",
|
||||||
@ -331,69 +296,14 @@ public class DashboardController extends BaseController {
|
|||||||
@ApiParam(value = "JSON array with the list of customer ids, or empty to remove all customers")
|
@ApiParam(value = "JSON array with the list of customer ids, or empty to remove all customers")
|
||||||
@RequestBody(required = false) String[] strCustomerIds) throws ThingsboardException {
|
@RequestBody(required = false) String[] strCustomerIds) throws ThingsboardException {
|
||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
try {
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
Dashboard dashboard = checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
||||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
return tbDashboardService.updateDashboardCustomers(getTenantId(), dashboard, strCustomerIds, getCurrentUser());
|
||||||
|
|
||||||
Set<CustomerId> customerIds = new HashSet<>();
|
|
||||||
if (strCustomerIds != null) {
|
|
||||||
for (String strCustomerId : strCustomerIds) {
|
|
||||||
customerIds.add(new CustomerId(toUUID(strCustomerId)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<CustomerId> addedCustomerIds = new HashSet<>();
|
|
||||||
Set<CustomerId> removedCustomerIds = new HashSet<>();
|
|
||||||
for (CustomerId customerId : customerIds) {
|
|
||||||
if (!dashboard.isAssignedToCustomer(customerId)) {
|
|
||||||
addedCustomerIds.add(customerId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<ShortCustomerInfo> assignedCustomers = dashboard.getAssignedCustomers();
|
|
||||||
if (assignedCustomers != null) {
|
|
||||||
for (ShortCustomerInfo customerInfo : assignedCustomers) {
|
|
||||||
if (!customerIds.contains(customerInfo.getCustomerId())) {
|
|
||||||
removedCustomerIds.add(customerInfo.getCustomerId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addedCustomerIds.isEmpty() && removedCustomerIds.isEmpty()) {
|
|
||||||
return dashboard;
|
|
||||||
} else {
|
|
||||||
Dashboard savedDashboard = null;
|
|
||||||
for (CustomerId customerId : addedCustomerIds) {
|
|
||||||
savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(getCurrentUser().getTenantId(), dashboardId, customerId));
|
|
||||||
ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
|
|
||||||
logEntityAction(dashboardId, savedDashboard,
|
|
||||||
customerId,
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
|
|
||||||
sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
|
|
||||||
}
|
|
||||||
for (CustomerId customerId : removedCustomerIds) {
|
|
||||||
ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
|
|
||||||
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(getCurrentUser().getTenantId(), dashboardId, customerId));
|
|
||||||
logEntityAction(dashboardId, dashboard,
|
|
||||||
customerId,
|
|
||||||
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
|
|
||||||
sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
|
|
||||||
}
|
|
||||||
return savedDashboard;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
|
||||||
null,
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
|
|
||||||
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Adds the Dashboard Customers (addDashboardCustomers)",
|
@ApiOperation(value = "Adds the Dashboard Customers (addDashboardCustomers)",
|
||||||
notes = "Adds the list of Customers to the existing list of assignments for the Dashboard. Keeps previous assignments to customers that are not in the provided list. " +
|
notes = "Adds the list of Customers to the existing list of assignments for the Dashboard. Keeps previous assignments to customers that are not in the provided list. " +
|
||||||
"Returns the Dashboard object." + TENANT_AUTHORITY_PARAGRAPH,
|
"Returns the Dashboard object." + TENANT_AUTHORITY_PARAGRAPH,
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE,
|
produces = MediaType.APPLICATION_JSON_VALUE,
|
||||||
consumes = MediaType.APPLICATION_JSON_VALUE)
|
consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||||
@ -405,42 +315,9 @@ public class DashboardController extends BaseController {
|
|||||||
@ApiParam(value = "JSON array with the list of customer ids")
|
@ApiParam(value = "JSON array with the list of customer ids")
|
||||||
@RequestBody String[] strCustomerIds) throws ThingsboardException {
|
@RequestBody String[] strCustomerIds) throws ThingsboardException {
|
||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
try {
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
Dashboard dashboard = checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
||||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
return tbDashboardService.addDashboardCustomers(getTenantId(), dashboard, strCustomerIds, getCurrentUser());
|
||||||
|
|
||||||
Set<CustomerId> customerIds = new HashSet<>();
|
|
||||||
if (strCustomerIds != null) {
|
|
||||||
for (String strCustomerId : strCustomerIds) {
|
|
||||||
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
|
||||||
if (!dashboard.isAssignedToCustomer(customerId)) {
|
|
||||||
customerIds.add(customerId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (customerIds.isEmpty()) {
|
|
||||||
return dashboard;
|
|
||||||
} else {
|
|
||||||
Dashboard savedDashboard = null;
|
|
||||||
for (CustomerId customerId : customerIds) {
|
|
||||||
savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(getCurrentUser().getTenantId(), dashboardId, customerId));
|
|
||||||
ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
|
|
||||||
logEntityAction(dashboardId, savedDashboard,
|
|
||||||
customerId,
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
|
|
||||||
sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
|
|
||||||
}
|
|
||||||
return savedDashboard;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
|
||||||
null,
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
|
|
||||||
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Remove the Dashboard Customers (removeDashboardCustomers)",
|
@ApiOperation(value = "Remove the Dashboard Customers (removeDashboardCustomers)",
|
||||||
@ -457,42 +334,10 @@ public class DashboardController extends BaseController {
|
|||||||
@ApiParam(value = "JSON array with the list of customer ids")
|
@ApiParam(value = "JSON array with the list of customer ids")
|
||||||
@RequestBody String[] strCustomerIds) throws ThingsboardException {
|
@RequestBody String[] strCustomerIds) throws ThingsboardException {
|
||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
try {
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
Dashboard dashboard = checkDashboardId(dashboardId, Operation.UNASSIGN_FROM_CUSTOMER);
|
||||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.UNASSIGN_FROM_CUSTOMER);
|
return tbDashboardService.removeDashboardCustomers(getTenantId(), dashboard, strCustomerIds, getCurrentUser());
|
||||||
|
|
||||||
Set<CustomerId> customerIds = new HashSet<>();
|
|
||||||
if (strCustomerIds != null) {
|
|
||||||
for (String strCustomerId : strCustomerIds) {
|
|
||||||
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
|
||||||
if (dashboard.isAssignedToCustomer(customerId)) {
|
|
||||||
customerIds.add(customerId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (customerIds.isEmpty()) {
|
|
||||||
return dashboard;
|
|
||||||
} else {
|
|
||||||
Dashboard savedDashboard = null;
|
|
||||||
for (CustomerId customerId : customerIds) {
|
|
||||||
ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
|
|
||||||
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(getCurrentUser().getTenantId(), dashboardId, customerId));
|
|
||||||
logEntityAction(dashboardId, dashboard,
|
|
||||||
customerId,
|
|
||||||
ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
|
|
||||||
sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
|
|
||||||
}
|
|
||||||
return savedDashboard;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
|
||||||
null,
|
|
||||||
ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);
|
|
||||||
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Assign the Dashboard to Public Customer (assignDashboardToPublicCustomer)",
|
@ApiOperation(value = "Assign the Dashboard to Public Customer (assignDashboardToPublicCustomer)",
|
||||||
@ -510,26 +355,10 @@ public class DashboardController extends BaseController {
|
|||||||
@ApiParam(value = DASHBOARD_ID_PARAM_DESCRIPTION)
|
@ApiParam(value = DASHBOARD_ID_PARAM_DESCRIPTION)
|
||||||
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
try {
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
||||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.ASSIGN_TO_CUSTOMER);
|
return tbDashboardService.assignDashboardToPublicCustomer(getTenantId(), dashboardId, getCurrentUser());
|
||||||
Customer publicCustomer = customerService.findOrCreatePublicCustomer(dashboard.getTenantId());
|
}
|
||||||
Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(getCurrentUser().getTenantId(), dashboardId, publicCustomer.getId()));
|
|
||||||
|
|
||||||
logEntityAction(dashboardId, savedDashboard,
|
|
||||||
publicCustomer.getId(),
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, publicCustomer.getId().toString(), publicCustomer.getName());
|
|
||||||
|
|
||||||
return savedDashboard;
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
|
||||||
null,
|
|
||||||
ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
|
|
||||||
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "Unassign the Dashboard from Public Customer (unassignDashboardFromPublicCustomer)",
|
@ApiOperation(value = "Unassign the Dashboard from Public Customer (unassignDashboardFromPublicCustomer)",
|
||||||
notes = "Unassigns the dashboard from a special, auto-generated 'Public' Customer. Once unassigned, unauthenticated users may no longer browse the dashboard. " +
|
notes = "Unassigns the dashboard from a special, auto-generated 'Public' Customer. Once unassigned, unauthenticated users may no longer browse the dashboard. " +
|
||||||
@ -775,6 +604,7 @@ public class DashboardController extends BaseController {
|
|||||||
public void setTenantHomeDashboardInfo(
|
public void setTenantHomeDashboardInfo(
|
||||||
@ApiParam(value = "A JSON object that represents home dashboard id and other parameters", required = true)
|
@ApiParam(value = "A JSON object that represents home dashboard id and other parameters", required = true)
|
||||||
@RequestBody HomeDashboardInfo homeDashboardInfo) throws ThingsboardException {
|
@RequestBody HomeDashboardInfo homeDashboardInfo) throws ThingsboardException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (homeDashboardInfo.getDashboardId() != null) {
|
if (homeDashboardInfo.getDashboardId() != null) {
|
||||||
checkDashboardId(homeDashboardInfo.getDashboardId(), Operation.READ);
|
checkDashboardId(homeDashboardInfo.getDashboardId(), Operation.READ);
|
||||||
@ -847,30 +677,34 @@ public class DashboardController extends BaseController {
|
|||||||
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
||||||
checkParameter("edgeId", strEdgeId);
|
checkParameter("edgeId", strEdgeId);
|
||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
try {
|
|
||||||
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
|
||||||
Edge edge = checkEdgeId(edgeId, Operation.READ);
|
|
||||||
|
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
||||||
checkDashboardId(dashboardId, Operation.READ);
|
Edge edge = checkEdgeId(edgeId, Operation.READ);
|
||||||
|
|
||||||
Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
|
checkDashboardId(dashboardId, Operation.READ);
|
||||||
logEntityAction(dashboardId, savedDashboard,
|
return tbDashboardService.asignDashboardToEdge(getTenantId(), dashboardId, edge, getCurrentUser());
|
||||||
null,
|
// try {
|
||||||
ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
|
//
|
||||||
|
//
|
||||||
sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
|
//
|
||||||
|
// Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
|
||||||
return savedDashboard;
|
//
|
||||||
} catch (Exception e) {
|
// logEntityAction(dashboardId, savedDashboard,
|
||||||
|
// null,
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
// ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
|
||||||
null,
|
//
|
||||||
ActionType.ASSIGNED_TO_EDGE, e, strDashboardId, strEdgeId);
|
// sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||||
|
//
|
||||||
throw handleException(e);
|
// return savedDashboard;
|
||||||
}
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
||||||
|
// null,
|
||||||
|
// ActionType.ASSIGNED_TO_EDGE, e, strDashboardId, strEdgeId);
|
||||||
|
//
|
||||||
|
// throw handleException(e);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Unassign dashboard from edge (unassignDashboardFromEdge)",
|
@ApiOperation(value = "Unassign dashboard from edge (unassignDashboardFromEdge)",
|
||||||
@ -886,37 +720,22 @@ public class DashboardController extends BaseController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Dashboard unassignDashboardFromEdge(@PathVariable("edgeId") String strEdgeId,
|
public Dashboard unassignDashboardFromEdge(@PathVariable("edgeId") String strEdgeId,
|
||||||
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
@PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
|
||||||
checkParameter("edgeId", strEdgeId);
|
checkParameter(EDGE_ID, strEdgeId);
|
||||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||||
try {
|
|
||||||
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
|
||||||
Edge edge = checkEdgeId(edgeId, Operation.READ);
|
|
||||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
|
||||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.READ);
|
|
||||||
|
|
||||||
Dashboard savedDashboard = checkNotNull(dashboardService.unassignDashboardFromEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
|
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
||||||
|
Edge edge = checkEdgeId(edgeId, Operation.READ);
|
||||||
|
|
||||||
logEntityAction(dashboardId, dashboard,
|
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||||
null,
|
Dashboard dashboard = checkDashboardId(dashboardId, Operation.READ);
|
||||||
ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName());
|
|
||||||
|
|
||||||
sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
return tbDashboardService.unassignDeviceFromEdge(dashboard, edge, getCurrentUser());
|
||||||
|
|
||||||
return savedDashboard;
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
|
||||||
null,
|
|
||||||
ActionType.UNASSIGNED_FROM_EDGE, e, strDashboardId, strEdgeId);
|
|
||||||
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Get Edge Dashboards (getEdgeDashboards)",
|
@ApiOperation(value = "Get Edge Dashboards (getEdgeDashboards)",
|
||||||
notes = "Returns a page of dashboard info objects assigned to the specified edge. "
|
notes = "Returns a page of dashboard info objects assigned to the specified edge. "
|
||||||
+ DASHBOARD_INFO_DEFINITION + " " + PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
+ DASHBOARD_INFO_DEFINITION + " " + PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH,
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/edge/{edgeId}/dashboards", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
@RequestMapping(value = "/edge/{edgeId}/dashboards", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import lombok.Getter;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.thingsboard.server.cluster.TbClusterService;
|
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.HasName;
|
import org.thingsboard.server.common.data.HasName;
|
||||||
import org.thingsboard.server.common.data.User;
|
import org.thingsboard.server.common.data.User;
|
||||||
@ -43,6 +42,7 @@ import org.thingsboard.server.common.data.page.TimePageLink;
|
|||||||
import org.thingsboard.server.dao.alarm.AlarmService;
|
import org.thingsboard.server.dao.alarm.AlarmService;
|
||||||
import org.thingsboard.server.dao.asset.AssetService;
|
import org.thingsboard.server.dao.asset.AssetService;
|
||||||
import org.thingsboard.server.dao.customer.CustomerService;
|
import org.thingsboard.server.dao.customer.CustomerService;
|
||||||
|
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||||
import org.thingsboard.server.dao.device.ClaimDevicesService;
|
import org.thingsboard.server.dao.device.ClaimDevicesService;
|
||||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||||
import org.thingsboard.server.dao.device.DeviceService;
|
import org.thingsboard.server.dao.device.DeviceService;
|
||||||
@ -106,6 +106,8 @@ public abstract class AbstractTbEntityService {
|
|||||||
protected RuleChainService ruleChainService;
|
protected RuleChainService ruleChainService;
|
||||||
@Autowired
|
@Autowired
|
||||||
protected EdgeNotificationService edgeNotificationService;
|
protected EdgeNotificationService edgeNotificationService;
|
||||||
|
@Autowired
|
||||||
|
protected DashboardService dashboardService;
|
||||||
|
|
||||||
protected ListenableFuture<Void> removeAlarmsByEntityId(TenantId tenantId, EntityId entityId) {
|
protected ListenableFuture<Void> removeAlarmsByEntityId(TenantId tenantId, EntityId entityId) {
|
||||||
ListenableFuture<PageData<AlarmInfo>> alarmsFuture =
|
ListenableFuture<PageData<AlarmInfo>> alarmsFuture =
|
||||||
|
|||||||
@ -0,0 +1,254 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2022 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.service.entitiy.dashboard;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thingsboard.server.common.data.Customer;
|
||||||
|
import org.thingsboard.server.common.data.Dashboard;
|
||||||
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
|
import org.thingsboard.server.common.data.ShortCustomerInfo;
|
||||||
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||||
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
|
import org.thingsboard.server.common.data.id.DashboardId;
|
||||||
|
import org.thingsboard.server.common.data.id.EdgeId;
|
||||||
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
|
import org.thingsboard.server.service.entitiy.AbstractTbEntityService;
|
||||||
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@TbCoreComponent
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DefaultTbDashboardService extends AbstractTbEntityService implements TbDashboardService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dashboard save(Dashboard dashboard, SecurityUser user) throws ThingsboardException {
|
||||||
|
ActionType actionType = dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED;
|
||||||
|
TenantId tenantId = dashboard.getTenantId();
|
||||||
|
try {
|
||||||
|
Dashboard savedDashboard = checkNotNull(dashboardService.saveDashboard(dashboard));
|
||||||
|
notificationEntityService.notifyCreateOrUpdateEntity(tenantId, savedDashboard.getId(), savedDashboard,
|
||||||
|
null, actionType, user);
|
||||||
|
return savedDashboard;
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), dashboard, null, actionType, user, e);
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dashboard assignDashboardToCustomer(TenantId tenantId, DashboardId dashboardId, Customer customer, SecurityUser user) throws ThingsboardException {
|
||||||
|
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;
|
||||||
|
CustomerId customerId = customer.getId();
|
||||||
|
try {
|
||||||
|
Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(tenantId, dashboardId, customerId));
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, dashboardId, customerId, savedDashboard,
|
||||||
|
actionType, EdgeEventActionType.ASSIGNED_TO_CUSTOMER, user, true, customerId.toString(), customer.getName());
|
||||||
|
return savedDashboard;
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
|
||||||
|
actionType, user, e, dashboardId.toString(), customerId.toString());
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dashboard assignDashboardToPublicCustomer(TenantId tenantId, DashboardId dashboardId, SecurityUser user) throws ThingsboardException {
|
||||||
|
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;
|
||||||
|
try {
|
||||||
|
|
||||||
|
Customer publicCustomer = customerService.findOrCreatePublicCustomer(tenantId);
|
||||||
|
Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(tenantId, dashboardId, publicCustomer.getId()));
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, dashboardId, user.getCustomerId(), savedDashboard,
|
||||||
|
actionType, null, user, false, dashboardId.toString(),
|
||||||
|
publicCustomer.getId().toString(), publicCustomer.getName());
|
||||||
|
return savedDashboard;
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
|
||||||
|
actionType, user, e, dashboardId.toString());
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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) {
|
||||||
|
customerIds.add(new CustomerId(UUID.fromString(strCustomerId)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<CustomerId> addedCustomerIds = new HashSet<>();
|
||||||
|
Set<CustomerId> removedCustomerIds = new HashSet<>();
|
||||||
|
for (CustomerId customerId : customerIds) {
|
||||||
|
if (!dashboard.isAssignedToCustomer(customerId)) {
|
||||||
|
addedCustomerIds.add(customerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<ShortCustomerInfo> assignedCustomers = dashboard.getAssignedCustomers();
|
||||||
|
if (assignedCustomers != null) {
|
||||||
|
for (ShortCustomerInfo customerInfo : assignedCustomers) {
|
||||||
|
if (!customerIds.contains(customerInfo.getCustomerId())) {
|
||||||
|
removedCustomerIds.add(customerInfo.getCustomerId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addedCustomerIds.isEmpty() && removedCustomerIds.isEmpty()) {
|
||||||
|
return dashboard;
|
||||||
|
} else {
|
||||||
|
Dashboard savedDashboard = null;
|
||||||
|
for (CustomerId customerId : addedCustomerIds) {
|
||||||
|
savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), customerId));
|
||||||
|
ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, savedDashboard.getId(), customerId, savedDashboard,
|
||||||
|
actionType, EdgeEventActionType.ASSIGNED_TO_CUSTOMER, user, true, customerInfo.getTitle());
|
||||||
|
}
|
||||||
|
for (CustomerId customerId : removedCustomerIds) {
|
||||||
|
ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
|
||||||
|
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(tenantId, dashboard.getId(), customerId));
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, savedDashboard.getId(), customerId, savedDashboard,
|
||||||
|
ActionType.UNASSIGNED_FROM_CUSTOMER, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER, user, true, customerInfo.getTitle());
|
||||||
|
}
|
||||||
|
return savedDashboard;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
|
||||||
|
actionType, user, e, dashboard.getId().toString());
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dashboard addDashboardCustomers(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) {
|
||||||
|
CustomerId customerId = new CustomerId(UUID.fromString(strCustomerId));
|
||||||
|
if (!dashboard.isAssignedToCustomer(customerId)) {
|
||||||
|
customerIds.add(customerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customerIds.isEmpty()) {
|
||||||
|
return dashboard;
|
||||||
|
} else {
|
||||||
|
Dashboard savedDashboard = null;
|
||||||
|
for (CustomerId customerId : customerIds) {
|
||||||
|
savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(tenantId, dashboard.getId(), customerId));
|
||||||
|
ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, savedDashboard.getId(), customerId, savedDashboard,
|
||||||
|
actionType, EdgeEventActionType.ASSIGNED_TO_CUSTOMER, user, true, customerInfo.getTitle());
|
||||||
|
}
|
||||||
|
return savedDashboard;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
|
||||||
|
actionType, user, e, dashboard.getId().toString());
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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) {
|
||||||
|
CustomerId customerId = new CustomerId(UUID.fromString(strCustomerId));
|
||||||
|
if (dashboard.isAssignedToCustomer(customerId)) {
|
||||||
|
customerIds.add(customerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customerIds.isEmpty()) {
|
||||||
|
return dashboard;
|
||||||
|
} else {
|
||||||
|
Dashboard savedDashboard = null;
|
||||||
|
for (CustomerId customerId : customerIds) {
|
||||||
|
ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
|
||||||
|
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(tenantId, dashboard.getId(), customerId));
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, savedDashboard.getId(), customerId, savedDashboard,
|
||||||
|
actionType, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER, user, true, customerInfo.getTitle());
|
||||||
|
}
|
||||||
|
return savedDashboard;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
|
||||||
|
actionType, user, e, dashboard.getId().toString());
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dashboard asignDashboardToEdge(TenantId tenantId, DashboardId dashboardId, Edge edge, SecurityUser user) throws ThingsboardException {
|
||||||
|
ActionType actionType = ActionType.ASSIGNED_TO_EDGE;
|
||||||
|
EdgeId edgeId = edge.getId();
|
||||||
|
try {
|
||||||
|
Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToEdge(tenantId, dashboardId, edgeId));
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, dashboardId, user.getCustomerId(),
|
||||||
|
edgeId, savedDashboard, actionType, EdgeEventActionType.ASSIGNED_TO_EDGE, user, dashboardId.toString(),
|
||||||
|
edgeId.toString(), edge.getName());
|
||||||
|
return savedDashboard;
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DEVICE), null, null,
|
||||||
|
actionType, user, e, dashboardId.toString(), edgeId.toString());
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dashboard unassignDeviceFromEdge(Dashboard dashboard, Edge edge, SecurityUser user) throws ThingsboardException {
|
||||||
|
ActionType actionType = ActionType.UNASSIGNED_FROM_EDGE;
|
||||||
|
TenantId tenantId = dashboard.getTenantId();
|
||||||
|
DashboardId dashboardId = dashboard.getId();
|
||||||
|
EdgeId edgeId = edge.getId();
|
||||||
|
try {
|
||||||
|
Dashboard savedDevice = checkNotNull(dashboardService.unassignDashboardFromEdge(tenantId, dashboardId, edgeId));
|
||||||
|
|
||||||
|
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, dashboardId, user.getCustomerId(),
|
||||||
|
edgeId, dashboard, actionType, EdgeEventActionType.UNASSIGNED_FROM_EDGE, user, dashboardId.toString(),
|
||||||
|
edgeId.toString(), edge.getName());
|
||||||
|
return savedDevice;
|
||||||
|
} catch (Exception e) {
|
||||||
|
notificationEntityService.notifyEntity(tenantId, emptyId(EntityType.DASHBOARD), null, null,
|
||||||
|
actionType, user, e, dashboardId.toString(), edgeId.toString());
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2022 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.service.entitiy.dashboard;
|
||||||
|
|
||||||
|
import org.thingsboard.server.common.data.Customer;
|
||||||
|
import org.thingsboard.server.common.data.Dashboard;
|
||||||
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
|
import org.thingsboard.server.common.data.id.DashboardId;
|
||||||
|
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> {
|
||||||
|
|
||||||
|
Dashboard assignDashboardToCustomer(TenantId tenantId, DashboardId dashboardId, Customer customer, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
|
Dashboard assignDashboardToPublicCustomer(TenantId tenantId, DashboardId dashboardId, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
|
Dashboard updateDashboardCustomers(TenantId tenantId, Dashboard dashboard, String[] strCustomerIds, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
|
Dashboard addDashboardCustomers(TenantId tenantId, Dashboard dashboard, String[] strCustomerIds, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
|
Dashboard removeDashboardCustomers(TenantId tenantId, Dashboard dashboard, String[] strCustomerIds, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
|
Dashboard asignDashboardToEdge(TenantId tenantId, DashboardId dashboardId, Edge edge, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
|
Dashboard unassignDeviceFromEdge(Dashboard dashboard, Edge edge, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user