class VulnerabilityController implements Constants {

	@Cacheable(cacheNames = "trendsvuln", key = "#request.vulnCacheKey", unless = "#result.statusCodeValue!=200")
	@RequestMapping(path = "/v1/vulnerabilities/trend/total-affected", method = RequestMethod.POST)
	public ResponseEntity<Object> getVulnerabilityAssetsTrend(@RequestBody(required = true) TrendRequest request) {

		String ag = request.getAg();
		if (Strings.isNullOrEmpty(ag)) {
			return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY));
		}
		Date from = request.getFrom();
		if (from == null) {
			Calendar cal = Calendar.getInstance();
			cal.setTimeZone(TimeZone.getTimeZone("UTC"));
			cal.add(Calendar.DATE, NEG_THIRTY);
			from = cal.getTime();
		}

		Map<String, String> filter = request.getFilter();
		String severity = SEVERITY_LEVELS;
		if (filter != null) {
			severity = filter.get("severity");
			if (severity == null) {
				severity = SEVERITY_LEVELS;
			}
		}

		Map<String, Object> response = new HashMap<>();
		try {
			response.put("trend", vulnerabilityService.getVulnerabilityAssetsTrend(ag, severity, from));
		} catch (DataException e) {
			LOGGER.error("Error in getVulnerabilityAssetsTrend ", e);
			return ResponseUtils.buildFailureResponse(e);
		}

		return ResponseUtils.buildSucessResponse(response);

	}

}