@Test public void getCertTrendTest() throws Exception { when(issueTrendService.getTrendProgress(anyString(),anyString(),anyObject(),anyObject(),anyString())).thenReturn(CommonTestUtil.getMapObject()); assertThat(trendController.getCertTrend(CommonTestUtil.getRuleTrendRequest()), is(notNullValue())); assertThat(trendController.getCertTrend(CommonTestUtil.getRuleTrendRequestEmpty()), is(notNullValue())); when(issueTrendService.getTrendProgress(anyString(),anyString(),anyObject(),anyObject(),anyString())).thenThrow(new ServiceException()); ResponseEntity<Object> responseObj = trendController.getCertTrend(CommonTestUtil.getRuleTrendRequest()); assertTrue(responseObj.getStatusCode() == HttpStatus.EXPECTATION_FAILED); }
@RequestMapping(path = "/v1/trend/compliance/certificates", method = RequestMethod.POST) public ResponseEntity<Object> getCertTrend(@RequestBody(required = true) CompliantTrendRequest request) { Map<String, Object> response = new HashMap<>(); String assetGroup = request.getAg(); Date input = request.getFrom(); if (input == null) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.add(Calendar.DATE, NEG_THIRTY); input = cal.getTime(); } Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate fromDate = zdt.toLocalDate(); LocalDate toDate = LocalDate.now(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY)); } try { Map<String, Object> ruleTrendProgressList = trendService.getTrendProgress(assetGroup, null, fromDate, toDate, "certcompliance"); response.put(RESPONSE, ruleTrendProgressList); } catch (ServiceException e) { LOGGER.error("Exception in getCertTrend" , e.getMessage()); return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }
TrendController implements Constants { @RequestMapping(path = "/v1/trend/compliance/certificates", method = RequestMethod.POST) public ResponseEntity<Object> getCertTrend(@RequestBody(required = true) CompliantTrendRequest request) { Map<String, Object> response = new HashMap<>(); String assetGroup = request.getAg(); Date input = request.getFrom(); if (input == null) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.add(Calendar.DATE, NEG_THIRTY); input = cal.getTime(); } Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate fromDate = zdt.toLocalDate(); LocalDate toDate = LocalDate.now(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY)); } try { Map<String, Object> ruleTrendProgressList = trendService.getTrendProgress(assetGroup, null, fromDate, toDate, "certcompliance"); response.put(RESPONSE, ruleTrendProgressList); } catch (ServiceException e) { LOGGER.error("Exception in getCertTrend" , e.getMessage()); return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); } }
TrendController implements Constants { @RequestMapping(path = "/v1/trend/compliance/certificates", method = RequestMethod.POST) public ResponseEntity<Object> getCertTrend(@RequestBody(required = true) CompliantTrendRequest request) { Map<String, Object> response = new HashMap<>(); String assetGroup = request.getAg(); Date input = request.getFrom(); if (input == null) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.add(Calendar.DATE, NEG_THIRTY); input = cal.getTime(); } Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate fromDate = zdt.toLocalDate(); LocalDate toDate = LocalDate.now(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY)); } try { Map<String, Object> ruleTrendProgressList = trendService.getTrendProgress(assetGroup, null, fromDate, toDate, "certcompliance"); response.put(RESPONSE, ruleTrendProgressList); } catch (ServiceException e) { LOGGER.error("Exception in getCertTrend" , e.getMessage()); return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }  }
TrendController implements Constants { @RequestMapping(path = "/v1/trend/compliance/certificates", method = RequestMethod.POST) public ResponseEntity<Object> getCertTrend(@RequestBody(required = true) CompliantTrendRequest request) { Map<String, Object> response = new HashMap<>(); String assetGroup = request.getAg(); Date input = request.getFrom(); if (input == null) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.add(Calendar.DATE, NEG_THIRTY); input = cal.getTime(); } Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate fromDate = zdt.toLocalDate(); LocalDate toDate = LocalDate.now(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY)); } try { Map<String, Object> ruleTrendProgressList = trendService.getTrendProgress(assetGroup, null, fromDate, toDate, "certcompliance"); response.put(RESPONSE, ruleTrendProgressList); } catch (ServiceException e) { LOGGER.error("Exception in getCertTrend" , e.getMessage()); return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }  @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) @RequestMapping(path = "/v1/trend", method = RequestMethod.GET) String getTrend(); @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) 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); String getTrendFromCache(); ResponseEntity<Object> getTrendFromCache(String assetGroup, String fromDate, String toDate, String severity,
            String ruleId); @RequestMapping(path = "/v1/trend/compliance", method = RequestMethod.POST) ResponseEntity<Object> getCompliantTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/compliancebyrule", method = RequestMethod.POST) ResponseEntity<Object> getRuleTrend(@RequestBody(required = true) RuleTrendRequest request); @RequestMapping(path = "/v1/trend/compliance/vulnerabilities", method = RequestMethod.POST) ResponseEntity<Object> getVulnTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/compliance/certificates", method = RequestMethod.POST) ResponseEntity<Object> getCertTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/compliance/tagging", method = RequestMethod.POST) ResponseEntity<Object> getTagTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/issues", method = RequestMethod.POST) ResponseEntity<Object> getTrendIssues(@RequestBody(required = true) CompliantTrendRequest request); }
TrendController implements Constants { @RequestMapping(path = "/v1/trend/compliance/certificates", method = RequestMethod.POST) public ResponseEntity<Object> getCertTrend(@RequestBody(required = true) CompliantTrendRequest request) { Map<String, Object> response = new HashMap<>(); String assetGroup = request.getAg(); Date input = request.getFrom(); if (input == null) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.add(Calendar.DATE, NEG_THIRTY); input = cal.getTime(); } Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate fromDate = zdt.toLocalDate(); LocalDate toDate = LocalDate.now(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY)); } try { Map<String, Object> ruleTrendProgressList = trendService.getTrendProgress(assetGroup, null, fromDate, toDate, "certcompliance"); response.put(RESPONSE, ruleTrendProgressList); } catch (ServiceException e) { LOGGER.error("Exception in getCertTrend" , e.getMessage()); return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }  @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) @RequestMapping(path = "/v1/trend", method = RequestMethod.GET) String getTrend(); @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) 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); String getTrendFromCache(); ResponseEntity<Object> getTrendFromCache(String assetGroup, String fromDate, String toDate, String severity,
            String ruleId); @RequestMapping(path = "/v1/trend/compliance", method = RequestMethod.POST) ResponseEntity<Object> getCompliantTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/compliancebyrule", method = RequestMethod.POST) ResponseEntity<Object> getRuleTrend(@RequestBody(required = true) RuleTrendRequest request); @RequestMapping(path = "/v1/trend/compliance/vulnerabilities", method = RequestMethod.POST) ResponseEntity<Object> getVulnTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/compliance/certificates", method = RequestMethod.POST) ResponseEntity<Object> getCertTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/compliance/tagging", method = RequestMethod.POST) ResponseEntity<Object> getTagTrend(@RequestBody(required = true) CompliantTrendRequest request); @RequestMapping(path = "/v1/trend/issues", method = RequestMethod.POST) ResponseEntity<Object> getTrendIssues(@RequestBody(required = true) CompliantTrendRequest request);  }