Added new relation between rule chains if RuleChainInput node is used
This commit is contained in:
parent
f920010786
commit
f87aa0b142
@ -41,6 +41,7 @@ public class EntityRelation implements HasVersion, Serializable {
|
||||
public static final String EDGE_TYPE = "ManagedByEdge";
|
||||
public static final String CONTAINS_TYPE = "Contains";
|
||||
public static final String MANAGES_TYPE = "Manages";
|
||||
public static final String USES_TYPE = "Uses";
|
||||
|
||||
@Setter
|
||||
private EntityId from;
|
||||
|
||||
@ -71,11 +71,13 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -196,11 +198,18 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RuleChainId ruleChainId = ruleChain.getId();
|
||||
List<RuleNodeUpdateResult> updatedRuleNodes = new ArrayList<>();
|
||||
List<RuleNode> existingRuleNodes = getRuleChainNodes(tenantId, ruleChainMetaData.getRuleChainId());
|
||||
for (RuleNode existingNode : existingRuleNodes) {
|
||||
relationService.deleteEntityRelations(tenantId, existingNode.getId());
|
||||
if (existingNode.getType().equals("org.thingsboard.rule.engine.flow.TbRuleChainInputNode")) {
|
||||
if (existingNode.getConfiguration().has("ruleChainId")) {
|
||||
RuleChainId targetRuleChainId = extractRuleChainIdFromInputNode(existingNode);
|
||||
var relation = createRuleChainInputRelation(ruleChainId, targetRuleChainId);
|
||||
relationService.deleteRelation(tenantId, relation);
|
||||
}
|
||||
}
|
||||
Integer index = ruleNodeIndexMap.get(existingNode.getId());
|
||||
RuleNode newRuleNode = null;
|
||||
if (index != null) {
|
||||
@ -212,7 +221,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
||||
}
|
||||
updatedRuleNodes.add(new RuleNodeUpdateResult(existingNode, newRuleNode));
|
||||
}
|
||||
RuleChainId ruleChainId = ruleChain.getId();
|
||||
|
||||
if (nodes != null) {
|
||||
long now = System.currentTimeMillis();
|
||||
for (RuleNode node : toAddOrUpdate) {
|
||||
@ -225,6 +234,13 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
||||
RuleNode savedNode = ruleNodeDao.save(tenantId, node);
|
||||
relations.add(new EntityRelation(ruleChainMetaData.getRuleChainId(), savedNode.getId(),
|
||||
EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN));
|
||||
if (node.getType().equals("org.thingsboard.rule.engine.flow.TbRuleChainInputNode")) {
|
||||
if (node.getConfiguration().has("ruleChainId")) {
|
||||
RuleChainId targetRuleChainId = extractRuleChainIdFromInputNode(node);
|
||||
var relation = createRuleChainInputRelation(ruleChainId, targetRuleChainId);
|
||||
relations.add(relation);
|
||||
}
|
||||
}
|
||||
int index = nodes.indexOf(node);
|
||||
nodes.set(index, savedNode);
|
||||
ruleNodeIndexMap.put(savedNode.getId(), index);
|
||||
@ -295,6 +311,21 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
||||
return RuleChainUpdateResult.successful(updatedRuleNodes);
|
||||
}
|
||||
|
||||
private EntityRelation createRuleChainInputRelation(RuleChainId ruleChainId, RuleChainId targetRuleChainId) {
|
||||
EntityRelation relation = new EntityRelation();
|
||||
relation.setFrom(ruleChainId);
|
||||
relation.setTo(targetRuleChainId);
|
||||
relation.setType(EntityRelation.USES_TYPE);
|
||||
relation.setTypeGroup(RelationTypeGroup.COMMON);
|
||||
return relation;
|
||||
}
|
||||
|
||||
private RuleChainId extractRuleChainIdFromInputNode(RuleNode node) {
|
||||
JsonNode configuration = node.getConfiguration();
|
||||
UUID targetUuid = UUID.fromString(configuration.get("ruleChainId").asText());
|
||||
return new RuleChainId(targetUuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleChainMetaData loadRuleChainMetaData(TenantId tenantId, RuleChainId ruleChainId) {
|
||||
Validator.validateId(ruleChainId, "Incorrect rule chain id.");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user