From 01d32427c3665296e7c0172b218a348c24f23ffa Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Mon, 24 Jan 2022 11:30:03 +0200 Subject: [PATCH] Add additional checks when generating world documents --- .../utilities/documents/word/WordBuilder.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java index ad3dc1d27..a7d1f9d0d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java @@ -248,7 +248,7 @@ public class WordBuilder { if (field.getValue() != null && !field.getValue().toString().isEmpty()) { this.indent = indent; String format = this.formatter(field); - if(format != null){ + if(format != null && !format.isEmpty()){ if(format.charAt(0) == '['){ format = format.substring(1, format.length() - 1).replaceAll(",", ", "); } @@ -310,6 +310,9 @@ public class WordBuilder { private String formatter(Field field) throws IOException { String comboboxType = null; + if (field.getValue() == null) { + return null; + } switch (field.getViewStyle().getRenderStyle()) { case "researchers": case "projects": @@ -383,12 +386,15 @@ public class WordBuilder { case "datepicker": case "datePicker":{ Instant instant; - try { - instant = Instant.parse((String) field.getValue()); - } catch (DateTimeParseException ex) { - instant = Instant.from(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).parse((String)field.getValue())); + if (!((String)field.getValue()).isEmpty()) { + try { + instant = Instant.parse((String) field.getValue()); + } catch (DateTimeParseException ex) { + instant = Instant.from(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).parse((String) field.getValue())); + } + return field.getValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant) : ""; } - return field.getValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant) : ""; + return (String) field.getValue(); } case "freetext": case "textarea":