use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class EdgeServiceImpl method deleteEdge.
@Override
public void deleteEdge(TenantId tenantId, EdgeId edgeId) {
log.trace("Executing deleteEdge [{}]", edgeId);
validateId(edgeId, INCORRECT_EDGE_ID + edgeId);
Edge edge = edgeDao.findById(tenantId, edgeId.getId());
deleteEntityRelations(tenantId, edgeId);
cacheManager.removeEdgeFromCacheByName(edge.getTenantId(), edge.getName());
edgeDao.removeById(tenantId, edgeId.getId());
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class EdgeServiceImpl method findEdgesByQuery.
@Override
public ListenableFuture<List<Edge>> findEdgesByQuery(TenantId tenantId, EdgeSearchQuery query) {
log.trace("[{}] Executing findEdgesByQuery [{}]", tenantId, query);
ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(tenantId, query.toEntitySearchQuery());
ListenableFuture<List<Edge>> edges = Futures.transformAsync(relations, r -> {
EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
List<ListenableFuture<Edge>> futures = new ArrayList<>();
for (EntityRelation relation : r) {
EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
if (entityId.getEntityType() == EntityType.EDGE) {
futures.add(findEdgeByIdAsync(tenantId, new EdgeId(entityId.getId())));
}
}
return Futures.successfulAsList(futures);
}, MoreExecutors.directExecutor());
edges = Futures.transform(edges, new Function<List<Edge>, List<Edge>>() {
@Nullable
@Override
public List<Edge> apply(@Nullable List<Edge> edgeList) {
return edgeList == null ? Collections.emptyList() : edgeList.stream().filter(edge -> query.getEdgeTypes().contains(edge.getType())).collect(Collectors.toList());
}
}, MoreExecutors.directExecutor());
return edges;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class EntityViewServiceImpl method unassignEntityViewFromEdge.
@Override
public EntityView unassignEntityViewFromEdge(TenantId tenantId, EntityViewId entityViewId, EdgeId edgeId) {
EntityView entityView = findEntityViewById(tenantId, entityViewId);
Edge edge = edgeService.findEdgeById(tenantId, edgeId);
if (edge == null) {
throw new DataValidationException("Can't unassign entityView from non-existent edge!");
}
try {
deleteRelation(tenantId, new EntityRelation(edgeId, entityViewId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to delete entityView relation. Edge Id: [{}]", entityViewId, edgeId);
throw new RuntimeException(e);
}
return entityView;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class EntityViewServiceImpl method assignEntityViewToEdge.
@CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}")
@Override
public EntityView assignEntityViewToEdge(TenantId tenantId, EntityViewId entityViewId, EdgeId edgeId) {
EntityView entityView = findEntityViewById(tenantId, entityViewId);
Edge edge = edgeService.findEdgeById(tenantId, edgeId);
if (edge == null) {
throw new DataValidationException("Can't assign entityView to non-existent edge!");
}
if (!edge.getTenantId().getId().equals(entityView.getTenantId().getId())) {
throw new DataValidationException("Can't assign entityView to edge from different tenant!");
}
try {
Boolean relationExists = relationService.checkRelation(tenantId, edgeId, entityView.getEntityId(), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE).get();
if (!relationExists) {
throw new DataValidationException("Can't assign entity view to edge because related device/asset doesn't assigned to edge!");
}
} catch (ExecutionException | InterruptedException e) {
log.error("Exception during relation check", e);
throw new RuntimeException("Exception during relation check", e);
}
try {
createRelation(tenantId, new EntityRelation(edgeId, entityViewId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to create entityView relation. Edge Id: [{}]", entityViewId, edgeId);
throw new RuntimeException(e);
}
return entityView;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class AbstractEdgeEntity method toEdge.
protected Edge toEdge() {
Edge edge = new Edge(new EdgeId(getUuid()));
edge.setCreatedTime(createdTime);
if (tenantId != null) {
edge.setTenantId(TenantId.fromUUID(tenantId));
}
if (customerId != null) {
edge.setCustomerId(new CustomerId(customerId));
}
if (rootRuleChainId != null) {
edge.setRootRuleChainId(new RuleChainId(rootRuleChainId));
}
edge.setType(type);
edge.setName(name);
edge.setLabel(label);
edge.setRoutingKey(routingKey);
edge.setSecret(secret);
edge.setAdditionalInfo(additionalInfo);
return edge;
}
Aggregations