class AssetDetailController {

    @RequestMapping(path = "/v1/{assetGroup}/ec2/{resourceId}/open-ports", method = RequestMethod.GET)
    public ResponseEntity<Object> getOpenPortsByInstanceId(
            @PathVariable(name = "resourceId", required = true) String instanceId,
            @RequestParam(name = "from", required = false) Integer from,
            @RequestParam(name = "size", required = false) Integer size,
            @RequestParam(name = "searchtext", required = false) String searchText) {
    	if (!qualysEnabled) {
            return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_QUALYS_NOT_ENABLED));
    	}
        List<Map<String, Object>> subDetailList ;
        if (Strings.isNullOrEmpty(instanceId)) {
            return ResponseUtils.buildFailureResponse(new Exception("Instance Id is Mandatory"));
        }
        ResponseWithCount response;
        try {
            List<Map<String, Object>> openPortList = assetService
                    .getOpenPortDetails(instanceId, from, size, searchText);

            if (openPortList.isEmpty()) {
                throw new NoDataFoundException(" No data found");
            }
            if (from != null && size != null) {
                if (from >= openPortList.size()) {
                    throw new DataException(AssetConstants.ERROR_FROM_EXCEEDS);
                }

                int endIndex = 0;

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

                if (from == 0 && size == 0) {
                    subDetailList = openPortList;
                } else {
                    subDetailList = openPortList.subList(from, endIndex);
                }
            } else {
                subDetailList = openPortList;
            }
            response = new ResponseWithCount(subDetailList, openPortList.size());
        } catch (Exception e) {
            return ResponseUtils.buildFailureResponse(e);
        }
        return ResponseUtils.buildSucessResponse(response);
    }

}