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

}