Skip to content

Commit

Permalink
♻️ refactor data import to be easier extendable #58
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Apr 17, 2024
1 parent ad2b8c1 commit 5f46ebe
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.plugin.conference;

import org.jetbrains.annotations.NotNull;
import swiss.fihlon.apus.conference.Session;

import java.util.List;

public interface ConferencePlugin {

@NotNull List<Session> getSessions();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.service;
package swiss.fihlon.apus.plugin.conference;

import jakarta.annotation.PreDestroy;
import org.jetbrains.annotations.NotNull;
Expand All @@ -26,7 +26,7 @@
import swiss.fihlon.apus.conference.Room;
import swiss.fihlon.apus.conference.Session;
import swiss.fihlon.apus.conference.SessionImportException;
import swiss.fihlon.apus.conference.doag.ConferenceAPI;
import swiss.fihlon.apus.plugin.conference.doag.DoagPlugin;
import swiss.fihlon.apus.configuration.Configuration;

import java.time.Duration;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void stopUpdateScheduler() {

private void updateSessions() {
try {
final var sessions = new ConferenceAPI(configuration).getSessions().stream()
final var sessions = new DoagPlugin(configuration).getSessions().stream()
.sorted()
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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;
package swiss.fihlon.apus.plugin.conference.doag;

import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
Expand All @@ -29,6 +29,7 @@
import swiss.fihlon.apus.conference.SessionImportException;
import swiss.fihlon.apus.conference.Speaker;
import swiss.fihlon.apus.configuration.Configuration;
import swiss.fihlon.apus.plugin.conference.ConferencePlugin;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -43,18 +44,18 @@
import java.util.Iterator;
import java.util.List;

public final class ConferenceAPI {
public final class DoagPlugin implements ConferencePlugin {

public static final Logger LOGGER = LoggerFactory.getLogger(ConferenceAPI.class);
public static final Logger LOGGER = LoggerFactory.getLogger(DoagPlugin.class);
public static final String CONFERENCE_API_LOCATION = "https://meine.doag.org/api/event/action.getCPEventAgenda/eventId.%d/";

private final int eventId;

public ConferenceAPI(@NotNull final Configuration configuration) {
public DoagPlugin(@NotNull final Configuration configuration) {
this.eventId = configuration.getDoag().eventId();
}

public List<Session> getSessions() {
@NotNull public List<Session> getSessions() {
if (eventId == 0) {
return List.of();
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/swiss/fihlon/apus/plugin/social/SocialPlugin.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.plugin.social;

public interface SocialPlugin {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.service;
package swiss.fihlon.apus.plugin.social;

import jakarta.annotation.PreDestroy;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,8 +25,8 @@
import org.springframework.scheduling.TaskScheduler;
import org.springframework.stereotype.Service;
import swiss.fihlon.apus.configuration.Configuration;
import swiss.fihlon.apus.plugin.social.mastodon.MastodonPlugin;
import swiss.fihlon.apus.social.Message;
import swiss.fihlon.apus.social.mastodon.MastodonAPI;
import swiss.fihlon.apus.util.HtmlUtil;

import java.io.IOException;
Expand All @@ -49,7 +49,7 @@ public final class SocialService {
private static final Logger LOGGER = LoggerFactory.getLogger(SocialService.class);

private final ScheduledFuture<?> updateScheduler;
private final MastodonAPI mastodonAPI;
private final MastodonPlugin mastodonPlugin;
private final int filterLength;
private final boolean filterReplies;
private final boolean filterSensitive;
Expand All @@ -60,7 +60,7 @@ public final class SocialService {

public SocialService(@NotNull final TaskScheduler taskScheduler,
@NotNull final Configuration configuration) {
mastodonAPI = new MastodonAPI(configuration);
mastodonPlugin = new MastodonPlugin(configuration);
filterLength = configuration.getFilter().length();
filterReplies = configuration.getFilter().replies();
filterSensitive = configuration.getFilter().sensitive();
Expand All @@ -79,7 +79,7 @@ public void stopUpdateScheduler() {
}

private void updateMessages() {
final var newMessages = mastodonAPI.getMessages().stream()
final var newMessages = mastodonPlugin.getMessages().stream()
.filter(message -> !hiddenMessages.contains(message.id()))
.filter(message -> !blockedProfiles.contains(message.profile()))
.filter(message -> !filterSensitive || !message.isSensitive())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.social.mastodon;
package swiss.fihlon.apus.plugin.social.mastodon;

import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand All @@ -27,6 +27,7 @@
import social.bigbone.api.entity.MediaAttachment;
import social.bigbone.api.entity.Status;
import swiss.fihlon.apus.configuration.Configuration;
import swiss.fihlon.apus.plugin.social.SocialPlugin;
import swiss.fihlon.apus.social.Message;

import java.time.Instant;
Expand All @@ -37,16 +38,16 @@

import static social.bigbone.api.method.TimelineMethods.StatusOrigin.LOCAL_AND_REMOTE;

public final class MastodonAPI {
public final class MastodonPlugin implements SocialPlugin {

private static final Logger LOGGER = LoggerFactory.getLogger(MastodonAPI.class);
private static final Logger LOGGER = LoggerFactory.getLogger(MastodonPlugin.class);

private final String instance;
private final String hashtag;
private final boolean imagesEnabled;
private final int imageLimit;

public MastodonAPI(@NotNull final Configuration configuration) {
public MastodonPlugin(@NotNull final Configuration configuration) {
final var mastodonConfig = configuration.getMastodon();
this.instance = mastodonConfig.instance();
this.hashtag = mastodonConfig.hashtag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import swiss.fihlon.apus.conference.Room;
import swiss.fihlon.apus.conference.RoomStyle;
import swiss.fihlon.apus.conference.Session;
import swiss.fihlon.apus.service.ConferenceService;
import swiss.fihlon.apus.plugin.conference.ConferenceService;

import java.time.Duration;
import java.time.Instant;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/swiss/fihlon/apus/ui/view/SocialView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.jetbrains.annotations.NotNull;
import org.springframework.scheduling.TaskScheduler;
import swiss.fihlon.apus.configuration.Configuration;
import swiss.fihlon.apus.service.SocialService;
import swiss.fihlon.apus.plugin.social.SocialService;
import swiss.fihlon.apus.social.Message;
import swiss.fihlon.apus.util.PasswordUtil;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/swiss/fihlon/apus/ui/view/SocialWallView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.jetbrains.annotations.NotNull;
import org.springframework.scheduling.TaskScheduler;
import swiss.fihlon.apus.configuration.Configuration;
import swiss.fihlon.apus.service.ConferenceService;
import swiss.fihlon.apus.service.SocialService;
import swiss.fihlon.apus.plugin.conference.ConferenceService;
import swiss.fihlon.apus.plugin.social.SocialService;

@Route("")
@CssImport(value = "./themes/apus/views/social-wall-view.css")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.service;
package swiss.fihlon.apus.plugin.conference;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* 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;
package swiss.fihlon.apus.plugin.conference.doag;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

class ConferenceAPITest {
class DoagPluginTest {

@Test
@Disabled // TODO make the ConferenceAPI testable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.social.mastodon;
package swiss.fihlon.apus.plugin.social.mastodon;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -31,7 +31,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class MastodonAPITest {
class MastodonPluginTest {

@Mock
private Configuration configuration;
Expand All @@ -41,8 +41,8 @@ void getMessages() {
when(configuration.getMastodon()).thenReturn(
new Mastodon("mastodon.social", "java", true, 0));

final MastodonAPI mastodonAPI = new MastodonAPI(configuration);
final List<Message> messages = mastodonAPI.getMessages();
final MastodonPlugin mastodonPlugin = new MastodonPlugin(configuration);
final List<Message> messages = mastodonPlugin.getMessages();

assertNotNull(messages);
}
Expand Down

0 comments on commit 5f46ebe

Please sign in to comment.