class VulnerabilityRepository implements Constants {

	public Map<String, Object> getVulnInfo(String assetGroup, String severity) {

		Map<String, Object> vulnInfo = new HashMap<>();
		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(assetGroup);
		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\":["
						+ severity + "]}}]}}}}]}},\"aggs\":{\"vulninfo\":{\"children\":{\"type\":\"vulninfo\"},"
						+ "\"aggs\":{\"sev-filter\":{\"filter\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},{\"terms\":{\"severitylevel.keyword\":["
						+ severity + "]}}]}},"
						+ "\"aggs\":{\"severity\":{\"terms\":{\"field\":\"severitylevel.keyword\",\"size\":5},"
						+ "\"aggs\":{\"unique-qid\":{\"cardinality\":{\"script\":\"doc['qid.keyword'].toString().replace('.0','')\",\"precision_threshold\": 40000}}}}}}}}}}");

		String responseJson = "";
		try {
			responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
		} catch (Exception e) {
			LOGGER.error(Constants.ERROR_UNIQUEHOST, e);
		}

		JsonParser jsonParser = new JsonParser();
		if (StringUtils.isNotEmpty(responseJson)) {
			JsonObject resultJson = (JsonObject) jsonParser.parse(responseJson);
			JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(AGGREGATIONS).toString());
			long total = aggsJson.getAsJsonObject(VULN_INFO).getAsJsonObject("sev-filter").get(DOC_COUNT).getAsLong();
			vulnInfo.put(TOTAL, total);
			JsonArray buckets = aggsJson.getAsJsonObject(VULN_INFO).getAsJsonObject("sev-filter")
					.getAsJsonObject(SEVERITY).getAsJsonArray(BUCKETS);

			Map<String, Object> sevInfo;
			if (buckets.size() > 0) {
				for (int i = 0; i < buckets.size(); i++) {
					String sevKey = buckets.get(i).getAsJsonObject().get("key").getAsString();
					sevInfo = new HashMap<>();
					sevInfo.put(SEVERITY, sevKey);
					sevInfo.put(UNIQUE_VULN_COUNT,
							buckets.get(i).getAsJsonObject().get(UNIQUE_QID).getAsJsonObject().get(VALUE).getAsLong());
					sevInfo.put(VULN_COUNT, buckets.get(i).getAsJsonObject().get(DOC_COUNT).getAsLong());
					vulnInfo.put(sevKey, sevInfo);
				}
			}
		}
		return vulnInfo;
	}

}