move utility method to service (fix #463)

This commit is contained in:
Athou
2013-07-27 13:01:28 +02:00
parent 4b080510e7
commit 1131d70645
4 changed files with 10 additions and 14 deletions

View File

@@ -35,7 +35,7 @@ public class ScheduledTasks {
*/ */
@Schedule(hour = "0", persistent = false) @Schedule(hour = "0", persistent = false)
private void cleanupOldStatuses() { private void cleanupOldStatuses() {
Date threshold = applicationSettingsService.get().getUnreadThreshold(); Date threshold = applicationSettingsService.getUnreadThreshold();
if (threshold != null) { if (threshold != null) {
cleaner.cleanStatusesOlderThan(threshold); cleaner.cleanStatusesOlderThan(threshold);
} }

View File

@@ -85,7 +85,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
private FeedEntryStatus handleStatus(FeedEntryStatus status, FeedSubscription sub, FeedEntry entry) { private FeedEntryStatus handleStatus(FeedEntryStatus status, FeedSubscription sub, FeedEntry entry) {
if (status == null) { if (status == null) {
Date unreadThreshold = applicationSettingsService.get().getUnreadThreshold(); Date unreadThreshold = applicationSettingsService.getUnreadThreshold();
boolean read = unreadThreshold == null ? false : entry.getUpdated().before(unreadThreshold); boolean read = unreadThreshold == null ? false : entry.getUpdated().before(unreadThreshold);
status = new FeedEntryStatus(sub.getUser(), sub, entry); status = new FeedEntryStatus(sub.getUser(), sub, entry);
status.setRead(read); status.setRead(read);
@@ -149,7 +149,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
or.add(Restrictions.eq(FeedEntryStatus_.read.getName(), false)); or.add(Restrictions.eq(FeedEntryStatus_.read.getName(), false));
statusJoin.add(or); statusJoin.add(or);
Date unreadThreshold = applicationSettingsService.get().getUnreadThreshold(); Date unreadThreshold = applicationSettingsService.getUnreadThreshold();
if (unreadThreshold != null) { if (unreadThreshold != null) {
criteria.add(Restrictions.ge(FeedEntry_.updated.getName(), unreadThreshold)); criteria.add(Restrictions.ge(FeedEntry_.updated.getName(), unreadThreshold));
} }

View File

@@ -1,7 +1,5 @@
package com.commafeed.backend.model; package com.commafeed.backend.model;
import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; 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.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity @Entity
@Table(name = "APPLICATIONSETTINGS") @Table(name = "APPLICATIONSETTINGS")
@SuppressWarnings("serial") @SuppressWarnings("serial")
@@ -45,12 +40,6 @@ public class ApplicationSettings extends AbstractModel {
@Column(length = 255) @Column(length = 255)
private String announcement; private String announcement;
@JsonIgnore
public Date getUnreadThreshold() {
int keepStatusDays = getKeepStatusDays();
return keepStatusDays > 0 ? DateUtils.addDays(new Date(), -1 * keepStatusDays) : null;
}
/* getters and setters below */ /* getters and setters below */
public String getPublicUrl() { public String getPublicUrl() {

View File

@@ -1,10 +1,12 @@
package com.commafeed.backend.services; package com.commafeed.backend.services;
import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import javax.ejb.Singleton; import javax.ejb.Singleton;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@@ -34,6 +36,11 @@ public class ApplicationSettingsService {
return settings; return settings;
} }
public Date getUnreadThreshold() {
int keepStatusDays = get().getKeepStatusDays();
return keepStatusDays > 0 ? DateUtils.addDays(new Date(), -1 * keepStatusDays) : null;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void applyLogLevel() { public void applyLogLevel() {
String logLevel = get().getLogLevel(); String logLevel = get().getLogLevel();