From 1131d7064562c52895de4886e57943ead2df8e6b Mon Sep 17 00:00:00 2001 From: Athou Date: Sat, 27 Jul 2013 13:01:28 +0200 Subject: [PATCH] move utility method to service (fix #463) --- .../java/com/commafeed/backend/ScheduledTasks.java | 2 +- .../com/commafeed/backend/dao/FeedEntryStatusDAO.java | 4 ++-- .../commafeed/backend/model/ApplicationSettings.java | 11 ----------- .../backend/services/ApplicationSettingsService.java | 7 +++++++ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/commafeed/backend/ScheduledTasks.java b/src/main/java/com/commafeed/backend/ScheduledTasks.java index f4e792e9..c39ff00f 100644 --- a/src/main/java/com/commafeed/backend/ScheduledTasks.java +++ b/src/main/java/com/commafeed/backend/ScheduledTasks.java @@ -35,7 +35,7 @@ public class ScheduledTasks { */ @Schedule(hour = "0", persistent = false) private void cleanupOldStatuses() { - Date threshold = applicationSettingsService.get().getUnreadThreshold(); + Date threshold = applicationSettingsService.getUnreadThreshold(); if (threshold != null) { cleaner.cleanStatusesOlderThan(threshold); } diff --git a/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java b/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java index a4ea8155..e6c39d84 100644 --- a/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java +++ b/src/main/java/com/commafeed/backend/dao/FeedEntryStatusDAO.java @@ -85,7 +85,7 @@ public class FeedEntryStatusDAO extends GenericDAO { private FeedEntryStatus handleStatus(FeedEntryStatus status, FeedSubscription sub, FeedEntry entry) { if (status == null) { - Date unreadThreshold = applicationSettingsService.get().getUnreadThreshold(); + Date unreadThreshold = applicationSettingsService.getUnreadThreshold(); boolean read = unreadThreshold == null ? false : entry.getUpdated().before(unreadThreshold); status = new FeedEntryStatus(sub.getUser(), sub, entry); status.setRead(read); @@ -149,7 +149,7 @@ public class FeedEntryStatusDAO extends GenericDAO { or.add(Restrictions.eq(FeedEntryStatus_.read.getName(), false)); statusJoin.add(or); - Date unreadThreshold = applicationSettingsService.get().getUnreadThreshold(); + Date unreadThreshold = applicationSettingsService.getUnreadThreshold(); if (unreadThreshold != null) { criteria.add(Restrictions.ge(FeedEntry_.updated.getName(), unreadThreshold)); } diff --git a/src/main/java/com/commafeed/backend/model/ApplicationSettings.java b/src/main/java/com/commafeed/backend/model/ApplicationSettings.java index a9fbfcfb..618a6f32 100644 --- a/src/main/java/com/commafeed/backend/model/ApplicationSettings.java +++ b/src/main/java/com/commafeed/backend/model/ApplicationSettings.java @@ -1,7 +1,5 @@ package com.commafeed.backend.model; -import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; @@ -9,11 +7,8 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; -import org.apache.commons.lang3.time.DateUtils; import org.apache.log4j.Level; -import com.fasterxml.jackson.annotation.JsonIgnore; - @Entity @Table(name = "APPLICATIONSETTINGS") @SuppressWarnings("serial") @@ -45,12 +40,6 @@ public class ApplicationSettings extends AbstractModel { @Column(length = 255) private String announcement; - @JsonIgnore - public Date getUnreadThreshold() { - int keepStatusDays = getKeepStatusDays(); - return keepStatusDays > 0 ? DateUtils.addDays(new Date(), -1 * keepStatusDays) : null; - } - /* getters and setters below */ public String getPublicUrl() { diff --git a/src/main/java/com/commafeed/backend/services/ApplicationSettingsService.java b/src/main/java/com/commafeed/backend/services/ApplicationSettingsService.java index 2ef75cd5..ce6aa506 100644 --- a/src/main/java/com/commafeed/backend/services/ApplicationSettingsService.java +++ b/src/main/java/com/commafeed/backend/services/ApplicationSettingsService.java @@ -1,10 +1,12 @@ package com.commafeed.backend.services; +import java.util.Date; import java.util.Enumeration; import javax.ejb.Singleton; import javax.inject.Inject; +import org.apache.commons.lang.time.DateUtils; import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; @@ -34,6 +36,11 @@ public class ApplicationSettingsService { return settings; } + public Date getUnreadThreshold() { + int keepStatusDays = get().getKeepStatusDays(); + return keepStatusDays > 0 ? DateUtils.addDays(new Date(), -1 * keepStatusDays) : null; + } + @SuppressWarnings("unchecked") public void applyLogLevel() { String logLevel = get().getLogLevel();