use of org.thingsboard.server.common.data.rule.RuleChain in project thingsboard by thingsboard.
the class EdgeServiceImpl method findMissingToRelatedRuleChains.
@Override
public String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId) {
List<RuleChain> edgeRuleChains = findEdgeRuleChains(tenantId, edgeId);
List<RuleChainId> edgeRuleChainIds = edgeRuleChains.stream().map(IdBased::getId).collect(Collectors.toList());
ObjectNode result = mapper.createObjectNode();
for (RuleChain edgeRuleChain : edgeRuleChains) {
List<RuleChainConnectionInfo> connectionInfos = ruleChainService.loadRuleChainMetaData(edgeRuleChain.getTenantId(), edgeRuleChain.getId()).getRuleChainConnections();
if (connectionInfos != null && !connectionInfos.isEmpty()) {
List<RuleChainId> connectedRuleChains = connectionInfos.stream().map(RuleChainConnectionInfo::getTargetRuleChainId).collect(Collectors.toList());
List<String> missingRuleChains = new ArrayList<>();
for (RuleChainId connectedRuleChain : connectedRuleChains) {
if (!edgeRuleChainIds.contains(connectedRuleChain)) {
RuleChain ruleChainById = ruleChainService.findRuleChainById(tenantId, connectedRuleChain);
missingRuleChains.add(ruleChainById.getName());
}
}
if (!missingRuleChains.isEmpty()) {
ArrayNode array = mapper.createArrayNode();
for (String missingRuleChain : missingRuleChains) {
array.add(missingRuleChain);
}
result.set(edgeRuleChain.getName(), array);
}
}
}
return result.toString();
}
use of org.thingsboard.server.common.data.rule.RuleChain in project thingsboard by thingsboard.
the class EdgeServiceImpl method findEdgeRuleChains.
private List<RuleChain> findEdgeRuleChains(TenantId tenantId, EdgeId edgeId) {
List<RuleChain> result = new ArrayList<>();
PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
PageData<RuleChain> pageData;
do {
pageData = ruleChainService.findRuleChainsByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
result.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
}
} while (pageData != null && pageData.hasNext());
return result;
}
use of org.thingsboard.server.common.data.rule.RuleChain 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.rule.RuleChain in project thingsboard by thingsboard.
the class BaseRuleChainServiceTest method testDeleteRuleChain.
@Test
public void testDeleteRuleChain() {
RuleChain ruleChain = new RuleChain();
ruleChain.setTenantId(tenantId);
ruleChain.setName("My RuleChain");
RuleChain savedRuleChain = ruleChainService.saveRuleChain(ruleChain);
RuleChain foundRuleChain = ruleChainService.findRuleChainById(tenantId, savedRuleChain.getId());
Assert.assertNotNull(foundRuleChain);
ruleChainService.deleteRuleChainById(tenantId, savedRuleChain.getId());
foundRuleChain = ruleChainService.findRuleChainById(tenantId, savedRuleChain.getId());
Assert.assertNull(foundRuleChain);
}
use of org.thingsboard.server.common.data.rule.RuleChain in project thingsboard by thingsboard.
the class BaseRuleChainServiceTest method testSaveRuleChainWithEmptyName.
@Test(expected = DataValidationException.class)
public void testSaveRuleChainWithEmptyName() {
RuleChain ruleChain = new RuleChain();
ruleChain.setTenantId(tenantId);
ruleChainService.saveRuleChain(ruleChain);
}
Aggregations