From c702f47927368dcdd8cab5b50a732aaeb9a8890a Mon Sep 17 00:00:00 2001 From: Athou Date: Thu, 4 Dec 2014 10:52:41 +0100 Subject: [PATCH] more config checks on startup --- .openshift/config.mysql.yml | 3 ++ config.dev.yml | 3 ++ .../com/commafeed/CommaFeedConfiguration.java | 42 ++++++++++++------- .../commafeed/backend/feed/FeedQueues.java | 2 +- .../backend/feed/FeedRefreshUpdater.java | 2 +- .../backend/feed/FeedRefreshWorker.java | 4 +- .../backend/service/StartupService.java | 2 +- .../backend/service/UserService.java | 2 +- .../service/internal/PostLoginActivities.java | 2 +- .../frontend/resource/CategoryREST.java | 6 +-- .../commafeed/frontend/resource/FeedREST.java | 2 +- .../resource/PubSubHubbubCallbackREST.java | 4 +- .../frontend/resource/ServerREST.java | 4 +- 13 files changed, 47 insertions(+), 31 deletions(-) diff --git a/.openshift/config.mysql.yml b/.openshift/config.mysql.yml index dd7c5c39..e4b9cc63 100644 --- a/.openshift/config.mysql.yml +++ b/.openshift/config.mysql.yml @@ -7,6 +7,9 @@ app: # wether to allow user registrations allowRegistrations: false + # create a demo account the first time the app starts + createDemoAccount: false + # put your google analytics tracking code here googleAnalyticsTrackingCode: diff --git a/config.dev.yml b/config.dev.yml index 0e8accc0..67cfc3e8 100644 --- a/config.dev.yml +++ b/config.dev.yml @@ -7,6 +7,9 @@ app: # wether to allow user registrations allowRegistrations: true + # create a demo account the first time the app starts + createDemoAccount: false + # put your google analytics tracking code here googleAnalyticsTrackingCode: diff --git a/src/main/java/com/commafeed/CommaFeedConfiguration.java b/src/main/java/com/commafeed/CommaFeedConfiguration.java index cdcbfc88..7b7b619f 100644 --- a/src/main/java/com/commafeed/CommaFeedConfiguration.java +++ b/src/main/java/com/commafeed/CommaFeedConfiguration.java @@ -64,64 +64,74 @@ public class CommaFeedConfiguration extends Configuration { public static class ApplicationSettings { @NotNull @NotBlank + @Valid private String publicUrl; @NotNull - private boolean allowRegistrations; + @Valid + private Boolean allowRegistrations; - private boolean createDemoAccount; + @NotNull + @Valid + private Boolean createDemoAccount; private String googleAnalyticsTrackingCode; @NotNull @Min(1) - private int backgroundThreads; + @Valid + private Integer backgroundThreads; @NotNull @Min(1) - private int databaseUpdateThreads; + @Valid + private Integer databaseUpdateThreads; private String smtpHost; - private int smtpPort; - private boolean smtpTls; - private String smtpUserName; - private String smtpPassword; - private String smtpFromAddress; @NotNull - private boolean heavyLoad; + @Valid + private Boolean heavyLoad; @NotNull - private boolean pubsubhubbub; + @Valid + private Boolean pubsubhubbub; @NotNull - private boolean imageProxyEnabled; + @Valid + private Boolean imageProxyEnabled; @NotNull @Min(0) - private int queryTimeout; + @Valid + private Integer queryTimeout; @NotNull @Min(0) - private int keepStatusDays; + @Valid + private Integer keepStatusDays; @NotNull @Min(0) - private int maxFeedCapacity; + @Valid + private Integer maxFeedCapacity; @NotNull @Min(0) - private int refreshIntervalMinutes; + @Valid + private Integer refreshIntervalMinutes; @NotNull + @Valid private CacheType cache; @NotNull + @Valid private String announcement; public Date getUnreadThreshold() { diff --git a/src/main/java/com/commafeed/backend/feed/FeedQueues.java b/src/main/java/com/commafeed/backend/feed/FeedQueues.java index 288e4f2f..aa927530 100644 --- a/src/main/java/com/commafeed/backend/feed/FeedQueues.java +++ b/src/main/java/com/commafeed/backend/feed/FeedQueues.java @@ -154,7 +154,7 @@ public class FeedQueues { } private Date getLastLoginThreshold() { - if (config.getApplicationSettings().isHeavyLoad()) { + if (config.getApplicationSettings().getHeavyLoad()) { return DateUtils.addDays(new Date(), -30); } else { return null; diff --git a/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java b/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java index 52beb7ca..7139ffc0 100644 --- a/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java +++ b/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java @@ -152,7 +152,7 @@ public class FeedRefreshUpdater implements Managed { } } - if (config.getApplicationSettings().isPubsubhubbub()) { + if (config.getApplicationSettings().getPubsubhubbub()) { handlePubSub(feed); } if (!ok) { diff --git a/src/main/java/com/commafeed/backend/feed/FeedRefreshWorker.java b/src/main/java/com/commafeed/backend/feed/FeedRefreshWorker.java index 70c66cae..6f57b1e0 100644 --- a/src/main/java/com/commafeed/backend/feed/FeedRefreshWorker.java +++ b/src/main/java/com/commafeed/backend/feed/FeedRefreshWorker.java @@ -90,7 +90,7 @@ public class FeedRefreshWorker implements Managed { // stops here if NotModifiedException or any other exception is thrown List entries = fetchedFeed.getEntries(); - if (config.getApplicationSettings().isHeavyLoad()) { + if (config.getApplicationSettings().getHeavyLoad()) { disabledUntil = FeedUtils.buildDisabledUntil(fetchedFeed.getFeed().getLastEntryDate(), fetchedFeed.getFeed() .getAverageEntryInterval(), disabledUntil); } @@ -118,7 +118,7 @@ public class FeedRefreshWorker implements Managed { } catch (NotModifiedException e) { log.debug("Feed not modified : {} - {}", feed.getUrl(), e.getMessage()); - if (config.getApplicationSettings().isHeavyLoad()) { + if (config.getApplicationSettings().getHeavyLoad()) { disabledUntil = FeedUtils.buildDisabledUntil(feed.getLastEntryDate(), feed.getAverageEntryInterval(), disabledUntil); } feed.setErrorCount(0); diff --git a/src/main/java/com/commafeed/backend/service/StartupService.java b/src/main/java/com/commafeed/backend/service/StartupService.java index 685f21bc..51734ccf 100644 --- a/src/main/java/com/commafeed/backend/service/StartupService.java +++ b/src/main/java/com/commafeed/backend/service/StartupService.java @@ -97,7 +97,7 @@ public class StartupService implements Managed { try { userService.register(CommaFeedApplication.USERNAME_ADMIN, "admin", "admin@commafeed.com", Arrays.asList(Role.ADMIN, Role.USER), true); - if (config.getApplicationSettings().isCreateDemoAccount()) { + if (config.getApplicationSettings().getCreateDemoAccount()) { userService.register(CommaFeedApplication.USERNAME_DEMO, "demo", "demo@commafeed.com", Arrays.asList(Role.USER), true); } } catch (Exception e) { diff --git a/src/main/java/com/commafeed/backend/service/UserService.java b/src/main/java/com/commafeed/backend/service/UserService.java index 4a67461a..f5c0446b 100644 --- a/src/main/java/com/commafeed/backend/service/UserService.java +++ b/src/main/java/com/commafeed/backend/service/UserService.java @@ -92,7 +92,7 @@ public class UserService { Preconditions.checkNotNull(password); if (!forceRegistration) { - Preconditions.checkState(config.getApplicationSettings().isAllowRegistrations(), + Preconditions.checkState(config.getApplicationSettings().getAllowRegistrations(), "Registrations are closed on this CommaFeed instance"); Preconditions.checkNotNull(email); diff --git a/src/main/java/com/commafeed/backend/service/internal/PostLoginActivities.java b/src/main/java/com/commafeed/backend/service/internal/PostLoginActivities.java index 69f8042e..d27ab4b8 100644 --- a/src/main/java/com/commafeed/backend/service/internal/PostLoginActivities.java +++ b/src/main/java/com/commafeed/backend/service/internal/PostLoginActivities.java @@ -33,7 +33,7 @@ public class PostLoginActivities { user.setLastLogin(now); saveUser = true; } - if (config.getApplicationSettings().isHeavyLoad() && user.shouldRefreshFeedsAt(now)) { + if (config.getApplicationSettings().getHeavyLoad() && user.shouldRefreshFeedsAt(now)) { feedSubscriptionService.refreshAll(user); user.setLastFullRefresh(now); saveUser = true; diff --git a/src/main/java/com/commafeed/frontend/resource/CategoryREST.java b/src/main/java/com/commafeed/frontend/resource/CategoryREST.java index 28893c9c..fd1859b9 100644 --- a/src/main/java/com/commafeed/frontend/resource/CategoryREST.java +++ b/src/main/java/com/commafeed/frontend/resource/CategoryREST.java @@ -143,7 +143,7 @@ public class CategoryREST { for (FeedEntryStatus status : list) { entries.getEntries().add( Entry.build(status, config.getApplicationSettings().getPublicUrl(), config.getApplicationSettings() - .isImageProxyEnabled())); + .getImageProxyEnabled())); } } else if (STARRED.equals(id)) { @@ -152,7 +152,7 @@ public class CategoryREST { for (FeedEntryStatus status : starred) { entries.getEntries().add( Entry.build(status, config.getApplicationSettings().getPublicUrl(), config.getApplicationSettings() - .isImageProxyEnabled())); + .getImageProxyEnabled())); } } else { FeedCategory parent = feedCategoryDAO.findById(user, Long.valueOf(id)); @@ -166,7 +166,7 @@ public class CategoryREST { for (FeedEntryStatus status : list) { entries.getEntries().add( Entry.build(status, config.getApplicationSettings().getPublicUrl(), config.getApplicationSettings() - .isImageProxyEnabled())); + .getImageProxyEnabled())); } entries.setName(parent.getName()); } else { diff --git a/src/main/java/com/commafeed/frontend/resource/FeedREST.java b/src/main/java/com/commafeed/frontend/resource/FeedREST.java index 4253e2b3..a3d74903 100644 --- a/src/main/java/com/commafeed/frontend/resource/FeedREST.java +++ b/src/main/java/com/commafeed/frontend/resource/FeedREST.java @@ -173,7 +173,7 @@ public class FeedREST { for (FeedEntryStatus status : list) { entries.getEntries().add( Entry.build(status, config.getApplicationSettings().getPublicUrl(), config.getApplicationSettings() - .isImageProxyEnabled())); + .getImageProxyEnabled())); } boolean hasMore = entries.getEntries().size() > limit; diff --git a/src/main/java/com/commafeed/frontend/resource/PubSubHubbubCallbackREST.java b/src/main/java/com/commafeed/frontend/resource/PubSubHubbubCallbackREST.java index 716fde4b..6f22191f 100644 --- a/src/main/java/com/commafeed/frontend/resource/PubSubHubbubCallbackREST.java +++ b/src/main/java/com/commafeed/frontend/resource/PubSubHubbubCallbackREST.java @@ -57,7 +57,7 @@ public class PubSubHubbubCallbackREST { public Response verify(@QueryParam("hub.mode") String mode, @QueryParam("hub.topic") String topic, @QueryParam("hub.challenge") String challenge, @QueryParam("hub.lease_seconds") String leaseSeconds, @QueryParam("hub.verify_token") String verifyToken) { - if (!config.getApplicationSettings().isPubsubhubbub()) { + if (!config.getApplicationSettings().getPubsubhubbub()) { return Response.status(Status.FORBIDDEN).entity("pubsubhubbub is disabled").build(); } @@ -87,7 +87,7 @@ public class PubSubHubbubCallbackREST { @Consumes({ MediaType.APPLICATION_ATOM_XML, "application/rss+xml" }) public Response callback() { - if (!config.getApplicationSettings().isPubsubhubbub()) { + if (!config.getApplicationSettings().getPubsubhubbub()) { return Response.status(Status.FORBIDDEN).entity("pubsubhubbub is disabled").build(); } diff --git a/src/main/java/com/commafeed/frontend/resource/ServerREST.java b/src/main/java/com/commafeed/frontend/resource/ServerREST.java index 2407973d..2bbcdfad 100644 --- a/src/main/java/com/commafeed/frontend/resource/ServerREST.java +++ b/src/main/java/com/commafeed/frontend/resource/ServerREST.java @@ -47,7 +47,7 @@ public class ServerREST { infos.setAnnouncement(config.getApplicationSettings().getAnnouncement()); infos.setVersion(config.getVersion()); infos.setGitCommit(config.getGitCommit()); - infos.setAllowRegistrations(config.getApplicationSettings().isAllowRegistrations()); + infos.setAllowRegistrations(config.getApplicationSettings().getAllowRegistrations()); infos.setGoogleAnalyticsCode(config.getApplicationSettings().getGoogleAnalyticsTrackingCode()); infos.setSmtpEnabled(StringUtils.isNotBlank(config.getApplicationSettings().getSmtpHost())); return Response.ok(infos).build(); @@ -59,7 +59,7 @@ public class ServerREST { @ApiOperation(value = "proxy image") @Produces("image/png") public Response get(@SecurityCheck User user, @QueryParam("u") String url) { - if (!config.getApplicationSettings().isImageProxyEnabled()) { + if (!config.getApplicationSettings().getImageProxyEnabled()) { return Response.status(Status.FORBIDDEN).build(); }