DomainTemplatesPrintAllService.java

package fr.tiogars.inception.domains.domaintemplate.services;

import java.io.IOException;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/** Generates a printable PDF for all active DomainTemplates. */
@Service
public class DomainTemplatesPrintAllService {

    private final DomainTemplateFindAllService findAllService;
    private final DomainTemplatePdfRenderer renderer;

    public DomainTemplatesPrintAllService(DomainTemplateFindAllService findAllService, DomainTemplatePdfRenderer renderer) {
        this.findAllService = findAllService;
        this.renderer = renderer;
    }

    /**
     * Prints all active records ordered by code.
     *
     * @return PDF bytes, including an empty-list message when there are no records
     * @throws IOException when the PDF cannot be generated
     */
    @Transactional(readOnly = true)
    public byte[] printAll() throws IOException {
        return renderer.render("DomainTemplates", findAllService.findAll());
    }
}