Skip to content

Commit

Permalink
fix: Feature/fix cover page (#166)
Browse files Browse the repository at this point in the history
* chore: Add cover page placeholder after applying webhooks, to exclude possibility to break cover page logic

Refs: #91

* chore: Remove not anymore relevant test

Refs: #91

---------

Co-authored-by: Adam Ruberti <adam.ruberti@sbb.ch>
  • Loading branch information
yurtsevich-sbb and ariwk authored Aug 21, 2024
1 parent 457dd05 commit 5fb657c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
3 changes: 3 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,9 @@
},
"watermark": {
"type": "boolean"
},
"webhooks": {
"type": "string"
}
},
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ public byte[] convertToPdf(@NotNull ExportParams exportParams, @Nullable ExportM
metaInfoCallback.setLinkedWorkItems(WorkItemRefData.extractListFromHtml(htmlContent, exportParams.getProjectId()));
}
htmlContent = htmlProcessor.internalizeLinks(htmlContent);
htmlContent = applyWebooks(exportParams, htmlContent);
return htmlContent;
htmlContent = applyWebhooks(exportParams, htmlContent);

// Add a fake page which later will be replaced with cover page. This should be done post-webhooks not to break this approach.
return (exportParams.getCoverPage() != null ? "<div style='break-after:page'>page to be removed</div>" : "") + htmlContent;
}

private @NotNull String applyWebooks(@NotNull ExportParams exportParams, @NotNull String htmlContent) {
private @NotNull String applyWebhooks(@NotNull ExportParams exportParams, @NotNull String htmlContent) {
if (exportParams.getWebhooks() == null) {
return htmlContent;
}
Expand Down Expand Up @@ -219,7 +221,6 @@ String composeHtml(@NotNull String documentName,
@NotNull HtmlData htmlData,
@NotNull ExportParams exportParams) {
String content = htmlData.headerFooterContent
+ (exportParams.getCoverPage() != null ? "<div style='break-after:page'>page to be removed</div>" : "") //add fake page which later will be replaced with title
+ "<div class='content'>" + htmlData.documentContent + "</div>";
return pdfTemplateProcessor.processUsing(exportParams, documentName, htmlData.cssContent, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,6 @@ void shouldConvertToPdfInSimplestWorkflow() {
assertThat(result).isEqualTo("test document content".getBytes());
}

@ParameterizedTest
@MethodSource("provideParamsForHtmlCompose")
void shouldComposeHtmlWithCoverPage(String coverPage, String expectedHtmlContent) {
PdfConverter.HtmlData htmlData = new PdfConverter.HtmlData(
"-test css content-",
"-test document content-",
"-test header-footer content-");
ExportParams exportParams = ExportParams.builder().coverPage(coverPage).build();
when(pdfTemplateProcessor.processUsing(eq(exportParams), anyString(), anyString(), anyString())).thenReturn("test");

PdfConverter pdfConverter = new PdfConverter(null, null, cssSettings, null, null, null, null, null, null, pdfTemplateProcessor);
String result = pdfConverter.composeHtml("testDocumentName", htmlData, exportParams);

assertThat(result).isEqualTo("test");
ArgumentCaptor<String> content = ArgumentCaptor.forClass(String.class);
verify(pdfTemplateProcessor).processUsing(eq(exportParams), eq("testDocumentName"), eq("-test css content-"), content.capture());
assertThat(content.getValue()).isEqualTo(expectedHtmlContent);
}

private static Stream<Arguments> provideParamsForHtmlCompose() {
return Stream.of(
Arguments.of(null, "-test header-footer content-<div class='content'>-test document content-</div>"),
Arguments.of("test cover page", "-test header-footer content-<div style='break-after:page'>page to be removed</div><div class='content'>-test document content-</div>"));
}

@Test
void shouldGetAndReplaceCss() {
LiveDocHelper.DocumentData documentData = LiveDocHelper.DocumentData.builder()
Expand Down

0 comments on commit 5fb657c

Please sign in to comment.