Bufdir Preview Service
Component Detail
Description
Orchestrates the assembly of the report preview by combining aggregated data from the Bufdir Data Aggregation feature with the official form structure definition. Produces a structured, section-ordered representation of the report that the UI can render directly. Also coordinates the field validation pass before returning the preview model.
bufdir-preview-service
Summaries
The Bufdir Preview Service is the central orchestration engine that transforms raw activity data into a complete, validated, submission-ready view of the official government report. Without this component, coordinators would see unstructured aggregated numbers with no mapping to the actual Bufdir form fields and sections — making it impossible to review or verify the report before submission. By assembling the full report structure, applying field-level validation, and delivering a decorated preview model in a single coordinated operation, this service eliminates the manual cross-referencing that previously consumed significant coordinator time. It is the critical enabler for accurate, on-time government reporting, directly protecting the organisation's compliance standing and funding relationships.
This is the highest-complexity component in the preview feature and sits at the centre of the dependency graph, blocking the preview UI, the diff view, and validation summary components until it is stable. It depends on the Bufdir Preview Repository, the Report Structure Mapper, and the Field Validation Service — all of which must be available before end-to-end integration testing can begin. Development scope includes async data orchestration, form field mapping logic, validation embedding, and a clean preview model contract consumed by the UI. The mapping logic between aggregated data and official Bufdir form fields is high-risk: errors here will surface as incorrect field values in the submitted report.
Plan for structured review of the mapping logic with a domain expert, and ensure dedicated testing against the official Bufdir form specification. Budget for iterative refinement as edge cases in the form structure are discovered.
Acts as the application-layer facade for the preview feature, coordinating three downstream services in sequence. `getReportPreview(organizationId, periodId)` first calls `BufdirPreviewRepository` to fetch aggregated data, then passes it through `BufdirReportStructureMapper` to produce a section-ordered field map aligned to the official Bufdir form schema, and finally invokes `BufdirFieldValidationService` to annotate each field with its validation state before returning the composite `ReportPreviewModel`. `refreshPreview()` invalidates the cached preview and re-runs the full pipeline, useful after data corrections. `getPreviewForExport()` returns a clean, validation-stripped model suitable for PDF or submission serialisation.
`getValidationIssues()` exposes the flat list of all flagged fields for the validation summary banner and issue list panel. Implement with an injectable service pattern to support unit testing each orchestration step in isolation using mock collaborators. Cache the assembled preview model to avoid redundant re-aggregation on repeated UI rebuilds within the same session.
Responsibilities
- Fetch aggregated report data for the selected period
- Map aggregated values to official Bufdir form fields and sections
- Invoke field validation and embed results in the preview model
- Return a fully decorated preview model to the UI layer
Interfaces
getReportPreview(organizationId, periodId)
refreshPreview()
getPreviewForExport()
getValidationIssues()
Relationships
Dependencies (3)
Components this component depends on
Dependents (2)
Components that depend on this component