Skip to content

Commit

Permalink
♻️ small code cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Jun 28, 2024
1 parent b77c1f3 commit f1157da
Showing 1 changed file with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,9 @@ public boolean isEnabled() {
final JSONObject jsonObject = new JSONArray(json).getJSONObject(0);
final JSONArray sessionizeSessions = jsonObject.getJSONArray("sessions");
for (int counter = 0; counter < sessionizeSessions.length(); counter++) {
JSONObject singleSession = sessionizeSessions.getJSONObject(counter);
String sessionId = singleSession.getString("id");
lastSessionId = sessionId;
LocalDateTime startDate = LocalDateTime.parse(singleSession.getString("startsAt"));
if (startDate.toLocalDate().getDayOfMonth() == 16) {
continue;
}
LocalDateTime endDate = LocalDateTime.parse(singleSession.getString("endsAt"));
Room room = new Room(singleSession.getString("room"));
String title = singleSession.getString("title");
final JSONArray persons = singleSession.getJSONArray("speakers");
final ArrayList<String> speakers = new ArrayList<>(persons.length());
for (int personCounter = 0; personCounter < persons.length(); personCounter++) {
final JSONObject person = persons.getJSONObject(personCounter);
final String publicName = person.getString("name");
speakers.add(publicName);
}


Session session = new Session(
String.format("%s:%s", eventId, sessionId),
startDate, endDate, room, title,
speakers.stream().map(Speaker::new).toList(),
getLanguage(singleSession),
Track.NONE);

sessions.add(session);
final JSONObject sessionData = sessionizeSessions.getJSONObject(counter);
lastSessionId = sessionData.getString("id");
sessions.add(getSession(sessionData));
}
LOGGER.info("Successfully loaded {} sessions for event ID {}", sessions.size(), eventId);
} catch (IOException | URISyntaxException | JSONException e) {
Expand All @@ -107,6 +83,25 @@ public boolean isEnabled() {
return sessions;
}

private Session getSession(@NotNull final JSONObject sessionData) {
final JSONArray speakersData = sessionData.getJSONArray("speakers");
final ArrayList<String> speakers = new ArrayList<>(speakersData.length());
for (int speakerCounter = 0; speakerCounter < speakersData.length(); speakerCounter++) {
final JSONObject speakerData = speakersData.getJSONObject(speakerCounter);
speakers.add(speakerData.getString("name"));
}

return new Session(
String.format("%s:%s", eventId, sessionData.getString("id")),
LocalDateTime.parse(sessionData.getString("startsAt")),
LocalDateTime.parse(sessionData.getString("endsAt")),
new Room(sessionData.getString("room")),
sessionData.getString("title"),
speakers.stream().map(Speaker::new).toList(),
getLanguage(sessionData),
Track.NONE);
}

private Language getLanguage(@NotNull final JSONObject singleSession) {
final JSONArray categories = singleSession.getJSONArray("categories");
for (int categoryCounter = 0; categoryCounter < categories.length(); categoryCounter++) {
Expand Down

0 comments on commit f1157da

Please sign in to comment.