class 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);
    }

}