class DownloadController implements Constants {

    @ApiOperation(httpMethod = "POST", value = "Download Service Details in CSV or Excel")
    @RequestMapping(path = "/v1/download/services", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
    public ResponseEntity<Object> getIssuesDownload(final HttpServletRequest servletRequest,
            final HttpServletResponse servletResponse,
            @ApiParam(value = "Provide Download File Format (excel or csv). Default is csv", required = false) @RequestParam(name = "fileFormat", required = false) String fileFormat,
            @ApiParam(value = "Provide serviceId 1-policyViolationList,2-policyOverviewList,3-patchingList,4-taggingList,5-certificateList,6-vulnerabilitiesList", required = false) @RequestParam("serviceId") int serviceId,
            @ApiParam(value = "Provide Service Search Filter", required = false) @RequestBody(required = false) Request request)
            throws Exception {
        try {
            String assetGroup = request.getAg();
            JsonArray responseArray = null;

            String serviceName = null;
            String serviceEndpoint = null;
            if (Strings.isNullOrEmpty(assetGroup)) {
                return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY));
            }
            if (request.getSize() <= 0 || request.getSize() > 100000) {
                return ResponseUtils.buildFailureResponse(new Exception(
                        "enter valid size/ you can max download 100k records"));
            }
          
            List<Map<String, Object>> filterMap = downloadRepository.getFiltersFromDb(serviceId);
            if (!filterMap.isEmpty()) {
                for (Map<String, Object> filterMethodName : filterMap) {
                    if (filterMethodName.get("serviceName") != null && filterMethodName.get("serviceEndpoint") != null) {
                        serviceName = filterMethodName.get("serviceName").toString();
                        serviceEndpoint = filterMethodName.get("serviceEndpoint").toString();
                    }
                }
                Gson gson = new GsonBuilder().disableHtmlEscaping().create();
                String jsonString = gson.toJson(request);

                if (!StringUtils.isEmpty(serviceEndpoint) && !StringUtils.isEmpty(serviceDnsName) && !StringUtils.isEmpty(jsonString)) {

                    String serviceResponse = PacHttpUtils.doHttpsPost(serviceDnsName+serviceEndpoint, jsonString, getTokenHeader(servletRequest));
                    if(!StringUtil.isNullOrEmpty(serviceResponse)){
                    responseArray = getServiceDetails(serviceResponse);
                    downloadFileService.downloadData(servletResponse, responseArray, fileFormat, serviceName);
                    return new ResponseEntity<>(HttpStatus.OK);
                    }else{
                    	return new ResponseEntity<>(HttpStatus.FORBIDDEN);
                    }
                } else {
                    return ResponseUtils.buildFailureResponse(new Exception(
                            "Please configure the serviceEndpoint or urlParameters"));
                }
            } else {
                return ResponseUtils.buildFailureResponse(new Exception(
                        "Please configure the serviceName and serviceEndpoint"));
            }
           
        } catch (Exception e) {
            LOGGER.error(e.toString());
            return new ResponseEntity<>(HttpStatus.FORBIDDEN);
        }
    }

}