class VulnerabilityRepository implements Constants {

	public Map<String, Object> getCompliantHostsBySeverity(String assetGroup) throws DataException {

		Map<String, Object> severityInfo = new HashMap<>();

		List<String> nonCompliantResourceIds = getNonCompliantResourceIds(assetGroup);
		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(assetGroup).append("/vulninfo/_search");
		StringBuilder requestBody = new StringBuilder(
				"{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":true}},{\"terms\":{\"severitylevel.keyword\":[3,4,5]}}],\"must_not\":[{\"terms\":{\"_resourceid.keyword\":");
		requestBody.append(nonCompliantResourceIds);
		requestBody.append("}}]}},\"aggs\":{\"severity\":{\"terms\":{\"field\":\"severitylevel.keyword\",\"size\":10}}}}");

		String responseDetails = "";
		try {
			responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
		} catch (Exception e) {
			LOGGER.error("Error in getCompliantHostsBySeverity", e);
			throw new DataException(e);
		}

		JsonParser jsonParser = new JsonParser();
		if (StringUtils.isNotEmpty(responseDetails)) {
			JsonObject resultJson = (JsonObject) jsonParser.parse(responseDetails);
			JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(AGGREGATIONS).toString());
			JsonArray outerBuckets = aggsJson.getAsJsonObject("severity").getAsJsonArray(BUCKETS);
			if (outerBuckets.size() > 0) {
				for (int i = 0; i < outerBuckets.size(); i++) {
					severityInfo.put("S" + outerBuckets.get(i).getAsJsonObject().get("key").getAsString(),
							outerBuckets.get(i).getAsJsonObject().get(DOC_COUNT).getAsLong());
				}
			} else {
				severityInfo.put("S3",0);
				severityInfo.put("S4",0);
				severityInfo.put("S5",0);
			}
		}

		return severityInfo;
	}

}