@Test public void getDistributionSummaryByInfraTypeTest() throws Exception { ReflectionTestUtils.setField(vulnerabilityService, "vulnTypes", "ec2,onpremserver"); Map<String, Object> infraInfo = new HashMap<>(); infraInfo.put(Constants.TOTAL_VULN_ASSETS, 1); infraInfo.put(Constants.VULNEREBILITIES, 1); infraInfo.put(Constants.UNIQUE_VULN_COUNT, 1); when(vulnerabilityRepository.getDistributionSummaryByInfraType(anyString(), anyString(), anyString())) .thenReturn(infraInfo); assertThat(vulnerabilityService.getDistributionSummaryByInfraType("ag", null), is(notNullValue())); ReflectionTestUtils.setField(vulnerabilityService, "vulnTypes", "ec2"); when(vulnerabilityRepository.getDistributionSummaryByInfraType(anyString(), anyString(), anyString())) .thenReturn(infraInfo); assertThat(vulnerabilityService.getDistributionSummaryByInfraType("ag", "3"), is(notNullValue())); }
public List<Map<String, Object>> getDistributionSummaryByInfraType(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; for (String vulnType : vulnTargetTypes) { Map<String, Object> info = new HashMap<>(); try { info = vulnerabilityRepository.getDistributionSummaryByInfraType(assetGroup, severity, vulnType); } catch (Exception e) { logger.error("Error in getDistributionSummaryByInfraType ", e); throw new ServiceException(); } totalVulnCount += Long.valueOf(info.get(VULNEREBILITIES).toString()); if (vulnType.equals(ONPREMSERVER)) { info.put(CATEGORY, "On-Prem"); distributionList.add(info); } else { Optional<Map<String, Object>> cloudInfoOptional = distributionList.stream() .filter(distro -> distro.get(CATEGORY).equals("Cloud")).findAny(); if (cloudInfoOptional.isPresent()) { Map<String, Object> currentCloudInfo = cloudInfoOptional.get(); currentCloudInfo.put(TOTAL_VULN_ASSETS, Long.valueOf(currentCloudInfo.get(TOTAL_VULN_ASSETS).toString()) + Long.valueOf(info.get(TOTAL_VULN_ASSETS).toString())); currentCloudInfo.put(VULNEREBILITIES, Long.valueOf(currentCloudInfo.get(VULNEREBILITIES).toString()) + Long.valueOf(info.get(VULNEREBILITIES).toString())); currentCloudInfo.put(UNIQUE_VULN_COUNT, Long.valueOf(currentCloudInfo.get(UNIQUE_VULN_COUNT).toString()) + Long.valueOf(info.get(UNIQUE_VULN_COUNT).toString())); } else { info.put(CATEGORY, "Cloud"); distributionList.add(info); } } } double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); 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; } } return distributionList; }
VulnerabilityService implements Constants { public List<Map<String, Object>> getDistributionSummaryByInfraType(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; for (String vulnType : vulnTargetTypes) { Map<String, Object> info = new HashMap<>(); try { info = vulnerabilityRepository.getDistributionSummaryByInfraType(assetGroup, severity, vulnType); } catch (Exception e) { logger.error("Error in getDistributionSummaryByInfraType ", e); throw new ServiceException(); } totalVulnCount += Long.valueOf(info.get(VULNEREBILITIES).toString()); if (vulnType.equals(ONPREMSERVER)) { info.put(CATEGORY, "On-Prem"); distributionList.add(info); } else { Optional<Map<String, Object>> cloudInfoOptional = distributionList.stream() .filter(distro -> distro.get(CATEGORY).equals("Cloud")).findAny(); if (cloudInfoOptional.isPresent()) { Map<String, Object> currentCloudInfo = cloudInfoOptional.get(); currentCloudInfo.put(TOTAL_VULN_ASSETS, Long.valueOf(currentCloudInfo.get(TOTAL_VULN_ASSETS).toString()) + Long.valueOf(info.get(TOTAL_VULN_ASSETS).toString())); currentCloudInfo.put(VULNEREBILITIES, Long.valueOf(currentCloudInfo.get(VULNEREBILITIES).toString()) + Long.valueOf(info.get(VULNEREBILITIES).toString())); currentCloudInfo.put(UNIQUE_VULN_COUNT, Long.valueOf(currentCloudInfo.get(UNIQUE_VULN_COUNT).toString()) + Long.valueOf(info.get(UNIQUE_VULN_COUNT).toString())); } else { info.put(CATEGORY, "Cloud"); distributionList.add(info); } } } double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); 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; } } return distributionList; } }
VulnerabilityService implements Constants { public List<Map<String, Object>> getDistributionSummaryByInfraType(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; for (String vulnType : vulnTargetTypes) { Map<String, Object> info = new HashMap<>(); try { info = vulnerabilityRepository.getDistributionSummaryByInfraType(assetGroup, severity, vulnType); } catch (Exception e) { logger.error("Error in getDistributionSummaryByInfraType ", e); throw new ServiceException(); } totalVulnCount += Long.valueOf(info.get(VULNEREBILITIES).toString()); if (vulnType.equals(ONPREMSERVER)) { info.put(CATEGORY, "On-Prem"); distributionList.add(info); } else { Optional<Map<String, Object>> cloudInfoOptional = distributionList.stream() .filter(distro -> distro.get(CATEGORY).equals("Cloud")).findAny(); if (cloudInfoOptional.isPresent()) { Map<String, Object> currentCloudInfo = cloudInfoOptional.get(); currentCloudInfo.put(TOTAL_VULN_ASSETS, Long.valueOf(currentCloudInfo.get(TOTAL_VULN_ASSETS).toString()) + Long.valueOf(info.get(TOTAL_VULN_ASSETS).toString())); currentCloudInfo.put(VULNEREBILITIES, Long.valueOf(currentCloudInfo.get(VULNEREBILITIES).toString()) + Long.valueOf(info.get(VULNEREBILITIES).toString())); currentCloudInfo.put(UNIQUE_VULN_COUNT, Long.valueOf(currentCloudInfo.get(UNIQUE_VULN_COUNT).toString()) + Long.valueOf(info.get(UNIQUE_VULN_COUNT).toString())); } else { info.put(CATEGORY, "Cloud"); distributionList.add(info); } } } double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); 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; } } return distributionList; }  }
VulnerabilityService implements Constants { public List<Map<String, Object>> getDistributionSummaryByInfraType(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; for (String vulnType : vulnTargetTypes) { Map<String, Object> info = new HashMap<>(); try { info = vulnerabilityRepository.getDistributionSummaryByInfraType(assetGroup, severity, vulnType); } catch (Exception e) { logger.error("Error in getDistributionSummaryByInfraType ", e); throw new ServiceException(); } totalVulnCount += Long.valueOf(info.get(VULNEREBILITIES).toString()); if (vulnType.equals(ONPREMSERVER)) { info.put(CATEGORY, "On-Prem"); distributionList.add(info); } else { Optional<Map<String, Object>> cloudInfoOptional = distributionList.stream() .filter(distro -> distro.get(CATEGORY).equals("Cloud")).findAny(); if (cloudInfoOptional.isPresent()) { Map<String, Object> currentCloudInfo = cloudInfoOptional.get(); currentCloudInfo.put(TOTAL_VULN_ASSETS, Long.valueOf(currentCloudInfo.get(TOTAL_VULN_ASSETS).toString()) + Long.valueOf(info.get(TOTAL_VULN_ASSETS).toString())); currentCloudInfo.put(VULNEREBILITIES, Long.valueOf(currentCloudInfo.get(VULNEREBILITIES).toString()) + Long.valueOf(info.get(VULNEREBILITIES).toString())); currentCloudInfo.put(UNIQUE_VULN_COUNT, Long.valueOf(currentCloudInfo.get(UNIQUE_VULN_COUNT).toString()) + Long.valueOf(info.get(UNIQUE_VULN_COUNT).toString())); } else { info.put(CATEGORY, "Cloud"); distributionList.add(info); } } } double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); 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; } } 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>> getDistributionSummaryByInfraType(String assetGroup, String severity) throws ServiceException { List<Map<String, Object>> distributionList = new ArrayList<>(); List<String> vulnTargetTypes = getVulnTargetTypes(assetGroup); if (StringUtils.isBlank(severity)) { severity = SEVERITY_LEVELS; } long totalVulnCount = 0; for (String vulnType : vulnTargetTypes) { Map<String, Object> info = new HashMap<>(); try { info = vulnerabilityRepository.getDistributionSummaryByInfraType(assetGroup, severity, vulnType); } catch (Exception e) { logger.error("Error in getDistributionSummaryByInfraType ", e); throw new ServiceException(); } totalVulnCount += Long.valueOf(info.get(VULNEREBILITIES).toString()); if (vulnType.equals(ONPREMSERVER)) { info.put(CATEGORY, "On-Prem"); distributionList.add(info); } else { Optional<Map<String, Object>> cloudInfoOptional = distributionList.stream() .filter(distro -> distro.get(CATEGORY).equals("Cloud")).findAny(); if (cloudInfoOptional.isPresent()) { Map<String, Object> currentCloudInfo = cloudInfoOptional.get(); currentCloudInfo.put(TOTAL_VULN_ASSETS, Long.valueOf(currentCloudInfo.get(TOTAL_VULN_ASSETS).toString()) + Long.valueOf(info.get(TOTAL_VULN_ASSETS).toString())); currentCloudInfo.put(VULNEREBILITIES, Long.valueOf(currentCloudInfo.get(VULNEREBILITIES).toString()) + Long.valueOf(info.get(VULNEREBILITIES).toString())); currentCloudInfo.put(UNIQUE_VULN_COUNT, Long.valueOf(currentCloudInfo.get(UNIQUE_VULN_COUNT).toString()) + Long.valueOf(info.get(UNIQUE_VULN_COUNT).toString())); } else { info.put(CATEGORY, "Cloud"); distributionList.add(info); } } } double contribution = HUNDRED; for (int i = 0; i < distributionList.size(); i++) { Map<String, Object> info = distributionList.get(i); 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; } } 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);  }