class RecommendationsRepository {

	public Map<String,Object> getGeneralRecommendations(String category, List<String> providers) throws DataException {
		
		Map<String,Object> result = new HashMap<>();
		List<Map<String,Object>> recommendations = new ArrayList<>();
		
		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append("global_recommendations").append("/")
    			.append("recommendation").append("/").append(Constants.SEARCH);
		StringBuilder requestBody = new StringBuilder("{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":true}},{\"match\":{\"category.keyword\":\"");
		requestBody.append(category);
		requestBody.append("\"}}],\"filter\":[{\"terms\":{\"_cloudType\":[\"");
		requestBody.append(String.join("\",\" ", providers.stream().collect(Collectors.toList())));
		requestBody.append("\"]}}]}},\"aggs\":{\"recommendations\":{\"terms\":{\"field\":\"recommendationId.keyword\",\"size\":10000}}}}");
		String responseDetails;
		try {
			responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
		} catch (Exception e) {
			LOGGER.error("Error in getGeneralRecommendations "+e);
			throw new DataException(e);
		}
        JsonParser parser = new JsonParser();
        JsonObject responseDetailsjson = parser.parse(responseDetails).getAsJsonObject();
        JsonObject aggregations = responseDetailsjson.get(Constants.AGGREGATIONS).getAsJsonObject();
        JsonArray recommendationBuckets = aggregations.get("recommendations").getAsJsonObject().get(Constants.BUCKETS).getAsJsonArray();
        if (recommendationBuckets.size() > 0) {
            for (int i=0; i<recommendationBuckets.size();i++) {
            	JsonObject recommendationObj = (JsonObject) recommendationBuckets.get(i);
                if (recommendationObj != null) {
                	String recommendationId = recommendationObj.get(Constants.KEY).getAsString();
					Map<String,Object> recommendationInfo = getRecommendation(recommendationId);
					if(!recommendationInfo.isEmpty()) {
						Map<String,Object> recommendation = new HashMap<>();
    					recommendation.put("recommendationId", recommendationId);
    					recommendation.put("recommendation", recommendationInfo.get("checkname"));
    					recommendation.put("description", recommendationInfo.get("checkdescription").toString().replace("[NL]", "<br />"));
    					recommendation.put("recommended", recommendationObj.get(Constants.DOC_COUNT).getAsLong());
    					recommendations.add(recommendation);
					}
                }
            }
        }
		
		result.put("category", category);
		result.put("response", recommendations);
		return result;
	}

}