class 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;
	}

}