Skip to content

Commit

Permalink
#3055 Added validation Cyclic dependency for Meta Data Point:
Browse files Browse the repository at this point in the history
- Refactoring ValidationUtils.isCyclicDependency
  • Loading branch information
Limraj committed Nov 29, 2024
1 parent c4b0875 commit 8218732
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void validate(DwrResponseI18n response, int dataPointId) {
.stream()
.collect(Collectors.toMap(DataPointVO::getId, Function.identity()));

List<String> varNameSpace = new ArrayList<String>();
List<String> varNameSpace = new ArrayList<>();
for (IntValuePair point : context) {
String varName = point.getValue();
int pointId = point.getKey();
Expand Down
28 changes: 14 additions & 14 deletions src/org/scada_lts/utils/ValidationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,29 @@ public static void checkIfNonAdminThenUnauthorized(HttpServletRequest request) {
}
}

public static boolean isCyclicDependency(int starDataPointId, int checkDataPointId, Map<Integer, DataPointVO> dataPoints, int safe) {
public static boolean isCyclicDependency(int starDataPointId, int findDataPointId, Map<Integer, DataPointVO> 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<IntValuePair> pairs = metaPointLocator.getContext();
if (pairs.isEmpty()) {
List<IntValuePair> 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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8218732

Please sign in to comment.