Skip to content

Commit

Permalink
Added changes in mt for count issue map
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark2307 committed Jan 7, 2025
1 parent 32a779d commit a24eee3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
11 changes: 0 additions & 11 deletions apps/database-abstractor/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,6 @@
</result>
</action>

<action name="api/updateIssueCountInSummary" class="com.akto.action.DbAction" method="updateIssueCountInSummary">
<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/updateTestRunResultSummary" class="com.akto.action.DbAction" method="updateTestRunResultSummary">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
Expand Down
14 changes: 12 additions & 2 deletions libs/utils/src/main/java/com/akto/data_actor/ClientActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2015,11 +2015,14 @@ public void insertActivity(int count) {
}
}

public TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<String, Integer> totalCountIssues) {
private TestingRunResultSummary getUpdatedSummaryAfterCount(String summaryId, Map<String, Integer> totalCountIssues, String operator){
Map<String, List<String>> headers = buildHeaders();
BasicDBObject obj = new BasicDBObject();
obj.put("summaryId", summaryId);
obj.put("totalCountIssues", totalCountIssues);
if(operator != null && !operator.isEmpty()){
obj.put("operator", operator);
}
OriginalHttpRequest request = new OriginalHttpRequest(url + "/updateIssueCountInSummary", "", "POST", obj.toString(), headers, "");
try {
OriginalHttpResponse response = ApiExecutor.sendRequest(request, true, null, false, null);
Expand Down Expand Up @@ -2047,11 +2050,18 @@ public TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<S
}
}

public TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<String, Integer> totalCountIssues, String operator) {
return getUpdatedSummaryAfterCount(summaryId, totalCountIssues, operator);
}

public TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<String, Integer> totalCountIssues) {
return getUpdatedSummaryAfterCount(summaryId, totalCountIssues, null);
}

public TestingRunResultSummary updateIssueCountAndStateInSummary(String summaryId, Map<String, Integer> totalCountIssues, String state) {
Map<String, List<String>> headers = buildHeaders();
BasicDBObject obj = new BasicDBObject();
obj.put("summaryId", summaryId);
obj.put("totalCountIssues", totalCountIssues);
obj.put("state", state);
OriginalHttpRequest request = new OriginalHttpRequest(url + "/updateIssueCountAndStateInSummary", "", "POST", obj.toString(), headers, "");
try {
Expand Down
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 @@ -170,6 +170,8 @@ public abstract class DataActor {

public abstract TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<String, Integer> totalCountIssues);

public abstract TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<String, Integer> totalCountIssues, String operator);

public abstract TestingRunResultSummary updateIssueCountAndStateInSummary(String summaryId, Map<String, Integer> totalCountIssues, String state);

public abstract List<TestingRunResult> fetchLatestTestingRunResultBySummaryId(String summaryId, int limit, int skip);
Expand Down
5 changes: 5 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 @@ -423,6 +423,11 @@ public TestingRunResultSummary updateIssueCountInSummary(String summaryId,
return DbLayer.updateIssueCountInSummary(summaryId, totalCountIssues);
}

public TestingRunResultSummary updateIssueCountInSummary(String summaryId,
Map<String, Integer> totalCountIssues, String operator) {
return DbLayer.updateIssueCountInSummary(summaryId, totalCountIssues, operator);
}

public TestingRunResultSummary updateIssueCountAndStateInSummary(String summaryId, Map<String, Integer> totalCountIssues, String state) {
return DbLayer.updateIssueCountAndStateInSummary(summaryId, totalCountIssues, state);
}
Expand Down
26 changes: 23 additions & 3 deletions libs/utils/src/main/java/com/akto/data_actor/DbLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,27 @@ public static void insertActivity(int count) {
ActivitiesDao.instance.insertActivity("High Vulnerability detected", count + " HIGH vulnerabilites detected");
}

public static TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<String, Integer> totalCountIssues, String operator) {
if(operator == null || !operator.equals("increment")){
return updateIssueCountInSummary(summaryId,totalCountIssues);
}else{
ObjectId summaryObjectId = new ObjectId(summaryId);
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
Bson updateIncrement = Updates.combine(
Updates.inc("countIssues.HIGH", totalCountIssues.getOrDefault("HIGH", 0)),
Updates.inc("countIssues.MEDIUM", totalCountIssues.getOrDefault("MEDIUM", 0)),
Updates.inc("countIssues.LOW", totalCountIssues.getOrDefault("LOW", 0))
);
return TestingRunResultSummariesDao.instance.getMCollection().findOneAndUpdate(
Filters.eq(Constants.ID, summaryObjectId),
Updates.combine(
Updates.set(TestingRunResultSummary.END_TIMESTAMP, Context.now()),
Updates.set(TestingRunResultSummary.STATE, State.COMPLETED),
updateIncrement),options);
}
}

public static TestingRunResultSummary updateIssueCountInSummary(String summaryId, Map<String, Integer> totalCountIssues) {
ObjectId summaryObjectId = new ObjectId(summaryId);
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
Expand All @@ -694,9 +715,8 @@ public static TestingRunResultSummary updateIssueCountAndStateInSummary(String s
Filters.eq(Constants.ID, summaryObjectId),
Updates.combine(
Updates.set(TestingRunResultSummary.END_TIMESTAMP, Context.now()),
Updates.set(TestingRunResultSummary.STATE, state),
Updates.set(TestingRunResultSummary.COUNT_ISSUES, totalCountIssues)),
options);
Updates.set(TestingRunResultSummary.STATE, state)
),options);
}

public static List<Integer> fetchDeactivatedCollections() {
Expand Down

0 comments on commit a24eee3

Please sign in to comment.