class PatchingController implements Constants {

    @RequestMapping(path = "/v1/patching/detail", method = RequestMethod.POST)
    public ResponseEntity<Object> getPatchingDetails(@RequestBody(required = true) Request request) {

        ResponseWithCount response = null;
        String assetGroup = request.getAg();
        if (Strings.isNullOrEmpty(assetGroup)) {
            return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY));
        }

        int from = request.getFrom();
        int size = request.getSize();
        if (from < 0) {
            return ResponseUtils.buildFailureResponse(new Exception("From should not be a negative number"));

        }

        String searchText = request.getSearchtext();

        Map<String, String> filter = request.getFilter();
        try {

            List<Map<String, Object>> masterDetailList = patchingService.getPatchingDetails(assetGroup, filter);

            masterDetailList = (List<Map<String, Object>>) patchingService.filterMatchingCollectionElements(
                    masterDetailList, searchText, true);

            if (masterDetailList.isEmpty()) {
                return ResponseUtils.buildSucessResponse(new ArrayList<Map<String, Object>>());
            }

            if (from >= masterDetailList.size()) {
                return ResponseUtils.buildFailureResponse(new ServiceException("From exceeds the size of list"));
            }

            int endIndex = 0;

            if ((from + size) > masterDetailList.size()) {
                endIndex = masterDetailList.size();
            } else {
                endIndex = from + size;
            }

            if (endIndex == 0) {
                endIndex = masterDetailList.size();
            }
            // from - inclusive, endIndex - exclusive
            List<Map<String, Object>> subDetailList = masterDetailList.subList(from, endIndex);

            response = new ResponseWithCount(subDetailList, masterDetailList.size());

        } catch (ServiceException e) {
            LOGGER.error(PATCHING_EXCEPTION, e.getMessage());
            return complianceService.formatException(e);
        }
        return ResponseUtils.buildSucessResponse(response);
    }

}