Skip to content

Commit

Permalink
♻️ make Java Forum Stuttgart database URL configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Jul 12, 2024
1 parent 1619e0d commit 9e66739
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 55 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ To modify the default configuration values, just specify environment variables w
| FILTER_REPLIES | true | Hide social media posts which are replies. |
| FILTER_SENSITIVE | true | Hide social media posts which contain sensitive information. |
| FILTER_WORDS | | Hide social media posts which contain these words. |
| JFS_DB_URL | | The URL of the database file for Java Forum Stuttgart. |
| MASTODON_HASHTAG | | The hashtag for the mastodon wall (empty = disabled). |
| MASTODON_IMAGE_LIMIT | 1 | Limit number of images per post (0 = no limit). |
| MASTODON_IMAGES_ENABLED | true | Enable or disable images in mastodon posts. |
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/swiss/fihlon/apus/configuration/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import swiss.fihlon.apus.plugin.event.EventConfig;
import swiss.fihlon.apus.plugin.event.demo.DemoConfig;
import swiss.fihlon.apus.plugin.event.doag.DoagConfig;
import swiss.fihlon.apus.plugin.event.jfs.JavaForumStuttgartConfig;
import swiss.fihlon.apus.plugin.event.sessionize.SessionizeConfig;
import swiss.fihlon.apus.plugin.social.mastodon.MastodonConfig;

Expand All @@ -42,6 +43,7 @@ public class Configuration {
// Event Plugin Configs
private DemoConfig demo;
private DoagConfig doag;
private JavaForumStuttgartConfig jfs;
private SessionizeConfig sessionize;

// Social Plugin Configs
Expand Down Expand Up @@ -111,6 +113,14 @@ public void setDoag(@NotNull final DoagConfig doag) {
this.doag = doag;
}

public JavaForumStuttgartConfig getJfs() {
return jfs;
}

public void setJfs(@NotNull final JavaForumStuttgartConfig jfs) {
this.jfs = jfs;
}

public SessionizeConfig getSessionize() {
return sessionize;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.event.jfs;

public record JavaForumStuttgartConfig(String dbUrl) { }
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import swiss.fihlon.apus.configuration.Configuration;
import swiss.fihlon.apus.event.Language;
import swiss.fihlon.apus.event.Room;
import swiss.fihlon.apus.event.Session;
Expand Down Expand Up @@ -55,9 +56,15 @@ public final class JavaForumStuttgartPlugin implements EventPlugin {

public static final Logger LOGGER = LoggerFactory.getLogger(JavaForumStuttgartPlugin.class);

private final String dbUrl;

public JavaForumStuttgartPlugin(@NotNull final Configuration configuration) {
dbUrl = configuration.getJfs().dbUrl();
}

@Override
public boolean isEnabled() {
return false;
return dbUrl != null && !dbUrl.isEmpty();
}

@Override
Expand Down Expand Up @@ -110,11 +117,10 @@ public boolean isEnabled() {
}

private @NotNull Path downloadDatabaseFile() {
final String location = "https://www.nevernull.io/jfs/javaforum2.db";
try {
final Path temporaryDatabaseFile = Files.createTempFile("jfs-", ".db");
LOGGER.info("Start downloading database from {} ...", location);
final URI uri = URI.create(location);
LOGGER.info("Start downloading database from {} ...", dbUrl);
final URI uri = URI.create(dbUrl);
final URL url = uri.toURL();
try (
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
Expand All @@ -127,7 +133,7 @@ public boolean isEnabled() {
} catch (final IOException e) {
throw new SessionImportException(String.format(
"Error downloading database file from '%s': %s",
location, e.getMessage()), e);
dbUrl, e.getMessage()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,83 +1,89 @@
{
"properties" : [
"properties": [
{
"name" : "apus.admin.password",
"type" : "java.lang.String",
"description" : "The password to get admin access (empty = disabled)."
"name": "apus.admin.password",
"type": "java.lang.String",
"description": "The password to get admin access (empty = disabled)."
},
{
"name" : "apus.custom.styles",
"type" : "java.lang.String",
"description" : "Inject custom styles into the user interface."
"name": "apus.custom.styles",
"type": "java.lang.String",
"description": "Inject custom styles into the user interface."
},
{
"name" : "apus.demo.roomCount",
"type" : "java.lang.String",
"description" : "Number of rooms for the event demo plugin."
"name": "apus.demo.roomCount",
"type": "java.lang.String",
"description": "Number of rooms for the event demo plugin."
},
{
"name" : "apus.doag.eventApi",
"type" : "java.lang.String",
"description" : "The URL of the DOAG event API to read the conference agenda."
"name": "apus.doag.eventApi",
"type": "java.lang.String",
"description": "The URL of the DOAG event API to read the conference agenda."
},
{
"name" : "apus.doag.eventId",
"type" : "java.lang.Integer",
"description" : "The ID of the DOAG event to read the conference agenda."
"name": "apus.doag.eventId",
"type": "java.lang.Integer",
"description": "The ID of the DOAG event to read the conference agenda."
},
{
"name" : "apus.event.updateFrequency",
"type" : "java.lang.Integer",
"description" : "How often (in minutes) to update event data."
"name": "apus.event.updateFrequency",
"type": "java.lang.Integer",
"description": "How often (in minutes) to update event data."
},
{
"name" : "apus.filter.length",
"type" : "java.lang.Integer",
"description" : "Hide social media messages which exceed this length."
"name": "apus.filter.length",
"type": "java.lang.Integer",
"description": "Hide social media messages which exceed this length."
},
{
"name" : "apus.filter.replies",
"type" : "java.lang.Boolean",
"description" : "Hide social media messages which are replies."
"name": "apus.filter.replies",
"type": "java.lang.Boolean",
"description": "Hide social media messages which are replies."
},
{
"name" : "apus.filter.sensitive",
"type" : "java.lang.Boolean",
"description" : "Hide social media messages which contain sensitive information."
"name": "apus.filter.sensitive",
"type": "java.lang.Boolean",
"description": "Hide social media messages which contain sensitive information."
},
{
"name" : "apus.filter.words",
"type" : "java.lang.String",
"description" : "Hide social media messages which contain these words."
"name": "apus.filter.words",
"type": "java.lang.String",
"description": "Hide social media messages which contain these words."
},
{
"name" : "apus.mastodon.hashtag",
"type" : "java.lang.String",
"description" : "The hashtag for the Mastodon wall."
"name": "apus.jfs.dbUrl",
"type": "java.lang.String",
"description": "The URL of the database file for Java Forum Stuttgart."
},
{
"name" : "apus.mastodon.imageLimit",
"type" : "java.lang.Integer",
"description" : "Limit number of images per post."
"name": "apus.mastodon.hashtag",
"type": "java.lang.String",
"description": "The hashtag for the Mastodon wall."
},
{
"name" : "apus.mastodon.imagesEnabled",
"type" : "java.lang.Boolean",
"description" : "Enable or disable images in mastodon posts."
"name": "apus.mastodon.imageLimit",
"type": "java.lang.Integer",
"description": "Limit number of images per post."
},
{
"name" : "apus.mastodon.instance",
"type" : "java.lang.String",
"description" : "The Mastodon instance used to read the posts from."
"name": "apus.mastodon.imagesEnabled",
"type": "java.lang.Boolean",
"description": "Enable or disable images in mastodon posts."
},
{
"name" : "apus.sessionize.eventId",
"type" : "java.lang.String",
"description" : "The ID of the Sessionize event to read the conference agenda."
"name": "apus.mastodon.instance",
"type": "java.lang.String",
"description": "The Mastodon instance used to read the posts from."
},
{
"name" : "apus.sessionize.eventApi",
"type" : "java.lang.String",
"description" : "The URL of the Sessionize event API to read the conference agenda."
"name": "apus.sessionize.eventId",
"type": "java.lang.String",
"description": "The ID of the Sessionize event to read the conference agenda."
},
{
"name": "apus.sessionize.eventApi",
"type": "java.lang.String",
"description": "The URL of the Sessionize event API to read the conference agenda."
}
] }
]
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ apus.filter.length=${FILTER_LENGTH:500}
apus.filter.replies=${FILTER_REPLIES:true}
apus.filter.sensitive=${FILTER_SENSITIVE:true}
apus.filter.words=${FILTER_WORDS:}
apus.jfs.dbUrl=${JFS_DB_URL:}
apus.mastodon.hashtag=${MASTODON_HASHTAG:}
apus.mastodon.imageLimit=${MASTODON_IMAGE_LIMIT:1}
apus.mastodon.imagesEnabled=${MASTODON_IMAGES_ENABLED:true}
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ apus.filter.length=500
apus.filter.replies=false
apus.filter.sensitive=true
apus.filter.words=foo, bar, foobar, barfoo
apus.jfs.dbUrl=
apus.mastodon.hashtag=java
apus.mastodon.imageLimit=1
apus.mastodon.imagesEnabled=true
Expand Down

0 comments on commit 9e66739

Please sign in to comment.