use of org.thingsboard.server.common.data.id.RuleChainId 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;
}
use of org.thingsboard.server.common.data.id.RuleChainId in project thingsboard by thingsboard.
the class BaseRuleChainServiceTest method testGetDefaultEdgeRuleChains.
@Test
public void testGetDefaultEdgeRuleChains() throws Exception {
RuleChainId ruleChainId = saveRuleChainAndSetAutoAssignToEdge("Default Edge Rule Chain 1");
saveRuleChainAndSetAutoAssignToEdge("Default Edge Rule Chain 2");
PageData<RuleChain> result = ruleChainService.findAutoAssignToEdgeRuleChainsByTenantId(tenantId, new PageLink(100));
Assert.assertEquals(2, result.getData().size());
ruleChainService.unsetAutoAssignToEdgeRuleChain(tenantId, ruleChainId);
result = ruleChainService.findAutoAssignToEdgeRuleChainsByTenantId(tenantId, new PageLink(100));
Assert.assertEquals(1, result.getData().size());
}
use of org.thingsboard.server.common.data.id.RuleChainId in project thingsboard by thingsboard.
the class RuleChainManagerActor method initRuleChains.
protected void initRuleChains() {
for (RuleChain ruleChain : new PageDataIterable<>(link -> ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, link), ContextAwareActor.ENTITY_PACK_LIMIT)) {
RuleChainId ruleChainId = ruleChain.getId();
log.debug("[{}|{}] Creating rule chain actor", ruleChainId.getEntityType(), ruleChain.getId());
TbActorRef actorRef = getOrCreateActor(ruleChainId, id -> ruleChain);
visit(ruleChain, actorRef);
log.debug("[{}|{}] Rule Chain actor created.", ruleChainId.getEntityType(), ruleChainId.getId());
}
}
use of org.thingsboard.server.common.data.id.RuleChainId in project thingsboard by thingsboard.
the class AccessValidator method validateRuleChain.
private void validateRuleChain(final SecurityUser currentUser, Operation operation, EntityId entityId, FutureCallback<ValidationResult> callback) {
if (currentUser.isCustomerUser()) {
callback.onSuccess(ValidationResult.accessDenied(CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION));
} else {
ListenableFuture<RuleChain> ruleChainFuture = ruleChainService.findRuleChainByIdAsync(currentUser.getTenantId(), new RuleChainId(entityId.getId()));
Futures.addCallback(ruleChainFuture, getCallback(callback, ruleChain -> {
if (ruleChain == null) {
return ValidationResult.entityNotFound("Rule chain with requested id wasn't found!");
} else {
try {
accessControlService.checkPermission(currentUser, Resource.RULE_CHAIN, operation, entityId, ruleChain);
} catch (ThingsboardException e) {
return ValidationResult.accessDenied(e.getMessage());
}
return ValidationResult.ok(ruleChain);
}
}), executor);
}
}
use of org.thingsboard.server.common.data.id.RuleChainId in project thingsboard by thingsboard.
the class DefaultTbRuleChainService method getOutputLabelUsage.
@Override
public List<RuleChainOutputLabelsUsage> getOutputLabelUsage(TenantId tenantId, RuleChainId ruleChainId) {
List<RuleNode> ruleNodes = ruleChainService.findRuleNodesByTenantIdAndType(tenantId, TbRuleChainInputNode.class.getName(), ruleChainId.getId().toString());
Map<RuleChainId, String> ruleChainNamesCache = new HashMap<>();
// Additional filter, "just in case" the structure of the JSON configuration will change.
var filteredRuleNodes = ruleNodes.stream().filter(node -> {
try {
TbRuleChainInputNodeConfiguration configuration = JacksonUtil.treeToValue(node.getConfiguration(), TbRuleChainInputNodeConfiguration.class);
return ruleChainId.getId().toString().equals(configuration.getRuleChainId());
} catch (Exception e) {
log.warn("[{}][{}] Failed to decode rule node configuration", tenantId, ruleChainId, e);
return false;
}
}).collect(Collectors.toList());
return filteredRuleNodes.stream().map(ruleNode -> {
RuleChainOutputLabelsUsage usage = new RuleChainOutputLabelsUsage();
usage.setRuleNodeId(ruleNode.getId());
usage.setRuleNodeName(ruleNode.getName());
usage.setRuleChainId(ruleNode.getRuleChainId());
List<EntityRelation> relations = ruleChainService.getRuleNodeRelations(tenantId, ruleNode.getId());
if (relations != null && !relations.isEmpty()) {
usage.setLabels(relations.stream().map(EntityRelation::getType).collect(Collectors.toSet()));
}
return usage;
}).filter(usage -> usage.getLabels() != null).peek(usage -> {
String ruleChainName = ruleChainNamesCache.computeIfAbsent(usage.getRuleChainId(), id -> ruleChainService.findRuleChainById(tenantId, id).getName());
usage.setRuleChainName(ruleChainName);
}).sorted(Comparator.comparing(RuleChainOutputLabelsUsage::getRuleChainName).thenComparing(RuleChainOutputLabelsUsage::getRuleNodeName)).collect(Collectors.toList());
}
Aggregations