Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of non-ISO dates for display in UI (RPB-157) #389

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/models/AuthorityResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private String process(String field, String value, String label, int i, int size
} else if (Arrays.asList("dateOfBirth", "dateOfDeath").contains(field)) {
result = germanDate(value);
}
else if (value.startsWith("http")) {
else if (value.startsWith("http") && !value.contains(" ")) {
List<String> facets = Arrays.asList(HomeController.AGGREGATIONS);
boolean labelBasedFacet = facets.contains(field + ".label");
boolean qBasedSearch = facets.stream().noneMatch(s -> s.startsWith(field));
Expand Down Expand Up @@ -511,6 +511,7 @@ private String labelFor(String uri) {
: response;
return entity.get("title").asText();
} catch (InterruptedException | ExecutionException e) {
Logger.error("Could not get label for {}", uri);
e.printStackTrace();
}
return uri;
Expand All @@ -522,7 +523,7 @@ public static String germanDate(String value) {
.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(cleanDate(value)))
.format(DateTimeFormatter.ofPattern("dd.MM.uuuu", Locale.GERMAN));
} catch (DateTimeParseException e) {
e.printStackTrace();
Logger.warn("Non-ISO date: {}", value);
return value;
}

Expand Down Expand Up @@ -561,6 +562,6 @@ private static String year(JsonNode node) {
return "";
}
String text = node.elements().next().asText();
return text.matches("\\d{4}-\\d{2}-\\d{2}") ? text.split("-")[0] : text;
return text.replaceAll(".*(\\d{4}).*", "$1");
}
}
Loading