class VulnerabilityController implements Constants {

	@Cacheable(cacheNames = "trends", key = "#request.vulnCacheKey", unless = "#result.statusCodeValue!=200")
	@RequestMapping(path = "/v1/vulnerabilities/trend/open-new", method = RequestMethod.POST)
	public ResponseEntity<Object> getVulnerabilityTrend(@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 {
			List<Map<String, Object>> trendList = vulnerabilityService.getVulnerabilityNewOpenTrend(ag, severity, from);
			response.put("trend", trendList);
			return ResponseUtils.buildSucessResponse(response);
		} catch (Exception e) {
			return ResponseUtils.buildFailureResponse(e);
		}

	}

}