class TrendController implements Constants {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @ApiResponses(value = { @ApiResponse(code = 200, message = "Successfully retrieved trend"),
            @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
            @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
            @ApiResponse(code = 404, message = "The resource you were trying to reach is not found"),
            @ApiResponse(code = 417, message = "Expectation Failed") })
    
    @ApiOperation(value = "view the issue trends over the period of last 3 months", response = Iterable.class)
    // @Cacheable(cacheNames="trends",unless="#result.status==200")
    @Cacheable(cacheNames = "trends", key = "T(java.util.Objects).hash(#p0,#p1, #p2, #p3, #p4, #p5, #p6, #p7)")
    @RequestMapping(path = "/v1/trend/issueTrend", method = RequestMethod.GET)
    public ResponseEntity<Object> getTrendForIssues(@RequestParam("ag") String assetGroup,
            @RequestParam(name = "frdt", required = false) String fromDate,
            @RequestParam(name = "todt", required = false) String toDate,
            @RequestParam(name = "severity", required = false) String severity,
            @RequestParam(name = "ruleId", required = false) String ruleId,
            @RequestParam(name = "policyId", required = false) String policyId,
            @RequestParam(name = "app", required = false) String app,
            @RequestParam(name = "env", required = false) String env) {
        try {
            return ResponseUtils.buildSucessResponse(trendService.getTrendForIssues(assetGroup, fromDate, toDate,
                    severity, ruleId, policyId, app, env));
        } catch (ServiceException e) {
            if (null!=e.getCause() && e.getCause().toString().contains(NO_DATA_FOUND)) {
                LOGGER.error("Exception in getPatchingDetails" , e.getMessage());
                Date endDate = new Date(System.currentTimeMillis());
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.DATE, NEG_FIFTEEN);
                Date startDate = cal.getTime();
                List dates = DateUtils.getAllDatesBetweenDates(startDate, endDate, "yyyy-MM-dd'T'HH:mm:ssZ");
                Map<String, Long> data = new HashMap<>();
                dates.stream().forEach(obj -> data.put((String) obj, 0L));
                return ResponseUtils.buildSucessResponse(data);
            } else {
                return ResponseUtils.buildFailureResponse(e);
            }
        }

    }

}