use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseAssetService method unassignAssetFromEdge.
@Override
public Asset unassignAssetFromEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId) {
Asset asset = findAssetById(tenantId, assetId);
Edge edge = edgeService.findEdgeById(tenantId, edgeId);
if (edge == null) {
throw new DataValidationException("Can't unassign asset from non-existent edge!");
}
checkAssignedEntityViewsToEdge(tenantId, assetId, edgeId);
try {
deleteRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to delete asset relation. Edge Id: [{}]", assetId, edgeId);
throw new RuntimeException(e);
}
return asset;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseAssetService method assignAssetToEdge.
@Override
public Asset assignAssetToEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId) {
Asset asset = findAssetById(tenantId, assetId);
Edge edge = edgeService.findEdgeById(tenantId, edgeId);
if (edge == null) {
throw new DataValidationException("Can't assign asset to non-existent edge!");
}
if (!edge.getTenantId().getId().equals(asset.getTenantId().getId())) {
throw new DataValidationException("Can't assign asset to edge from different tenant!");
}
try {
createRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to create asset relation. Edge Id: [{}]", assetId, edgeId);
throw new RuntimeException(e);
}
return asset;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class DashboardServiceImpl method assignDashboardToEdge.
@Override
public Dashboard assignDashboardToEdge(TenantId tenantId, DashboardId dashboardId, EdgeId edgeId) {
Dashboard dashboard = findDashboardById(tenantId, dashboardId);
Edge edge = edgeDao.findById(tenantId, edgeId.getId());
if (edge == null) {
throw new DataValidationException("Can't assign dashboard to non-existent edge!");
}
if (!edge.getTenantId().equals(dashboard.getTenantId())) {
throw new DataValidationException("Can't assign dashboard to edge from different tenant!");
}
try {
createRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to create dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
throw new RuntimeException(e);
}
return dashboard;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class DashboardServiceImpl method unassignDashboardFromEdge.
@Override
public Dashboard unassignDashboardFromEdge(TenantId tenantId, DashboardId dashboardId, EdgeId edgeId) {
Dashboard dashboard = findDashboardById(tenantId, dashboardId);
Edge edge = edgeDao.findById(tenantId, edgeId.getId());
if (edge == null) {
throw new DataValidationException("Can't unassign dashboard from non-existent edge!");
}
try {
deleteRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to delete dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
throw new RuntimeException(e);
}
return dashboard;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseRuleChainService method unassignRuleChainFromEdge.
@Override
public RuleChain unassignRuleChainFromEdge(TenantId tenantId, RuleChainId ruleChainId, EdgeId edgeId, boolean remove) {
RuleChain ruleChain = findRuleChainById(tenantId, ruleChainId);
Edge edge = edgeService.findEdgeById(tenantId, edgeId);
if (edge == null) {
throw new DataValidationException("Can't unassign rule chain from non-existent edge!");
}
if (!remove && edge.getRootRuleChainId() != null && edge.getRootRuleChainId().equals(ruleChainId)) {
throw new DataValidationException("Can't unassign root rule chain from edge [" + edge.getName() + "]. Please assign another root rule chain first!");
}
try {
deleteRelation(tenantId, new EntityRelation(edgeId, ruleChainId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to delete rule chain relation. Edge Id: [{}]", ruleChainId, edgeId);
throw new RuntimeException(e);
}
return ruleChain;
}
Aggregations