@Test public void getVulnerabilitiesDetailsTest() throws Exception { List<Map<String, Object>> vulnerabilitiesData = new ArrayList<>(); ReflectionTestUtils.setField(vulnerabilityService, "vulnTypes", "ec2"); when(vulnerabilityRepository.getAssetsAffectedCount(anyString(), anyObject(), anyString())) .thenReturn(new HashMap<>()); when(vulnerabilityRepository.getAllVulnerabilities(anyObject())).thenReturn(vulnerabilitiesData); assertThat(vulnerabilityService.getVulnerabilitiesDetails("ag", null), is(notNullValue())); ReflectionTestUtils.setField(vulnerabilityService, "vulnTypes", "test"); assertThat(vulnerabilityService.getVulnerabilitiesDetails("ag", null), is(notNullValue())); Map<String, Object> vuln = new HashMap<>(); vuln.put("qid", "123"); vuln.put("assetsAffected", 1); vuln.put(Constants.TITLE, "test"); vuln.put(Constants.SEVEITY_LEVEL, "3"); vuln.put(Constants.CATEGORY, "test"); vuln.put(Constants.VULN_TYPE, "type"); vuln.put(Constants.PATCHABLE, "1"); vulnerabilitiesData.add(vuln); vuln = new HashMap<>(); vuln.put("qid", "456"); vuln.put("assetsAffected", 2); vuln.put(Constants.TITLE, "test"); vuln.put(Constants.SEVEITY_LEVEL, "5"); vuln.put(Constants.CATEGORY, "test"); vuln.put(Constants.VULN_TYPE, "type"); vuln.put(Constants.PATCHABLE, "0"); vulnerabilitiesData.add(vuln); vuln = new HashMap<>(); vuln.put("qid", "789"); vuln.put("assetsAffected", 2); vuln.put(Constants.TITLE, "test"); vuln.put(Constants.SEVEITY_LEVEL, "5"); vuln.put(Constants.CATEGORY, "test"); vuln.put(Constants.VULN_TYPE, "type"); vulnerabilitiesData.add(vuln); Map<String, Long> assetsAffected = new HashMap<String, Long>(); assetsAffected.put("123", 10L); assetsAffected.put("456", 10L); assetsAffected.put("789", 10L); ReflectionTestUtils.setField(vulnerabilityService, "vulnTypes", "ec2,onpremserver"); when(vulnerabilityRepository.getAssetsAffectedCount(anyString(), anyObject(), anyString())) .thenReturn(assetsAffected); when(vulnerabilityRepository.getAllVulnerabilities(anyObject())).thenReturn(vulnerabilitiesData); assertThat(vulnerabilityService.getVulnerabilitiesDetails("ag", null), is(notNullValue())); }
public List<Map<String, Object>> getVulnerabilitiesDetails(String assetGroup, Map<String, String> filter) throws Exception { List<Map<String, Object>> vulnerabilitiesDetails = new ArrayList<>(); try { List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (!vulnTargetTypes.isEmpty()) { for (String parentType : vulnTargetTypes) { Map<String, Long> vulnAssetsAffected = vulnerabilityRepository.getAssetsAffectedCount(assetGroup, filter, parentType); List<Map<String, Object>> vulnerabilitiesData = formVulnerabilitiesData(vulnerabilityRepository .getAllVulnerabilities(new ArrayList<String>(vulnAssetsAffected.keySet())), vulnAssetsAffected); List<Map<String, Object>> vulnerabilitiesDetailsTemp = new ArrayList<>(); if (vulnerabilitiesDetails.isEmpty()) { vulnerabilitiesDetails = new ArrayList<>(vulnerabilitiesData); } else { for (Map<String, Object> vulnData : vulnerabilitiesData) { boolean qidMatched = false; for (Map<String, Object> vulnDetail : vulnerabilitiesDetails) { if (vulnData.get("qid").equals(vulnDetail.get("qid"))) { vulnDetail.put(ASSETS_AFFECTED, Long.valueOf(vulnDetail.get(ASSETS_AFFECTED).toString()) + Long.valueOf(vulnData.get(ASSETS_AFFECTED).toString())); qidMatched = true; break; } } if (!qidMatched) { vulnerabilitiesDetailsTemp.add(vulnData); } } vulnerabilitiesDetails.addAll(vulnerabilitiesDetailsTemp); } } } } catch (Exception e) { logger.error("Error in getVulnerabilitiesDetails ", e); throw e; } return vulnerabilitiesDetails; }
VulnerabilityService implements Constants { public List<Map<String, Object>> getVulnerabilitiesDetails(String assetGroup, Map<String, String> filter) throws Exception { List<Map<String, Object>> vulnerabilitiesDetails = new ArrayList<>(); try { List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (!vulnTargetTypes.isEmpty()) { for (String parentType : vulnTargetTypes) { Map<String, Long> vulnAssetsAffected = vulnerabilityRepository.getAssetsAffectedCount(assetGroup, filter, parentType); List<Map<String, Object>> vulnerabilitiesData = formVulnerabilitiesData(vulnerabilityRepository .getAllVulnerabilities(new ArrayList<String>(vulnAssetsAffected.keySet())), vulnAssetsAffected); List<Map<String, Object>> vulnerabilitiesDetailsTemp = new ArrayList<>(); if (vulnerabilitiesDetails.isEmpty()) { vulnerabilitiesDetails = new ArrayList<>(vulnerabilitiesData); } else { for (Map<String, Object> vulnData : vulnerabilitiesData) { boolean qidMatched = false; for (Map<String, Object> vulnDetail : vulnerabilitiesDetails) { if (vulnData.get("qid").equals(vulnDetail.get("qid"))) { vulnDetail.put(ASSETS_AFFECTED, Long.valueOf(vulnDetail.get(ASSETS_AFFECTED).toString()) + Long.valueOf(vulnData.get(ASSETS_AFFECTED).toString())); qidMatched = true; break; } } if (!qidMatched) { vulnerabilitiesDetailsTemp.add(vulnData); } } vulnerabilitiesDetails.addAll(vulnerabilitiesDetailsTemp); } } } } catch (Exception e) { logger.error("Error in getVulnerabilitiesDetails ", e); throw e; } return vulnerabilitiesDetails; } }
VulnerabilityService implements Constants { public List<Map<String, Object>> getVulnerabilitiesDetails(String assetGroup, Map<String, String> filter) throws Exception { List<Map<String, Object>> vulnerabilitiesDetails = new ArrayList<>(); try { List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (!vulnTargetTypes.isEmpty()) { for (String parentType : vulnTargetTypes) { Map<String, Long> vulnAssetsAffected = vulnerabilityRepository.getAssetsAffectedCount(assetGroup, filter, parentType); List<Map<String, Object>> vulnerabilitiesData = formVulnerabilitiesData(vulnerabilityRepository .getAllVulnerabilities(new ArrayList<String>(vulnAssetsAffected.keySet())), vulnAssetsAffected); List<Map<String, Object>> vulnerabilitiesDetailsTemp = new ArrayList<>(); if (vulnerabilitiesDetails.isEmpty()) { vulnerabilitiesDetails = new ArrayList<>(vulnerabilitiesData); } else { for (Map<String, Object> vulnData : vulnerabilitiesData) { boolean qidMatched = false; for (Map<String, Object> vulnDetail : vulnerabilitiesDetails) { if (vulnData.get("qid").equals(vulnDetail.get("qid"))) { vulnDetail.put(ASSETS_AFFECTED, Long.valueOf(vulnDetail.get(ASSETS_AFFECTED).toString()) + Long.valueOf(vulnData.get(ASSETS_AFFECTED).toString())); qidMatched = true; break; } } if (!qidMatched) { vulnerabilitiesDetailsTemp.add(vulnData); } } vulnerabilitiesDetails.addAll(vulnerabilitiesDetailsTemp); } } } } catch (Exception e) { logger.error("Error in getVulnerabilitiesDetails ", e); throw e; } return vulnerabilitiesDetails; }  }
VulnerabilityService implements Constants { public List<Map<String, Object>> getVulnerabilitiesDetails(String assetGroup, Map<String, String> filter) throws Exception { List<Map<String, Object>> vulnerabilitiesDetails = new ArrayList<>(); try { List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (!vulnTargetTypes.isEmpty()) { for (String parentType : vulnTargetTypes) { Map<String, Long> vulnAssetsAffected = vulnerabilityRepository.getAssetsAffectedCount(assetGroup, filter, parentType); List<Map<String, Object>> vulnerabilitiesData = formVulnerabilitiesData(vulnerabilityRepository .getAllVulnerabilities(new ArrayList<String>(vulnAssetsAffected.keySet())), vulnAssetsAffected); List<Map<String, Object>> vulnerabilitiesDetailsTemp = new ArrayList<>(); if (vulnerabilitiesDetails.isEmpty()) { vulnerabilitiesDetails = new ArrayList<>(vulnerabilitiesData); } else { for (Map<String, Object> vulnData : vulnerabilitiesData) { boolean qidMatched = false; for (Map<String, Object> vulnDetail : vulnerabilitiesDetails) { if (vulnData.get("qid").equals(vulnDetail.get("qid"))) { vulnDetail.put(ASSETS_AFFECTED, Long.valueOf(vulnDetail.get(ASSETS_AFFECTED).toString()) + Long.valueOf(vulnData.get(ASSETS_AFFECTED).toString())); qidMatched = true; break; } } if (!qidMatched) { vulnerabilitiesDetailsTemp.add(vulnData); } } vulnerabilitiesDetails.addAll(vulnerabilitiesDetailsTemp); } } } } catch (Exception e) { logger.error("Error in getVulnerabilitiesDetails ", e); throw e; } return vulnerabilitiesDetails; }  List<Map<String, Object>> getVulnerabilitiesDetails(String assetGroup, Map<String, String> filter); @SuppressWarnings("unchecked") List<Map<String, Object>> getAllVulnerabilitiesDetailsByAssetGroup(String assetGroup,
			Map<String, String> filter,String applicationFilter,String environmentFilter, String searchText, int from, int size); List<Map<String, Object>> getResourcedetailsByResourceId(String assetGroup,
			List<String> listDistinctResourceId, boolean flag); @SuppressWarnings({ "unchecked" }) Map<String, Object> getVulnerabilitySummary(String assetGroup, String reqSeverity); List<Map<String, Object>> getVulnerabilityByAppAndEnv(String assetGroup, String filter, String application); List<Map<String, Object>> getVulnerabilityTrend(String assetGroup, Map<String, String> filter, Date from,
			Date to); List<Map<String, Object>> getVulnerabilityNewOpenTrend(String assetGroup, String severity, Date from); List<Map<String, Object>> getVulnerabilitiesDistribution(String assetGroup); Object filterMatchingCollectionElements(List<Map<String, Object>> masterDetailList, String searchText,
			boolean b); Map<String, Object> getVulnerabilitysummaryByResourceId(String instanceId); List<Map<String, Object>> getVulnerabilityDetailsByResourceId(String instanceId); List<Map<String, Object>> getAgingSummary(String assetGroup); List<Map<String, Object>> getVulnerabilityByQid(String qid); @SuppressWarnings("unchecked") Map<String, Integer> getHighestLowestPerformers(String assetGroup, String severity, String type); List<Map<String, Object>> getDistributionSummaryByInfraType(String assetGroup, String severity); List<Map<String, Object>> getDistributionSummaryByEnv(String assetGroup, String severity); List<Map<String, Object>> getDistributionSummaryByVulnType(String assetGroup, String severity); List<Map<String, Object>> getRemediationActionsSummary(String assetGroup, String severity); boolean createTrendAnnotation(TrendNote request); List<Map<String, Object>> getTrendAnnotations(String assetGroup, Date from); boolean deleteTrendAnnotation(String noteId); Map<String, Object> getVulnerabilitySummaryByAssets(String assetGroup); List<Map<String, Object>> getVulnerabilityAssetsTrend(String assetGroup, String severity, Date from); Map<String, Map<String, String>> getDirectorsForAGByApp(Set<String> appNames); ResponseEntity<Object> formatException(ServiceException e); Map<String, Object> getTrendProgress(String assetGroup, String ruleId, LocalDate startDate,
			LocalDate endDate, String trendCategory); void useRealTimeDataForLatestDate(List<Map<String, Object>> trendList, String ag, String trendCategory,
			String ruleId, String domain); List<String> getResourceId(List<Map<String, Object>> vulnerabilityOccuranceList); List<Map<String, Object>> getCartesianProduct(List<Map<String, Object>> vulnerabilityOccuranceList,
			List<Map<String, Object>> resourceIdDetails); int vulnerabilityAssetCount(String assetGroup, Map<String, String> termsFilter, String applicationFilter,
			String environmentFilter, int from, int size); int countForTargetType(String assetGroup, String parentType, Map<String, String> termsFilter,
			String applicationFilter, String environmentFilter, int from, int size); }
VulnerabilityService implements Constants { public List<Map<String, Object>> getVulnerabilitiesDetails(String assetGroup, Map<String, String> filter) throws Exception { List<Map<String, Object>> vulnerabilitiesDetails = new ArrayList<>(); try { List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (!vulnTargetTypes.isEmpty()) { for (String parentType : vulnTargetTypes) { Map<String, Long> vulnAssetsAffected = vulnerabilityRepository.getAssetsAffectedCount(assetGroup, filter, parentType); List<Map<String, Object>> vulnerabilitiesData = formVulnerabilitiesData(vulnerabilityRepository .getAllVulnerabilities(new ArrayList<String>(vulnAssetsAffected.keySet())), vulnAssetsAffected); List<Map<String, Object>> vulnerabilitiesDetailsTemp = new ArrayList<>(); if (vulnerabilitiesDetails.isEmpty()) { vulnerabilitiesDetails = new ArrayList<>(vulnerabilitiesData); } else { for (Map<String, Object> vulnData : vulnerabilitiesData) { boolean qidMatched = false; for (Map<String, Object> vulnDetail : vulnerabilitiesDetails) { if (vulnData.get("qid").equals(vulnDetail.get("qid"))) { vulnDetail.put(ASSETS_AFFECTED, Long.valueOf(vulnDetail.get(ASSETS_AFFECTED).toString()) + Long.valueOf(vulnData.get(ASSETS_AFFECTED).toString())); qidMatched = true; break; } } if (!qidMatched) { vulnerabilitiesDetailsTemp.add(vulnData); } } vulnerabilitiesDetails.addAll(vulnerabilitiesDetailsTemp); } } } } catch (Exception e) { logger.error("Error in getVulnerabilitiesDetails ", e); throw e; } return vulnerabilitiesDetails; }  List<Map<String, Object>> getVulnerabilitiesDetails(String assetGroup, Map<String, String> filter); @SuppressWarnings("unchecked") List<Map<String, Object>> getAllVulnerabilitiesDetailsByAssetGroup(String assetGroup,
			Map<String, String> filter,String applicationFilter,String environmentFilter, String searchText, int from, int size); List<Map<String, Object>> getResourcedetailsByResourceId(String assetGroup,
			List<String> listDistinctResourceId, boolean flag); @SuppressWarnings({ "unchecked" }) Map<String, Object> getVulnerabilitySummary(String assetGroup, String reqSeverity); List<Map<String, Object>> getVulnerabilityByAppAndEnv(String assetGroup, String filter, String application); List<Map<String, Object>> getVulnerabilityTrend(String assetGroup, Map<String, String> filter, Date from,
			Date to); List<Map<String, Object>> getVulnerabilityNewOpenTrend(String assetGroup, String severity, Date from); List<Map<String, Object>> getVulnerabilitiesDistribution(String assetGroup); Object filterMatchingCollectionElements(List<Map<String, Object>> masterDetailList, String searchText,
			boolean b); Map<String, Object> getVulnerabilitysummaryByResourceId(String instanceId); List<Map<String, Object>> getVulnerabilityDetailsByResourceId(String instanceId); List<Map<String, Object>> getAgingSummary(String assetGroup); List<Map<String, Object>> getVulnerabilityByQid(String qid); @SuppressWarnings("unchecked") Map<String, Integer> getHighestLowestPerformers(String assetGroup, String severity, String type); List<Map<String, Object>> getDistributionSummaryByInfraType(String assetGroup, String severity); List<Map<String, Object>> getDistributionSummaryByEnv(String assetGroup, String severity); List<Map<String, Object>> getDistributionSummaryByVulnType(String assetGroup, String severity); List<Map<String, Object>> getRemediationActionsSummary(String assetGroup, String severity); boolean createTrendAnnotation(TrendNote request); List<Map<String, Object>> getTrendAnnotations(String assetGroup, Date from); boolean deleteTrendAnnotation(String noteId); Map<String, Object> getVulnerabilitySummaryByAssets(String assetGroup); List<Map<String, Object>> getVulnerabilityAssetsTrend(String assetGroup, String severity, Date from); Map<String, Map<String, String>> getDirectorsForAGByApp(Set<String> appNames); ResponseEntity<Object> formatException(ServiceException e); Map<String, Object> getTrendProgress(String assetGroup, String ruleId, LocalDate startDate,
			LocalDate endDate, String trendCategory); void useRealTimeDataForLatestDate(List<Map<String, Object>> trendList, String ag, String trendCategory,
			String ruleId, String domain); List<String> getResourceId(List<Map<String, Object>> vulnerabilityOccuranceList); List<Map<String, Object>> getCartesianProduct(List<Map<String, Object>> vulnerabilityOccuranceList,
			List<Map<String, Object>> resourceIdDetails); int vulnerabilityAssetCount(String assetGroup, Map<String, String> termsFilter, String applicationFilter,
			String environmentFilter, int from, int size); int countForTargetType(String assetGroup, String parentType, Map<String, String> termsFilter,
			String applicationFilter, String environmentFilter, int from, int size);  }