Skip to content

Document merging service for report combination

The Document merging service is a specialized component within the report generation system designed to combine multiple individual report files into a single downloadable document^[001-todo-code-copy.md]. This process is primarily utilized to aggregate results that have been generated separately but need to be presented as a unified file^[001-todo-code-copy.md].

Implementation

The merging logic is handled by implementations of the ReportDocumentService interface^[001-todo-code-copy.md]. Currently, the system provides specific handling for different document types:

  • CSV Combination: The CSVDocumentServiceImpl handles the merging of Comma-Separated Values files^[001-todo-code-copy.md]. Its combineDocument method accepts a list of byte arrays (representing the file contents)1, strips the header row from subsequent documents to prevent duplication, and joins the data using the system's line separator^[001-todo-code-copy.md].
  • PDF Handling: The system currently supports a placeholder for PDF generation and merging (PDFDocumentServiceImpl), but the actual functionality throws an UnsupportedOperationException stating it is not yet supported^[001-todo-code-copy.md].

Workflow Integration

The merging process is triggered asynchronously via a Message queue listener. The system uses a specific listener method, handleCombineDocument, which consumes messages from the COMBINE_FILE_Q (Combine File Queue)2[001-todo-code-copy.md]. Upon receiving a ReportDocumentCombineVo payload, which contains the target ID and document type, the service invokes the domain layer to execute the combination logic^[001-todo-code-copy.md].

Data Flow

  1. Trigger: A request to combine documents is sent to the plt.basic.report.combine.file.ex exchange, routing it to the COMBINE_FILE_Q^[001-todo-code-copy.md].
  2. Processing: The ReportListener picks up the message and calls reportDomainService.makeCombineDocument^[001-todo-code-copy.md].
  3. Execution: The domain service orchestrates the retrieval of existing documents (likely stored in a file system or blob storage as implied by GcsFileManageServiceImpl^[001-todo-code-copy.md]) and passes their byte content to the appropriate ReportDocumentService implementation.
  4. Output: The combined byte array is returned, which is then typically stored or returned to the user as a single file.
  • [[Asynchronous processing]]
  • [[Report generation workflow]]
  • [[File storage abstraction]]

Sources

^[001-todo-code-copy.md]


  1. Method signature combineDocument(@NonNull List<byte[]> documents) in CSVDocumentServiceImpl^[001-todo-code-copy.md] 

  2. Configuration constants COMBINE_FILE_EX and COMBINE_FILE_Q in ReportConfig^[001-todo-code-copy.md]