diff --git a/src/main/java/app/coronawarn/quicktest/config/PdfConfig.java b/src/main/java/app/coronawarn/quicktest/config/PdfConfig.java
index 9629547b..ee9fd537 100644
--- a/src/main/java/app/coronawarn/quicktest/config/PdfConfig.java
+++ b/src/main/java/app/coronawarn/quicktest/config/PdfConfig.java
@@ -132,6 +132,8 @@ public class PdfConfig {
private String certTestTypeRat = "Rapid immunoassay";
private String certTestTypePcr = "Nucleic acid amplification";
private String certIssuerState = "DE";
+ private String certForTrainingEn = "Only for training purposes";
+ private String certForTrainingDe = "Nur zu Schulungszwecken";
private String certQrDescription = "Scannen Sie den
nebenstehenden
QR-Code mit der
"
+ "CovPass-App oder der
Corona-Warn-App, um
Ihren digitalen Nachweis
zu erstellen. Laden Sie
"
diff --git a/src/main/java/app/coronawarn/quicktest/utils/DccPdfGenerator.java b/src/main/java/app/coronawarn/quicktest/utils/DccPdfGenerator.java
index ac756d21..8a6c4f80 100644
--- a/src/main/java/app/coronawarn/quicktest/utils/DccPdfGenerator.java
+++ b/src/main/java/app/coronawarn/quicktest/utils/DccPdfGenerator.java
@@ -23,6 +23,7 @@
import static app.coronawarn.quicktest.utils.PdfUtils.splitStringToParagraph;
import app.coronawarn.quicktest.config.PdfConfig;
+import app.coronawarn.quicktest.config.QuickTestConfig;
import app.coronawarn.quicktest.dgc.DccDecodeResult;
import app.coronawarn.quicktest.dgc.DccDecoder;
import app.coronawarn.quicktest.domain.QuickTest;
@@ -55,6 +56,7 @@
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.util.Matrix;
@@ -67,6 +69,7 @@
public class DccPdfGenerator {
private final PdfConfig pdfConfig;
+ private final QuickTestConfig quickTestConfig;
private final DccDecoder dccDecoder;
@@ -138,6 +141,9 @@ private void generateCertPage(PDDocument document, QuickTest quicktest, String d
generateQrCode(document, cos, rect, dcc, false);
generateMemberStateInfoPage(document, cos, rect, false);
generateCertificateInfoPage(cos, rect, quicktest, dccDecodeResult, false);
+ if (!isEnvironmentNameEmpty()) {
+ generateTrainingText(cos, rect, false);
+ }
cos.close();
}
@@ -161,6 +167,9 @@ private void generateCertPageFoldable(PDDocument document, QuickTest quicktest,
generateMemberStateInfoPage(document, cos, rect, true);
generateCertificateInfoPage(cos, rect, quicktest, dccDecodeResult, true);
+ if (!isEnvironmentNameEmpty()) {
+ generateTrainingText(cos, rect, true);
+ }
cos.close();
}
@@ -596,4 +605,42 @@ private void close(PDDocument document, ByteArrayOutputStream output) throws IOE
document.save(output);
document.close();
}
+
+ private void generateTrainingText(PDPageContentStream cos, PDRectangle rect, boolean foldable) throws IOException {
+ PDFont font = PDType1Font.HELVETICA_BOLD;
+ int trainingFontSize = 28;
+
+ cos.beginText();
+ cos.setFont(font, trainingFontSize);
+ cos.setNonStrokingColor(Color.ORANGE);
+
+ float trainingFontWidth = 0.0f;
+ trainingFontWidth = font.getStringWidth(pdfConfig.getCertForTrainingDe()) / 1000 * trainingFontSize;
+ float x = 0;
+ float y = 0;
+ float tx = (trainingFontWidth / 2) / (float)Math.sqrt(2);
+ if (foldable) {
+ x = rect.getWidth() / 2 - tx;
+ y = rect.getHeight() - tx;
+ } else {
+ x = rect.getWidth() / 2 - tx;
+ y = rect.getHeight() / 2 - tx;
+ }
+
+ cos.transform(Matrix.getRotateInstance(
+ Math.toRadians(45), x, y));
+ cos.showText(pdfConfig.getCertForTrainingDe());
+ cos.endText();
+ }
+
+ private boolean isEnvironmentNameEmpty() {
+ if (quickTestConfig != null
+ && quickTestConfig.getFrontendContextConfig() != null
+ && quickTestConfig.getFrontendContextConfig().getEnvironmentName() != null
+ && !quickTestConfig.getFrontendContextConfig().getEnvironmentName().isEmpty()) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/src/main/java/app/coronawarn/quicktest/utils/PdfGenerator.java b/src/main/java/app/coronawarn/quicktest/utils/PdfGenerator.java
index 519154e1..8a236ea7 100644
--- a/src/main/java/app/coronawarn/quicktest/utils/PdfGenerator.java
+++ b/src/main/java/app/coronawarn/quicktest/utils/PdfGenerator.java
@@ -25,7 +25,9 @@
import static app.coronawarn.quicktest.utils.PdfUtils.splitStringToParagraph;
import app.coronawarn.quicktest.config.PdfConfig;
+import app.coronawarn.quicktest.config.QuickTestConfig;
import app.coronawarn.quicktest.domain.QuickTest;
+import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -49,6 +51,7 @@
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
+import org.apache.pdfbox.util.Matrix;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
@@ -58,6 +61,7 @@
public class PdfGenerator {
private final PdfConfig pdfConfig;
+ private final QuickTestConfig quickTestConfig;
private final int pendingPcr = 10;
private final int negativePcr = 11;
@@ -138,6 +142,9 @@ private void write(PDDocument document, PDPageContentStream cos, PDRectangle rec
generateSubject(cos, rect, quicktest, english);
generateText(cos, rect, quicktest, user, english);
generateEnd(cos, rect, english);
+ if (!isEnvironmentNameEmpty()) {
+ generateTrainingText(cos, rect, english);
+ }
cos.close();
}
@@ -449,6 +456,33 @@ private void generateText(PDPageContentStream cos, PDRectangle rect, QuickTest q
}
+ private void generateTrainingText(PDPageContentStream cos, PDRectangle rect,
+ boolean english) throws IOException {
+ PDFont font = PDType1Font.HELVETICA_BOLD;
+ int trainingFontSize = 28;
+ float trainingFontWidth = 0.0f;
+
+ cos.beginText();
+ cos.setFont(font, trainingFontSize);
+ cos.setNonStrokingColor(Color.ORANGE);
+ if (english) {
+ trainingFontWidth = font.getStringWidth(pdfConfig.getCertForTrainingEn()) / 1000 * trainingFontSize;
+ float tx = (trainingFontWidth / 2) / (float)Math.sqrt(2);
+ cos.transform(Matrix.getRotateInstance(
+ Math.toRadians(45), rect.getWidth() / 2 - tx, rect.getHeight() / 2 - tx));
+ cos.showText(pdfConfig.getCertForTrainingEn());
+ } else {
+ trainingFontWidth = font.getStringWidth(pdfConfig.getCertForTrainingDe()) / 1000 * trainingFontSize;
+ //Horizontal zentrierte Schrift
+ //cos.newLineAtOffset(rect.getWidth() / 2 - trainingFontWidth /2, (rect.getHeight() / 2));
+ float tx = (trainingFontWidth / 2) / (float)Math.sqrt(2);
+ cos.transform(Matrix.getRotateInstance(
+ Math.toRadians(45), rect.getWidth() / 2 - tx, rect.getHeight() / 2 - tx));
+ cos.showText(pdfConfig.getCertForTrainingDe());
+ }
+ cos.endText();
+ }
+
private void generateEnd(PDPageContentStream cos, PDRectangle rect, boolean english) throws IOException {
cos.beginText();
cos.setFont(fontType, fontSize);
@@ -461,7 +495,6 @@ private void generateEnd(PDPageContentStream cos, PDRectangle rect, boolean engl
}
cos.newLine();
cos.endText();
-
}
private void close(PDDocument document, ByteArrayOutputStream output) throws IOException {
@@ -469,4 +502,14 @@ private void close(PDDocument document, ByteArrayOutputStream output) throws IOE
document.close();
}
+ private boolean isEnvironmentNameEmpty() {
+ if (quickTestConfig != null
+ && quickTestConfig.getFrontendContextConfig() != null
+ && quickTestConfig.getFrontendContextConfig().getEnvironmentName() != null
+ && !quickTestConfig.getFrontendContextConfig().getEnvironmentName().isEmpty()) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/src/test/java/app/coronawarn/quicktest/utils/DccPdfGeneratorTest.java b/src/test/java/app/coronawarn/quicktest/utils/DccPdfGeneratorTest.java
index ffbdf8ce..8a39c569 100644
--- a/src/test/java/app/coronawarn/quicktest/utils/DccPdfGeneratorTest.java
+++ b/src/test/java/app/coronawarn/quicktest/utils/DccPdfGeneratorTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.when;
import app.coronawarn.quicktest.config.PdfConfig;
+import app.coronawarn.quicktest.config.QuickTestConfig;
import app.coronawarn.quicktest.dgc.DccDecoder;
import app.coronawarn.quicktest.domain.QuickTest;
import java.io.ByteArrayOutputStream;
@@ -59,6 +60,10 @@ class DccPdfGeneratorTest {
private PdfConfig pdc = new PdfConfig();
+ @Mock
+ private QuickTestConfig quickTestConfig;
+ QuickTestConfig.FrontendContextConfig frontendContextConfig = new QuickTestConfig.FrontendContextConfig();
+
@BeforeEach
void setUp() {
when(dccDecoderMock.decodeDcc(any())).thenCallRealMethod();
@@ -102,6 +107,14 @@ void setUp() {
@Test
void appendDccPageTest() throws IOException {
+ frontendContextConfig.setEnvironmentName("");
+ when(quickTestConfig.getFrontendContextConfig()).thenReturn(frontendContextConfig);
+
+ String environment = frontendContextConfig.getEnvironmentName();
+ if(environment != null && !environment.isEmpty()) {
+ when(pdfConfig.getCertForTrainingDe()).thenReturn(pdc.getCertForTrainingDe());
+ }
+
when(pdfConfig.getCertTestTypeRat()).thenReturn(pdc.getCertTestTypeRat());
QuickTest quicktest = getQuickTest();
@@ -134,6 +147,14 @@ void appendDccPageTest() throws IOException {
@Test
void appendPcrDccPageTest() throws IOException {
+ frontendContextConfig.setEnvironmentName("testsystem");
+ when(quickTestConfig.getFrontendContextConfig()).thenReturn(frontendContextConfig);
+
+ String environment = frontendContextConfig.getEnvironmentName();
+ if(environment != null && !environment.isEmpty()) {
+ when(pdfConfig.getCertForTrainingDe()).thenReturn(pdc.getCertForTrainingDe());
+ }
+
when(pdfConfig.getCertTestTypePcr()).thenReturn(pdc.getCertTestTypePcr());
QuickTest quicktest = getQuickTest("LP6464-4", 1);
diff --git a/src/test/java/app/coronawarn/quicktest/utils/PdfGeneratorTest.java b/src/test/java/app/coronawarn/quicktest/utils/PdfGeneratorTest.java
index 83f990df..dea3822b 100644
--- a/src/test/java/app/coronawarn/quicktest/utils/PdfGeneratorTest.java
+++ b/src/test/java/app/coronawarn/quicktest/utils/PdfGeneratorTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.when;
import app.coronawarn.quicktest.config.PdfConfig;
+import app.coronawarn.quicktest.config.QuickTestConfig;
import app.coronawarn.quicktest.domain.QuickTest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -48,10 +49,13 @@ public class PdfGeneratorTest {
private PdfGenerator pdfGenerator;
@Mock
private PdfConfig pdfConfig;
+ @Mock
+ private QuickTestConfig quickTestConfig;
@Test
void generatePdfTest() throws IOException {
PdfConfig pdc = new PdfConfig();
+ QuickTestConfig.FrontendContextConfig frontendContextConfig = new QuickTestConfig.FrontendContextConfig();
when(pdfConfig.getLogoPath()).thenReturn("/logo");
when(pdfConfig.getAuthorPdfPropertiesText()).thenReturn("Unittest");
when(pdfConfig.getQuickTestHeadlineText()).thenReturn("Unittest");
@@ -89,6 +93,15 @@ void generatePdfTest() throws IOException {
when(pdfConfig.getAdditionalInfoDescriptionText()).thenReturn("Zusätzliche Informationen: ");
when(pdfConfig.getAdditionalInfoDescriptionTextEn()).thenReturn(pdc.getAdditionalInfoDescriptionTextEn());
+ frontendContextConfig.setEnvironmentName("testsystem");
+ when(quickTestConfig.getFrontendContextConfig()).thenReturn(frontendContextConfig);
+
+ String environment = frontendContextConfig.getEnvironmentName();
+ if(environment != null && !environment.isEmpty()) {
+ when(pdfConfig.getCertForTrainingDe()).thenReturn(pdc.getCertForTrainingDe());
+ when(pdfConfig.getCertForTrainingEn()).thenReturn(pdc.getCertForTrainingEn());
+ }
+
List pocInformation = new ArrayList();
pocInformation.add("PoC Unittest");
pocInformation.add("Unittest Way 15");