@Test public void getDistributionSummaryByEnvTest() throws Exception { ReflectionTestUtils.setField(vulnerabilityService, "vulnTypes", "ec2,onpremserver"); Map<String, Long> prodInfo = new HashMap<>(); prodInfo.put("totalVulnerableAssets", 1L); prodInfo.put(Constants.VULNEREBILITIES, 1L); prodInfo.put("uniqueVulnCount", 1L); Map<String, Long> nonProdInfo = new HashMap<>(); nonProdInfo.put("totalVulnerableAssets", 1L); nonProdInfo.put(Constants.VULNEREBILITIES, 1L); nonProdInfo.put("uniqueVulnCount", 1L); when(vulnerabilityRepository.getProdInfoByEnv(anyString(), anyString())).thenReturn(prodInfo); when(vulnerabilityRepository.getNonProdInfoByEnv(anyString(), anyString())).thenReturn(nonProdInfo); assertThat(vulnerabilityService.getDistributionSummaryByEnv("ag", "3"), is(notNullValue())); ReflectionTestUtils.setField(vulnerabilityService, "vulnTypes", "ec2"); prodInfo = new HashMap<>(); prodInfo.put("totalVulnerableAssets", 0L); prodInfo.put(Constants.VULNEREBILITIES, 0L); prodInfo.put("uniqueVulnCount", 0L); nonProdInfo = new HashMap<>(); nonProdInfo.put("totalVulnerableAssets", 0L); nonProdInfo.put(Constants.VULNEREBILITIES, 0L); nonProdInfo.put("uniqueVulnCount", 0L); when(vulnerabilityRepository.getProdInfoByEnv(anyString(), anyString())).thenReturn(prodInfo); when(vulnerabilityRepository.getNonProdInfoByEnv(anyString(), anyString())).thenReturn(nonProdInfo); assertThat(vulnerabilityService.getDistributionSummaryByEnv("ag", ""), is(notNullValue())); }
public List<Map<String, Object>> getDistributionSummaryByEnv(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; Map<String, Object> prodInfo = new HashMap<>(); prodInfo.put(TOTAL_VULN_ASSETS, 0); prodInfo.put(VULNEREBILITIES, 0); prodInfo.put(UNIQUE_VULN_COUNT, 0); Map<String, Object> nonProdInfo = new HashMap<>(); nonProdInfo.put(TOTAL_VULN_ASSETS, 0); nonProdInfo.put(VULNEREBILITIES, 0); nonProdInfo.put(UNIQUE_VULN_COUNT, 0); try { Map<String, Long> prodInfoTemp = vulnerabilityRepository.getProdInfoByEnv(assetGroup, severity); Map<String, Long> nonProdInfoTemp = vulnerabilityRepository.getNonProdInfoByEnv(assetGroup, severity); totalVulnCount += prodInfoTemp.get(VULNEREBILITIES) + nonProdInfoTemp.get(VULNEREBILITIES); for (Entry<String, Object> entry : prodInfo.entrySet()) { prodInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + prodInfoTemp.get(entry.getKey())); } for (Entry<String, Object> entry : nonProdInfo.entrySet()) { nonProdInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + nonProdInfoTemp.get(entry.getKey())); } } catch (Exception e) { throw new ServiceException(e); } prodInfo.put(CATEGORY, "Prod"); distributionList.add(prodInfo); nonProdInfo.put(CATEGORY, "Non-Prod"); distributionList.add(nonProdInfo); double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); if (totalVulnCount > 0) { double contributionPercent = Math .floor((Double.valueOf(info.get(VULNEREBILITIES).toString()) / totalVulnCount) * HUNDRED); if (i == distributionList.size() - 1) { info.put(CONTRIBUTION, contribution); } else { info.put(CONTRIBUTION, contributionPercent); contribution = contribution - contributionPercent; } } else { info.put(CONTRIBUTION, 0); } } return distributionList; }
VulnerabilityService implements Constants { public List<Map<String, Object>> getDistributionSummaryByEnv(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; Map<String, Object> prodInfo = new HashMap<>(); prodInfo.put(TOTAL_VULN_ASSETS, 0); prodInfo.put(VULNEREBILITIES, 0); prodInfo.put(UNIQUE_VULN_COUNT, 0); Map<String, Object> nonProdInfo = new HashMap<>(); nonProdInfo.put(TOTAL_VULN_ASSETS, 0); nonProdInfo.put(VULNEREBILITIES, 0); nonProdInfo.put(UNIQUE_VULN_COUNT, 0); try { Map<String, Long> prodInfoTemp = vulnerabilityRepository.getProdInfoByEnv(assetGroup, severity); Map<String, Long> nonProdInfoTemp = vulnerabilityRepository.getNonProdInfoByEnv(assetGroup, severity); totalVulnCount += prodInfoTemp.get(VULNEREBILITIES) + nonProdInfoTemp.get(VULNEREBILITIES); for (Entry<String, Object> entry : prodInfo.entrySet()) { prodInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + prodInfoTemp.get(entry.getKey())); } for (Entry<String, Object> entry : nonProdInfo.entrySet()) { nonProdInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + nonProdInfoTemp.get(entry.getKey())); } } catch (Exception e) { throw new ServiceException(e); } prodInfo.put(CATEGORY, "Prod"); distributionList.add(prodInfo); nonProdInfo.put(CATEGORY, "Non-Prod"); distributionList.add(nonProdInfo); double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); if (totalVulnCount > 0) { double contributionPercent = Math .floor((Double.valueOf(info.get(VULNEREBILITIES).toString()) / totalVulnCount) * HUNDRED); if (i == distributionList.size() - 1) { info.put(CONTRIBUTION, contribution); } else { info.put(CONTRIBUTION, contributionPercent); contribution = contribution - contributionPercent; } } else { info.put(CONTRIBUTION, 0); } } return distributionList; } }
VulnerabilityService implements Constants { public List<Map<String, Object>> getDistributionSummaryByEnv(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; Map<String, Object> prodInfo = new HashMap<>(); prodInfo.put(TOTAL_VULN_ASSETS, 0); prodInfo.put(VULNEREBILITIES, 0); prodInfo.put(UNIQUE_VULN_COUNT, 0); Map<String, Object> nonProdInfo = new HashMap<>(); nonProdInfo.put(TOTAL_VULN_ASSETS, 0); nonProdInfo.put(VULNEREBILITIES, 0); nonProdInfo.put(UNIQUE_VULN_COUNT, 0); try { Map<String, Long> prodInfoTemp = vulnerabilityRepository.getProdInfoByEnv(assetGroup, severity); Map<String, Long> nonProdInfoTemp = vulnerabilityRepository.getNonProdInfoByEnv(assetGroup, severity); totalVulnCount += prodInfoTemp.get(VULNEREBILITIES) + nonProdInfoTemp.get(VULNEREBILITIES); for (Entry<String, Object> entry : prodInfo.entrySet()) { prodInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + prodInfoTemp.get(entry.getKey())); } for (Entry<String, Object> entry : nonProdInfo.entrySet()) { nonProdInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + nonProdInfoTemp.get(entry.getKey())); } } catch (Exception e) { throw new ServiceException(e); } prodInfo.put(CATEGORY, "Prod"); distributionList.add(prodInfo); nonProdInfo.put(CATEGORY, "Non-Prod"); distributionList.add(nonProdInfo); double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); if (totalVulnCount > 0) { double contributionPercent = Math .floor((Double.valueOf(info.get(VULNEREBILITIES).toString()) / totalVulnCount) * HUNDRED); if (i == distributionList.size() - 1) { info.put(CONTRIBUTION, contribution); } else { info.put(CONTRIBUTION, contributionPercent); contribution = contribution - contributionPercent; } } else { info.put(CONTRIBUTION, 0); } } return distributionList; }  }
VulnerabilityService implements Constants { public List<Map<String, Object>> getDistributionSummaryByEnv(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; Map<String, Object> prodInfo = new HashMap<>(); prodInfo.put(TOTAL_VULN_ASSETS, 0); prodInfo.put(VULNEREBILITIES, 0); prodInfo.put(UNIQUE_VULN_COUNT, 0); Map<String, Object> nonProdInfo = new HashMap<>(); nonProdInfo.put(TOTAL_VULN_ASSETS, 0); nonProdInfo.put(VULNEREBILITIES, 0); nonProdInfo.put(UNIQUE_VULN_COUNT, 0); try { Map<String, Long> prodInfoTemp = vulnerabilityRepository.getProdInfoByEnv(assetGroup, severity); Map<String, Long> nonProdInfoTemp = vulnerabilityRepository.getNonProdInfoByEnv(assetGroup, severity); totalVulnCount += prodInfoTemp.get(VULNEREBILITIES) + nonProdInfoTemp.get(VULNEREBILITIES); for (Entry<String, Object> entry : prodInfo.entrySet()) { prodInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + prodInfoTemp.get(entry.getKey())); } for (Entry<String, Object> entry : nonProdInfo.entrySet()) { nonProdInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + nonProdInfoTemp.get(entry.getKey())); } } catch (Exception e) { throw new ServiceException(e); } prodInfo.put(CATEGORY, "Prod"); distributionList.add(prodInfo); nonProdInfo.put(CATEGORY, "Non-Prod"); distributionList.add(nonProdInfo); double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); if (totalVulnCount > 0) { double contributionPercent = Math .floor((Double.valueOf(info.get(VULNEREBILITIES).toString()) / totalVulnCount) * HUNDRED); if (i == distributionList.size() - 1) { info.put(CONTRIBUTION, contribution); } else { info.put(CONTRIBUTION, contributionPercent); contribution = contribution - contributionPercent; } } else { info.put(CONTRIBUTION, 0); } } return distributionList; }  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>> getDistributionSummaryByEnv(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; Map<String, Object> prodInfo = new HashMap<>(); prodInfo.put(TOTAL_VULN_ASSETS, 0); prodInfo.put(VULNEREBILITIES, 0); prodInfo.put(UNIQUE_VULN_COUNT, 0); Map<String, Object> nonProdInfo = new HashMap<>(); nonProdInfo.put(TOTAL_VULN_ASSETS, 0); nonProdInfo.put(VULNEREBILITIES, 0); nonProdInfo.put(UNIQUE_VULN_COUNT, 0); try { Map<String, Long> prodInfoTemp = vulnerabilityRepository.getProdInfoByEnv(assetGroup, severity); Map<String, Long> nonProdInfoTemp = vulnerabilityRepository.getNonProdInfoByEnv(assetGroup, severity); totalVulnCount += prodInfoTemp.get(VULNEREBILITIES) + nonProdInfoTemp.get(VULNEREBILITIES); for (Entry<String, Object> entry : prodInfo.entrySet()) { prodInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + prodInfoTemp.get(entry.getKey())); } for (Entry<String, Object> entry : nonProdInfo.entrySet()) { nonProdInfo.put(entry.getKey(), Long.valueOf(entry.getValue().toString()) + nonProdInfoTemp.get(entry.getKey())); } } catch (Exception e) { throw new ServiceException(e); } prodInfo.put(CATEGORY, "Prod"); distributionList.add(prodInfo); nonProdInfo.put(CATEGORY, "Non-Prod"); distributionList.add(nonProdInfo); double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); if (totalVulnCount > 0) { double contributionPercent = Math .floor((Double.valueOf(info.get(VULNEREBILITIES).toString()) / totalVulnCount) * HUNDRED); if (i == distributionList.size() - 1) { info.put(CONTRIBUTION, contribution); } else { info.put(CONTRIBUTION, contributionPercent); contribution = contribution - contributionPercent; } } else { info.put(CONTRIBUTION, 0); } } return distributionList; }  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);  }