diff --git a/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java b/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java index d4e240485..e0288988c 100644 --- a/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java +++ b/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java @@ -194,7 +194,7 @@ public void validate(DwrResponseI18n response, int dataPointId) { .stream() .collect(Collectors.toMap(DataPointVO::getId, Function.identity())); - List varNameSpace = new ArrayList(); + List varNameSpace = new ArrayList<>(); for (IntValuePair point : context) { String varName = point.getValue(); int pointId = point.getKey(); diff --git a/src/org/scada_lts/utils/ValidationUtils.java b/src/org/scada_lts/utils/ValidationUtils.java index a34acb0b2..013f76c60 100644 --- a/src/org/scada_lts/utils/ValidationUtils.java +++ b/src/org/scada_lts/utils/ValidationUtils.java @@ -135,29 +135,29 @@ public static void checkIfNonAdminThenUnauthorized(HttpServletRequest request) { } } - public static boolean isCyclicDependency(int starDataPointId, int checkDataPointId, Map dataPoints, int safe) { + public static boolean isCyclicDependency(int starDataPointId, int findDataPointId, Map dataPoints, int safe) { + if(starDataPointId == findDataPointId) { + return true; + } if(safe < 0) { return false; } - if(starDataPointId == checkDataPointId) { - return true; - } DataPointVO dataPoint = dataPoints.get(starDataPointId); PointLocatorVO pointLocator = dataPoint.getPointLocator(); if(pointLocator instanceof MetaPointLocatorVO) { MetaPointLocatorVO metaPointLocator = (MetaPointLocatorVO) pointLocator; - List pairs = metaPointLocator.getContext(); - if (pairs.isEmpty()) { + List context = metaPointLocator.getContext(); + if (context == null || context.isEmpty()) { return false; } - for(IntValuePair pair: pairs) { - int id = pair.getKey(); - if(id == checkDataPointId) { - return true; - } else { - DataPointVO dp = dataPoints.get(id); - if(dp.getPointLocator() instanceof MetaPointLocatorVO) { - return isCyclicDependency(id, checkDataPointId, dataPoints, --safe); + for (IntValuePair keyValue : context) { + int contextDataPointId = keyValue.getKey(); + DataPointVO contextDataPoint = dataPoints.get(contextDataPointId); + if(contextDataPoint.getPointLocator() instanceof MetaPointLocatorVO) { + if (contextDataPointId == findDataPointId) { + return true; + } else { + return isCyclicDependency(contextDataPointId, findDataPointId, dataPoints, --safe); } } } diff --git a/test/org/scada_lts/utils/CyclicDependencyValidationUtilsTest.java b/test/org/scada_lts/utils/CyclicDependencyValidationUtilsTest.java index dd26b09b1..503e17925 100644 --- a/test/org/scada_lts/utils/CyclicDependencyValidationUtilsTest.java +++ b/test/org/scada_lts/utils/CyclicDependencyValidationUtilsTest.java @@ -16,7 +16,7 @@ @RunWith(Parameterized.class) public class CyclicDependencyValidationUtilsTest { - @Parameterized.Parameters(name = "{index}: starDataPointId: {0}, checkDataPointId: {1}, cyclicDependency: {2}") + @Parameterized.Parameters(name = "{index}: starDataPointId: {0}, findDataPointId: {1}, cyclicDependency: {2}") public static Object[][] data() { return new Object[][] { { 1, 1, true }, @@ -58,12 +58,12 @@ public static Object[][] data() { }; } private final int starDataPointId; - private final int checkDataPointId; + private final int findDataPointId; private final boolean cyclicDependencyExpected; - public CyclicDependencyValidationUtilsTest(int starDataPointId, int checkDataPointId, boolean cyclicDependency) { + public CyclicDependencyValidationUtilsTest(int starDataPointId, int findDataPointId, boolean cyclicDependency) { this.starDataPointId = starDataPointId; - this.checkDataPointId = checkDataPointId; + this.findDataPointId = findDataPointId; this.cyclicDependencyExpected = cyclicDependency; } @@ -107,7 +107,7 @@ public static void config() { public void when_isCyclicDependency() { //when: - boolean cyclicDependencyResult = ValidationUtils.isCyclicDependency(starDataPointId, checkDataPointId, DATA_POINTS, 10); + boolean cyclicDependencyResult = ValidationUtils.isCyclicDependency(starDataPointId, findDataPointId, DATA_POINTS, 10); //then: Assert.assertEquals(cyclicDependencyExpected, cyclicDependencyResult);