From 3ab3b30bc5143ff41843f01f227038a510034ab1 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Fri, 29 Mar 2024 12:46:34 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20DOAG=20conference=20API?= =?UTF-8?q?=20changed=20handling=20of=20language?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcus Fihlon --- .../conference/SessionImportException.java | 6 ++++-- .../apus/conference/doag/ConferenceAPI.java | 20 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/swiss/fihlon/apus/conference/SessionImportException.java b/src/main/java/swiss/fihlon/apus/conference/SessionImportException.java index d44e03d..54ec34f 100644 --- a/src/main/java/swiss/fihlon/apus/conference/SessionImportException.java +++ b/src/main/java/swiss/fihlon/apus/conference/SessionImportException.java @@ -20,7 +20,9 @@ import org.jetbrains.annotations.NotNull; public class SessionImportException extends RuntimeException { - public SessionImportException(@NotNull final Exception e) { - super(e); + + public SessionImportException(@NotNull final String message, @NotNull final Exception e) { + super(message, e); } + } diff --git a/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java b/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java index 6e1d668..4936020 100644 --- a/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java +++ b/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java @@ -18,9 +18,9 @@ package swiss.fihlon.apus.conference.doag; import org.jetbrains.annotations.NotNull; -import org.springframework.boot.configurationprocessor.json.JSONArray; -import org.springframework.boot.configurationprocessor.json.JSONException; -import org.springframework.boot.configurationprocessor.json.JSONObject; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import swiss.fihlon.apus.conference.Session; import swiss.fihlon.apus.conference.SessionImportException; import swiss.fihlon.apus.configuration.Configuration; @@ -52,6 +52,7 @@ public ConferenceAPI(@NotNull final Configuration configuration) { public List getSessions() { final ArrayList sessions = new ArrayList<>(); + int lastSlotId = 0; try { final String json = getJSON(); final JSONObject jsonObject = new JSONObject(json); @@ -77,11 +78,12 @@ public List getSessions() { final JSONArray slots = rooms.getJSONArray(room); for (int slotCounter = 0; slotCounter < slots.length(); slotCounter++) { final JSONObject slot = slots.getJSONObject(slotCounter); + lastSlotId = slot.getInt("id"); final String type = slot.getString("type"); if (!"lecture".equalsIgnoreCase(type)) { continue; } - final String language = slot.getString("language"); + final String language = getLanguage(slot); final String title = getTitle(slot, language); final LocalTime startTime = LocalTime.parse(slot.getString("start")); final Duration duration = parseDuration(slot.getString("duration")); @@ -104,11 +106,19 @@ public List getSessions() { } } } catch (IOException | URISyntaxException | JSONException e) { - throw new SessionImportException(e); + throw new SessionImportException(String.format("Error parsing slot %d: %s", lastSlotId, e.getMessage()), e); } return sessions; } + private String getLanguage(@NotNull final JSONObject slot) { + try { + return slot.getJSONArray("language").getString(0); + } catch (final JSONException e) { + return "de"; + } + } + private String getTitle(@NotNull final JSONObject slot, @NotNull final String defaultLanguage) throws JSONException { for (final String language : List.of(defaultLanguage, "de", "en")) { try {