Service Layer low complexity backend
1
Dependencies
2
Dependents
1
Entities
0
Integrations

Description

Queries the aggregated activity data to return the number of records that fall within a given date range. Delegates to the Bufdir data aggregation layer and exposes a lightweight count endpoint consumed by the UI banner.

Feature: Bufdir Report Period Selection

period-record-count-service

Summaries

The Period Record Count Service provides the real-time data assurance layer that tells report authors exactly how many activity records exist for a chosen reporting window before they submit. This is a direct risk-reduction mechanism: without it, staff could submit reports covering periods with missing or incomplete data without any warning, leading to under-reporting of activities and potential funding implications. By surfacing record counts and flagging future end dates or incomplete periods, the service gives organizations the information needed to submit with confidence. The downstream effect is fewer rejected or queried reports from Bufdir and stronger trust in the organization's data governance.

Period Record Count Service is a low-complexity backend service but sits on the critical path for the report submission confirmation flow, which means it must be ready before the Record Count Confirmation Banner UI can be end-to-end tested. Its dependency on bufdir-aggregation-repository means scheduling must account for that layer being available and returning stable test data. Development is two to three days including unit and integration tests. A key risk is performance: count queries over large activity datasets can be slow, so the service should be tested with realistic data volumes early.

The async stream interface (getCountStream) adds implementation complexity that should be scoped and estimated separately from the simpler synchronous count endpoint.

Period Record Count Service is a backend service that queries activity data to return record counts within a given DateTimeRange for a specific organization. It depends on bufdir-aggregation-repository for data access. Three methods are exposed: countRecordsInRange(String orgId, DateTimeRange range) returns a Future count; isPeriodComplete(DateTimeRange range) returns a Future indicating whether the period end date is in the past (i.e., no future-date warning needed); getCountStream(String orgId, DateTimeRange range) returns a Stream for reactive UI updates without blocking. The stream variant is the primary integration point for the Record Count Confirmation Banner, which subscribes to it via StreamBuilder.

The service delegates all data access to bufdir-aggregation-repository and must not contain raw query logic. Data models used are activity and report-period. Ensure the isPeriodComplete logic uses a server-side clock, not a client-supplied timestamp, to prevent spoofing. Cache invalidation should be considered if the same range is queried repeatedly within a session.

Responsibilities

  • Count activity records within a DateTimeRange
  • Determine whether the period end date is in the future
  • Return count asynchronously to avoid blocking the UI

Interfaces

countRecordsInRange(String orgId, DateTimeRange range)
isPeriodComplete(DateTimeRange range)
getCountStream(String orgId, DateTimeRange range)

Relationships

Dependencies (1)

Components this component depends on

Dependents (2)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/period-record-counts 6 endpoints
GET /api/v1/period-record-counts List record count summaries for multiple ranges (paginated)
GET /api/v1/period-record-counts/:id Get a specific record count snapshot by ID
POST /api/v1/period-record-counts Count records for an org within a specified DateTimeRange
PUT /api/v1/period-record-counts/:id Force-refresh a count snapshot for an existing range
DELETE /api/v1/period-record-counts/:id Delete a count snapshot
GET /api/v1/period-record-counts/stream Server-sent events stream of live record counts for a range (getCountStream)