Skip to content

Commit

Permalink
👽️ DOAG conference API changed handling of language
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Mar 29, 2024
1 parent 120a60e commit 3ab3b30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
20 changes: 15 additions & 5 deletions src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +52,7 @@ public ConferenceAPI(@NotNull final Configuration configuration) {

public List<Session> getSessions() {
final ArrayList<Session> sessions = new ArrayList<>();
int lastSlotId = 0;
try {
final String json = getJSON();
final JSONObject jsonObject = new JSONObject(json);
Expand All @@ -77,11 +78,12 @@ public List<Session> 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"));
Expand All @@ -104,11 +106,19 @@ public List<Session> 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 {
Expand Down

0 comments on commit 3ab3b30

Please sign in to comment.