Skip to content

Commit

Permalink
✨ import sessions from DOAG
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Mar 24, 2024
1 parent 71c9767 commit af9aeee
Show file tree
Hide file tree
Showing 7 changed files with 5,965 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
<version>4.8.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240303</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/swiss/fihlon/apus/conference/Session.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.conference;

import java.time.LocalDateTime;

public record Session(String id, LocalDateTime date, String title, String speaker) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.conference;

import org.jetbrains.annotations.NotNull;

public class SessionImportException extends RuntimeException {
public SessionImportException(@NotNull final Exception e) {
super(e);
}
}
98 changes: 98 additions & 0 deletions src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 swiss.fihlon.apus.conference.Session;
import swiss.fihlon.apus.conference.SessionImportException;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public final class ConferenceAPI {

private final String location;

public ConferenceAPI(@NotNull final String location) {
this.location = location;
}

public List<Session> getSessions() {
final ArrayList<Session> sessions = new ArrayList<>();
try {
final String json = getJSON();
final JSONObject jsonObject = new JSONObject(json);
final JSONObject schedule = jsonObject.getJSONObject("schedule");
final JSONObject conference = schedule.getJSONObject("conference");
final String acronym = conference.getString("acronym");
final JSONArray days = conference.getJSONArray("days");
for (int dayCounter = 0; dayCounter < days.length(); dayCounter++) {
final JSONObject day = days.getJSONObject(dayCounter);
final LocalDate date = LocalDate.parse(day.getString("date"));
final JSONObject rooms = day.getJSONObject("rooms");
final Iterator<String> roomKeys = rooms.keys();
while (roomKeys.hasNext()) {
final String roomKey = roomKeys.next();
final JSONArray slots = rooms.getJSONArray(roomKey);
for (int slotCounter = 0; slotCounter < slots.length(); slotCounter++) {
final JSONObject slot = slots.getJSONObject(slotCounter);
final String type = slot.getString("type");
if (!"lecture".equalsIgnoreCase(type)) {
continue;
}
final LocalTime time = LocalTime.parse(slot.getString("start"));
final JSONArray persons = slot.getJSONArray("persons");
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("public_name");
speakers.add(publicName);
}
final Session session = new Session(
String.format("%s:%d", acronym, slot.getInt("id")),
LocalDateTime.of(date, time),
slot.getString("title"),
String.join(", ", speakers));
sessions.add(session);
}
}
}
} catch (IOException | URISyntaxException | JSONException e) {
throw new SessionImportException(e);
}
return sessions;
}

private String getJSON() throws IOException, URISyntaxException {
try (InputStream in = new URI(location).toURL().openStream()) {
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/swiss/fihlon/apus/conference/doag/Schedule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.conference.doag;

public record Schedule(String baseUrl) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.conference.doag;

import org.junit.jupiter.api.Test;
import swiss.fihlon.apus.conference.Session;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ConferenceAPITest {

@Test
void importViaHttps() {
final String location = "file:src/test/resources/DOAG.json";
final ConferenceAPI conferenceAPI = new ConferenceAPI(location);
final List<Session> sessions = conferenceAPI.getSessions();
assertEquals(159, sessions.size());
}

}
Loading

0 comments on commit af9aeee

Please sign in to comment.