use of org.thingsboard.server.common.data.rule.RuleNode in project thingsboard by thingsboard.
the class BaseController method checkRuleNode.
protected RuleNode checkRuleNode(RuleNodeId ruleNodeId, Operation operation) throws ThingsboardException {
validateId(ruleNodeId, "Incorrect ruleNodeId " + ruleNodeId);
RuleNode ruleNode = ruleChainService.findRuleNodeById(getTenantId(), ruleNodeId);
checkNotNull(ruleNode, "Rule node with id [" + ruleNodeId + "] is not found");
checkRuleChain(ruleNode.getRuleChainId(), operation);
return ruleNode;
}
use of org.thingsboard.server.common.data.rule.RuleNode in project thingsboard by thingsboard.
the class MqttClientTest method createRootRuleChainForRpcResponse.
private RuleChainId createRootRuleChainForRpcResponse() throws Exception {
RuleChain newRuleChain = new RuleChain();
newRuleChain.setName("testRuleChain");
ResponseEntity<RuleChain> ruleChainResponse = restClient.getRestTemplate().postForEntity(HTTPS_URL + "/api/ruleChain", newRuleChain, RuleChain.class);
Assert.assertTrue(ruleChainResponse.getStatusCode().is2xxSuccessful());
RuleChain ruleChain = ruleChainResponse.getBody();
JsonNode configuration = mapper.readTree(this.getClass().getClassLoader().getResourceAsStream("RpcResponseRuleChainMetadata.json"));
RuleChainMetaData ruleChainMetaData = new RuleChainMetaData();
ruleChainMetaData.setRuleChainId(ruleChain.getId());
ruleChainMetaData.setFirstNodeIndex(configuration.get("firstNodeIndex").asInt());
ruleChainMetaData.setNodes(Arrays.asList(mapper.treeToValue(configuration.get("nodes"), RuleNode[].class)));
ruleChainMetaData.setConnections(Arrays.asList(mapper.treeToValue(configuration.get("connections"), NodeConnectionInfo[].class)));
ResponseEntity<RuleChainMetaData> ruleChainMetadataResponse = restClient.getRestTemplate().postForEntity(HTTPS_URL + "/api/ruleChain/metadata", ruleChainMetaData, RuleChainMetaData.class);
Assert.assertTrue(ruleChainMetadataResponse.getStatusCode().is2xxSuccessful());
// Set a new rule chain as root
ResponseEntity<RuleChain> rootRuleChainResponse = restClient.getRestTemplate().postForEntity(HTTPS_URL + "/api/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChain.getId());
Assert.assertTrue(rootRuleChainResponse.getStatusCode().is2xxSuccessful());
return ruleChain.getId();
}
use of org.thingsboard.server.common.data.rule.RuleNode in project thingsboard by thingsboard.
the class BaseRuleChainService method resetRuleChainMetadataTenantIds.
private void resetRuleChainMetadataTenantIds(TenantId tenantId, List<RuleChainMetaData> metaData) {
for (RuleChainMetaData md : metaData) {
for (RuleNode node : md.getNodes()) {
JsonNode nodeConfiguration = node.getConfiguration();
searchTenantIdRecursive(tenantId, nodeConfiguration);
}
}
}
use of org.thingsboard.server.common.data.rule.RuleNode in project thingsboard by thingsboard.
the class BaseRuleChainService method getReferencingRuleChainNodes.
@Override
public List<RuleNode> getReferencingRuleChainNodes(TenantId tenantId, RuleChainId ruleChainId) {
Validator.validateId(ruleChainId, "Incorrect rule chain id for search request.");
List<EntityRelation> relations = getNodeToRuleChainRelations(tenantId, ruleChainId);
List<RuleNode> ruleNodes = new ArrayList<>();
for (EntityRelation relation : relations) {
RuleNode ruleNode = ruleNodeDao.findById(tenantId, relation.getFrom().getId());
if (ruleNode != null) {
ruleNodes.add(ruleNode);
}
}
return ruleNodes;
}
use of org.thingsboard.server.common.data.rule.RuleNode in project thingsboard by thingsboard.
the class BaseRuleChainService method loadRuleChainMetaData.
@Override
public RuleChainMetaData loadRuleChainMetaData(TenantId tenantId, RuleChainId ruleChainId) {
Validator.validateId(ruleChainId, "Incorrect rule chain id.");
RuleChain ruleChain = findRuleChainById(tenantId, ruleChainId);
if (ruleChain == null) {
return null;
}
RuleChainMetaData ruleChainMetaData = new RuleChainMetaData();
ruleChainMetaData.setRuleChainId(ruleChainId);
List<RuleNode> ruleNodes = getRuleChainNodes(tenantId, ruleChainId);
Map<RuleNodeId, Integer> ruleNodeIndexMap = new HashMap<>();
for (RuleNode node : ruleNodes) {
ruleNodeIndexMap.put(node.getId(), ruleNodes.indexOf(node));
}
ruleChainMetaData.setNodes(ruleNodes);
if (ruleChain.getFirstRuleNodeId() != null) {
ruleChainMetaData.setFirstNodeIndex(ruleNodeIndexMap.get(ruleChain.getFirstRuleNodeId()));
}
for (RuleNode node : ruleNodes) {
int fromIndex = ruleNodeIndexMap.get(node.getId());
List<EntityRelation> nodeRelations = getRuleNodeRelations(tenantId, node.getId());
for (EntityRelation nodeRelation : nodeRelations) {
String type = nodeRelation.getType();
if (nodeRelation.getTo().getEntityType() == EntityType.RULE_NODE) {
RuleNodeId toNodeId = new RuleNodeId(nodeRelation.getTo().getId());
int toIndex = ruleNodeIndexMap.get(toNodeId);
ruleChainMetaData.addConnectionInfo(fromIndex, toIndex, type);
} else if (nodeRelation.getTo().getEntityType() == EntityType.RULE_CHAIN) {
log.warn("[{}][{}] Unsupported node relation: {}", tenantId, ruleChainId, nodeRelation.getTo());
}
}
}
return ruleChainMetaData;
}
Aggregations