Skip to content

feat: ab#2156: added max value for area occupancy jobs#111

Open
witchpou wants to merge 4 commits intomainfrom
feature/ab2156-add-max-count
Open

feat: ab#2156: added max value for area occupancy jobs#111
witchpou wants to merge 4 commits intomainfrom
feature/ab2156-add-max-count

Conversation

@witchpou
Copy link
Copy Markdown
Collaborator

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • [] My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_count column to observation_job and exposed it via ObservationJobEntity.
  • Added service + REST endpoints to update maxCount for FLOW/AREA_OCCUPANCY jobs by observation area or job name.
  • Applied maxCount logic 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.

Comment on lines +85 to +87
if (existingJobs == null || existingJobs.isEmpty()) {
return null;
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +101 to +103
if (existingJobs == null || existingJobs.isEmpty()) {
return null;
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +102
@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);
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants