diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfModel.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfModel.java index 5db38b383707939caaddb23dd55d66f74fa3acc5..402876136b533c8665d75abfd84740ae5a3e467b 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfModel.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfModel.java @@ -76,6 +76,9 @@ class PostfachNachrichtPdfModel { @Getter @Builder static class Nachricht { + + @XmlElement + private boolean isFirst; @XmlElement private String subject; diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfService.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfService.java index a9c12631da0083fef955b12a0af257411bae1080..59eb71fe004500ea80d74cb382289686f28a9957 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfService.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfService.java @@ -36,6 +36,7 @@ import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; import de.itvsh.goofy.common.user.UserProfile; +import de.itvsh.goofy.postfach.PostfachMail.Direction; import de.itvsh.goofy.vorgang.Antragsteller; import de.itvsh.goofy.vorgang.VorgangWithEingang; import de.itvsh.kop.common.errorhandling.TechnicalException; @@ -54,6 +55,8 @@ class PostfachNachrichtPdfService { @Autowired private PdfService pdfService; + private boolean isFirstNachricht; + @Value(PostfachNachrichtPdfService.PDF_TEMPLATE_PATH) private Resource pdfTemplate; @@ -73,6 +76,8 @@ class PostfachNachrichtPdfService { var pdfModelBuilder = PostfachNachrichtPdfModel.builder().vorgangNummer(vorgang.getNummer()).vorgangName(vorgang.getName()); Optional.ofNullable(vorgang.getEingang().getAntragsteller()).ifPresent(antragsteller -> mapAntragsteller(pdfModelBuilder, antragsteller)); + + isFirstNachricht = true; pdfModelBuilder.nachrichten(postfachNachrichten.map(this::mapPostfachNachricht).toList()); return pdfModelBuilder.build(); @@ -88,17 +93,26 @@ class PostfachNachrichtPdfService { .antragstellerOrt(antragsteller.getOrt()); } - PostfachNachrichtPdfModel.Nachricht mapPostfachNachricht(PostfachNachrichtPdfData postfachmail) { + PostfachNachrichtPdfModel.Nachricht mapPostfachNachricht(PostfachNachrichtPdfData postfachMail) { return PostfachNachrichtPdfModel.Nachricht.builder() - .subject(postfachmail.getSubject()) - .mailBody(postfachmail.getMailBody()) - .createdAt(CREATED_AT_FORMATTER.format(postfachmail.getCreatedAt())) - .createdBy(buildUserName(postfachmail.getUser())) - .attachments(postfachmail.getAttachmentNames()) + .isFirst(isFirstNachricht()) + .subject(postfachMail.getSubject()) + .mailBody(postfachMail.getMailBody()) + .createdAt(CREATED_AT_FORMATTER.format(postfachMail.getCreatedAt())) + .createdBy(buildUserName(postfachMail.getUser(), postfachMail.getDirection())) + .attachments(postfachMail.getAttachmentNames()) .build(); } - String buildUserName(UserProfile userProfile) { + private boolean isFirstNachricht() { + if (isFirstNachricht) { + isFirstNachricht = false; + return true; + } + return false; + } + + String buildUserName(UserProfile userProfile, Direction direction) { return Optional.ofNullable(userProfile).map(this::formatUserName).orElseGet(() -> FALLBACK_USER_NAME); } diff --git a/goofy-server/src/main/resources/fop/postfach-nachrichten.xsl b/goofy-server/src/main/resources/fop/postfach-nachrichten.xsl index a91697e90d3e731108f897fee60ebdedc0295400..b030aacd5e9d4f8127ce23fe7a65b7cf5402da04 100644 --- a/goofy-server/src/main/resources/fop/postfach-nachrichten.xsl +++ b/goofy-server/src/main/resources/fop/postfach-nachrichten.xsl @@ -76,52 +76,55 @@ <xsl:template name="nachricht"> <fo:block font-size="11pt" margin-bottom="2mm"> + <xsl:if test="isFirst='false'"> + <fo:leader leader-pattern="rule" leader-length="175mm" rule-style="solid" rule-thickness="1pt"/> + </xsl:if> <fo:table> <fo:table-column column-width="30mm" /> <fo:table-column column-width="145mm"/> <fo:table-body> <fo:table-row> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-cell padding="3px"> <fo:block>Absender</fo:block> </fo:table-cell> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-cell padding="3px"> <fo:block><xsl:value-of select="createdBy" /></fo:block> </fo:table-cell> </fo:table-row> - <fo:table-row border-color="#ccc" border-width="1px" border-style="solid"> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-row> + <fo:table-cell padding="3px"> <fo:block>Datum</fo:block> </fo:table-cell> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-cell padding="3px"> <fo:block><xsl:value-of select="createdAt" /></fo:block> </fo:table-cell> </fo:table-row> - <fo:table-row border-color="#ccc" border-width="1px" border-style="solid"> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-row> + <fo:table-cell padding="3px"> <fo:block>Betreff</fo:block> </fo:table-cell> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-cell padding="3px"> <fo:block><xsl:value-of select="subject" /></fo:block> </fo:table-cell> </fo:table-row> - <fo:table-row border-color="#ccc" border-width="1px" border-style="solid"> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-row> + <fo:table-cell padding="3px"> <fo:block>Text</fo:block> </fo:table-cell> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-cell padding="3px"> <fo:block><xsl:value-of select="mailBody" /></fo:block> </fo:table-cell> </fo:table-row> - <fo:table-row border-color="#ccc" border-width="1px" border-style="solid"> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-row> + <fo:table-cell padding="3px"> <fo:block>Anhänge</fo:block> </fo:table-cell> <xsl:if test="attachments/attachment"> - <fo:table-cell padding="3px" border-color="#ccc" border-width="1px" border-style="solid"> + <fo:table-cell padding="3px"> <xsl:for-each select="attachments/attachment"> <fo:block><xsl:value-of select="."/></fo:block> </xsl:for-each> @@ -129,8 +132,7 @@ </xsl:if> </fo:table-row> </fo:table-body> - </fo:table> - <fo:leader leader-pattern="rule" leader-length="175mm" rule-style="solid" rule-thickness="1pt"/> + </fo:table> </fo:block> </xsl:template> diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfServiceTest.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfServiceTest.java index d221b35f24018fb3eee8d60c3b6bc717149b5343..4ed6014afa34a6d728165a1f970ca05b3645d759 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfServiceTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachNachrichtPdfServiceTest.java @@ -132,6 +132,28 @@ class PostfachNachrichtPdfServiceTest { assertThat(model.getVorgangName()).isEqualTo(VorgangHeaderTestFactory.NAME); } + + @Nested + class TestSetIsFirst { + + @Test + void shouldSetIsFirstTrueOnFirstMessage() { + var model = service.buildModel(VorgangWithEingangTestFactory.create(), + Stream.of(PostfachNachrichtPdfDataTestFactory.create())); + + assertThat(model.getNachrichten().get(0).isFirst()).isTrue(); + } + + @Test + void shouldSetIsFirstFalseOnOtherMessage() { + var model = service.buildModel(VorgangWithEingangTestFactory.create(), + Stream.of(PostfachNachrichtPdfDataTestFactory.create(), PostfachNachrichtPdfDataTestFactory.create(), + PostfachNachrichtPdfDataTestFactory.create())); + + assertThat(model.getNachrichten().get(1).isFirst()).isFalse(); + assertThat(model.getNachrichten().get(2).isFirst()).isFalse(); + } + } } @DisplayName("by Antragsteller")