Commit 44a700e89a6cf783df6e4e6bf681ea33db072497

Authored by YevhenBondarenko
Committed by Andrew Shvayka
1 parent 17457061

rule chain circles validation improvements

... ... @@ -47,8 +47,10 @@ import org.thingsboard.server.dao.tenant.TenantDao;
47 47
48 48 import java.util.ArrayList;
49 49 import java.util.HashMap;
  50 +import java.util.HashSet;
50 51 import java.util.List;
51 52 import java.util.Map;
  53 +import java.util.Set;
52 54 import java.util.concurrent.ExecutionException;
53 55 import java.util.stream.Collectors;
54 56
... ... @@ -212,16 +214,19 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
212 214 }
213 215
214 216 private void validateCircles(List<NodeConnectionInfo> connectionInfos) {
215   - Map<Integer, List<Integer>> connectionsMap = new HashMap<>();
  217 + Map<Integer, Set<Integer>> connectionsMap = new HashMap<>();
216 218 for (NodeConnectionInfo nodeConnection : connectionInfos) {
  219 + if (nodeConnection.getFromIndex() == nodeConnection.getToIndex()) {
  220 + throw new IncorrectParameterException("Can't create the relation to yourself.");
  221 + }
217 222 connectionsMap
218   - .computeIfAbsent(nodeConnection.getFromIndex(), from -> new ArrayList<>())
  223 + .computeIfAbsent(nodeConnection.getFromIndex(), from -> new HashSet<>())
219 224 .add(nodeConnection.getToIndex());
220 225 }
221 226 connectionsMap.keySet().forEach(key -> validateCircles(key, connectionsMap.get(key), connectionsMap));
222 227 }
223 228
224   - private void validateCircles(int from, List<Integer> toList, Map<Integer, List<Integer>> connectionsMap) {
  229 + private void validateCircles(int from, Set<Integer> toList, Map<Integer, Set<Integer>> connectionsMap) {
225 230 if (toList == null) {
226 231 return;
227 232 }
... ...