Removed assigned edges from dashboard
This commit is contained in:
parent
6ab3714ac5
commit
85a88ee499
@ -540,158 +540,6 @@ public class DashboardController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/dashboard/{dashboardId}/edges", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Dashboard updateDashboardEdges(@PathVariable(DASHBOARD_ID) String strDashboardId,
|
||||
@RequestBody String[] strEdgeIds) throws ThingsboardException {
|
||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||
try {
|
||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.ASSIGN_TO_EDGE);
|
||||
|
||||
Set<EdgeId> edgeIds = new HashSet<>();
|
||||
if (strEdgeIds != null) {
|
||||
for (String strEdgeId : strEdgeIds) {
|
||||
edgeIds.add(new EdgeId(toUUID(strEdgeId)));
|
||||
}
|
||||
}
|
||||
|
||||
Set<EdgeId> addedEdgeIds = new HashSet<>();
|
||||
Set<EdgeId> removedEdgeIds = new HashSet<>();
|
||||
for (EdgeId edgeId : edgeIds) {
|
||||
if (!dashboard.isAssignedToEdge(edgeId)) {
|
||||
addedEdgeIds.add(edgeId);
|
||||
}
|
||||
}
|
||||
|
||||
Set<ShortEdgeInfo> assignedEdges = dashboard.getAssignedEdges();
|
||||
if (assignedEdges != null) {
|
||||
for (ShortEdgeInfo edgeInfo : assignedEdges) {
|
||||
if (!edgeIds.contains(edgeInfo.getEdgeId())) {
|
||||
removedEdgeIds.add(edgeInfo.getEdgeId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addedEdgeIds.isEmpty() && removedEdgeIds.isEmpty()) {
|
||||
return dashboard;
|
||||
} else {
|
||||
Dashboard savedDashboard = null;
|
||||
for (EdgeId edgeId : addedEdgeIds) {
|
||||
savedDashboard = checkNotNull(dashboardService.assignDashboardToEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
|
||||
ShortEdgeInfo edgeInfo = savedDashboard.getAssignedEdgeInfo(edgeId);
|
||||
logEntityAction(dashboardId, savedDashboard,
|
||||
null,
|
||||
ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, edgeId.toString(), edgeInfo.getTitle());
|
||||
}
|
||||
for (EdgeId edgeId : removedEdgeIds) {
|
||||
ShortEdgeInfo edgeInfo = dashboard.getAssignedEdgeInfo(edgeId);
|
||||
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
|
||||
logEntityAction(dashboardId, dashboard,
|
||||
null,
|
||||
ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, edgeId.toString(), edgeInfo.getTitle());
|
||||
|
||||
}
|
||||
return savedDashboard;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
||||
null,
|
||||
ActionType.ASSIGNED_TO_EDGE, e, strDashboardId);
|
||||
|
||||
throw handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/dashboard/{dashboardId}/edges/add", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Dashboard addDashboardEdges(@PathVariable(DASHBOARD_ID) String strDashboardId,
|
||||
@RequestBody String[] strEdgeIds) throws ThingsboardException {
|
||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||
try {
|
||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.ASSIGN_TO_EDGE);
|
||||
|
||||
Set<EdgeId> edgeIds = new HashSet<>();
|
||||
if (strEdgeIds != null) {
|
||||
for (String strEdgeId : strEdgeIds) {
|
||||
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
||||
if (!dashboard.isAssignedToEdge(edgeId)) {
|
||||
edgeIds.add(edgeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (edgeIds.isEmpty()) {
|
||||
return dashboard;
|
||||
} else {
|
||||
Dashboard savedDashboard = null;
|
||||
for (EdgeId edgeId : edgeIds) {
|
||||
savedDashboard = checkNotNull(dashboardService.assignDashboardToEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
|
||||
ShortEdgeInfo edgeInfo = savedDashboard.getAssignedEdgeInfo(edgeId);
|
||||
logEntityAction(dashboardId, savedDashboard,
|
||||
null,
|
||||
ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, edgeId.toString(), edgeInfo.getTitle());
|
||||
}
|
||||
return savedDashboard;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
||||
null,
|
||||
ActionType.ASSIGNED_TO_EDGE, e, strDashboardId);
|
||||
|
||||
throw handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/dashboard/{dashboardId}/edges/remove", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Dashboard removeDashboardEdges(@PathVariable(DASHBOARD_ID) String strDashboardId,
|
||||
@RequestBody String[] strEdgeIds) throws ThingsboardException {
|
||||
checkParameter(DASHBOARD_ID, strDashboardId);
|
||||
try {
|
||||
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
|
||||
Dashboard dashboard = checkDashboardId(dashboardId, Operation.UNASSIGN_FROM_EDGE);
|
||||
|
||||
Set<EdgeId> edgeIds = new HashSet<>();
|
||||
if (strEdgeIds != null) {
|
||||
for (String strEdgeId : strEdgeIds) {
|
||||
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
||||
if (dashboard.isAssignedToEdge(edgeId)) {
|
||||
edgeIds.add(edgeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (edgeIds.isEmpty()) {
|
||||
return dashboard;
|
||||
} else {
|
||||
Dashboard savedDashboard = null;
|
||||
for (EdgeId edgeId : edgeIds) {
|
||||
ShortEdgeInfo edgeInfo = dashboard.getAssignedEdgeInfo(edgeId);
|
||||
savedDashboard = checkNotNull(dashboardService.unassignDashboardFromEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
|
||||
logEntityAction(dashboardId, dashboard,
|
||||
null,
|
||||
ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, edgeId.toString(), edgeInfo.getTitle());
|
||||
|
||||
}
|
||||
return savedDashboard;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
logEntityAction(emptyId(EntityType.DASHBOARD), null,
|
||||
null,
|
||||
ActionType.UNASSIGNED_FROM_EDGE, e, strDashboardId);
|
||||
|
||||
throw handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/{edgeId}/dashboards", params = { "limit" }, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
|
||||
@ -61,7 +61,5 @@ public interface DashboardService {
|
||||
|
||||
void unassignEdgeDashboards(TenantId tenantId, EdgeId edgeId);
|
||||
|
||||
void updateEdgeDashboards(TenantId tenantId, EdgeId edgeId);
|
||||
|
||||
ListenableFuture<TimePageData<DashboardInfo>> findDashboardsByTenantIdAndEdgeId(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink);
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import org.thingsboard.server.common.data.Event;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.edge.EdgeSearchQuery;
|
||||
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.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -82,6 +83,8 @@ public interface EdgeService {
|
||||
Edge setEdgeRootRuleChain(TenantId tenantId, Edge edge, RuleChainId ruleChainId) throws IOException;
|
||||
|
||||
ListenableFuture<TimePageData<Edge>> findEdgesByTenantIdAndRuleChainId(TenantId tenantId, RuleChainId ruleChainId, TimePageLink pageLink);
|
||||
|
||||
ListenableFuture<TimePageData<Edge>> findEdgesByTenantIdAndDashboardId(TenantId tenantId, DashboardId dashboardId, TimePageLink pageLink);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -32,9 +32,6 @@ public class DashboardInfo extends SearchTextBased<DashboardId> implements HasNa
|
||||
private String title;
|
||||
private Set<ShortCustomerInfo> assignedCustomers;
|
||||
|
||||
@Getter @Setter
|
||||
private Set<ShortEdgeInfo> assignedEdges;
|
||||
|
||||
public DashboardInfo() {
|
||||
super();
|
||||
}
|
||||
@ -123,29 +120,6 @@ public class DashboardInfo extends SearchTextBased<DashboardId> implements HasNa
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAssignedToEdge(EdgeId edgeId) {
|
||||
return EdgeUtils.isAssignedToEdge(this.assignedEdges, edgeId);
|
||||
}
|
||||
|
||||
public ShortEdgeInfo getAssignedEdgeInfo(EdgeId edgeId) {
|
||||
return EdgeUtils.getAssignedEdgeInfo(this.assignedEdges, edgeId);
|
||||
}
|
||||
|
||||
public boolean addAssignedEdge(Edge edge) {
|
||||
if (this.assignedEdges == null) {
|
||||
this.assignedEdges = new HashSet<>();
|
||||
}
|
||||
return EdgeUtils.addAssignedEdge(this.assignedEdges, edge.toShortEdgeInfo());
|
||||
}
|
||||
|
||||
public boolean updateAssignedEdge(Edge edge) {
|
||||
return EdgeUtils.updateAssignedEdge(this.assignedEdges, edge.toShortEdgeInfo());
|
||||
}
|
||||
|
||||
public boolean removeAssignedEdge(Edge edge) {
|
||||
return EdgeUtils.removeAssignedEdge(this.assignedEdges, edge.toShortEdgeInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
public String getName() {
|
||||
|
||||
@ -245,17 +245,13 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
if (!edge.getTenantId().getId().equals(dashboard.getTenantId().getId())) {
|
||||
throw new DataValidationException("Can't assign dashboard to edge from different tenant!");
|
||||
}
|
||||
if (dashboard.addAssignedEdge(edge)) {
|
||||
try {
|
||||
createRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
log.warn("[{}] Failed to create dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return saveDashboard(dashboard);
|
||||
} else {
|
||||
return dashboard;
|
||||
try {
|
||||
createRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
log.warn("[{}] Failed to create dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -265,17 +261,13 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
if (edge == null) {
|
||||
throw new DataValidationException("Can't unassign dashboard from non-existent edge!");
|
||||
}
|
||||
if (dashboard.removeAssignedEdge(edge)) {
|
||||
try {
|
||||
deleteRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
log.warn("[{}] Failed to delete dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return saveDashboard(dashboard);
|
||||
} else {
|
||||
return dashboard;
|
||||
try {
|
||||
deleteRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
log.warn("[{}] Failed to delete dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -289,17 +281,6 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
new EdgeDashboardsUnassigner(edge).removeEntities(tenantId, edge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEdgeDashboards(TenantId tenantId, EdgeId edgeId) {
|
||||
log.trace("Executing updateEdgeDashboards, edgeId [{}]", edgeId);
|
||||
Validator.validateId(edgeId, "Incorrect edgeId " + edgeId);
|
||||
Edge edge = edgeDao.findById(tenantId, edgeId.getId());
|
||||
if (edge == null) {
|
||||
throw new DataValidationException("Can't update dashboards for non-existent edge!");
|
||||
}
|
||||
new EdgeDashboardsUpdater(edge).removeEntities(tenantId, edge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<TimePageData<DashboardInfo>> findDashboardsByTenantIdAndEdgeId(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink) {
|
||||
log.trace("Executing findDashboardsByTenantIdAndEdgeId, tenantId [{}], edgeId [{}], pageLink [{}]", tenantId, edgeId, pageLink);
|
||||
@ -317,15 +298,6 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
private Dashboard updateAssignedEdge(TenantId tenantId, DashboardId dashboardId, Edge edge) {
|
||||
Dashboard dashboard = findDashboardById(tenantId, dashboardId);
|
||||
if (dashboard.updateAssignedEdge(edge)) {
|
||||
return saveDashboard(dashboard);
|
||||
} else {
|
||||
return dashboard;
|
||||
}
|
||||
}
|
||||
|
||||
private DataValidator<Dashboard> dashboardValidator =
|
||||
new DataValidator<Dashboard>() {
|
||||
@Override
|
||||
@ -432,29 +404,4 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class EdgeDashboardsUpdater extends TimePaginatedRemover<Edge, DashboardInfo> {
|
||||
|
||||
private Edge edge;
|
||||
|
||||
EdgeDashboardsUpdater(Edge edge) {
|
||||
this.edge = edge;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DashboardInfo> findEntities(TenantId tenantId, Edge edge, TimePageLink pageLink) {
|
||||
try {
|
||||
return dashboardInfoDao.findDashboardsByTenantIdAndEdgeId(edge.getTenantId().getId(), edge.getId().getId(), pageLink).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.warn("Failed to get dashboards by tenantId [{}] and edgeId [{}].", edge.getTenantId().getId(), edge.getId().getId());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
|
||||
updateAssignedEdge(edge.getTenantId(), new DashboardId(entity.getUuidId()), this.edge);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -120,4 +121,17 @@ public class CassandraEdgeDao extends CassandraAbstractSearchTextDao<EdgeEntity,
|
||||
return Futures.successfulAsList(edgeFutures);
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<List<Edge>> findEdgesByTenantIdAndDashboardId(UUID tenantId, UUID dashboardId, TimePageLink pageLink) {
|
||||
log.debug("Try to find edges by tenantId [{}], dashboardId [{}] and pageLink [{}]", tenantId, dashboardId, pageLink);
|
||||
ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByToAndType(new TenantId(tenantId), new DashboardId(dashboardId), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE);
|
||||
return Futures.transformAsync(relations, input -> {
|
||||
List<ListenableFuture<Edge>> edgeFutures = new ArrayList<>(input.size());
|
||||
for (EntityRelation relation : input) {
|
||||
edgeFutures.add(findByIdAsync(new TenantId(tenantId), relation.getTo().getId()));
|
||||
}
|
||||
return Futures.successfulAsList(edgeFutures);
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,4 +135,14 @@ public interface EdgeDao extends Dao<Edge> {
|
||||
* @return the list of rule chain objects
|
||||
*/
|
||||
ListenableFuture<List<Edge>> findEdgesByTenantIdAndRuleChainId(UUID tenantId, UUID ruleChainId, TimePageLink pageLink);
|
||||
|
||||
/**
|
||||
* Find edges by tenantId, dashboardId and page link.
|
||||
*
|
||||
* @param tenantId the tenantId
|
||||
* @param dashboardId the dashboardId
|
||||
* @param pageLink the page link
|
||||
* @return the list of rule chain objects
|
||||
*/
|
||||
ListenableFuture<List<Edge>> findEdgesByTenantIdAndDashboardId(UUID tenantId, UUID dashboardId, TimePageLink pageLink);
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.DashboardInfo;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
@ -48,6 +49,7 @@ import org.thingsboard.server.common.data.edge.EdgeQueueEntry;
|
||||
import org.thingsboard.server.common.data.edge.EdgeSearchQuery;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -191,9 +193,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
|
||||
public Edge saveEdge(Edge edge) {
|
||||
log.trace("Executing saveEdge [{}]", edge);
|
||||
edgeValidator.validate(edge, Edge::getTenantId);
|
||||
Edge savedEdge = edgeDao.save(edge.getTenantId(), edge);
|
||||
dashboardService.updateEdgeDashboards(savedEdge.getTenantId(), savedEdge.getId());
|
||||
return savedEdge;
|
||||
return edgeDao.save(edge.getTenantId(), edge);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -568,11 +568,19 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
|
||||
case DataConstants.ENTITY_CREATED:
|
||||
case DataConstants.ENTITY_UPDATED:
|
||||
Dashboard dashboard = mapper.readValue(tbMsg.getData(), Dashboard.class);
|
||||
if (dashboard.getAssignedEdges() != null && !dashboard.getAssignedEdges().isEmpty()) {
|
||||
for (ShortEdgeInfo assignedEdge : dashboard.getAssignedEdges()) {
|
||||
pushEventToEdge(tenantId, assignedEdge.getEdgeId(), EdgeQueueEntityType.DASHBOARD, tbMsg, callback);
|
||||
ListenableFuture<TimePageData<Edge>> future = findEdgesByTenantIdAndDashboardId(tenantId, dashboard.getId(), new TimePageLink(Integer.MAX_VALUE));
|
||||
Futures.transform(future, edges -> {
|
||||
if (edges != null && edges.getData() != null && !edges.getData().isEmpty()) {
|
||||
try {
|
||||
for (Edge edge : edges.getData()) {
|
||||
pushEventToEdge(tenantId, edge.getId(), EdgeQueueEntityType.DASHBOARD, tbMsg, callback);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Can't push event to edge", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, MoreExecutors.directExecutor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -674,6 +682,24 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<TimePageData<Edge>> findEdgesByTenantIdAndDashboardId(TenantId tenantId, DashboardId dashboardId, TimePageLink pageLink) {
|
||||
log.trace("Executing findEdgesByTenantIdAndDashboardId, tenantId [{}], dashboardId [{}], pageLink [{}]", tenantId, dashboardId, pageLink);
|
||||
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
|
||||
Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId);
|
||||
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
|
||||
ListenableFuture<List<Edge>> edges = edgeDao.findEdgesByTenantIdAndDashboardId(tenantId.getId(), dashboardId.getId(), pageLink);
|
||||
|
||||
return Futures.transform(edges, new Function<List<Edge>, TimePageData<Edge>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public TimePageData<Edge> apply(@Nullable List<Edge> edges) {
|
||||
return new TimePageData<>(edges, pageLink);
|
||||
}
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
|
||||
private DataValidator<Edge> edgeValidator =
|
||||
new DataValidator<Edge>() {
|
||||
|
||||
|
||||
@ -302,7 +302,6 @@ public class ModelConstants {
|
||||
public static final String DASHBOARD_TITLE_PROPERTY = TITLE_PROPERTY;
|
||||
public static final String DASHBOARD_CONFIGURATION_PROPERTY = "configuration";
|
||||
public static final String DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY = "assigned_customers";
|
||||
public static final String DASHBOARD_ASSIGNED_EDGES_PROPERTY = "assigned_edges";
|
||||
|
||||
public static final String DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "dashboard_by_tenant_and_search_text";
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.DashboardInfo;
|
||||
import org.thingsboard.server.common.data.ShortCustomerInfo;
|
||||
import org.thingsboard.server.common.data.ShortEdgeInfo;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.model.SearchTextEntity;
|
||||
@ -38,7 +37,6 @@ import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_ASSIGNED_EDGES_PROPERTY;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TENANT_ID_PROPERTY;
|
||||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TITLE_PROPERTY;
|
||||
@ -54,8 +52,6 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final JavaType assignedCustomersType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class);
|
||||
private static final JavaType assignedEdgesType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortEdgeInfo.class);
|
||||
|
||||
@PartitionKey(value = 0)
|
||||
@Column(name = ID_PROPERTY)
|
||||
@ -74,9 +70,6 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
|
||||
@Column(name = DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY)
|
||||
private String assignedCustomers;
|
||||
|
||||
@Column(name = DASHBOARD_ASSIGNED_EDGES_PROPERTY)
|
||||
private String assignedEdges;
|
||||
|
||||
public DashboardInfoEntity() {
|
||||
super();
|
||||
}
|
||||
@ -96,13 +89,6 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
|
||||
log.error("Unable to serialize assigned customers to string!", e);
|
||||
}
|
||||
}
|
||||
if (dashboardInfo.getAssignedEdges() != null) {
|
||||
try {
|
||||
this.assignedEdges = objectMapper.writeValueAsString(dashboardInfo.getAssignedEdges());
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Unable to serialize assigned edges to string!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
@ -137,14 +123,6 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
|
||||
this.assignedCustomers = assignedCustomers;
|
||||
}
|
||||
|
||||
public String getAssignedEdges() {
|
||||
return assignedEdges;
|
||||
}
|
||||
|
||||
public void setAssignedEdges(String assignedEdges) {
|
||||
this.assignedEdges = assignedEdges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSearchTextSource() {
|
||||
return getTitle();
|
||||
@ -174,13 +152,6 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
|
||||
log.warn("Unable to parse assigned customers!", e);
|
||||
}
|
||||
}
|
||||
if (!StringUtils.isEmpty(assignedEdges)) {
|
||||
try {
|
||||
dashboardInfo.setAssignedEdges(objectMapper.readValue(assignedEdges, assignedEdgesType));
|
||||
} catch (IOException e) {
|
||||
log.warn("Unable to parse assigned edges!", e);
|
||||
}
|
||||
}
|
||||
return dashboardInfo;
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ import org.hibernate.annotations.TypeDef;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.ShortCustomerInfo;
|
||||
import org.thingsboard.server.common.data.ShortEdgeInfo;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.model.BaseSqlEntity;
|
||||
@ -53,8 +52,6 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final JavaType assignedCustomersType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class);
|
||||
private static final JavaType assignedEdgesType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortEdgeInfo.class);
|
||||
|
||||
@Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
|
||||
private String tenantId;
|
||||
@ -68,9 +65,6 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
|
||||
@Column(name = ModelConstants.DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY)
|
||||
private String assignedCustomers;
|
||||
|
||||
@Column(name = ModelConstants.DASHBOARD_ASSIGNED_EDGES_PROPERTY)
|
||||
private String assignedEdges;
|
||||
|
||||
@Type(type = "json")
|
||||
@Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY)
|
||||
private JsonNode configuration;
|
||||
@ -94,13 +88,6 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
|
||||
log.error("Unable to serialize assigned customers to string!", e);
|
||||
}
|
||||
}
|
||||
if (dashboard.getAssignedEdges() != null) {
|
||||
try {
|
||||
this.assignedEdges = objectMapper.writeValueAsString(dashboard.getAssignedEdges());
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Unable to serialize assigned edges to string!", e);
|
||||
}
|
||||
}
|
||||
this.configuration = dashboard.getConfiguration();
|
||||
}
|
||||
|
||||
@ -129,13 +116,6 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
|
||||
log.warn("Unable to parse assigned customers!", e);
|
||||
}
|
||||
}
|
||||
if (!StringUtils.isEmpty(assignedEdges)) {
|
||||
try {
|
||||
dashboard.setAssignedEdges(objectMapper.readValue(assignedEdges, assignedEdgesType));
|
||||
} catch (IOException e) {
|
||||
log.warn("Unable to parse assigned edges!", e);
|
||||
}
|
||||
}
|
||||
dashboard.setConfiguration(configuration);
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
* 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
|
||||
* 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,
|
||||
@ -25,7 +25,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.DashboardInfo;
|
||||
import org.thingsboard.server.common.data.ShortCustomerInfo;
|
||||
import org.thingsboard.server.common.data.ShortEdgeInfo;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.model.BaseSqlEntity;
|
||||
@ -48,8 +47,6 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final JavaType assignedCustomersType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class);
|
||||
private static final JavaType assignedEdgesType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortEdgeInfo.class);
|
||||
|
||||
@Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
|
||||
private String tenantId;
|
||||
@ -63,9 +60,6 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
|
||||
@Column(name = ModelConstants.DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY)
|
||||
private String assignedCustomers;
|
||||
|
||||
@Column(name = ModelConstants.DASHBOARD_ASSIGNED_EDGES_PROPERTY)
|
||||
private String assignedEdges;
|
||||
|
||||
public DashboardInfoEntity() {
|
||||
super();
|
||||
}
|
||||
@ -85,13 +79,6 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
|
||||
log.error("Unable to serialize assigned customers to string!", e);
|
||||
}
|
||||
}
|
||||
if (dashboardInfo.getAssignedEdges() != null) {
|
||||
try {
|
||||
this.assignedEdges = objectMapper.writeValueAsString(dashboardInfo.getAssignedEdges());
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Unable to serialize assigned edges to string!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,13 +110,6 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
|
||||
log.warn("Unable to parse assigned customers!", e);
|
||||
}
|
||||
}
|
||||
if (!StringUtils.isEmpty(assignedEdges)) {
|
||||
try {
|
||||
dashboardInfo.setAssignedEdges(objectMapper.readValue(assignedEdges, assignedEdgesType));
|
||||
} catch (IOException e) {
|
||||
log.warn("Unable to parse assigned edges!", e);
|
||||
}
|
||||
}
|
||||
return dashboardInfo;
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.UUIDConverter;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -159,6 +160,19 @@ public class JpaEdgeDao extends JpaAbstractSearchTextDao<EdgeEntity, Edge> imple
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<List<Edge>> findEdgesByTenantIdAndDashboardId(UUID tenantId, UUID dashboardId, TimePageLink pageLink) {
|
||||
log.debug("Try to find edges by tenantId [{}], dashboardId [{}] and pageLink [{}]", tenantId, dashboardId, pageLink);
|
||||
ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByToAndType(new TenantId(tenantId), new DashboardId(dashboardId), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE);
|
||||
return Futures.transformAsync(relations, input -> {
|
||||
List<ListenableFuture<Edge>> edgeFutures = new ArrayList<>(input.size());
|
||||
for (EntityRelation relation : input) {
|
||||
edgeFutures.add(findByIdAsync(new TenantId(tenantId), relation.getTo().getId()));
|
||||
}
|
||||
return Futures.successfulAsList(edgeFutures);
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
private List<EntitySubtype> convertTenantEdgeTypesToDto(UUID tenantId, List<String> types) {
|
||||
List<EntitySubtype> list = Collections.emptyList();
|
||||
if (types != null && !types.isEmpty()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user