class VulnerabilityRepository implements Constants {

	public Map<String, Object> getDistributionSummaryByInfraType(String assetGroup, String severitylevel,
			String parentType) throws DataException {

		Map<String, Object> infraInfo = new HashMap<>();
		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(assetGroup);
		urlToQuery.append("/").append(parentType);
		urlToQuery.append("/").append(SEARCH);
		StringBuilder requestBody = new StringBuilder(
				"{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},"
						+ "{\"has_child\":{\"type\":\"vulninfo\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},"
						+ "{\"terms\":{\"severitylevel.keyword\":[%s]}}]}}}}]}},\"aggs\":{\"NAME\":{\"children\":{\"type\":\"vulninfo\"},"
						+ "\"aggs\":{\"NAME\":{\"filter\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},{\"terms\":{\"severitylevel.keyword\":[%s]}}]}},"
						+ "\"aggs\":{\"NAME\":{\"cardinality\":{\"script\":\"doc['qid.keyword'].toString().replace('.0','')\",\"precision_threshold\":40000}}}}}}}}");
		String requestJson = String.format(requestBody.toString(), severitylevel, severitylevel);
		String responseJson = "";
		try {
			responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestJson);
		} catch (Exception e) {
			LOGGER.error("Error in getDistributionSummaryByInfraType", e);
			throw new DataException(e);
		}
		JsonParser jsonParser = new JsonParser();
		if (StringUtils.isNotEmpty(responseJson)) {
			JsonObject resultJson = (JsonObject) jsonParser.parse(responseJson);
			JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get(HITS).toString());
			JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(AGGREGATIONS).toString());
			long totalVulnerableAssets = hitsJson.get(TOTAL).getAsLong();
			long vulnerabilities = aggsJson.getAsJsonObject(NAME.toUpperCase()).getAsJsonObject(NAME.toUpperCase())
					.get(DOC_COUNT).getAsLong();
			long uniqueVulnCount = aggsJson.getAsJsonObject(NAME.toUpperCase()).getAsJsonObject(NAME.toUpperCase())
					.getAsJsonObject(NAME.toUpperCase()).get(VALUE).getAsLong();

			infraInfo.put(TOTAL_VULN_ASSETS, totalVulnerableAssets);
			infraInfo.put(VULNEREBILITIES, vulnerabilities);
			infraInfo.put(UNIQUE_VULN_COUNT, uniqueVulnCount);
		}
		return infraInfo;
	}

}