@Test public void testFetchIssuesInfo() throws Exception { String issueDistrJson = "{\"data\":{\"distribution\":{\"total_issues\":113688,\"ruleCategory_percentage\":{\"tagging\":57,\"security\":25,\"costOptimization\":7,\"governance\":11},\"distribution_by_severity\":{\"high\":27918,\"critical\":718,\"low\":79342,\"medium\":5710},\"distribution_ruleCategory\":{\"tagging\":64914,\"security\":29327,\"costOptimization\":8962,\"governance\":10485}}},\"message\":\"success\"}"; when(HttpUtil.get(anyString(),anyString())).thenReturn(issueDistrJson); List<Map<String, Object>> issueDistribution = AssetGroupUtil.fetchIssuesInfo("", "",Arrays.asList("infra"),""); assertThat(issueDistribution.get(0).get("domain"), is("infra")); assertThat(issueDistribution.get(0).get("total"), is(113688l)); }
public static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> issueInfoList = new ArrayList<>(); Map<String, Object> issuesInfo; try { for (String domain : domains) { String distributionResponse = HttpUtil .get(compapiuri + "/issues/distribution?ag=" + ag + "&domain=" + Util.encodeUrl(domain),token); JsonObject distributionJson = new JsonParser().parse(distributionResponse).getAsJsonObject(); JsonObject distributionObj = distributionJson.get("data").getAsJsonObject().get(DISTRIBUTION) .getAsJsonObject(); issuesInfo = new HashMap<>(); issuesInfo.put(DOMAIN, domain); issuesInfo.put(TOTAL, distributionObj.get("total_issues").getAsLong()); JsonObject distributionSeverity = distributionObj.get("distribution_by_severity").getAsJsonObject(); JsonObject distributionCategory = distributionObj.get("distribution_ruleCategory").getAsJsonObject(); Set<String> severityKeys = distributionSeverity.keySet(); for (String severityKey : severityKeys) { issuesInfo.put(severityKey, distributionSeverity.get(severityKey).getAsLong()); } Set<String> categoryKeys = distributionCategory.keySet(); for (String categoryKey : categoryKeys) { issuesInfo.put(categoryKey, distributionCategory.get(categoryKey).getAsLong()); } issueInfoList.add(issuesInfo); } } catch (Exception e) { LOGGER.error("Error retrieving issues info " , e); throw e; } return issueInfoList; }
AssetGroupUtil { public static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> issueInfoList = new ArrayList<>(); Map<String, Object> issuesInfo; try { for (String domain : domains) { String distributionResponse = HttpUtil .get(compapiuri + "/issues/distribution?ag=" + ag + "&domain=" + Util.encodeUrl(domain),token); JsonObject distributionJson = new JsonParser().parse(distributionResponse).getAsJsonObject(); JsonObject distributionObj = distributionJson.get("data").getAsJsonObject().get(DISTRIBUTION) .getAsJsonObject(); issuesInfo = new HashMap<>(); issuesInfo.put(DOMAIN, domain); issuesInfo.put(TOTAL, distributionObj.get("total_issues").getAsLong()); JsonObject distributionSeverity = distributionObj.get("distribution_by_severity").getAsJsonObject(); JsonObject distributionCategory = distributionObj.get("distribution_ruleCategory").getAsJsonObject(); Set<String> severityKeys = distributionSeverity.keySet(); for (String severityKey : severityKeys) { issuesInfo.put(severityKey, distributionSeverity.get(severityKey).getAsLong()); } Set<String> categoryKeys = distributionCategory.keySet(); for (String categoryKey : categoryKeys) { issuesInfo.put(categoryKey, distributionCategory.get(categoryKey).getAsLong()); } issueInfoList.add(issuesInfo); } } catch (Exception e) { LOGGER.error("Error retrieving issues info " , e); throw e; } return issueInfoList; } }
AssetGroupUtil { public static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> issueInfoList = new ArrayList<>(); Map<String, Object> issuesInfo; try { for (String domain : domains) { String distributionResponse = HttpUtil .get(compapiuri + "/issues/distribution?ag=" + ag + "&domain=" + Util.encodeUrl(domain),token); JsonObject distributionJson = new JsonParser().parse(distributionResponse).getAsJsonObject(); JsonObject distributionObj = distributionJson.get("data").getAsJsonObject().get(DISTRIBUTION) .getAsJsonObject(); issuesInfo = new HashMap<>(); issuesInfo.put(DOMAIN, domain); issuesInfo.put(TOTAL, distributionObj.get("total_issues").getAsLong()); JsonObject distributionSeverity = distributionObj.get("distribution_by_severity").getAsJsonObject(); JsonObject distributionCategory = distributionObj.get("distribution_ruleCategory").getAsJsonObject(); Set<String> severityKeys = distributionSeverity.keySet(); for (String severityKey : severityKeys) { issuesInfo.put(severityKey, distributionSeverity.get(severityKey).getAsLong()); } Set<String> categoryKeys = distributionCategory.keySet(); for (String categoryKey : categoryKeys) { issuesInfo.put(categoryKey, distributionCategory.get(categoryKey).getAsLong()); } issueInfoList.add(issuesInfo); } } catch (Exception e) { LOGGER.error("Error retrieving issues info " , e); throw e; } return issueInfoList; } private  AssetGroupUtil(); }
AssetGroupUtil { public static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> issueInfoList = new ArrayList<>(); Map<String, Object> issuesInfo; try { for (String domain : domains) { String distributionResponse = HttpUtil .get(compapiuri + "/issues/distribution?ag=" + ag + "&domain=" + Util.encodeUrl(domain),token); JsonObject distributionJson = new JsonParser().parse(distributionResponse).getAsJsonObject(); JsonObject distributionObj = distributionJson.get("data").getAsJsonObject().get(DISTRIBUTION) .getAsJsonObject(); issuesInfo = new HashMap<>(); issuesInfo.put(DOMAIN, domain); issuesInfo.put(TOTAL, distributionObj.get("total_issues").getAsLong()); JsonObject distributionSeverity = distributionObj.get("distribution_by_severity").getAsJsonObject(); JsonObject distributionCategory = distributionObj.get("distribution_ruleCategory").getAsJsonObject(); Set<String> severityKeys = distributionSeverity.keySet(); for (String severityKey : severityKeys) { issuesInfo.put(severityKey, distributionSeverity.get(severityKey).getAsLong()); } Set<String> categoryKeys = distributionCategory.keySet(); for (String categoryKey : categoryKeys) { issuesInfo.put(categoryKey, distributionCategory.get(categoryKey).getAsLong()); } issueInfoList.add(issuesInfo); } } catch (Exception e) { LOGGER.error("Error retrieving issues info " , e); throw e; } return issueInfoList; } private  AssetGroupUtil(); @SuppressWarnings("unchecked") static Map<String, List<String>> fetchAssetGroups(String asstApiUri,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchTypeCounts(String asstApiUri, String ag,String token); static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchComplianceInfo(String apiUrl, String ag, List<String> domains ,String token); static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag,
            List<String> domains ,String token); static Map<String, Object> fetchVulnSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchTaggingSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token); static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token); }
AssetGroupUtil { public static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> issueInfoList = new ArrayList<>(); Map<String, Object> issuesInfo; try { for (String domain : domains) { String distributionResponse = HttpUtil .get(compapiuri + "/issues/distribution?ag=" + ag + "&domain=" + Util.encodeUrl(domain),token); JsonObject distributionJson = new JsonParser().parse(distributionResponse).getAsJsonObject(); JsonObject distributionObj = distributionJson.get("data").getAsJsonObject().get(DISTRIBUTION) .getAsJsonObject(); issuesInfo = new HashMap<>(); issuesInfo.put(DOMAIN, domain); issuesInfo.put(TOTAL, distributionObj.get("total_issues").getAsLong()); JsonObject distributionSeverity = distributionObj.get("distribution_by_severity").getAsJsonObject(); JsonObject distributionCategory = distributionObj.get("distribution_ruleCategory").getAsJsonObject(); Set<String> severityKeys = distributionSeverity.keySet(); for (String severityKey : severityKeys) { issuesInfo.put(severityKey, distributionSeverity.get(severityKey).getAsLong()); } Set<String> categoryKeys = distributionCategory.keySet(); for (String categoryKey : categoryKeys) { issuesInfo.put(categoryKey, distributionCategory.get(categoryKey).getAsLong()); } issueInfoList.add(issuesInfo); } } catch (Exception e) { LOGGER.error("Error retrieving issues info " , e); throw e; } return issueInfoList; } private  AssetGroupUtil(); @SuppressWarnings("unchecked") static Map<String, List<String>> fetchAssetGroups(String asstApiUri,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchTypeCounts(String asstApiUri, String ag,String token); static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchComplianceInfo(String apiUrl, String ag, List<String> domains ,String token); static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag,
            List<String> domains ,String token); static Map<String, Object> fetchVulnSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchTaggingSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token); static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token);  }