class VulnerabilityController implements Constants {

	@SuppressWarnings("unchecked")
	@PostMapping(value = "/v1/vulnerabilities/detail")
	public ResponseEntity<Object> getVulnerabilitiesDetails(@RequestBody(required = true) Request request) {

		ResponseWithCount response;
		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();
		if (filter == null) {
			filter = new HashMap<>();
		}

		try {

			List<Map<String, Object>> masterDetailList = vulnerabilityService.getVulnerabilitiesDetails(assetGroup,
					filter);

			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 (from >= masterDetailList.size()) {
				return ResponseUtils.buildFailureResponse(new Exception("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 (Exception e) {
			LOGGER.error(EXE_VULN, e);
			return ResponseUtils.buildFailureResponse(e);
		}
		return ResponseUtils.buildSucessResponse(response);
	}

}