From f8e8077ed29c587203d1d485ea44f8bc37d01d30 Mon Sep 17 00:00:00 2001 From: DemchaAV Date: Mon, 29 Jun 2026 16:55:24 +0100 Subject: [PATCH] refactor(examples): render invoice/proposal examples via the layered presets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate the example + demo-test consumers of builtins.InvoiceTemplateV2 / ProposalTemplateV2 to the layered ModernInvoice / ModernProposal presets, so the cinematic builtins keep no example consumer — only their own unit tests, which retire with them in 2.0. - InvoiceCinematicFileExample / ProposalCinematicFileExample: render ModernInvoice / ModernProposal on a BrandTheme (same filenames + output paths). The proposal output now includes its header — ModernProposal fixes the builtin's dropped-header bug. - HttpStreamingExample / LayoutSnapshotRegressionExample: swap the invoice fixture to ModernInvoice; the snapshot baseline (generated dir) regenerates. - HttpStreamingDemoTest / LayoutSnapshotRegressionDemoTest: follow their examples onto ModernInvoice. No engine change. CustomBusinessThemeExample (demos the 2.0-removed BusinessTheme) and the builtins' own tests are intentionally left for the 2.0 cleanup; the template-doc repointing is a separate coherent pass. --- .../LayoutSnapshotRegressionExample.java | 12 +++++------ .../streaming/HttpStreamingExample.java | 13 ++++++------ .../invoice/InvoiceCinematicFileExample.java | 21 ++++++++++--------- .../ProposalCinematicFileExample.java | 18 +++++++++------- .../testing/visual/HttpStreamingDemoTest.java | 11 +++++----- .../LayoutSnapshotRegressionDemoTest.java | 17 +++++++-------- 6 files changed, 48 insertions(+), 44 deletions(-) diff --git a/examples/src/main/java/com/demcha/examples/features/snapshots/LayoutSnapshotRegressionExample.java b/examples/src/main/java/com/demcha/examples/features/snapshots/LayoutSnapshotRegressionExample.java index 03c7249aa..96f3b4922 100644 --- a/examples/src/main/java/com/demcha/examples/features/snapshots/LayoutSnapshotRegressionExample.java +++ b/examples/src/main/java/com/demcha/examples/features/snapshots/LayoutSnapshotRegressionExample.java @@ -5,8 +5,8 @@ import com.demcha.compose.document.api.DocumentSession; import com.demcha.compose.document.snapshot.LayoutSnapshot; import com.demcha.compose.document.style.DocumentInsets; -import com.demcha.compose.document.templates.builtins.InvoiceTemplateV2; -import com.demcha.compose.document.theme.BusinessTheme; +import com.demcha.compose.document.templates.core.theme.BrandTheme; +import com.demcha.compose.document.templates.invoice.v2.presets.ModernInvoice; import com.demcha.compose.testing.layout.LayoutSnapshotJson; import com.demcha.examples.support.ExampleDataFactory; import com.demcha.examples.support.ExampleOutputPaths; @@ -56,7 +56,7 @@ private LayoutSnapshotRegressionExample() { } /** - * Composes the sample invoice through {@link InvoiceTemplateV2}, + * Composes the sample invoice through {@code ModernInvoice}, * extracts the layout snapshot, writes (or verifies) a JSON * baseline alongside the PDF, and renders the PDF for visual * inspection. @@ -65,16 +65,16 @@ private LayoutSnapshotRegressionExample() { * @throws Exception if rendering, snapshot extraction, or baseline IO fails */ public static Path generate() throws Exception { - BusinessTheme theme = BusinessTheme.modern(); + BrandTheme theme = BrandTheme.invoiceModern(); Path pdfFile = ExampleOutputPaths.prepare("features/snapshots", "invoice-snapshot-regression.pdf"); Path baselineFile = ExampleOutputPaths.prepare("features/snapshots", "invoice-snapshot-regression.layout.json"); try (DocumentSession document = GraphCompose.document() .pageSize(DocumentPageSize.A4) - .pageBackground(theme.pageBackground()) + .pageBackground(theme.palette().mainFill()) .margin(DocumentInsets.of(28)) .create()) { - new InvoiceTemplateV2(theme).compose(document, ExampleDataFactory.sampleInvoice()); + ModernInvoice.create(theme).compose(document, ExampleDataFactory.sampleInvoice()); // Step 1: extract the deterministic post-layout snapshot. LayoutSnapshot snapshot = document.layoutSnapshot(); diff --git a/examples/src/main/java/com/demcha/examples/features/streaming/HttpStreamingExample.java b/examples/src/main/java/com/demcha/examples/features/streaming/HttpStreamingExample.java index aec2921c0..04abf86b7 100644 --- a/examples/src/main/java/com/demcha/examples/features/streaming/HttpStreamingExample.java +++ b/examples/src/main/java/com/demcha/examples/features/streaming/HttpStreamingExample.java @@ -4,9 +4,10 @@ import com.demcha.compose.document.api.DocumentPageSize; import com.demcha.compose.document.api.DocumentSession; import com.demcha.compose.document.style.DocumentInsets; -import com.demcha.compose.document.templates.builtins.InvoiceTemplateV2; +import com.demcha.compose.document.templates.api.DocumentTemplate; +import com.demcha.compose.document.templates.core.theme.BrandTheme; import com.demcha.compose.document.templates.data.invoice.InvoiceDocumentSpec; -import com.demcha.compose.document.theme.BusinessTheme; +import com.demcha.compose.document.templates.invoice.v2.presets.ModernInvoice; import com.demcha.examples.support.ExampleDataFactory; import com.demcha.examples.support.ExampleOutputPaths; @@ -74,7 +75,7 @@ private HttpStreamingExample() { /** * Renders the supplied invoice into the supplied output stream - * via {@code InvoiceTemplateV2} on {@link BusinessTheme#modern()}. + * via {@code ModernInvoice} on {@link BrandTheme#invoiceModern()}. * *

The stream is intentionally not closed by * this method — that lets the same code be used from a Servlet, @@ -87,12 +88,12 @@ private HttpStreamingExample() { * @throws Exception if PDF rendering fails */ public static void streamInvoiceTo(InvoiceDocumentSpec invoice, OutputStream sink) throws Exception { - BusinessTheme theme = BusinessTheme.modern(); - InvoiceTemplateV2 template = new InvoiceTemplateV2(theme); + BrandTheme theme = BrandTheme.invoiceModern(); + DocumentTemplate template = ModernInvoice.create(theme); try (DocumentSession document = GraphCompose.document() .pageSize(DocumentPageSize.A4) - .pageBackground(theme.pageBackground()) + .pageBackground(theme.palette().mainFill()) .margin(DocumentInsets.of(28)) .create()) { template.compose(document, invoice); diff --git a/examples/src/main/java/com/demcha/examples/templates/invoice/InvoiceCinematicFileExample.java b/examples/src/main/java/com/demcha/examples/templates/invoice/InvoiceCinematicFileExample.java index 58a300c44..babfc9821 100644 --- a/examples/src/main/java/com/demcha/examples/templates/invoice/InvoiceCinematicFileExample.java +++ b/examples/src/main/java/com/demcha/examples/templates/invoice/InvoiceCinematicFileExample.java @@ -3,19 +3,20 @@ import com.demcha.compose.GraphCompose; import com.demcha.compose.document.api.DocumentPageSize; import com.demcha.compose.document.api.DocumentSession; -import com.demcha.compose.document.templates.builtins.InvoiceTemplateV2; -import com.demcha.compose.document.theme.BusinessTheme; +import com.demcha.compose.document.templates.api.DocumentTemplate; +import com.demcha.compose.document.templates.core.theme.BrandTheme; +import com.demcha.compose.document.templates.data.invoice.InvoiceDocumentSpec; +import com.demcha.compose.document.templates.invoice.v2.presets.ModernInvoice; import com.demcha.examples.support.ExampleDataFactory; import com.demcha.examples.support.ExampleOutputPaths; import java.nio.file.Path; /** - * Phase E.1 — runnable showcase for {@code InvoiceTemplateV2}, the - * cinematic theme-driven invoice template. Renders the same - * {@link com.demcha.compose.document.templates.data.invoice.InvoiceDocumentSpec} - * as the v1 template through the modern business theme so reviewers can - * compare the two outputs side by side. + * Runnable showcase for the cinematic invoice look on the layered + * {@code invoice.v2} surface — {@link ModernInvoice} on + * {@link BrandTheme#invoiceModern()}, rendering the shared + * {@link InvoiceDocumentSpec} sample on the cream page background. * * @author Artem Demchyshyn */ @@ -26,12 +27,12 @@ private InvoiceCinematicFileExample() { public static Path generate() throws Exception { Path outputFile = ExampleOutputPaths.prepare("templates/invoice", "invoice-cinematic.pdf"); - BusinessTheme theme = BusinessTheme.modern(); - InvoiceTemplateV2 template = new InvoiceTemplateV2(theme); + BrandTheme theme = BrandTheme.invoiceModern(); + DocumentTemplate template = ModernInvoice.create(theme); try (DocumentSession document = GraphCompose.document(outputFile) .pageSize(DocumentPageSize.A4) - .pageBackground(theme.pageBackground()) + .pageBackground(theme.palette().mainFill()) .margin(28, 28, 28, 28) .create()) { template.compose(document, ExampleDataFactory.sampleInvoice()); diff --git a/examples/src/main/java/com/demcha/examples/templates/proposal/ProposalCinematicFileExample.java b/examples/src/main/java/com/demcha/examples/templates/proposal/ProposalCinematicFileExample.java index bca329afc..a220c2efe 100644 --- a/examples/src/main/java/com/demcha/examples/templates/proposal/ProposalCinematicFileExample.java +++ b/examples/src/main/java/com/demcha/examples/templates/proposal/ProposalCinematicFileExample.java @@ -3,16 +3,20 @@ import com.demcha.compose.GraphCompose; import com.demcha.compose.document.api.DocumentPageSize; import com.demcha.compose.document.api.DocumentSession; -import com.demcha.compose.document.templates.builtins.ProposalTemplateV2; -import com.demcha.compose.document.theme.BusinessTheme; +import com.demcha.compose.document.templates.api.DocumentTemplate; +import com.demcha.compose.document.templates.core.theme.BrandTheme; +import com.demcha.compose.document.templates.data.proposal.ProposalDocumentSpec; +import com.demcha.compose.document.templates.proposal.v2.presets.ModernProposal; import com.demcha.examples.support.ExampleDataFactory; import com.demcha.examples.support.ExampleOutputPaths; import java.nio.file.Path; /** - * Phase E.2 — runnable showcase for {@code ProposalTemplateV2}, the - * cinematic theme-driven proposal template. + * Runnable showcase for the cinematic proposal look on the layered + * {@code proposal.v2} surface — {@link ModernProposal} on + * {@link BrandTheme#proposalModern()}, rendering the shared + * {@link ProposalDocumentSpec} sample on the cream page background. * * @author Artem Demchyshyn */ @@ -23,12 +27,12 @@ private ProposalCinematicFileExample() { public static Path generate() throws Exception { Path outputFile = ExampleOutputPaths.prepare("templates/proposal", "proposal-cinematic.pdf"); - BusinessTheme theme = BusinessTheme.modern(); - ProposalTemplateV2 template = new ProposalTemplateV2(theme); + BrandTheme theme = BrandTheme.proposalModern(); + DocumentTemplate template = ModernProposal.create(theme); try (DocumentSession document = GraphCompose.document(outputFile) .pageSize(DocumentPageSize.A4) - .pageBackground(theme.pageBackground()) + .pageBackground(theme.palette().mainFill()) .margin(28, 28, 28, 28) .create()) { template.compose(document, ExampleDataFactory.sampleProposal()); diff --git a/src/test/java/com/demcha/testing/visual/HttpStreamingDemoTest.java b/src/test/java/com/demcha/testing/visual/HttpStreamingDemoTest.java index 5812a7e9e..279343dec 100644 --- a/src/test/java/com/demcha/testing/visual/HttpStreamingDemoTest.java +++ b/src/test/java/com/demcha/testing/visual/HttpStreamingDemoTest.java @@ -4,9 +4,9 @@ import com.demcha.compose.document.api.DocumentPageSize; import com.demcha.compose.document.api.DocumentSession; import com.demcha.compose.document.style.DocumentInsets; -import com.demcha.compose.document.templates.builtins.InvoiceTemplateV2; +import com.demcha.compose.document.templates.core.theme.BrandTheme; import com.demcha.compose.document.templates.data.invoice.InvoiceDocumentSpec; -import com.demcha.compose.document.theme.BusinessTheme; +import com.demcha.compose.document.templates.invoice.v2.presets.ModernInvoice; import com.demcha.testing.VisualTestOutputs; import org.junit.jupiter.api.Test; @@ -63,7 +63,7 @@ void writePdfMatchesToPdfBytesForTheSameInputs() throws Exception { byte[] bufferedBytes; try (DocumentSession document = newSession()) { - new InvoiceTemplateV2(BusinessTheme.modern()) + ModernInvoice.create() .compose(document, sampleInvoice()); bufferedBytes = document.toPdfBytes(); } @@ -86,17 +86,16 @@ void writePdfMatchesToPdfBytesForTheSameInputs() throws Exception { private static void renderInvoice(OutputStream sink) throws Exception { try (DocumentSession document = newSession()) { - new InvoiceTemplateV2(BusinessTheme.modern()) + ModernInvoice.create() .compose(document, sampleInvoice()); document.writePdf(sink); } } private static DocumentSession newSession() { - BusinessTheme theme = BusinessTheme.modern(); return GraphCompose.document() .pageSize(DocumentPageSize.A4) - .pageBackground(theme.pageBackground()) + .pageBackground(BrandTheme.invoiceModern().palette().mainFill()) .margin(DocumentInsets.of(28)) .create(); } diff --git a/src/test/java/com/demcha/testing/visual/LayoutSnapshotRegressionDemoTest.java b/src/test/java/com/demcha/testing/visual/LayoutSnapshotRegressionDemoTest.java index 9cec272f5..9a374ce92 100644 --- a/src/test/java/com/demcha/testing/visual/LayoutSnapshotRegressionDemoTest.java +++ b/src/test/java/com/demcha/testing/visual/LayoutSnapshotRegressionDemoTest.java @@ -5,9 +5,9 @@ import com.demcha.compose.document.api.DocumentSession; import com.demcha.compose.document.snapshot.LayoutSnapshot; import com.demcha.compose.document.style.DocumentInsets; -import com.demcha.compose.document.templates.builtins.InvoiceTemplateV2; +import com.demcha.compose.document.templates.core.theme.BrandTheme; import com.demcha.compose.document.templates.data.invoice.InvoiceDocumentSpec; -import com.demcha.compose.document.theme.BusinessTheme; +import com.demcha.compose.document.templates.invoice.v2.presets.ModernInvoice; import com.demcha.compose.testing.layout.LayoutSnapshotJson; import org.junit.jupiter.api.Test; @@ -42,11 +42,11 @@ void identicalInvoicesProduceIdenticalSnapshotJson() throws Exception { String firstJson; String secondJson; try (DocumentSession a = newSession()) { - new InvoiceTemplateV2(BusinessTheme.modern()).compose(a, sampleInvoice(1)); + ModernInvoice.create().compose(a, sampleInvoice(1)); firstJson = LayoutSnapshotJson.toJson(a.layoutSnapshot()); } try (DocumentSession b = newSession()) { - new InvoiceTemplateV2(BusinessTheme.modern()).compose(b, sampleInvoice(1)); + ModernInvoice.create().compose(b, sampleInvoice(1)); secondJson = LayoutSnapshotJson.toJson(b.layoutSnapshot()); } assertThat(secondJson) @@ -63,11 +63,11 @@ void structurallyDifferentInvoicesProduceDifferentSnapshotJson() throws Exceptio String oneRow; String tenRows; try (DocumentSession a = newSession()) { - new InvoiceTemplateV2(BusinessTheme.modern()).compose(a, sampleInvoice(1)); + ModernInvoice.create().compose(a, sampleInvoice(1)); oneRow = LayoutSnapshotJson.toJson(a.layoutSnapshot()); } try (DocumentSession b = newSession()) { - new InvoiceTemplateV2(BusinessTheme.modern()).compose(b, sampleInvoice(20)); + ModernInvoice.create().compose(b, sampleInvoice(20)); tenRows = LayoutSnapshotJson.toJson(b.layoutSnapshot()); } assertThat(tenRows) @@ -78,7 +78,7 @@ void structurallyDifferentInvoicesProduceDifferentSnapshotJson() throws Exceptio @Test void snapshotReportsPagesAndNodes() throws Exception { try (DocumentSession document = newSession()) { - new InvoiceTemplateV2(BusinessTheme.modern()).compose(document, sampleInvoice(1)); + ModernInvoice.create().compose(document, sampleInvoice(1)); LayoutSnapshot snapshot = document.layoutSnapshot(); assertThat(snapshot.totalPages()).isPositive(); assertThat(snapshot.nodes()).isNotEmpty(); @@ -87,10 +87,9 @@ void snapshotReportsPagesAndNodes() throws Exception { } private static DocumentSession newSession() { - BusinessTheme theme = BusinessTheme.modern(); return GraphCompose.document() .pageSize(DocumentPageSize.A4) - .pageBackground(theme.pageBackground()) + .pageBackground(BrandTheme.invoiceModern().palette().mainFill()) .margin(DocumentInsets.of(28)) .create(); }