@Test public void getRecommendationDetailTest_Exception() throws Exception { Request request = new Request(); assertTrue(recommendationsController.getRecommendationDetail(request).getStatusCode() == HttpStatus.EXPECTATION_FAILED); Map<String,String> filter = new HashMap<>(); filter.put("test", "test"); request.setFilter(filter); assertTrue(recommendationsController.getRecommendationDetail(request).getStatusCode() == HttpStatus.EXPECTATION_FAILED); filter = new HashMap<>(); filter.put(AssetConstants.FILTER_RECOMMENDATION_ID,AssetConstants.FILTER_RECOMMENDATION_ID); request.setFilter(filter); assertTrue(recommendationsController.getRecommendationDetail(request).getStatusCode() == HttpStatus.EXPECTATION_FAILED); filter.put("general", "false"); request.setFilter(filter); assertTrue(recommendationsController.getRecommendationDetail(request).getStatusCode() == HttpStatus.EXPECTATION_FAILED); filter.put("general", "true"); request.setFilter(filter); request.setAg("ag"); request.setFrom(-1); assertTrue(recommendationsController.getRecommendationDetail(request).getStatusCode() == HttpStatus.EXPECTATION_FAILED); Map<String,Object> recommendations = new HashMap<>(); List<Map<String,Object>> resp = new ArrayList<>(); Map<String,Object> recommendation = new HashMap<>(); recommendation.put("recommendationId", "id"); resp.add(recommendation); recommendations.put("resources", resp); request.setFrom(2); when(recommendationsService.getRecommendationDetail(anyString(),anyString(),anyString(),anyString())).thenReturn(recommendations); ReflectionTestUtils.setField(recommendationsController, "recommendationsService", recommendationsService); assertTrue(recommendationsController.getRecommendationDetail(request).getStatusCode() == HttpStatus.EXPECTATION_FAILED); request.setFrom(0); request.setSize(1); when(recommendationsService.getRecommendationDetail(anyString(),anyString(),anyString(),anyString())).thenThrow(new DataException()); assertTrue(recommendationsController.getRecommendationDetail(request).getStatusCode() == HttpStatus.EXPECTATION_FAILED); }
@SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations/detail") public ResponseEntity<Object> getRecommendationDetail(@RequestBody(required = true) Request request) { Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION,AssetConstants.FILTER_RECOMMENDATION_ID,AssetConstants.FILTER_GENERAL); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } if (!filter.containsKey(AssetConstants.FILTER_RECOMMENDATION_ID)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_RECOMMENDATION_ID+" is mandatory in filter")); } if(!filter.containsKey(AssetConstants.FILTER_GENERAL)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_GENERAL+" is mandatory in filter")); } String general = filter.get(AssetConstants.FILTER_GENERAL); String assetGroup = request.getAg(); if (general.equals(AssetConstants.FALSE) && StringUtils.isBlank(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); String recommendationId = filter.get(AssetConstants.FILTER_RECOMMENDATION_ID); String application = filter.get(AssetConstants.FILTER_APPLICATION); Map<String, Object> recommendationDetails; try { recommendationDetails = recommendationsService.getRecommendationDetail(assetGroup,recommendationId,application,general); } catch (DataException e) { LOGGER.error("Error in getRecommendationDetail "+ e); return ResponseUtils.buildFailureResponse(e); } List<Map<String, Object>> masterList = (List<Map<String, Object>>) recommendationDetails.get("resources"); return formResponseWithCount(masterList, from, size, searchText); }
RecommendationsController { @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations/detail") public ResponseEntity<Object> getRecommendationDetail(@RequestBody(required = true) Request request) { Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION,AssetConstants.FILTER_RECOMMENDATION_ID,AssetConstants.FILTER_GENERAL); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } if (!filter.containsKey(AssetConstants.FILTER_RECOMMENDATION_ID)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_RECOMMENDATION_ID+" is mandatory in filter")); } if(!filter.containsKey(AssetConstants.FILTER_GENERAL)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_GENERAL+" is mandatory in filter")); } String general = filter.get(AssetConstants.FILTER_GENERAL); String assetGroup = request.getAg(); if (general.equals(AssetConstants.FALSE) && StringUtils.isBlank(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); String recommendationId = filter.get(AssetConstants.FILTER_RECOMMENDATION_ID); String application = filter.get(AssetConstants.FILTER_APPLICATION); Map<String, Object> recommendationDetails; try { recommendationDetails = recommendationsService.getRecommendationDetail(assetGroup,recommendationId,application,general); } catch (DataException e) { LOGGER.error("Error in getRecommendationDetail "+ e); return ResponseUtils.buildFailureResponse(e); } List<Map<String, Object>> masterList = (List<Map<String, Object>>) recommendationDetails.get("resources"); return formResponseWithCount(masterList, from, size, searchText); } }
RecommendationsController { @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations/detail") public ResponseEntity<Object> getRecommendationDetail(@RequestBody(required = true) Request request) { Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION,AssetConstants.FILTER_RECOMMENDATION_ID,AssetConstants.FILTER_GENERAL); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } if (!filter.containsKey(AssetConstants.FILTER_RECOMMENDATION_ID)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_RECOMMENDATION_ID+" is mandatory in filter")); } if(!filter.containsKey(AssetConstants.FILTER_GENERAL)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_GENERAL+" is mandatory in filter")); } String general = filter.get(AssetConstants.FILTER_GENERAL); String assetGroup = request.getAg(); if (general.equals(AssetConstants.FALSE) && StringUtils.isBlank(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); String recommendationId = filter.get(AssetConstants.FILTER_RECOMMENDATION_ID); String application = filter.get(AssetConstants.FILTER_APPLICATION); Map<String, Object> recommendationDetails; try { recommendationDetails = recommendationsService.getRecommendationDetail(assetGroup,recommendationId,application,general); } catch (DataException e) { LOGGER.error("Error in getRecommendationDetail "+ e); return ResponseUtils.buildFailureResponse(e); } List<Map<String, Object>> masterList = (List<Map<String, Object>>) recommendationDetails.get("resources"); return formResponseWithCount(masterList, from, size, searchText); }  }
RecommendationsController { @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations/detail") public ResponseEntity<Object> getRecommendationDetail(@RequestBody(required = true) Request request) { Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION,AssetConstants.FILTER_RECOMMENDATION_ID,AssetConstants.FILTER_GENERAL); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } if (!filter.containsKey(AssetConstants.FILTER_RECOMMENDATION_ID)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_RECOMMENDATION_ID+" is mandatory in filter")); } if(!filter.containsKey(AssetConstants.FILTER_GENERAL)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_GENERAL+" is mandatory in filter")); } String general = filter.get(AssetConstants.FILTER_GENERAL); String assetGroup = request.getAg(); if (general.equals(AssetConstants.FALSE) && StringUtils.isBlank(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); String recommendationId = filter.get(AssetConstants.FILTER_RECOMMENDATION_ID); String application = filter.get(AssetConstants.FILTER_APPLICATION); Map<String, Object> recommendationDetails; try { recommendationDetails = recommendationsService.getRecommendationDetail(assetGroup,recommendationId,application,general); } catch (DataException e) { LOGGER.error("Error in getRecommendationDetail "+ e); return ResponseUtils.buildFailureResponse(e); } List<Map<String, Object>> masterList = (List<Map<String, Object>>) recommendationDetails.get("resources"); return formResponseWithCount(masterList, from, size, searchText); }  @GetMapping(value = "/v1/recommendations/summary") ResponseEntity<Object> getRecommendationSummary(@RequestParam(name = "ag", required = false) String assetGroup, 
    		@RequestParam(name = "application", required = false) String application, @RequestParam(name = "general", required = true) Boolean general); @GetMapping(value = "/v1/recommendations/summaryByApplication") ResponseEntity<Object> getSummaryByApplication(@RequestParam(name = "ag", required = true) String assetGroup, 
    		@RequestParam(name = "category", required = false) String category); @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations") ResponseEntity<Object> getRecommendations(@RequestBody(required = true) Request request); @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations/detail") ResponseEntity<Object> getRecommendationDetail(@RequestBody(required = true) Request request); @GetMapping(value = "/v1/recommendations/info") ResponseEntity<Object> getRecommendationInfo(@RequestParam(name = "recommendationId", required = true) String recommendationId); }
RecommendationsController { @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations/detail") public ResponseEntity<Object> getRecommendationDetail(@RequestBody(required = true) Request request) { Map<String, String> filter = request.getFilter(); if (filter == null) { filter = new HashMap<>(); } List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION,AssetConstants.FILTER_RECOMMENDATION_ID,AssetConstants.FILTER_GENERAL); for (Map.Entry<String, String> entry : filter.entrySet()) { if (!acceptedFilterKeys.contains(entry.getKey())) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS + StringUtils.join(acceptedFilterKeys, ", "))); } } if (!filter.containsKey(AssetConstants.FILTER_RECOMMENDATION_ID)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_RECOMMENDATION_ID+" is mandatory in filter")); } if(!filter.containsKey(AssetConstants.FILTER_GENERAL)) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.FILTER_GENERAL+" is mandatory in filter")); } String general = filter.get(AssetConstants.FILTER_GENERAL); String assetGroup = request.getAg(); if (general.equals(AssetConstants.FALSE) && StringUtils.isBlank(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); } int from = request.getFrom(); int size = request.getSize(); if (from < 0) { return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); } String searchText = request.getSearchtext(); String recommendationId = filter.get(AssetConstants.FILTER_RECOMMENDATION_ID); String application = filter.get(AssetConstants.FILTER_APPLICATION); Map<String, Object> recommendationDetails; try { recommendationDetails = recommendationsService.getRecommendationDetail(assetGroup,recommendationId,application,general); } catch (DataException e) { LOGGER.error("Error in getRecommendationDetail "+ e); return ResponseUtils.buildFailureResponse(e); } List<Map<String, Object>> masterList = (List<Map<String, Object>>) recommendationDetails.get("resources"); return formResponseWithCount(masterList, from, size, searchText); }  @GetMapping(value = "/v1/recommendations/summary") ResponseEntity<Object> getRecommendationSummary(@RequestParam(name = "ag", required = false) String assetGroup, 
    		@RequestParam(name = "application", required = false) String application, @RequestParam(name = "general", required = true) Boolean general); @GetMapping(value = "/v1/recommendations/summaryByApplication") ResponseEntity<Object> getSummaryByApplication(@RequestParam(name = "ag", required = true) String assetGroup, 
    		@RequestParam(name = "category", required = false) String category); @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations") ResponseEntity<Object> getRecommendations(@RequestBody(required = true) Request request); @SuppressWarnings("unchecked") @PostMapping(value = "/v1/recommendations/detail") ResponseEntity<Object> getRecommendationDetail(@RequestBody(required = true) Request request); @GetMapping(value = "/v1/recommendations/info") ResponseEntity<Object> getRecommendationInfo(@RequestParam(name = "recommendationId", required = true) String recommendationId);  }