diff --git a/build.gradle b/build.gradle index 711ec0d32b..aa73543092 100644 --- a/build.gradle +++ b/build.gradle @@ -244,6 +244,7 @@ test { includeTestsMatching "org.scada_lts.web.security.XssUtilsTestsSuite" includeTestsMatching "org.scada_lts.web.mvc.api.validation.css.CssValidatorTestsSuite" includeTestsMatching "org.scada_lts.web.beans.validation.xss.XssValidatorTestsSuite" + includeTestsMatching "org.scada_lts.utils.CyclicDependencyValidationUtilsTest" } failFast = true diff --git a/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java b/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java index 8cd77cdb44..e0288988c9 100644 --- a/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java +++ b/src/com/serotonin/mango/vo/dataSource/meta/MetaPointLocatorVO.java @@ -21,10 +21,9 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; import com.serotonin.db.IntValuePair; import com.serotonin.json.JsonArray; @@ -47,13 +46,16 @@ import com.serotonin.mango.vo.DataPointVO; import com.serotonin.mango.vo.dataSource.AbstractPointLocatorVO; import com.serotonin.mango.vo.TimePeriodType; +import com.serotonin.mango.vo.dataSource.PointLocatorVO; import com.serotonin.timer.CronTimerTrigger; import com.serotonin.util.SerializationHelper; import com.serotonin.util.StringUtils; import com.serotonin.web.dwr.DwrResponseI18n; import com.serotonin.web.i18n.LocalizableMessage; +import org.scada_lts.mango.service.DataPointService; import static org.scada_lts.utils.ValidationDwrUtils.validateVarNameScript; +import static org.scada_lts.utils.ValidationUtils.isCyclicDependency; import static org.scada_lts.web.security.XssProtectUtils.escapeHtml; /** @@ -187,11 +189,21 @@ public void validate(DwrResponseI18n response, int dataPointId) { if (StringUtils.isEmpty(script)) response.addContextualMessage("script", "validate.required"); - List varNameSpace = new ArrayList(); + DataPointService dataPointService = new DataPointService(); + Map dataPoints = dataPointService.getDataPoints(null, true) + .stream() + .collect(Collectors.toMap(DataPointVO::getId, Function.identity())); + + List varNameSpace = new ArrayList<>(); for (IntValuePair point : context) { String varName = point.getValue(); int pointId = point.getKey(); + if(pointId != Common.NEW_ID && isCyclicDependency(pointId, dataPointId, dataPoints, 10)) { + response.addContextualMessage("context", "validate.cyclicDependency", escapeHtml(varName)); + break; + } + if(pointId != Common.NEW_ID && pointId == dataPointId) { response.addContextualMessage("context", "validate.invalidVariable", escapeHtml(varName)); break; diff --git a/src/org/scada_lts/mango/service/DataPointService.java b/src/org/scada_lts/mango/service/DataPointService.java index 8ada7ca949..758ee59c8e 100644 --- a/src/org/scada_lts/mango/service/DataPointService.java +++ b/src/org/scada_lts/mango/service/DataPointService.java @@ -254,27 +254,6 @@ public List valuesPointBooleanBaseOnNameFilter2DTO(Map dataPoints, int safe) { + if(starDataPointId == findDataPointId) { + return true; + } + if(safe < 0) { + return false; + } + DataPointVO dataPoint = dataPoints.get(starDataPointId); + PointLocatorVO pointLocator = dataPoint.getPointLocator(); + if(pointLocator instanceof MetaPointLocatorVO) { + MetaPointLocatorVO metaPointLocator = (MetaPointLocatorVO) pointLocator; + List context = metaPointLocator.getContext(); + if (context == null || context.isEmpty()) { + return false; + } + 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); + } + } + } + } + return false; + } } diff --git a/test/br/org/scadabr/db/dao/UsersProfileDaoTest.java b/test/br/org/scadabr/db/dao/UsersProfileDaoTest.java index b37225142d..94cbf39b4f 100644 --- a/test/br/org/scadabr/db/dao/UsersProfileDaoTest.java +++ b/test/br/org/scadabr/db/dao/UsersProfileDaoTest.java @@ -17,7 +17,7 @@ import br.org.scadabr.db.dao.mocks.MockViewDao; import br.org.scadabr.db.dao.mocks.MockWatchlistDao; import br.org.scadabr.db.scenarios.DatalessDatabaseScenario; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import br.org.scadabr.vo.permission.ViewAccess; import br.org.scadabr.vo.permission.WatchListAccess; import br.org.scadabr.vo.usersProfiles.UsersProfileVO; diff --git a/test/br/org/scadabr/vo/importer/UsersProfileImporterTest.java b/test/br/org/scadabr/vo/importer/UsersProfileImporterTest.java index 19306d9f49..942206ffe6 100644 --- a/test/br/org/scadabr/vo/importer/UsersProfileImporterTest.java +++ b/test/br/org/scadabr/vo/importer/UsersProfileImporterTest.java @@ -18,7 +18,7 @@ import br.org.scadabr.db.dao.mocks.MockViewDao; import br.org.scadabr.db.dao.mocks.MockWatchlistDao; import br.org.scadabr.db.scenarios.DatalessDatabaseScenario; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import br.org.scadabr.vo.permission.ViewAccess; import br.org.scadabr.vo.permission.WatchListAccess; import br.org.scadabr.vo.usersProfiles.UsersProfileVO; diff --git a/test/br/org/scadabr/vo/usersProfiles/UsersProfileVOTest.java b/test/br/org/scadabr/vo/usersProfiles/UsersProfileVOTest.java index a14291228f..93e590c49d 100644 --- a/test/br/org/scadabr/vo/usersProfiles/UsersProfileVOTest.java +++ b/test/br/org/scadabr/vo/usersProfiles/UsersProfileVOTest.java @@ -16,7 +16,7 @@ import br.org.scadabr.db.dao.mocks.MockDataSourceDao; import br.org.scadabr.db.dao.mocks.MockViewDao; import br.org.scadabr.db.dao.mocks.MockWatchlistDao; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import br.org.scadabr.vo.permission.ViewAccess; import br.org.scadabr.vo.permission.WatchListAccess; diff --git a/test/com/serotonin/mango/rt/dataImage/datapointrt/config/ConfigDataPointRtTest.java b/test/com/serotonin/mango/rt/dataImage/datapointrt/config/ConfigDataPointRtTest.java index 32c998c8d5..9e99bdcef8 100644 --- a/test/com/serotonin/mango/rt/dataImage/datapointrt/config/ConfigDataPointRtTest.java +++ b/test/com/serotonin/mango/rt/dataImage/datapointrt/config/ConfigDataPointRtTest.java @@ -1,6 +1,6 @@ package com.serotonin.mango.rt.dataImage.datapointrt.config; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.Common; import com.serotonin.mango.db.dao.DataPointDao; import com.serotonin.mango.db.dao.DataSourceDao; diff --git a/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java b/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java index 167ebcd17a..fc30139363 100644 --- a/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java +++ b/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java @@ -1,6 +1,6 @@ package com.serotonin.mango.rt.dataSource; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.db.IntValuePair; import com.serotonin.mango.Common; import com.serotonin.mango.db.dao.DataPointDao; diff --git a/test/com/serotonin/mango/util/AbstractStartStopDataPointsUtilsTest.java b/test/com/serotonin/mango/util/AbstractStartStopDataPointsUtilsTest.java index f1431d9638..d28d6f0897 100644 --- a/test/com/serotonin/mango/util/AbstractStartStopDataPointsUtilsTest.java +++ b/test/com/serotonin/mango/util/AbstractStartStopDataPointsUtilsTest.java @@ -1,6 +1,6 @@ package com.serotonin.mango.util; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.rt.dataSource.DataSourceRT; import com.serotonin.mango.vo.DataPointVO; import com.serotonin.mango.vo.dataSource.meta.MetaPointLocatorVO; diff --git a/test/com/serotonin/mango/vo/LoggedUsersMultiThreadTest.java b/test/com/serotonin/mango/vo/LoggedUsersMultiThreadTest.java index 9699286d63..b4fd5fe046 100644 --- a/test/com/serotonin/mango/vo/LoggedUsersMultiThreadTest.java +++ b/test/com/serotonin/mango/vo/LoggedUsersMultiThreadTest.java @@ -1,7 +1,6 @@ package com.serotonin.mango.vo; -import br.org.scadabr.db.utils.TestUtils; -import org.junit.After; +import utils.TestUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/test/com/serotonin/mango/vo/LoggedUsersTest.java b/test/com/serotonin/mango/vo/LoggedUsersTest.java index b44bc49113..9606708858 100644 --- a/test/com/serotonin/mango/vo/LoggedUsersTest.java +++ b/test/com/serotonin/mango/vo/LoggedUsersTest.java @@ -1,7 +1,6 @@ package com.serotonin.mango.vo; -import br.org.scadabr.db.utils.TestUtils; -import org.junit.After; +import utils.TestUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -13,7 +12,6 @@ import org.scada_lts.login.LoggedUsers; import org.scada_lts.web.beans.ApplicationBeans; import org.springframework.mock.web.MockHttpSession; -import utils.TestConcurrentUtils; import javax.servlet.http.HttpSession; import java.util.*; diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java index 120c0bc3fd..8cd78c5f16 100644 --- a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java @@ -10,7 +10,7 @@ import java.util.List; import java.util.stream.Collectors; -import static br.org.scadabr.db.utils.TestUtils.*; +import static utils.TestUtils.*; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java index fbf0525654..0656237a76 100644 --- a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java @@ -6,7 +6,7 @@ import java.util.List; -import static br.org.scadabr.db.utils.TestUtils.*; +import static utils.TestUtils.*; @RunWith(Parameterized.class) public class CalculateLinesImageChartUtilsExceptionTest { diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java index d68052ff33..120ae4bf05 100644 --- a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.List; -import static br.org.scadabr.db.utils.TestUtils.*; +import static utils.TestUtils.*; import static org.junit.Assert.assertEquals; @RunWith(Parameterized.class) diff --git a/test/org/scada_lts/dao/PointValueDAOTest.java b/test/org/scada_lts/dao/PointValueDAOTest.java index 92474d024b..0197dfede2 100644 --- a/test/org/scada_lts/dao/PointValueDAOTest.java +++ b/test/org/scada_lts/dao/PointValueDAOTest.java @@ -1,9 +1,8 @@ package org.scada_lts.dao; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.rt.dataImage.AnnotatedPointValueTime; import com.serotonin.mango.vo.User; -import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/test/org/scada_lts/ds/messaging/channel/MessagingChannelsMultiThreadTest.java b/test/org/scada_lts/ds/messaging/channel/MessagingChannelsMultiThreadTest.java index 77e3e1f700..667825bcf0 100644 --- a/test/org/scada_lts/ds/messaging/channel/MessagingChannelsMultiThreadTest.java +++ b/test/org/scada_lts/ds/messaging/channel/MessagingChannelsMultiThreadTest.java @@ -1,6 +1,6 @@ package org.scada_lts.ds.messaging.channel; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.rt.dataImage.DataPointRT; import com.serotonin.mango.vo.DataPointVO; import org.junit.Assert; diff --git a/test/org/scada_lts/ds/messaging/channel/MessagingChannelsTest.java b/test/org/scada_lts/ds/messaging/channel/MessagingChannelsTest.java index d3a52b680c..a23e20bdcc 100644 --- a/test/org/scada_lts/ds/messaging/channel/MessagingChannelsTest.java +++ b/test/org/scada_lts/ds/messaging/channel/MessagingChannelsTest.java @@ -1,14 +1,11 @@ package org.scada_lts.ds.messaging.channel; -import br.org.scadabr.db.utils.TestUtils; import com.serotonin.mango.rt.dataImage.DataPointRT; -import com.serotonin.mango.vo.DataPointVO; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import utils.mock.MockUtils; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; diff --git a/test/org/scada_lts/mango/service/UsersProfileServiceTest.java b/test/org/scada_lts/mango/service/UsersProfileServiceTest.java index ca57a0b010..dd6cfe466d 100644 --- a/test/org/scada_lts/mango/service/UsersProfileServiceTest.java +++ b/test/org/scada_lts/mango/service/UsersProfileServiceTest.java @@ -1,6 +1,6 @@ package org.scada_lts.mango.service; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import br.org.scadabr.vo.permission.ViewAccess; import br.org.scadabr.vo.permission.WatchListAccess; import br.org.scadabr.vo.usersProfiles.UsersProfileVO; diff --git a/test/org/scada_lts/permissions/migration/DataPointMigrationPermissionsCommandTest.java b/test/org/scada_lts/permissions/migration/DataPointMigrationPermissionsCommandTest.java index 77b9934d14..ad6ece5eb6 100644 --- a/test/org/scada_lts/permissions/migration/DataPointMigrationPermissionsCommandTest.java +++ b/test/org/scada_lts/permissions/migration/DataPointMigrationPermissionsCommandTest.java @@ -1,6 +1,6 @@ package org.scada_lts.permissions.migration; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import br.org.scadabr.vo.permission.ViewAccess; import br.org.scadabr.vo.permission.WatchListAccess; import br.org.scadabr.vo.usersProfiles.UsersProfileVO; diff --git a/test/org/scada_lts/permissions/migration/DataSourceMigrationPermissionsCommandTest.java b/test/org/scada_lts/permissions/migration/DataSourceMigrationPermissionsCommandTest.java index afd87d27cc..9471597483 100644 --- a/test/org/scada_lts/permissions/migration/DataSourceMigrationPermissionsCommandTest.java +++ b/test/org/scada_lts/permissions/migration/DataSourceMigrationPermissionsCommandTest.java @@ -1,6 +1,6 @@ package org.scada_lts.permissions.migration; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import br.org.scadabr.vo.permission.ViewAccess; import br.org.scadabr.vo.permission.WatchListAccess; import br.org.scadabr.vo.usersProfiles.UsersProfileVO; diff --git a/test/org/scada_lts/permissions/migration/MigrationPermissionsUtilsTest.java b/test/org/scada_lts/permissions/migration/MigrationPermissionsUtilsTest.java index 0ca753b075..cafd549df4 100644 --- a/test/org/scada_lts/permissions/migration/MigrationPermissionsUtilsTest.java +++ b/test/org/scada_lts/permissions/migration/MigrationPermissionsUtilsTest.java @@ -1,6 +1,6 @@ package org.scada_lts.permissions.migration; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import br.org.scadabr.vo.usersProfiles.UsersProfileVO; import com.serotonin.mango.view.ShareUser; import com.serotonin.mango.view.View; diff --git a/test/org/scada_lts/permissions/service/util/UpdateDataPointUserPermissionsTest.java b/test/org/scada_lts/permissions/service/util/UpdateDataPointUserPermissionsTest.java index 051519a3de..f8050e5f1c 100644 --- a/test/org/scada_lts/permissions/service/util/UpdateDataPointUserPermissionsTest.java +++ b/test/org/scada_lts/permissions/service/util/UpdateDataPointUserPermissionsTest.java @@ -1,6 +1,6 @@ package org.scada_lts.permissions.service.util; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.vo.User; import com.serotonin.mango.vo.permission.DataPointAccess; import org.junit.Test; diff --git a/test/org/scada_lts/permissions/service/util/UpdateDataSourceUserPermissionsTest.java b/test/org/scada_lts/permissions/service/util/UpdateDataSourceUserPermissionsTest.java index ecec676bfe..4258f03965 100644 --- a/test/org/scada_lts/permissions/service/util/UpdateDataSourceUserPermissionsTest.java +++ b/test/org/scada_lts/permissions/service/util/UpdateDataSourceUserPermissionsTest.java @@ -1,6 +1,6 @@ package org.scada_lts.permissions.service.util; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.vo.User; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java index 07792e276e..ce5d2ced81 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java @@ -7,7 +7,7 @@ import java.util.Arrays; import java.util.Collection; -import static br.org.scadabr.db.utils.TestUtils.*; +import static utils.TestUtils.*; @RunWith(Parameterized.class) public class TruncateStringUtilsExceptionTest { diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java index 46b0415e2c..67a02cb945 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java @@ -7,7 +7,7 @@ import java.util.Arrays; import java.util.Collection; -import static br.org.scadabr.db.utils.TestUtils.*; +import static utils.TestUtils.*; import static org.junit.Assert.*; @RunWith(Parameterized.class) diff --git a/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyByKeyTest.java b/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyByKeyTest.java index bbc500e108..b1eb72bef9 100644 --- a/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyByKeyTest.java +++ b/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyByKeyTest.java @@ -1,6 +1,6 @@ package org.scada_lts.service.pointhierarchy; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.view.ShareUser; import com.serotonin.mango.vo.DataPointVO; import com.serotonin.mango.vo.User; @@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.scada_lts.permissions.migration.MigrationPermissionsUtils.generateDataPointAccess; -import static org.scada_lts.utils.PointHierarchyUtils.sort; public class GetPointHierarchyByKeyTest { diff --git a/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyRootTest.java b/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyRootTest.java index a52fd81e0e..aacea81fc3 100644 --- a/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyRootTest.java +++ b/test/org/scada_lts/service/pointhierarchy/GetPointHierarchyRootTest.java @@ -1,6 +1,6 @@ package org.scada_lts.service.pointhierarchy; -import br.org.scadabr.db.utils.TestUtils; +import utils.TestUtils; import com.serotonin.mango.view.ShareUser; import com.serotonin.mango.vo.DataPointVO; import com.serotonin.mango.vo.User; @@ -13,7 +13,6 @@ import org.scada_lts.dao.HierarchyDAO; import org.scada_lts.dao.model.pointhierarchy.PointHierarchyNode; import org.scada_lts.dao.pointhierarchy.PointHierarchyXidDAO; -import org.scada_lts.utils.PointHierarchyUtils; import java.util.ArrayList; import java.util.Arrays; diff --git a/test/org/scada_lts/utils/CyclicDependencyValidationUtilsTest.java b/test/org/scada_lts/utils/CyclicDependencyValidationUtilsTest.java new file mode 100644 index 0000000000..503e179251 --- /dev/null +++ b/test/org/scada_lts/utils/CyclicDependencyValidationUtilsTest.java @@ -0,0 +1,115 @@ +package org.scada_lts.utils; + +import com.serotonin.db.IntValuePair; +import org.junit.BeforeClass; +import utils.TestUtils; +import com.serotonin.mango.vo.DataPointVO; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@RunWith(Parameterized.class) +public class CyclicDependencyValidationUtilsTest { + + @Parameterized.Parameters(name = "{index}: starDataPointId: {0}, findDataPointId: {1}, cyclicDependency: {2}") + public static Object[][] data() { + return new Object[][] { + { 1, 1, true }, + { 2, 1, false }, + { 3, 1, false }, + { 4, 1, false }, + { 5, 1, false }, + { 6, 1, false }, + { 1, 2, true }, + { 2, 2, true }, + { 3, 2, true }, + { 4, 2, true }, + { 5, 2, false }, + { 6, 2, false }, + { 1, 3, true }, + { 2, 3, true }, + { 3, 3, true }, + { 4, 3, true }, + { 5, 3, false }, + { 6, 3, false }, + { 1, 4, true }, + { 2, 4, true }, + { 3, 4, true }, + { 4, 4, true }, + { 5, 4, false }, + { 6, 4, false }, + { 1, 5, false }, + { 2, 5, false }, + { 3, 5, false }, + { 4, 5, false }, + { 5, 5, true }, + { 6, 5, true }, + { 1, 6, false }, + { 2, 6, false }, + { 3, 6, false }, + { 4, 6, false }, + { 5, 6, false }, + { 6, 6, true } + }; + } + private final int starDataPointId; + private final int findDataPointId; + private final boolean cyclicDependencyExpected; + + public CyclicDependencyValidationUtilsTest(int starDataPointId, int findDataPointId, boolean cyclicDependency) { + this.starDataPointId = starDataPointId; + this.findDataPointId = findDataPointId; + this.cyclicDependencyExpected = cyclicDependency; + } + + private static Map DATA_POINTS; + + @BeforeClass + public static void config() { + List context1 = new ArrayList<>(); + context1.add(new IntValuePair(2, "p2")); + context1.add(new IntValuePair(3, "p3")); + context1.add(new IntValuePair(4, "p4")); + + List context2 = new ArrayList<>(); + context2.add(new IntValuePair(3, "p3")); + + List context3 = new ArrayList<>(); + context3.add(new IntValuePair(4, "p4")); + + List context4 = new ArrayList<>(); + context4.add(new IntValuePair(2, "p2")); + + List context5 = new ArrayList<>(); + context5.add(new IntValuePair(5, "p5")); + + DataPointVO dataPoint1 = TestUtils.newMetaPointSettable(1, -1, context1); + DataPointVO dataPoint2 = TestUtils.newMetaPointSettable(2, -1, context2); + DataPointVO dataPoint3 = TestUtils.newMetaPointSettable(3, -1, context3); + DataPointVO dataPoint4 = TestUtils.newMetaPointSettable(4, -1, context4); + DataPointVO dataPoint5 = TestUtils.newMetaPointSettable(5, -1, new ArrayList<>()); + DataPointVO dataPoint6 = TestUtils.newMetaPointSettable(6, -1, context5); + + DATA_POINTS = Map.of(dataPoint1.getId(), dataPoint1, + dataPoint2.getId(), dataPoint2, + dataPoint3.getId(), dataPoint3, + dataPoint4.getId(), dataPoint4, + dataPoint5.getId(), dataPoint5, + dataPoint6.getId(), dataPoint6); + } + + @Test + public void when_isCyclicDependency() { + + //when: + boolean cyclicDependencyResult = ValidationUtils.isCyclicDependency(starDataPointId, findDataPointId, DATA_POINTS, 10); + + //then: + Assert.assertEquals(cyclicDependencyExpected, cyclicDependencyResult); + } +} \ No newline at end of file diff --git a/test/br/org/scadabr/db/utils/TestUtils.java b/test/utils/TestUtils.java similarity index 89% rename from test/br/org/scadabr/db/utils/TestUtils.java rename to test/utils/TestUtils.java index 1818966727..2f1de5a9b4 100644 --- a/test/br/org/scadabr/db/utils/TestUtils.java +++ b/test/utils/TestUtils.java @@ -1,12 +1,15 @@ -package br.org.scadabr.db.utils; +package utils; import java.util.ArrayList; +import java.util.List; +import com.serotonin.db.IntValuePair; import com.serotonin.mango.db.dao.UserDao; import com.serotonin.mango.vo.DataPointVO; import com.serotonin.mango.vo.User; import com.serotonin.mango.vo.dataSource.DataSourceVO; import com.serotonin.mango.vo.dataSource.PointLocatorVO; +import com.serotonin.mango.vo.dataSource.meta.MetaPointLocatorVO; import com.serotonin.mango.vo.dataSource.virtual.VirtualDataSourceVO; import com.serotonin.mango.vo.dataSource.virtual.VirtualPointLocatorVO; import com.serotonin.mango.vo.permission.DataPointAccess; @@ -175,4 +178,22 @@ public static User newUser(int id, String username) { user.setDataPointPermissions(new ArrayList()); return user; } + + public static DataPointVO newMetaPointSettable(int id, int folderId, List context) { + DataPointVO dataPoint1 = new DataPointVO(DataPointVO.LoggingTypes.ON_CHANGE); + dataPoint1.setId(id); + dataPoint1.setXid("DP_" + id); + dataPoint1.setName("dp_" + id); + dataPoint1.setDataSourceId(99999); + dataPoint1.setDataSourceName("ds_name"); + dataPoint1.setDataSourceTypeId(9); + dataPoint1.setDataSourceXid("DS_XID"); + dataPoint1.setPointFolderId(folderId); + MetaPointLocatorVO pointLocatorVO = new MetaPointLocatorVO(); + pointLocatorVO.setContext(context); + pointLocatorVO.setSettable(true); + dataPoint1.setPointLocator(pointLocatorVO); + dataPoint1.setEventDetectors(new ArrayList<>()); + return dataPoint1; + } } diff --git a/webapp-resources/messages_de.properties b/webapp-resources/messages_de.properties index 0d01b46410..9e67a3f58e 100644 --- a/webapp-resources/messages_de.properties +++ b/webapp-resources/messages_de.properties @@ -3367,4 +3367,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_en.properties b/webapp-resources/messages_en.properties index 63689c5ba2..ddb2048e2d 100644 --- a/webapp-resources/messages_en.properties +++ b/webapp-resources/messages_en.properties @@ -3370,4 +3370,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_es.properties b/webapp-resources/messages_es.properties index 7e42074984..a0e408caba 100644 --- a/webapp-resources/messages_es.properties +++ b/webapp-resources/messages_es.properties @@ -3410,4 +3410,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_fi.properties b/webapp-resources/messages_fi.properties index 624726b659..96294315e1 100644 --- a/webapp-resources/messages_fi.properties +++ b/webapp-resources/messages_fi.properties @@ -3495,4 +3495,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_fr.properties b/webapp-resources/messages_fr.properties index 46d62a9a69..774be1e8e2 100644 --- a/webapp-resources/messages_fr.properties +++ b/webapp-resources/messages_fr.properties @@ -3364,4 +3364,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_lu.properties b/webapp-resources/messages_lu.properties index f5f02ce064..317f71de78 100644 --- a/webapp-resources/messages_lu.properties +++ b/webapp-resources/messages_lu.properties @@ -3383,4 +3383,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_nl.properties b/webapp-resources/messages_nl.properties index ca24e2b770..c1a416ea0f 100644 --- a/webapp-resources/messages_nl.properties +++ b/webapp-resources/messages_nl.properties @@ -3485,4 +3485,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_pl.properties b/webapp-resources/messages_pl.properties index 027b4183b4..573d1e0fb3 100644 --- a/webapp-resources/messages_pl.properties +++ b/webapp-resources/messages_pl.properties @@ -3507,4 +3507,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_pt.properties b/webapp-resources/messages_pt.properties index 514c8df18f..cfc1cfb8d2 100644 --- a/webapp-resources/messages_pt.properties +++ b/webapp-resources/messages_pt.properties @@ -3522,4 +3522,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_ru.properties b/webapp-resources/messages_ru.properties index 3a4d6023d1..ea5b9c4d0d 100644 --- a/webapp-resources/messages_ru.properties +++ b/webapp-resources/messages_ru.properties @@ -3518,4 +3518,5 @@ systemSettings.customCssSaved=Custom Css has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file diff --git a/webapp-resources/messages_zh.properties b/webapp-resources/messages_zh.properties index 4664dc8235..899d2baccf 100644 --- a/webapp-resources/messages_zh.properties +++ b/webapp-resources/messages_zh.properties @@ -3470,4 +3470,5 @@ systemSettings.customCssSaved=Custom CSS has been saved systemSettings.invalidCustomCss=Invalid custom CSS systemsettings.reports.dataPointExtendedNameLengthLimit=Point name length limit in reports event.ds.recursiveError=Recursive Error -event.meta.recursiveError=Recursive error in point "{0}": {1} \ No newline at end of file +event.meta.recursiveError=Recursive error in point "{0}": {1} +validate.cyclicDependency=Cyclic dependency: {0} \ No newline at end of file