class AssetDetailController {

    @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/aws-notifications/details", method = RequestMethod.POST)
    public ResponseEntity<Object> getAwsNotificationDetails(@RequestBody(required = true) PageFilterRequest request,
            @PathVariable(name = "resourceId", required = true) String instanceId) {

        Map<String, Object> response = new HashMap<>();

        if (Strings.isNullOrEmpty(instanceId)) {
            return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_INSTANCEID));
        }
        int from = request.getFrom();
        if (from < 0) {
            return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE));

        }

        int size = request.getSize();

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

        List<Map<String, Object>> detailInfo = new ArrayList<>();

        try {
            detailInfo = assetService.getNotificationDetails(instanceId, filter, request.getSearchText());
            response.put("response", detailInfo);

            if (detailInfo.isEmpty()) {
                throw new NoDataFoundException("No data found");
            }

            if (from >= detailInfo.size()) {
                return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_EXCEEDS));
            }

            int endIndex = 0;

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

            if (endIndex == 0) {
                endIndex = detailInfo.size();
            }
            List<Map<String, Object>> subDetailList = detailInfo.subList(from, endIndex);
            return ResponseUtils.buildSucessResponse(subDetailList);

        } catch (Exception e) {
            LOGGER.error("Error in getAwsNotificationDetails ",e);
            List<Map<String, Object>> subDetailList = new ArrayList<>();
            return ResponseUtils.buildSucessResponse(subDetailList);
        }

    }

}