-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marcus Fihlon <[email protected]>
- Loading branch information
Showing
7 changed files
with
5,965 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } |
26 changes: 26 additions & 0 deletions
26
src/main/java/swiss/fihlon/apus/conference/SessionImportException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
98
src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
src/main/java/swiss/fihlon/apus/conference/doag/Schedule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/swiss/fihlon/apus/conference/doag/ConferenceAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
Oops, something went wrong.