class VulnerabilityRepository implements Constants {

	public List<Map<String, Object>> getAgingSummary(String assetGroup) {

		List<Map<String, Object>> agingSummary = new ArrayList<>();
		Map<String, Double> avgAgingMap = new HashMap<>();
		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(assetGroup);
		urlToQuery.append("/").append(VULN_INFO);
		urlToQuery.append("/").append(SEARCH);
		StringBuilder requestBody = new StringBuilder(
				"{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":true}},{\"terms\":{\"severitylevel.keyword\":[3,4,5]}}]}},"
						+ "\"aggs\":{\"severity\":{\"terms\":{\"field\":\"severitylevel.keyword\",\"size\":10},\"aggs\":{\"aging\":{\"avg\":{\"field\":\"_vulnage\"}}}}}}");
		String responseJson = "";
		try {
			responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
		} catch (Exception e) {
			LOGGER.error("Error in getAgingSummary from ES", e);
		}
		JsonParser jsonParser = new JsonParser();
		if (StringUtils.isNotEmpty(responseJson)) {
			JsonObject resultJson = (JsonObject) jsonParser.parse(responseJson);
			JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(AGGREGATIONS).toString());
			JsonArray buckets = aggsJson.getAsJsonObject(SEVERITY).getAsJsonArray(BUCKETS);
			if (buckets.size() > 0) {
				for (int i = 0; i < buckets.size(); i++) {
					avgAgingMap.put(buckets.get(i).getAsJsonObject().get("key").toString(), Math.floor(
							buckets.get(i).getAsJsonObject().get(AGING).getAsJsonObject().get(VALUE).getAsDouble()));
				}
			}

			avgAgingMap.forEach((severity, avg) -> {
				Map<String, Object> sevInfo = new HashMap<>();
				sevInfo.put(SEVERITY, "S" + severity);
				sevInfo.put("days", avg);
				agingSummary.add(sevInfo);
			});
		}
		return agingSummary;
	}

}