Skip to content

Commit

Permalink
add missing API
Browse files Browse the repository at this point in the history
  • Loading branch information
notshivansh committed Jan 2, 2025
1 parent d17d3d9 commit 54b8d12
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,23 @@ public String countTestingRunResultSummaries() {
return Action.SUCCESS.toUpperCase();
}

List<DependencyNode> dependencyNodes;

public List<DependencyNode> getDependencyNodes() {
return dependencyNodes;
}

public void setDependencyNodes(List<DependencyNode> dependencyNodes) {
this.dependencyNodes = dependencyNodes;
}

public String findDependencyNodes() {
if (filter != null) {
dependencyNodes = DbLayer.findDependencyNodes(filter);
}
return Action.SUCCESS.toUpperCase();
}

public String fetchTestScript() {
try {
testScript = DbLayer.fetchTestScript();
Expand Down
11 changes: 11 additions & 0 deletions apps/database-abstractor/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,17 @@
</result>
</action>

<action name="api/findDependencyNodes" class="com.akto.action.DbAction" method="findDependencyNodes">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<result name="SUCCESS" type="json"/>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

<action name="api/fetchTestScript" class="com.akto.action.DbAction" method="fetchTestScript">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
Expand Down
31 changes: 31 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/ClientActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3544,4 +3544,35 @@ public TestScript fetchTestScript(){
return testScript;
}

public List<DependencyNode> findDependencyNodes(Bson filter) {
BasicDBObject obj = new BasicDBObject();
obj.put("filter", filter);
Map<String, List<String>> headers = buildHeaders();
OriginalHttpRequest request = new OriginalHttpRequest(url + "/findDependencyNodes", "", "POST", obj.toString(), headers, "");
try {
OriginalHttpResponse response = ApiExecutor.sendRequest(request, true, null, false, null);
String responsePayload = response.getBody();
if (response.getStatusCode() != 200 || responsePayload == null) {
loggerMaker.errorAndAddToDb("non 2xx response in findDependencyNodes", LoggerMaker.LogDb.TESTING);
return new ArrayList<>();
}
BasicDBObject payloadObj;
try {
payloadObj = BasicDBObject.parse(responsePayload);
BasicDBList dependencyNodesObj = (BasicDBList) payloadObj.get("dependencyNodes");
List<DependencyNode> dependencyNodes = new ArrayList<>();
for (Object nodeObj : dependencyNodesObj) {
BasicDBObject obj2 = (BasicDBObject) nodeObj;
dependencyNodes.add(objectMapper.readValue(obj2.toJson(), DependencyNode.class));
}
return dependencyNodes;
} catch (Exception e) {
return new ArrayList<>();
}
} catch (Exception e) {
loggerMaker.errorAndAddToDb("error in findDependencyNodes" + e, LoggerMaker.LogDb.RUNTIME);
return new ArrayList<>();
}
}

}
2 changes: 2 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DataActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,6 @@ public abstract class DataActor {

public abstract TestScript fetchTestScript();

public abstract List<DependencyNode> findDependencyNodes(Bson filter);

}
4 changes: 4 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,8 @@ public TestScript fetchTestScript(){
return DbLayer.fetchTestScript();
}

public List<DependencyNode> findDependencyNodes(Bson filter){
return DbLayer.findDependencyNodes(filter);
}

}
4 changes: 4 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1066,4 +1066,8 @@ public static TestScript fetchTestScript(){
return TestScriptsDao.instance.fetchTestScript();
}

public static List<DependencyNode> findDependencyNodes(Bson filter){
return DependencyNodeDao.instance.findAll(filter);
}

}

0 comments on commit 54b8d12

Please sign in to comment.