class VulnerabilityController implements Constants {

	@SuppressWarnings("unchecked")
	@RequestMapping(path = "/v1/vulnerabilities/detail/{resourceId}", method = RequestMethod.GET)
	public ResponseEntity<Object> getVulnerabilityDetailsByResourceId(
			@PathVariable(name = "resourceId", required = true) String resourceId,
			@RequestParam(name = "searchtext", required = false) String searchtext,
			@RequestParam(name = "from", required = false) Integer from,
			@RequestParam(name = "size", required = false) Integer size) {

		Integer iFrom = from == null ? 0 : from;
		Integer iSize = size == null ? 0 : size;

		ResponseWithCount response;
		try {
			List<Map<String, Object>> masterDetailList = vulnerabilityService
					.getVulnerabilityDetailsByResourceId(resourceId);
			masterDetailList = (List<Map<String, Object>>) vulnerabilityService
					.filterMatchingCollectionElements(masterDetailList, searchtext, true);
			if (masterDetailList.isEmpty()) {
				return ResponseUtils
						.buildSucessResponse(new ResponseWithCount(new ArrayList<Map<String, Object>>(), 0));
			}

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

			int endIndex = 0;

			if (iSize == 0) {
				iSize = masterDetailList.size();
			}

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

			List<Map<String, Object>> subDetailList = masterDetailList.subList(iFrom, endIndex);

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

		} catch (Exception e) {
			LOGGER.error(EXE_VULN, e);
			return ResponseUtils.buildFailureResponse(e);
		}
		return ResponseUtils.buildSucessResponse(response);
	}

}