From ac8902f88b679a4582bbe4fb089b5adc1c5f2dce Mon Sep 17 00:00:00 2001 From: jacob6838 Date: Thu, 5 Dec 2024 12:40:00 -0700 Subject: [PATCH] Allow any role at or above requested --- .../api/controllers/AssessmentController.java | 42 ++-- .../ode/api/controllers/BsmController.java | 10 +- .../ode/api/controllers/ConfigController.java | 82 ++++---- .../api/controllers/DecoderController.java | 5 +- .../ode/api/controllers/EventController.java | 184 +++++++++--------- .../controllers/IntersectionController.java | 4 +- .../ode/api/controllers/MapController.java | 12 +- .../controllers/NotificationController.java | 56 +++--- .../ode/api/controllers/ReportController.java | 6 +- .../ode/api/controllers/SpatController.java | 6 +- .../ode/api/controllers/UserController.java | 97 ++++----- .../ode/api/services/PermissionService.java | 86 ++++---- 12 files changed, 300 insertions(+), 290 deletions(-) diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/AssessmentController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/AssessmentController.java index 9a84c263..17862104 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/AssessmentController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/AssessmentController.java @@ -56,7 +56,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/connection_of_travel", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity> findConnectionOfTravelAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -72,8 +72,7 @@ public ResponseEntity> findConnectionOfTravel } else { Query query = connectionOfTravelAssessmentRepo.getQuery(intersectionID, startTime, endTime, latest); long count = connectionOfTravelAssessmentRepo.getQueryResultCount(query); - - + logger.info("Returning ProcessedMap Response with Size: " + count); return ResponseEntity.ok(connectionOfTravelAssessmentRepo.find(query)); } @@ -81,7 +80,7 @@ public ResponseEntity> findConnectionOfTravel @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/connection_of_travel/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity countConnectionOfTravelAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -96,12 +95,12 @@ public ResponseEntity countConnectionOfTravelAssessment( Query query = connectionOfTravelAssessmentRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = connectionOfTravelAssessmentRepo.getQueryFullCount(query); - }else{ + } else { count = connectionOfTravelAssessmentRepo.getQueryResultCount(query); } - + logger.info("Found: " + count + " Connection of Travel Assessments"); return ResponseEntity.ok(count); } @@ -109,7 +108,7 @@ public ResponseEntity countConnectionOfTravelAssessment( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/lane_direction_of_travel", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity> findLaneDirectionOfTravelAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -133,7 +132,7 @@ public ResponseEntity> findLaneDirectionOf @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/lane_direction_of_travel/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity countLaneDirectionOfTravelAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -148,9 +147,9 @@ public ResponseEntity countLaneDirectionOfTravelAssessment( Query query = laneDirectionOfTravelAssessmentRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = laneDirectionOfTravelAssessmentRepo.getQueryFullCount(query); - }else{ + } else { count = laneDirectionOfTravelAssessmentRepo.getQueryResultCount(query); } @@ -162,7 +161,7 @@ public ResponseEntity countLaneDirectionOfTravelAssessment( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/signal_state_assessment", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity> findSignalStateAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -176,7 +175,7 @@ public ResponseEntity> findSignalStateAssessment( list.add(MockAssessmentGenerator.getStopLineStopAssessment()); return ResponseEntity.ok(list); } else { - + Query query = stopLineStopAssessmentRepo.getQuery(intersectionID, startTime, endTime, latest); long count = stopLineStopAssessmentRepo.getQueryResultCount(query); logger.info("Returning SignalStateAssessment Response with Size: " + count); @@ -186,7 +185,7 @@ public ResponseEntity> findSignalStateAssessment( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/signal_state_assessment/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity countSignalStateAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -198,17 +197,16 @@ public ResponseEntity countSignalStateAssessment( if (testData) { return ResponseEntity.ok(1L); } else { - + Query query = stopLineStopAssessmentRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = stopLineStopAssessmentRepo.getQueryFullCount(query); - }else{ + } else { count = stopLineStopAssessmentRepo.getQueryResultCount(query); } - logger.info("Found: " + count + " Lane Direction of Travel Assessments"); return ResponseEntity.ok(count); } @@ -216,7 +214,7 @@ public ResponseEntity countSignalStateAssessment( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/signal_state_event_assessment", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity> findSignalStateEventAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -239,7 +237,7 @@ public ResponseEntity> findSignalStateEventAsses @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/assessments/signal_state_event_assessment/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity countSignalStateEventAssessment( @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @@ -253,9 +251,9 @@ public ResponseEntity countSignalStateEventAssessment( } else { Query query = signalStateEventAssessmentRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = signalStateEventAssessmentRepo.getQueryFullCount(query); - }else{ + } else { count = signalStateEventAssessmentRepo.getQueryResultCount(query); } logger.info("Found: " + count + " Signal State Event Assessments"); diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/BsmController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/BsmController.java index 5bc83d50..bc212876 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/BsmController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/BsmController.java @@ -39,7 +39,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/bsm/json", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER')") public ResponseEntity> findBSMs( @RequestParam(name = "origin_ip", required = false) String originIp, @RequestParam(name = "vehicle_id", required = false) String vehicleId, @@ -53,7 +53,8 @@ public ResponseEntity> findBSMs( if (testData) { return ResponseEntity.ok(MockBsmGenerator.getJsonBsms()); } else { - List geoData = odeBsmJsonRepo.findOdeBsmDataGeo(originIp, vehicleId, startTime, endTime, longitude, latitude, distanceInMeters); + List geoData = odeBsmJsonRepo.findOdeBsmDataGeo(originIp, vehicleId, startTime, endTime, + longitude, latitude, distanceInMeters); logger.info("Found " + geoData.size() + " BSMs"); return ResponseEntity.ok(geoData); } @@ -61,7 +62,7 @@ public ResponseEntity> findBSMs( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/bsm/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER')") public ResponseEntity countBSMs( @RequestParam(name = "origin_ip", required = false) String originIp, @RequestParam(name = "vehicle_id", required = false) String vehicleId, @@ -75,7 +76,8 @@ public ResponseEntity countBSMs( if (testData) { return ResponseEntity.ok(10L); } else { - long counts = odeBsmJsonRepo.countOdeBsmDataGeo(originIp, vehicleId, startTime, endTime, longitude, latitude, distanceInMeters); + long counts = odeBsmJsonRepo.countOdeBsmDataGeo(originIp, vehicleId, startTime, endTime, longitude, + latitude, distanceInMeters); logger.info("Found " + counts + " BSMs"); return ResponseEntity.ok(counts); } diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ConfigController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ConfigController.java index 07b7f294..ee651c01 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ConfigController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ConfigController.java @@ -64,8 +64,6 @@ public class ConfigController { private final String intersectionConfigTemplate = "%s/config/intersection/%s/%s/%s"; private final String defaultConfigAllTemplate = "%s/config/defaults"; private final String intersectionConfigAllTemplate = "%s/config/intersections"; - - // General Setter for Default Configs @CrossOrigin(origins = "http://localhost:3000") @@ -74,32 +72,31 @@ public class ConfigController { public @ResponseBody ResponseEntity default_config(@RequestBody DefaultConfig config) { try { - // If Organization Intersection Checking is Enabled. Don't allow any parameter edits. - if(!props.getEnableOrganizationIntersectionChecking()){ + // If Organization Intersection Checking is Enabled. Don't allow any parameter + // edits. + if (!props.getEnableOrganizationIntersectionChecking()) { return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).contentType(MediaType.TEXT_PLAIN) - .body("This API is configured for multi-organization use. While multi-organization use is enabled users are not allowed to change default parameters for all intersections. If available consider using an intersection override parameter instead. Otherwise, please contact server administrator for options on updating default parameters"); + .body("This API is configured for multi-organization use. While multi-organization use is enabled users are not allowed to change default parameters for all intersections. If available consider using an intersection override parameter instead. Otherwise, please contact server administrator for options on updating default parameters"); } - + String resourceURL = String.format(defaultConfigTemplate, props.getCmServerURL(), config.getKey()); ResponseEntity response = restTemplate.getForEntity(resourceURL, DefaultConfig.class); - - if(response.getStatusCode().is2xxSuccessful()){ + if (response.getStatusCode().is2xxSuccessful()) { DefaultConfig previousConfig = response.getBody(); previousConfig.setValue(config.getValue()); - HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity requestEntity = new HttpEntity<>(previousConfig, headers); restTemplate.postForEntity(resourceURL, requestEntity, DefaultConfig.class); defaultConfigRepository.save(previousConfig); - }else{ - return ResponseEntity.status(response.getStatusCode()).contentType(MediaType.TEXT_PLAIN).body("Conflict Monitor API was unable to change setting on conflict monitor."); + } else { + return ResponseEntity.status(response.getStatusCode()).contentType(MediaType.TEXT_PLAIN) + .body("Conflict Monitor API was unable to change setting on conflict monitor."); } - return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(config.toString()); } catch (Exception e) { logger.error("Failure in Default Config" + e.getStackTrace()); @@ -111,16 +108,18 @@ public class ConfigController { // General Setter for Intersection Configs @CrossOrigin(origins = "http://localhost:3000") @PostMapping(value = "/config/intersection") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#config.intersectionID) and @PermissionService.hasRole('ADMIN'))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#config.intersectionID) and @PermissionService.hasRole('OPERATOR'))") public @ResponseBody ResponseEntity intersection_config(@RequestBody IntersectionConfig config) { try { - String resourceURL = String.format(intersectionConfigTemplate, props.getCmServerURL(),config.getRoadRegulatorID(),config.getIntersectionID(), config.getKey()); - ResponseEntity response = restTemplate.getForEntity(resourceURL, IntersectionConfig.class); - - if(response.getStatusCode().is2xxSuccessful()){ + String resourceURL = String.format(intersectionConfigTemplate, props.getCmServerURL(), + config.getRoadRegulatorID(), config.getIntersectionID(), config.getKey()); + ResponseEntity response = restTemplate.getForEntity(resourceURL, + IntersectionConfig.class); + + if (response.getStatusCode().is2xxSuccessful()) { IntersectionConfig previousConfig = response.getBody(); - if(previousConfig == null){ + if (previousConfig == null) { previousConfig = config; } previousConfig.setValue(config.getValue()); @@ -132,8 +131,9 @@ public class ConfigController { restTemplate.postForEntity(resourceURL, requestEntity, IntersectionConfig.class); intersectionConfigRepository.save(previousConfig); - }else{ - return ResponseEntity.status(response.getStatusCode()).contentType(MediaType.TEXT_PLAIN).body("Conflict Monitor API was unable to change setting on conflict monitor."); + } else { + return ResponseEntity.status(response.getStatusCode()).contentType(MediaType.TEXT_PLAIN) + .body("Conflict Monitor API was unable to change setting on conflict monitor."); } return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(config.toString()); @@ -146,12 +146,13 @@ public class ConfigController { @CrossOrigin(origins = "http://localhost:3000") @DeleteMapping(value = "/config/intersection") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#config.intersectionID) and @PermissionService.hasRole('ADMIN'))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#config.intersectionID) and @PermissionService.hasRole('OPERATOR'))") public @ResponseBody ResponseEntity intersection_config_delete(@RequestBody IntersectionConfig config) { Query query = intersectionConfigRepository.getQuery(config.getKey(), config.getRoadRegulatorID(), config.getIntersectionID()); try { - String resourceURL = String.format(intersectionConfigTemplate, props.getCmServerURL(),config.getRoadRegulatorID(),config.getIntersectionID(), config.getKey()); + String resourceURL = String.format(intersectionConfigTemplate, props.getCmServerURL(), + config.getRoadRegulatorID(), config.getIntersectionID(), config.getKey()); restTemplate.delete(resourceURL); intersectionConfigRepository.delete(query); return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(config.toString()); @@ -164,17 +165,17 @@ public class ConfigController { // Retrieve All Config Params for Intersection Configs @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/config/default/all", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('USER')") public @ResponseBody ResponseEntity> default_config_all() { - + String resourceURL = String.format(defaultConfigAllTemplate, props.getCmServerURL()); ResponseEntity response = restTemplate.getForEntity(resourceURL, DefaultConfigMap.class); - if(response.getStatusCode().is2xxSuccessful()){ + if (response.getStatusCode().is2xxSuccessful()) { DefaultConfigMap configMap = response.getBody(); ArrayList results = new ArrayList<>(configMap.values()); return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(results); - }else{ + } else { return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON) .body(new ArrayList()); } @@ -183,17 +184,17 @@ public class ConfigController { // Retrieve All Parameters for Unique Intersections @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/config/intersection/all", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public @ResponseBody ResponseEntity> intersection_config_all() { - String resourceURL = String.format(intersectionConfigAllTemplate, props.getCmServerURL()); - ResponseEntity response = restTemplate.getForEntity(resourceURL, IntersectionConfigMap.class); - if(response.getStatusCode().is2xxSuccessful()){ + ResponseEntity response = restTemplate.getForEntity(resourceURL, + IntersectionConfigMap.class); + if (response.getStatusCode().is2xxSuccessful()) { IntersectionConfigMap configMap = response.getBody(); ArrayList results = new ArrayList<>(configMap.listConfigs()); return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(results); - }else{ + } else { return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON) .body(new ArrayList()); } @@ -201,7 +202,7 @@ public class ConfigController { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/config/intersection/unique", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public @ResponseBody ResponseEntity> intersection_config_unique( @RequestParam(name = "road_regulator_id", required = true) int roadRegulatorID, @RequestParam(name = "intersection_id", required = true) int intersectionID) { @@ -209,8 +210,9 @@ public class ConfigController { // Query Default Configuration String defaultResourceURL = String.format(defaultConfigAllTemplate, props.getCmServerURL()); List defaultList = new ArrayList<>(); - ResponseEntity defaultConfigResponse = restTemplate.getForEntity(defaultResourceURL, DefaultConfigMap.class); - if(defaultConfigResponse.getStatusCode().is2xxSuccessful()){ + ResponseEntity defaultConfigResponse = restTemplate.getForEntity(defaultResourceURL, + DefaultConfigMap.class); + if (defaultConfigResponse.getStatusCode().is2xxSuccessful()) { DefaultConfigMap configMap = defaultConfigResponse.getBody(); defaultList = new ArrayList<>(configMap.values()); } @@ -218,20 +220,20 @@ public class ConfigController { // Query Intersection Configuration List intersectionList = new ArrayList<>(); String intersectionResourceURL = String.format(intersectionConfigAllTemplate, props.getCmServerURL()); - ResponseEntity intersectionConfigResponse = restTemplate.getForEntity(intersectionResourceURL, IntersectionConfigMap.class); - if(intersectionConfigResponse.getStatusCode().is2xxSuccessful()){ + ResponseEntity intersectionConfigResponse = restTemplate + .getForEntity(intersectionResourceURL, IntersectionConfigMap.class); + if (intersectionConfigResponse.getStatusCode().is2xxSuccessful()) { IntersectionConfigMap configMap = intersectionConfigResponse.getBody(); ArrayList results = new ArrayList<>(configMap.listConfigs()); - for(IntersectionConfig config: results){ - if(config.getRoadRegulatorID()== roadRegulatorID && config.getIntersectionID() == intersectionID){ + for (IntersectionConfig config : results) { + if (config.getRoadRegulatorID() == roadRegulatorID && config.getIntersectionID() == intersectionID) { intersectionList.add(config); } } } - List finalConfig = new ArrayList<>(); for (DefaultConfig defaultConfig : defaultList) { @@ -245,8 +247,6 @@ public class ConfigController { finalConfig.add(addConfig); } - - if (finalConfig.size() > -1) { return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(finalConfig); } else { diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/DecoderController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/DecoderController.java index 976e93a0..08cb38fe 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/DecoderController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/DecoderController.java @@ -40,7 +40,8 @@ public class DecoderController { @Autowired ConflictMonitorApiProperties props; - @Autowired DecoderManager decoderManager; + @Autowired + DecoderManager decoderManager; // private StringPublisher bsmPublisher; @@ -79,7 +80,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/decoder/upload", method = RequestMethod.POST, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER')") public @ResponseBody ResponseEntity decode_request( @RequestBody EncodedMessage encodedMessage, @RequestParam(name = "test", required = false, defaultValue = "false") boolean testData) { diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/EventController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/EventController.java index 3433b3a0..75fa0320 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/EventController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/EventController.java @@ -100,8 +100,6 @@ public class EventController { @Autowired BsmEventRepository bsmEventRepo; - - @Autowired ConflictMonitorApiProperties props; @@ -116,7 +114,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/intersection_reference_alignment", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findIntersectionReferenceAlignmentEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -138,7 +136,7 @@ public ResponseEntity> findIntersectio @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/intersection_reference_alignment/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countIntersectionReferenceAlignmentEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -152,9 +150,9 @@ public ResponseEntity countIntersectionReferenceAlignmentEvents( Query query = intersectionReferenceAlignmentEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = intersectionReferenceAlignmentEventRepo.getQueryFullCount(query); - }else{ + } else { count = intersectionReferenceAlignmentEventRepo.getQueryResultCount(query); } @@ -165,7 +163,7 @@ public ResponseEntity countIntersectionReferenceAlignmentEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/connection_of_travel", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findConnectionOfTravelEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -187,7 +185,7 @@ public ResponseEntity> findConnectionOfTravelEvent @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/connection_of_travel/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countConnectionOfTravelEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -201,9 +199,9 @@ public ResponseEntity countConnectionOfTravelEvents( Query query = connectionOfTravelEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = connectionOfTravelEventRepo.getQueryFullCount(query); - }else{ + } else { count = connectionOfTravelEventRepo.getQueryResultCount(query); } @@ -214,7 +212,7 @@ public ResponseEntity countConnectionOfTravelEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/connection_of_travel/daily_counts", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getDailyConnectionOfTravelEventCounts( @RequestParam(name = "intersection_id", required = true) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = true) Long startTime, @@ -224,13 +222,14 @@ public ResponseEntity> getDailyConnectionOfTravelEventCounts( if (testData) { return ResponseEntity.ok(MockIDCountGenerator.getDateIDCounts()); } else { - return ResponseEntity.ok(connectionOfTravelEventRepo.getConnectionOfTravelEventsByDay(intersectionID, startTime, endTime)); + return ResponseEntity.ok( + connectionOfTravelEventRepo.getConnectionOfTravelEventsByDay(intersectionID, startTime, endTime)); } } @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/lane_direction_of_travel", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findLaneDirectionOfTravelEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -252,7 +251,7 @@ public ResponseEntity> findLaneDirectionOfTrave @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/lane_direction_of_travel/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countLaneDirectionOfTravelEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -266,9 +265,9 @@ public ResponseEntity countLaneDirectionOfTravelEvent( Query query = laneDirectionOfTravelEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = laneDirectionOfTravelEventRepo.getQueryFullCount(query); - }else{ + } else { count = laneDirectionOfTravelEventRepo.getQueryResultCount(query); } @@ -279,7 +278,7 @@ public ResponseEntity countLaneDirectionOfTravelEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/lane_direction_of_travel/daily_counts", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getDailyLaneDirectionOfTravelEventCounts( @RequestParam(name = "intersection_id", required = true) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = true) Long startTime, @@ -289,13 +288,14 @@ public ResponseEntity> getDailyLaneDirectionOfTravelEventCounts( if (testData) { return ResponseEntity.ok(MockIDCountGenerator.getDateIDCounts()); } else { - return ResponseEntity.ok(laneDirectionOfTravelEventRepo.getLaneDirectionOfTravelEventsByDay(intersectionID, startTime, endTime)); + return ResponseEntity.ok(laneDirectionOfTravelEventRepo.getLaneDirectionOfTravelEventsByDay(intersectionID, + startTime, endTime)); } } @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_group_alignment", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSignalGroupAlignmentEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -317,7 +317,7 @@ public ResponseEntity> findSignalGroupAlignmentE @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_group_alignment/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSignalGroupAlignmentEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -331,9 +331,9 @@ public ResponseEntity countSignalGroupAlignmentEvent( Query query = signalGroupAlignmentEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = signalGroupAlignmentEventRepo.getQueryFullCount(query); - }else{ + } else { count = signalGroupAlignmentEventRepo.getQueryResultCount(query); } @@ -344,7 +344,7 @@ public ResponseEntity countSignalGroupAlignmentEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_group_alignment/daily_counts", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getDailySignalGroupAlignmentEventCounts( @RequestParam(name = "intersection_id", required = true) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = true) Long startTime, @@ -355,13 +355,14 @@ public ResponseEntity> getDailySignalGroupAlignmentEventCounts( if (testData) { return ResponseEntity.ok(MockIDCountGenerator.getDateIDCounts()); } else { - return ResponseEntity.ok(signalGroupAlignmentEventRepo.getSignalGroupAlignmentEventsByDay(intersectionID, startTime, endTime)); + return ResponseEntity.ok(signalGroupAlignmentEventRepo.getSignalGroupAlignmentEventsByDay(intersectionID, + startTime, endTime)); } } @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state_conflict", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSignalStateConflictEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -383,7 +384,7 @@ public ResponseEntity> findSignalStateConflictEve @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state_conflict/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSignalStateConflictEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -397,9 +398,9 @@ public ResponseEntity countSignalStateConflictEvent( Query query = signalStateConflictEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = signalStateConflictEventRepo.getQueryFullCount(query); - }else{ + } else { count = signalStateConflictEventRepo.getQueryResultCount(query); } @@ -410,7 +411,7 @@ public ResponseEntity countSignalStateConflictEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state_conflict/daily_counts", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getDailySignalStateConflictEventCounts( @RequestParam(name = "intersection_id", required = true) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = true) Long startTime, @@ -420,13 +421,14 @@ public ResponseEntity> getDailySignalStateConflictEventCounts( if (testData) { return ResponseEntity.ok(MockIDCountGenerator.getDateIDCounts()); } else { - return ResponseEntity.ok(signalStateConflictEventRepo.getSignalStateConflictEventsByDay(intersectionID, startTime, endTime)); + return ResponseEntity.ok( + signalStateConflictEventRepo.getSignalStateConflictEventsByDay(intersectionID, startTime, endTime)); } } @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSignalStateEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -448,7 +450,7 @@ public ResponseEntity> findSignalStateEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSignalStateEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -462,9 +464,9 @@ public ResponseEntity countSignalStateEvent( Query query = signalStateEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = signalStateEventRepo.getQueryFullCount(query); - }else{ + } else { count = signalStateEventRepo.getQueryResultCount(query); } @@ -475,7 +477,7 @@ public ResponseEntity countSignalStateEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state/daily_counts", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getDailySignalStateEventCounts( @RequestParam(name = "intersection_id", required = true) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = true) Long startTime, @@ -485,15 +487,14 @@ public ResponseEntity> getDailySignalStateEventCounts( if (testData) { return ResponseEntity.ok(MockIDCountGenerator.getDateIDCounts()); } else { - return ResponseEntity.ok(signalStateEventRepo.getSignalStateEventsByDay(intersectionID, startTime, endTime)); + return ResponseEntity + .ok(signalStateEventRepo.getSignalStateEventsByDay(intersectionID, startTime, endTime)); } } - - @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state_stop", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSignalStateStopEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -515,7 +516,7 @@ public ResponseEntity> findSignalStateStopEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state_stop/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSignalStateStopEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -529,9 +530,9 @@ public ResponseEntity countSignalStateStopEvent( Query query = signalStateStopEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = signalStateStopEventRepo.getQueryFullCount(query); - }else{ + } else { count = signalStateStopEventRepo.getQueryResultCount(query); } @@ -542,7 +543,7 @@ public ResponseEntity countSignalStateStopEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/signal_state_stop/daily_counts", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getDailySignalStateStopEventCounts( @RequestParam(name = "intersection_id", required = true) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = true) Long startTime, @@ -552,13 +553,14 @@ public ResponseEntity> getDailySignalStateStopEventCounts( if (testData) { return ResponseEntity.ok(MockIDCountGenerator.getDateIDCounts()); } else { - return ResponseEntity.ok(signalStateStopEventRepo.getSignalStateStopEventsByDay(intersectionID, startTime, endTime)); + return ResponseEntity + .ok(signalStateStopEventRepo.getSignalStateStopEventsByDay(intersectionID, startTime, endTime)); } } @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/time_change_details", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findTimeChangeDetailsEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -580,7 +582,7 @@ public ResponseEntity> findTimeChangeDetailsEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/time_change_details/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countTimeChangeDetailsEvent( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -594,9 +596,9 @@ public ResponseEntity countTimeChangeDetailsEvent( Query query = timeChangeDetailsEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = timeChangeDetailsEventRepo.getQueryFullCount(query); - }else{ + } else { count = timeChangeDetailsEventRepo.getQueryResultCount(query); } @@ -607,7 +609,7 @@ public ResponseEntity countTimeChangeDetailsEvent( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/time_change_details/daily_counts", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getTimeChangeDetailsEventCounts( @RequestParam(name = "intersection_id", required = true) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = true) Long startTime, @@ -617,13 +619,14 @@ public ResponseEntity> getTimeChangeDetailsEventCounts( if (testData) { return ResponseEntity.ok(MockIDCountGenerator.getDateIDCounts()); } else { - return ResponseEntity.ok(timeChangeDetailsEventRepo.getTimeChangeDetailsEventsByDay(intersectionID, startTime, endTime)); + return ResponseEntity + .ok(timeChangeDetailsEventRepo.getTimeChangeDetailsEventsByDay(intersectionID, startTime, endTime)); } } @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/spat_minimum_data", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSpatMinimumDataEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -644,7 +647,7 @@ public ResponseEntity> findSpatMinimumDataEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/spat_minimum_data/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSpatMinimumDataEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -658,9 +661,9 @@ public ResponseEntity countSpatMinimumDataEvents( Query query = spatMinimumDataEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = spatMinimumDataEventRepo.getQueryFullCount(query); - }else{ + } else { count = spatMinimumDataEventRepo.getQueryResultCount(query); } @@ -671,7 +674,7 @@ public ResponseEntity countSpatMinimumDataEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/map_minimum_data", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findMapMinimumDataEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -692,7 +695,7 @@ public ResponseEntity> findMapMinimumDataEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/map_minimum_data/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countMapMinimumDataEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -706,9 +709,9 @@ public ResponseEntity countMapMinimumDataEvents( Query query = mapMinimumDataEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - if(fullCount){ + if (fullCount) { count = mapMinimumDataEventRepo.getQueryFullCount(query); - }else{ + } else { count = mapMinimumDataEventRepo.getQueryResultCount(query); } @@ -719,7 +722,7 @@ public ResponseEntity countMapMinimumDataEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/map_broadcast_rate", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findMapBroadcastRateEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -742,7 +745,7 @@ public ResponseEntity> findMapBroadcastRateEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/map_broadcast_rate/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countMapBroadcastRateEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -755,10 +758,10 @@ public ResponseEntity countMapBroadcastRateEvents( } else { Query query = mapBroadcastRateEventRepo.getQuery(intersectionID, startTime, endTime, false); long count = 0; - - if(fullCount){ + + if (fullCount) { count = mapBroadcastRateEventRepo.getQueryFullCount(query); - }else{ + } else { count = mapBroadcastRateEventRepo.getQueryResultCount(query); } @@ -769,7 +772,7 @@ public ResponseEntity countMapBroadcastRateEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/spat_broadcast_rate", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSpatBroadcastRateEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -792,7 +795,7 @@ public ResponseEntity> findSpatBroadcastRateEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/spat_broadcast_rate/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSpatBroadcastRateEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -807,9 +810,9 @@ public ResponseEntity countSpatBroadcastRateEvents( long count = 0; - if(fullCount){ + if (fullCount) { count = spatBroadcastRateEventRepo.getQueryFullCount(query); - }else{ + } else { count = spatBroadcastRateEventRepo.getQueryResultCount(query); } @@ -820,7 +823,7 @@ public ResponseEntity countSpatBroadcastRateEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/bsm_events", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findBsmEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -842,7 +845,7 @@ public ResponseEntity> findBsmEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/bsm_events/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countBsmEvents( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -857,9 +860,9 @@ public ResponseEntity countBsmEvents( long count = 0; - if(fullCount){ + if (fullCount) { count = bsmEventRepo.getQueryFullCount(query); - }else{ + } else { count = bsmEventRepo.getQueryResultCount(query); } @@ -870,7 +873,7 @@ public ResponseEntity countBsmEvents( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/events/bsm_events_by_minute", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> getBsmActivityByMinuteInRange( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -881,14 +884,14 @@ public ResponseEntity> getBsmActivityByMinuteInRange( if (testData) { List list = new ArrayList<>(); Random rand = new Random(); - for(int i=0; i< 10; i++){ - int offset = rand.nextInt((int)(endTime - startTime)); + for (int i = 0; i < 10; i++) { + int offset = rand.nextInt((int) (endTime - startTime)); MinuteCount count = new MinuteCount(); - count.setMinute(((long)Math.round((startTime + offset) / 60000)) * 60000L); + count.setMinute(((long) Math.round((startTime + offset) / 60000)) * 60000L); count.setCount(rand.nextInt(10) + 1); list.add(count); } - + return ResponseEntity.ok(list); } else { Query query = bsmEventRepo.getQuery(intersectionID, startTime, endTime, latest); @@ -897,21 +900,25 @@ public ResponseEntity> getBsmActivityByMinuteInRange( Map> bsmEventMap = new HashMap<>(); - for(BsmEvent event: events){ - J2735Bsm bsm = ((J2735Bsm)event.getStartingBsm().getPayload().getData()); - Long eventStartMinute = Instant.from(formatter.parse(event.getStartingBsm().getMetadata().getOdeReceivedAt())).toEpochMilli() / (60 * 1000); + for (BsmEvent event : events) { + J2735Bsm bsm = ((J2735Bsm) event.getStartingBsm().getPayload().getData()); + Long eventStartMinute = Instant + .from(formatter.parse(event.getStartingBsm().getMetadata().getOdeReceivedAt())).toEpochMilli() + / (60 * 1000); Long eventEndMinute = eventStartMinute; - - if(event.getEndingBsm() != null){ - eventEndMinute = Instant.from(formatter.parse(event.getEndingBsm().getMetadata().getOdeReceivedAt())).toEpochMilli() / (60 * 1000); + + if (event.getEndingBsm() != null) { + eventEndMinute = Instant + .from(formatter.parse(event.getEndingBsm().getMetadata().getOdeReceivedAt())).toEpochMilli() + / (60 * 1000); } - if(eventStartMinute != null && eventEndMinute != null){ - for (Long i = eventStartMinute; i<= eventEndMinute; i++){ + if (eventStartMinute != null && eventEndMinute != null) { + for (Long i = eventStartMinute; i <= eventEndMinute; i++) { String bsmID = bsm.getCoreData().getId(); - if(bsmEventMap.get(i) != null){ + if (bsmEventMap.get(i) != null) { bsmEventMap.get(i).add(bsmID); - }else{ + } else { Set newSet = new HashSet<>(); newSet.add(bsmID); bsmEventMap.put(i, newSet); @@ -921,7 +928,7 @@ public ResponseEntity> getBsmActivityByMinuteInRange( } List outputEvents = new ArrayList<>(); - for(Long key: bsmEventMap.keySet()){ + for (Long key : bsmEventMap.keySet()) { MinuteCount count = new MinuteCount(); count.setMinute(key * 60000); count.setCount(bsmEventMap.get(key).size()); @@ -932,7 +939,4 @@ public ResponseEntity> getBsmActivityByMinuteInRange( } } - - - } diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/IntersectionController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/IntersectionController.java index 43fee444..7c64c38b 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/IntersectionController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/IntersectionController.java @@ -23,7 +23,7 @@ public class IntersectionController { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/intersection/list", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER')") public ResponseEntity> getIntersections( @RequestParam(name = "test", required = false, defaultValue = "false") boolean testData) { @@ -46,7 +46,7 @@ public ResponseEntity> getIntersections( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/intersection/list/location", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER')") public ResponseEntity> getIntersectionsByLocation( @RequestParam(name = "longitude", required = true, defaultValue = "false") Double longitude, @RequestParam(name = "latitude", required = true, defaultValue = "false") Double latitude, diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java index 96651257..ec7335d1 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java @@ -41,7 +41,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/map/json", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity>> findMaps( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -55,16 +55,16 @@ public ResponseEntity>> findMaps( } else { Query query = processedMapRepo.getQuery(intersectionID, startTime, endTime, latest, compact); long count = processedMapRepo.getQueryResultCount(query); - + logger.info("Returning ProcessedMap Response with Size: " + count); return ResponseEntity.ok(processedMapRepo.findProcessedMaps(query)); - + } } @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/map/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countMaps( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -76,10 +76,10 @@ public ResponseEntity countMaps( } else { Query query = processedMapRepo.getQuery(intersectionID, startTime, endTime, false, true); long count = processedMapRepo.getQueryResultCount(query); - + logger.info("Found: " + count + "Processed Map Messages"); return ResponseEntity.ok(count); - + } } } \ No newline at end of file diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/NotificationController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/NotificationController.java index c877fe5b..62f194b3 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/NotificationController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/NotificationController.java @@ -100,7 +100,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/active", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findActiveNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @@ -126,7 +126,7 @@ public ResponseEntity> findActiveNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/active/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countActiveNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @@ -161,7 +161,7 @@ public ResponseEntity countActiveNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/connection_of_travel", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findConnectionOfTravelNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -187,7 +187,7 @@ public ResponseEntity> findConnectionOfTrav @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/connection_of_travel/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countConnectionOfTravelNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -198,7 +198,7 @@ public ResponseEntity countConnectionOfTravelNotification( } else { Query query = connectionOfTravelNotificationRepo.getQuery(intersectionID, startTime, endTime, false); long count = connectionOfTravelNotificationRepo.getQueryResultCount(query); - + logger.info("Found: " + count + " Connection of Travel Notifications"); return ResponseEntity.ok(count); } @@ -206,7 +206,7 @@ public ResponseEntity countConnectionOfTravelNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/intersection_reference_alignment", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findIntersectionReferenceAlignmentNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -234,7 +234,7 @@ public ResponseEntity> findInte @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/intersection_reference_alignment/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countIntersectionReferenceAlignmentNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -247,7 +247,7 @@ public ResponseEntity countIntersectionReferenceAlignmentNotification( Query query = intersectionReferenceAlignmentNotificationRepo.getQuery(intersectionID, startTime, endTime, false); long count = intersectionReferenceAlignmentNotificationRepo.getQueryResultCount(query); - + logger.info("Found: " + count + " Intersection Reference Alignment"); return ResponseEntity.ok(count); } @@ -255,7 +255,7 @@ public ResponseEntity countIntersectionReferenceAlignmentNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/lane_direction_of_travel", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findLaneDirectionOfTravelNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -282,7 +282,7 @@ public ResponseEntity> findLaneDirection @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/lane_direction_of_travel/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countLaneDirectionOfTravelNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -294,7 +294,7 @@ public ResponseEntity countLaneDirectionOfTravelNotification( } else { Query query = laneDirectionOfTravelNotificationRepo.getQuery(intersectionID, startTime, endTime, false); long count = laneDirectionOfTravelNotificationRepo.getQueryResultCount(query); - + logger.info("Found: " + count + " Lane Direction of Travel"); return ResponseEntity.ok(count); @@ -303,7 +303,7 @@ public ResponseEntity countLaneDirectionOfTravelNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/map_broadcast_rate_notification", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findMapBroadcastRateNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -330,7 +330,7 @@ public ResponseEntity> findMapBroadcastRateNo @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/map_broadcast_rate_notification/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countMapBroadcastRateNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -342,7 +342,7 @@ public ResponseEntity countMapBroadcastRateNotification( } else { Query query = mapBroadcastRateNotificationRepo.getQuery(intersectionID, startTime, endTime, false); long count = mapBroadcastRateNotificationRepo.getQueryResultCount(query); - + logger.info("Found: " + count + " Map Broadcast Rate Notifications"); return ResponseEntity.ok(count); } @@ -350,7 +350,7 @@ public ResponseEntity countMapBroadcastRateNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/signal_group_alignment_notification", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSignalGroupAlignmentNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -376,7 +376,7 @@ public ResponseEntity> findSignalGroupAli @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/signal_group_alignment_notification/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSignalGroupAlignmentNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -394,7 +394,7 @@ public ResponseEntity countSignalGroupAlignmentNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/signal_state_conflict_notification", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSignalStateConflictNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -421,7 +421,7 @@ public ResponseEntity> findSignalStateConf @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/signal_state_conflict_notification/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSignalStateConflictNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -440,7 +440,7 @@ public ResponseEntity countSignalStateConflictNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/spat_broadcast_rate_notification", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findSpatBroadcastRateNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -467,7 +467,7 @@ public ResponseEntity> findSpatBroadcastRate @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/spat_broadcast_rate_notification/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countSpatBroadcastRateNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -486,7 +486,7 @@ public ResponseEntity countSpatBroadcastRateNotification( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/stop_line_stop", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findStopLineStopNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -512,7 +512,7 @@ public ResponseEntity> findStopLineStopNotificati @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/stop_line_stop/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countStopLineStopNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -528,10 +528,9 @@ public ResponseEntity countStopLineStopNotification( } } - @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/stop_line_passage", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findStopLinePassageNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -557,7 +556,7 @@ public ResponseEntity> findStopLinePassageNoti @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/stop_line_passage/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countStopLinePassageNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -573,10 +572,9 @@ public ResponseEntity countStopLinePassageNotification( } } - @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/time_change_details", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity> findTimeChangeDetailsNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -602,7 +600,7 @@ public ResponseEntity> findTimeChangeDetails @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/notifications/time_change_details/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public ResponseEntity countTimeChangeDetailsNotification( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -612,7 +610,7 @@ public ResponseEntity countTimeChangeDetailsNotification( return ResponseEntity.ok(1L); } else { Query query = timeChangeDetailsNotificationRepo.getQuery(intersectionID, startTime, endTime, false); - long count = timeChangeDetailsNotificationRepo.getQueryResultCount(query); + long count = timeChangeDetailsNotificationRepo.getQueryResultCount(query); logger.info("Found: " + count + " Time Change Detail Notifications"); return ResponseEntity.ok(count); } diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ReportController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ReportController.java index 46784f05..275cb587 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ReportController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/ReportController.java @@ -44,7 +44,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/reports/generate", method = RequestMethod.GET, produces = "application/octet-stream") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN'))) ") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER')) ") public byte[] generateReport( @RequestParam(name = "intersection_id", required = true) int intersectionID, @RequestParam(name = "road_regulator_id", required = false) Integer roadRegulatorID, @@ -64,7 +64,7 @@ public byte[] generateReport( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/reports/list", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER')") public ResponseEntity> listReports( @RequestParam(name = "report_name", required = false) String reportName, @RequestParam(name = "intersection_id", required = false) int intersectionID, @@ -88,7 +88,7 @@ public ResponseEntity> listReports( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/reports/download", method = RequestMethod.GET, produces = "application/octet-stream") - @PreAuthorize("@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") + @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER')") public ResponseEntity downloadReport( @RequestParam(name = "report_name", required = true) String reportName) { diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java index 24ae56b2..66a6eba4 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java @@ -41,7 +41,7 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/spat/json", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity> findSpats( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -63,7 +63,7 @@ public ResponseEntity> findSpats( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/spat/count", method = RequestMethod.GET, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and (@PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')))") + @PreAuthorize("@PermissionService.isSuperUser() || (@PermissionService.hasIntersection(#intersectionID) and @PermissionService.hasRole('USER'))") public ResponseEntity countSpats( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @@ -73,7 +73,7 @@ public ResponseEntity countSpats( if (testData) { return ResponseEntity.ok(80L); } else { - Query query = processedSpatRepo.getQuery(intersectionID, startTime, endTime,false, true); + Query query = processedSpatRepo.getQuery(intersectionID, startTime, endTime, false, true); long count = processedSpatRepo.getQueryResultCount(query); logger.info("Found: " + count + "Processed Spat Messages"); return ResponseEntity.ok(count); diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/UserController.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/UserController.java index d3368c4a..9bc504b3 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/UserController.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/UserController.java @@ -74,14 +74,13 @@ public String getCurrentTime() { @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/users/find_user_creation_request", method = RequestMethod.GET, produces = "application/json") public ResponseEntity> findUserCreationRequests( - @RequestParam(name = "id", required = false) String id, - @RequestParam(name = "firstName", required = false) String firstName, - @RequestParam(name = "lastName", required = false) String lastName, - @RequestParam(name = "email", required = false) String email, - @RequestParam(name = "role", required = false) String role, - @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, - @RequestParam(name = "end_time_utc_millis", required = false) Long endTime) { - + @RequestParam(name = "id", required = false) String id, + @RequestParam(name = "firstName", required = false) String firstName, + @RequestParam(name = "lastName", required = false) String lastName, + @RequestParam(name = "email", required = false) String email, + @RequestParam(name = "role", required = false) String role, + @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, + @RequestParam(name = "end_time_utc_millis", required = false) Long endTime) { Query query = userRepo.getQuery(id, firstName, lastName, email, role, startTime, endTime); long count = userRepo.getQueryResultCount(query); @@ -93,7 +92,7 @@ public ResponseEntity> findUserCreationRequests( "The requested query has more results than allowed by server. Please reduce the query bounds and try again."); } - + } @CrossOrigin(origins = "http://localhost:3000") @@ -106,26 +105,27 @@ public ResponseEntity> findUserCreationRequests( newUserCreationRequest.updateRequestSubmittedAt(); userRepo.save(newUserCreationRequest); - try{ - email.sendSimpleMessage(newUserCreationRequest.getEmail(),"User Request Received","Thank you for submitting a request for access to the Conflict Visualizer."+ - " An admin will review your request shortly."); - } catch(Exception e){ - logger.info("Failed to send email to new user: " + newUserCreationRequest.getEmail() + "Exception: " + e.getMessage()); + try { + email.sendSimpleMessage(newUserCreationRequest.getEmail(), "User Request Received", + "Thank you for submitting a request for access to the Conflict Visualizer." + + " An admin will review your request shortly."); + } catch (Exception e) { + logger.info("Failed to send email to new user: " + newUserCreationRequest.getEmail() + "Exception: " + + e.getMessage()); } - try{ + try { List admins = email.getSimpleEmailList("receiveNewUserRequests", "ADMIN", null); - email.emailList(admins, "New User Creation Request", "A new user would like access to the conflict monitor.\n\n User info: \n" + - "First Name: " + newUserCreationRequest.getFirstName() + "\n" + - "Last Name: " + newUserCreationRequest.getLastName() + "\n" + - "Email: " + newUserCreationRequest.getEmail() + "\n" + - "Desired Role: " + newUserCreationRequest.getRole() + "\n\n\n" + - "Please Log into the Conflict Monitor Management Console to accept or reject the new user request.\n\n" - ); - } catch(Exception e){ + email.emailList(admins, "New User Creation Request", + "A new user would like access to the conflict monitor.\n\n User info: \n" + + "First Name: " + newUserCreationRequest.getFirstName() + "\n" + + "Last Name: " + newUserCreationRequest.getLastName() + "\n" + + "Email: " + newUserCreationRequest.getEmail() + "\n" + + "Desired Role: " + newUserCreationRequest.getRole() + "\n\n\n" + + "Please Log into the Conflict Monitor Management Console to accept or reject the new user request.\n\n"); + } catch (Exception e) { logger.info("Failed to send email to admin group. Exception: " + e.getMessage()); } - return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON) .body(newUserCreationRequest.toString()); @@ -149,64 +149,56 @@ public ResponseEntity> findUserCreationRequests( user.setFirstName(newUserCreationRequest.getFirstName()); user.setLastName(newUserCreationRequest.getLastName()); user.setEnabled(true); - - + List groups = new ArrayList<>(); EmailSettings settings = new EmailSettings(); - - if(newUserCreationRequest.getRole().equals("USER")){ + if (newUserCreationRequest.getRole().equals("USER")) { settings.setReceiveNewUserRequests(false); groups.add("USER"); - } else if(newUserCreationRequest.getRole().equals("ADMIN")){ + } else if (newUserCreationRequest.getRole().equals("ADMIN")) { groups.add("ADMIN"); - settings.setReceiveNewUserRequests(true); + settings.setReceiveNewUserRequests(true); } Map> attributes = settings.toAttributes(); user.setGroups(groups); user.setAttributes(attributes); - - - - logger.info("Requesting New User Creation"); Response response = keycloak.realm(realm).users().create(user); - logger.info(response.getStatus() + " " + response.getHeaders()); + logger.info(response.getStatus() + " " + response.getHeaders()); if (response.getStatus() == 201) { logger.info("User Creation Successful"); Query query = userRepo.getQuery(null, null, null, newUserCreationRequest.getEmail(), null, null, null); userRepo.delete(query); - + return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON) - .body(newUserCreationRequest.toString()); - }else{ - + .body(newUserCreationRequest.toString()); + } else { + return ResponseEntity.status(HttpStatus.NOT_MODIFIED).contentType(MediaType.APPLICATION_JSON) - .body(newUserCreationRequest.toString()); + .body(newUserCreationRequest.toString()); } - + } catch (Exception e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).contentType(MediaType.TEXT_PLAIN) .body(ExceptionUtils.getStackTrace(e)); } } - @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/users/update_user_email_preference", method = RequestMethod.POST, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") public @ResponseBody ResponseEntity update_user_email_preference( @RequestBody EmailSettings newEmailSettings) { try { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); - + if (authentication.getPrincipal() instanceof KeycloakPrincipal) { KeycloakPrincipal principal = (KeycloakPrincipal) authentication.getPrincipal(); UserResource userResource = keycloak.realm(realm).users().get(principal.getName()); @@ -214,11 +206,10 @@ public ResponseEntity> findUserCreationRequests( user.setAttributes(newEmailSettings.toAttributes()); userResource.update(user); } - return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON) - .body(newEmailSettings.toString()); - + .body(newEmailSettings.toString()); + } catch (Exception e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).contentType(MediaType.TEXT_PLAIN) .body(ExceptionUtils.getStackTrace(e)); @@ -227,7 +218,6 @@ public ResponseEntity> findUserCreationRequests( @CrossOrigin(origins = "http://localhost:3000") @RequestMapping(value = "/users/get_user_email_preference", method = RequestMethod.POST, produces = "application/json") - @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('USER') || @PermissionService.hasRole('ADMIN')") public @ResponseBody ResponseEntity get_user_email_preference() { try { EmailSettings settings = new EmailSettings(); @@ -241,23 +231,20 @@ public ResponseEntity> findUserCreationRequests( } return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON) - .body(settings); - + .body(settings); + } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(MediaType.TEXT_PLAIN) .body(null); } } - - - - @CrossOrigin(origins = "http://localhost:3000") @DeleteMapping(value = "/users/delete_user_creation_request") @PreAuthorize("@PermissionService.isSuperUser() || @PermissionService.hasRole('ADMIN')") public @ResponseBody ResponseEntity intersection_config_delete(@RequestBody UserCreationRequest request) { - Query query = userRepo.getQuery(request.getId(), request.getFirstName(), request.getLastName(), request.getEmail(),null, null, null); + Query query = userRepo.getQuery(request.getId(), request.getFirstName(), request.getLastName(), + request.getEmail(), null, null, null); try { userRepo.delete(query); return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(request.toString()); diff --git a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/services/PermissionService.java b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/services/PermissionService.java index 4ba12d9f..fee3598e 100644 --- a/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/services/PermissionService.java +++ b/api/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/services/PermissionService.java @@ -10,12 +10,13 @@ import us.dot.its.jpo.ode.api.models.postgres.derived.UserOrgRole; import us.dot.its.jpo.ode.api.models.postgres.tables.Users; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - @Service("PermissionService") public class PermissionService { @@ -23,60 +24,82 @@ public class PermissionService { PostgresService postgresService; Logger logger = LoggerFactory.getLogger(PermissionService.class); - @Autowired ConflictMonitorApiProperties properties; + private static final Map ROLE_HIERARCHY = new HashMap<>(); + + static { + ROLE_HIERARCHY.put("ADMIN", 3); + ROLE_HIERARCHY.put("OPERATOR", 2); + ROLE_HIERARCHY.put("USER", 1); + } + // Allow Connection if the user is a SuperUser - public boolean isSuperUser(){ + public boolean isSuperUser() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - if(!isAuthValid(auth)){ + if (!isAuthValid(auth)) { return false; } String username = getUsername(auth); List users = postgresService.findUser(username); - for(Users user: users){ + for (Users user : users) { - if(user.isSuper_user()){ + if (user.isSuper_user()) { return true; } } - + return false; } - - // Allow Connection if the user is apart of at least one organization with a matching roll. - public boolean hasRole(String role){ + + // Allow Connection if the user is apart of at least one organization with a + // matching roll. + public boolean hasRole(String role) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - if(!isAuthValid(auth)){ + if (!isAuthValid(auth)) { return false; } String username = getUsername(auth); - List roles = postgresService.findUserOrgRoles(username); - - for(UserOrgRole userOrgRole: roles){ - if(userOrgRole.getRole_name().toUpperCase().equals(role)){ + + for (UserOrgRole userOrgRole : roles) { + if (isRoleAbove(userOrgRole.getRole_name(), role)) { return true; } } return false; } - - // Allow Connection if the users organization controls the specified intersection - public boolean hasIntersection(Integer intersectionID){ + private boolean isRoleAbove(String requiredRole, String role) { + String requiredRoleUpper = requiredRole.toUpperCase(); + String roleUpper = role.toUpperCase(); + + Integer requiredRoleLevel = ROLE_HIERARCHY.get(requiredRoleUpper); + Integer roleLevel = ROLE_HIERARCHY.get(roleUpper); + + if (requiredRoleLevel == null || roleLevel == null) { + logger.warn("Requested role not found in hierarchy: " + requiredRole + " or " + role); + return false; + } + + return roleLevel >= requiredRoleLevel; + } + + // Allow Connection if the users organization controls the specified + // intersection + public boolean hasIntersection(Integer intersectionID) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - if(!isAuthValid(auth)){ + if (!isAuthValid(auth)) { return false; } - if(!properties.getEnableOrganizationIntersectionChecking()){ + if (!properties.getEnableOrganizationIntersectionChecking()) { // Skip Validation if not enabled return true; } @@ -85,7 +108,7 @@ public boolean hasIntersection(Integer intersectionID){ List allowedIntersectionIds = postgresService.getAllowedIntersectionIdByEmail(username); allowedIntersectionIds.add(-1); // all users all allowed to access the empty intersection ID. - if(allowedIntersectionIds.contains(intersectionID)){ + if (allowedIntersectionIds.contains(intersectionID)) { return true; } @@ -93,48 +116,45 @@ public boolean hasIntersection(Integer intersectionID){ } - // Allow Connection if the users organization controls the specified RSU unit - public boolean hasRSU(String rsuIP){ + public boolean hasRSU(String rsuIP) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - if(!isAuthValid(auth)){ + if (!isAuthValid(auth)) { return false; } - if(!properties.getEnableOrganizationIntersectionChecking()){ + if (!properties.getEnableOrganizationIntersectionChecking()) { // Skip Validation if not enabled return true; } String username = getUsername(auth); List allowedIntersectionIds = postgresService.getAllowedRSUIPByEmail(username); - if(allowedIntersectionIds.contains(rsuIP)){ + if (allowedIntersectionIds.contains(rsuIP)) { return true; } return false; - } - + } // helper method to make sure authentication is valid - public boolean isAuthValid(Authentication auth){ - if(!auth.isAuthenticated()){ + public boolean isAuthValid(Authentication auth) { + if (!auth.isAuthenticated()) { return false; } - if(!(auth instanceof JwtAuthenticationToken)){ + if (!(auth instanceof JwtAuthenticationToken)) { return false; } return true; } - public String getUsername(Authentication auth){ + public String getUsername(Authentication auth) { JwtAuthenticationToken jwtAuth = (JwtAuthenticationToken) auth; String username = jwtAuth.getToken().getClaimAsString("preferred_username"); return username; } - } \ No newline at end of file