feat: ab#2156: added max value for area occupancy jobs#111
feat: ab#2156: added max value for area occupancy jobs#111
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable maxCount on observation jobs (AREA_OCCUPANCY and FLOW) to cap area-occupancy increments when sensor data is missing, preventing counts from growing indefinitely.
Changes:
- Added
max_countcolumn toobservation_joband exposed it viaObservationJobEntity. - Added service + REST endpoints to update
maxCountfor FLOW/AREA_OCCUPANCY jobs by observation area or job name. - Applied
maxCountlogic when updating occupancy counts from FLOW events.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| service/src/main/java/de/starwit/service/observatory/ObservationJobService.java | Adds service methods to bulk-update maxCount for relevant job types. |
| service/src/main/java/de/starwit/service/analytics/AreaOccupancyService.java | Applies maxCount when incrementing occupancy from flow direction events. |
| rest/src/main/java/de/starwit/rest/controller/ObservationJobController.java | Adds REST endpoints for setting maxCount by area id or job name. |
| persistence/src/main/resources/db/migration/observatory/V5_0__add_maxcount.sql | Adds the max_count DB column. |
| persistence/src/main/java/de/starwit/persistence/observatory/repository/ObservationJobRepository.java | Adds query methods to find jobs for bulk update. |
| persistence/src/main/java/de/starwit/persistence/observatory/entity/ObservationJobEntity.java | Adds maxCount field + accessor methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (existingJobs == null || existingJobs.isEmpty()) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
findBy... repository methods return an empty list when nothing matches, so returning null here adds avoidable null-handling for callers. Prefer returning an empty list (or throwing a not-found exception at the controller layer) to keep the service API non-nullable.
| if (existingJobs == null || existingJobs.isEmpty()) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Same as above: returning null for a list result is unnecessary (repository returns empty list). Returning an empty list will simplify callers and avoid potential NPEs if this service method is reused elsewhere.
| @GetMapping("/max-count-by-observation-area-id/{observationAreaId}/{classId}/{maxCount}") | ||
| public ResponseEntity<List<ObservationJobEntity>> setMaxCountByObservationAreaId( | ||
| @PathVariable Long observationAreaId, | ||
| @PathVariable Integer classId, | ||
| @Nullable @BindParam Integer maxCount) { | ||
| List<ObservationJobEntity> updatedJobs = observationJobService.updateMaxCount(observationAreaId, classId, | ||
| maxCount); | ||
| if (updatedJobs == null || updatedJobs.isEmpty()) { | ||
| throw new ResponseStatusException(HttpStatus.NOT_FOUND); | ||
| } | ||
| return new ResponseEntity<List<ObservationJobEntity>>(updatedJobs, HttpStatus.OK); | ||
| } | ||
|
|
||
| @GetMapping("/max-count-by-job-name/{jobName}/{classId}/{maxCount}") | ||
| public ResponseEntity<List<ObservationJobEntity>> setMaxCountByJobName( | ||
| @PathVariable String jobName, | ||
| @PathVariable Integer classId, | ||
| @Nullable @BindParam Integer maxCount) { | ||
| List<ObservationJobEntity> updatedJobs = observationJobService.updateMaxCountByName(jobName, classId, maxCount); | ||
| if (updatedJobs == null || updatedJobs.isEmpty()) { | ||
| throw new ResponseStatusException(HttpStatus.NOT_FOUND); | ||
| } | ||
| return new ResponseEntity<List<ObservationJobEntity>>(updatedJobs, HttpStatus.OK); | ||
| } |
There was a problem hiding this comment.
There are existing controller acceptance tests for ObservationJobController, but the new max-count update endpoints aren’t covered. Add acceptance/integration tests that verify updating maxCount by observationAreaId/jobName (including the not-found case) so the new API behavior is exercised in CI.
Max count is added for flow and area occupancy jobs.
Description
Motivation and Context
If sensor device misses data, the flow is not counting correctly and the count can grow and is not going back anymore. Hence, a max count is introduced.
How has this been tested?
Manually using rest api/swagger
Screenshots (if appropriate):
Types of changes
Checklist: