A Spring Boot REST API for generating financial reports in multiple formats (HTML, CSV, PDF). Built with Spring Boot 3.2.0, Java 17, and uses Thymeleaf templating with Playwright for PDF generation.
- 📊 Generate financial reports from JSON data
- 📄 Multiple output formats: HTML, CSV, PDF
- 🎨 Template-based rendering with Thymeleaf
- 🚀 High-performance PDF generation with Playwright
- 🔒 Secure file upload handling
- 📱 RESTful API design
- 🐳 Docker containerization with RHEL base
- ✅ Comprehensive test coverage
- Java 17+
- Maven 3.6+
- Docker & Docker Compose (for containerized deployment)
# Clone the repository
git clone <repository-url>
cd report-rendering-api
# Build and run
mvn clean install
mvn spring-boot:run
# Application will be available at http://localhost:8080# Build and run with Docker Compose
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f report-rendering-api
# Stop services
docker-compose down# Run with nginx reverse proxy
docker-compose --profile production up -dEndpoint: POST /reports
Generates a financial report from uploaded JSON data.
Request Parameters:
file(multipart): JSON file containing report datatemplate(form): Template name (currently: "statement")output(form): Output format ("HTML", "CSV", "PDF")
Example:
curl -X POST http://localhost:8080/reports \
-F "file=@sample-data.json" \
-F "template=statement" \
-F "output=PDF"Response:
- HTML:
text/htmlcontent - CSV:
text/csvwith download headers - PDF:
application/pdfbinary
Endpoint: GET /templates
Returns available report templates and supported formats.
Response:
{
"statement": ["HTML", "CSV", "PDF"]
}{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"accounts": [
{
"accountName": "John Doe Chequing Account",
"transitNumber": "00001",
"accountNumber": "1234567890",
"accountType": "Chequing",
"transactions": [
{
"actionDate": "2024-01-02",
"valueDate": "2024-01-02",
"transactionType": "Deposit",
"description": "Direct Deposit - Salary",
"creditAmount": 3500.00,
"debitAmount": null,
"balance": 5500.00
}
]
}
]
}Use the included sample data files for testing:
integration-test-data.json- Comprehensive test data with multiple accounts
- ReportController: REST API endpoints and request handling
- ReportService: Business logic and template orchestration
- Report Classes: Template-specific report generation (Strategy pattern)
- PdfService: Playwright-based PDF generation
- Models: Data transfer objects for reports and accounts
src/main/resources/templates/statement/
├── html.html # HTML report template
├── csv.html # CSV generation template
├── pdf.html # PDF main content
├── pdf_header.html # PDF header (optional)
└── pdf_footer.html # PDF footer (optional)
mvn clean install # Build and install dependencies
mvn test # Run all tests
mvn spring-boot:run # Run application (port 8080)
mvn clean package # Clean build and package
mvn test -Dtest=ClassName # Run specific testThe project includes comprehensive test coverage:
- Unit Tests: Service and controller logic testing
- Integration Tests: Full API testing with MockMvc
- End-to-End Tests: Complete application testing
# Run all tests
mvn test
# Run with coverage
mvn test jacoco:report
# Run specific test suite
mvn test -Dtest="*IntegrationTest"- Create a new report class extending
Report:
@ReportName("new-template")
@Component
public class NewTemplateReport extends Report {
// Implementation
}- Add template files in
src/main/resources/templates/new-template/ - Implement the
parseData()method for your data structure - Add tests for the new template
# Server configuration
server.port=8080
# Logging
logging.level.com.tvm.reportrendering=DEBUG
# File upload limits
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB- Base Image: Red Hat UBI 9
- Java: OpenJDK 17
- Memory: 1.5GB limit (configurable)
- Health Checks: Built-in endpoint monitoring
- Security: Non-root user execution
SPRING_PROFILES_ACTIVE: Active Spring profileJAVA_OPTS: JVM configuration optionsPLAYWRIGHT_BROWSERS_PATH: Browser installation path
The application provides health check endpoints:
- Docker:
http://localhost:8080/templates - Spring Actuator: Configure as needed
Logs are written to:
- Console (development)
/app/logsdirectory (Docker)- Configurable via
logback-spring.xml
- Memory: Optimized JVM settings for containers
- PDF Generation: Playwright with Chromium browser
- Template Caching: Available for production environments
- Connection Pooling: Spring Boot defaults
- File upload validation and size limits
- Non-root Docker container execution
- Input sanitization for template data
- Error handling without information disclosure
- No sensitive data in logs or responses
-
PDF Generation Fails
- Ensure Chromium dependencies are installed
- Check memory limits (PDF generation is memory-intensive)
- Verify font availability for text rendering
-
File Upload Issues
- Check file size limits in application properties
- Verify JSON format matches expected structure
- Ensure multipart form encoding
-
Template Not Found
- Verify template files exist in correct directory structure
- Check
@ReportNameannotation matches request parameter - Confirm Spring component scanning includes your report class
# Check container logs
docker-compose logs -f report-rendering-api
# Access container shell
docker-compose exec report-rendering-api bash
# Rebuild without cache
docker-compose build --no-cache
# Check resource usage
docker stats report-rendering-api- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
[Specify your license here]
For issues and questions:
- Create an issue in the repository
- Contact: igormusic@tvmsoftware.com