@Test public void getGeneralRecommendationSummaryTest() throws Exception { String summary = "{\"aggregations\":{\"category\":{\"buckets\":[{\"key\":\"performance\",\"doc_count\":55}]}}}"; mockStatic(PacHttpUtils.class); when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenReturn(summary); assertTrue(recommendationsRepository.getGeneralRecommendationSummary(new ArrayList<String>()).size() == 1); }
public List<Map<String,Object>> getGeneralRecommendationSummary(List<String> providers) throws DataException { List<Map<String,Object>> recommendationSummary = 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\": {\"filter\":[{\"term\":{\"latest\":\"true\"}},{\"terms\":{\"_cloudType\":[\""); requestBody.append(String.join("\",\" ", providers.stream().collect(Collectors.toList()))); requestBody.append("\"]}}]}},\"aggs\":{\"category\":{\"terms\":{\"field\":\"category.keyword\",\"size\":100}}}}"); String responseDetails; try { responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString()); } catch (Exception e) { LOGGER.error("Error in getGlobalRecommendationSummary "+e); throw new DataException(e); } JsonParser parser = new JsonParser(); JsonObject responseDetailsjson = parser.parse(responseDetails).getAsJsonObject(); JsonObject aggregations = responseDetailsjson.get(Constants.AGGREGATIONS).getAsJsonObject(); if (aggregations != null) { JsonArray categoryBuckets = aggregations.get("category").getAsJsonObject().get(Constants.BUCKETS) .getAsJsonArray(); if (categoryBuckets.size() > 0) { for (int i = 0; i < categoryBuckets.size(); i++) { JsonObject categoryObj = (JsonObject) categoryBuckets.get(i); if (categoryObj != null) { Map<String, Object> category = new HashMap<>(); category.put("category", categoryObj.get("key").getAsString()); category.put("recommendations", categoryObj.get("doc_count").getAsLong()); recommendationSummary.add(category); } } } else { String[] categories = recommendationCategories.split(","); for (int i = 0; i < categories.length; i++) { Map<String, Object> category = new HashMap<>(); category.put("category", categories[i]); category.put("recommendations", 0L); recommendationSummary.add(category); } } } return recommendationSummary; }
RecommendationsRepository { public List<Map<String,Object>> getGeneralRecommendationSummary(List<String> providers) throws DataException { List<Map<String,Object>> recommendationSummary = 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\": {\"filter\":[{\"term\":{\"latest\":\"true\"}},{\"terms\":{\"_cloudType\":[\""); requestBody.append(String.join("\",\" ", providers.stream().collect(Collectors.toList()))); requestBody.append("\"]}}]}},\"aggs\":{\"category\":{\"terms\":{\"field\":\"category.keyword\",\"size\":100}}}}"); String responseDetails; try { responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString()); } catch (Exception e) { LOGGER.error("Error in getGlobalRecommendationSummary "+e); throw new DataException(e); } JsonParser parser = new JsonParser(); JsonObject responseDetailsjson = parser.parse(responseDetails).getAsJsonObject(); JsonObject aggregations = responseDetailsjson.get(Constants.AGGREGATIONS).getAsJsonObject(); if (aggregations != null) { JsonArray categoryBuckets = aggregations.get("category").getAsJsonObject().get(Constants.BUCKETS) .getAsJsonArray(); if (categoryBuckets.size() > 0) { for (int i = 0; i < categoryBuckets.size(); i++) { JsonObject categoryObj = (JsonObject) categoryBuckets.get(i); if (categoryObj != null) { Map<String, Object> category = new HashMap<>(); category.put("category", categoryObj.get("key").getAsString()); category.put("recommendations", categoryObj.get("doc_count").getAsLong()); recommendationSummary.add(category); } } } else { String[] categories = recommendationCategories.split(","); for (int i = 0; i < categories.length; i++) { Map<String, Object> category = new HashMap<>(); category.put("category", categories[i]); category.put("recommendations", 0L); recommendationSummary.add(category); } } } return recommendationSummary; } }
RecommendationsRepository { public List<Map<String,Object>> getGeneralRecommendationSummary(List<String> providers) throws DataException { List<Map<String,Object>> recommendationSummary = 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\": {\"filter\":[{\"term\":{\"latest\":\"true\"}},{\"terms\":{\"_cloudType\":[\""); requestBody.append(String.join("\",\" ", providers.stream().collect(Collectors.toList()))); requestBody.append("\"]}}]}},\"aggs\":{\"category\":{\"terms\":{\"field\":\"category.keyword\",\"size\":100}}}}"); String responseDetails; try { responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString()); } catch (Exception e) { LOGGER.error("Error in getGlobalRecommendationSummary "+e); throw new DataException(e); } JsonParser parser = new JsonParser(); JsonObject responseDetailsjson = parser.parse(responseDetails).getAsJsonObject(); JsonObject aggregations = responseDetailsjson.get(Constants.AGGREGATIONS).getAsJsonObject(); if (aggregations != null) { JsonArray categoryBuckets = aggregations.get("category").getAsJsonObject().get(Constants.BUCKETS) .getAsJsonArray(); if (categoryBuckets.size() > 0) { for (int i = 0; i < categoryBuckets.size(); i++) { JsonObject categoryObj = (JsonObject) categoryBuckets.get(i); if (categoryObj != null) { Map<String, Object> category = new HashMap<>(); category.put("category", categoryObj.get("key").getAsString()); category.put("recommendations", categoryObj.get("doc_count").getAsLong()); recommendationSummary.add(category); } } } else { String[] categories = recommendationCategories.split(","); for (int i = 0; i < categories.length; i++) { Map<String, Object> category = new HashMap<>(); category.put("category", categories[i]); category.put("recommendations", 0L); recommendationSummary.add(category); } } } return recommendationSummary; }  }
RecommendationsRepository { public List<Map<String,Object>> getGeneralRecommendationSummary(List<String> providers) throws DataException { List<Map<String,Object>> recommendationSummary = 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\": {\"filter\":[{\"term\":{\"latest\":\"true\"}},{\"terms\":{\"_cloudType\":[\""); requestBody.append(String.join("\",\" ", providers.stream().collect(Collectors.toList()))); requestBody.append("\"]}}]}},\"aggs\":{\"category\":{\"terms\":{\"field\":\"category.keyword\",\"size\":100}}}}"); String responseDetails; try { responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString()); } catch (Exception e) { LOGGER.error("Error in getGlobalRecommendationSummary "+e); throw new DataException(e); } JsonParser parser = new JsonParser(); JsonObject responseDetailsjson = parser.parse(responseDetails).getAsJsonObject(); JsonObject aggregations = responseDetailsjson.get(Constants.AGGREGATIONS).getAsJsonObject(); if (aggregations != null) { JsonArray categoryBuckets = aggregations.get("category").getAsJsonObject().get(Constants.BUCKETS) .getAsJsonArray(); if (categoryBuckets.size() > 0) { for (int i = 0; i < categoryBuckets.size(); i++) { JsonObject categoryObj = (JsonObject) categoryBuckets.get(i); if (categoryObj != null) { Map<String, Object> category = new HashMap<>(); category.put("category", categoryObj.get("key").getAsString()); category.put("recommendations", categoryObj.get("doc_count").getAsLong()); recommendationSummary.add(category); } } } else { String[] categories = recommendationCategories.split(","); for (int i = 0; i < categories.length; i++) { Map<String, Object> category = new HashMap<>(); category.put("category", categories[i]); category.put("recommendations", 0L); recommendationSummary.add(category); } } } return recommendationSummary; }  List<Map<String,Object>> getRecommendationSummary(String assetGroup, String application); Map<String,Object> getSummaryByApplication(String assetGroup, String category); Map<String, Object> getSummaryByApplication(String assetGroup); Map<String,Object> getRecommendations(String assetGroup, String category, String application); Map<String,Object> getRecommendationDetail(String assetGroup, String recommendationId, String application); @SuppressWarnings("deprecation") Map<String,Object> getRecommendation(String recommendationId); List<Map<String,Object>> getGeneralRecommendationSummary(List<String> providers); Map<String,Object> getGeneralRecommendations(String category, List<String> providers); Map<String,Object> getGeneralRecommendationDetail(String recommendationId); }
RecommendationsRepository { public List<Map<String,Object>> getGeneralRecommendationSummary(List<String> providers) throws DataException { List<Map<String,Object>> recommendationSummary = 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\": {\"filter\":[{\"term\":{\"latest\":\"true\"}},{\"terms\":{\"_cloudType\":[\""); requestBody.append(String.join("\",\" ", providers.stream().collect(Collectors.toList()))); requestBody.append("\"]}}]}},\"aggs\":{\"category\":{\"terms\":{\"field\":\"category.keyword\",\"size\":100}}}}"); String responseDetails; try { responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString()); } catch (Exception e) { LOGGER.error("Error in getGlobalRecommendationSummary "+e); throw new DataException(e); } JsonParser parser = new JsonParser(); JsonObject responseDetailsjson = parser.parse(responseDetails).getAsJsonObject(); JsonObject aggregations = responseDetailsjson.get(Constants.AGGREGATIONS).getAsJsonObject(); if (aggregations != null) { JsonArray categoryBuckets = aggregations.get("category").getAsJsonObject().get(Constants.BUCKETS) .getAsJsonArray(); if (categoryBuckets.size() > 0) { for (int i = 0; i < categoryBuckets.size(); i++) { JsonObject categoryObj = (JsonObject) categoryBuckets.get(i); if (categoryObj != null) { Map<String, Object> category = new HashMap<>(); category.put("category", categoryObj.get("key").getAsString()); category.put("recommendations", categoryObj.get("doc_count").getAsLong()); recommendationSummary.add(category); } } } else { String[] categories = recommendationCategories.split(","); for (int i = 0; i < categories.length; i++) { Map<String, Object> category = new HashMap<>(); category.put("category", categories[i]); category.put("recommendations", 0L); recommendationSummary.add(category); } } } return recommendationSummary; }  List<Map<String,Object>> getRecommendationSummary(String assetGroup, String application); Map<String,Object> getSummaryByApplication(String assetGroup, String category); Map<String, Object> getSummaryByApplication(String assetGroup); Map<String,Object> getRecommendations(String assetGroup, String category, String application); Map<String,Object> getRecommendationDetail(String assetGroup, String recommendationId, String application); @SuppressWarnings("deprecation") Map<String,Object> getRecommendation(String recommendationId); List<Map<String,Object>> getGeneralRecommendationSummary(List<String> providers); Map<String,Object> getGeneralRecommendations(String category, List<String> providers); Map<String,Object> getGeneralRecommendationDetail(String recommendationId);  }