1 package org.unitedfront2.domain.communication;
2
3 import java.util.List;
4
5 import org.unitedfront2.dao.BlogDao;
6 import org.unitedfront2.dao.SimpleFindable;
7 import org.unitedfront2.domain.EmailForwarding;
8 import org.unitedfront2.domain.EmailForwardingTable;
9 import org.unitedfront2.domain.SimpleTableModule;
10
11 /**
12 * ブログのテーブルモジュールです。
13 *
14 * @author kurokkie
15 *
16 */
17 public class BlogTable extends SimpleTableModule<Blog> {
18
19 /** ブログデータアクセスオブジェクト */
20 private BlogDao blogDao;
21
22 /** e メール転送設定テーブルト */
23 private EmailForwardingTable emailForwardingTable;
24
25 @Override
26 protected SimpleFindable<Blog> getSimpleDao() {
27 return blogDao;
28 }
29
30 /**
31 * コードを指定してブログを取得します。
32 *
33 * @param code コード
34 * @return ブログ、見つからなければ <code>null</code>
35 */
36 public Blog findByCode(String code) {
37 return blogDao.findByCode(code);
38 }
39
40 /**
41 * コードを指定してブログを取得します。
42 *
43 * @param code コード
44 * @return ブログ
45 * @throws IllegalArgumentException 指定したコードが存在しない
46 */
47 public Blog getByCode(String code) throws IllegalArgumentException {
48 Blog blog = findByCode(code);
49 if (blog == null) {
50 String message = "The blog code '" + code + "' not found.";
51 logger.error(message);
52 throw new IllegalArgumentException(message);
53 }
54 return blog;
55 }
56
57 /**
58 * コードが存在するか判定します。
59 *
60 * @param code コード
61 * @return 存在するなら <code>true</code> 、存在しないなら <code>false</code>
62 */
63 public boolean existByCode(String code) {
64 return findByCode(code) != null;
65 }
66
67 /**
68 * 指定した所有者のブログリストを取得します。
69 *
70 * @param ownerId 所有者のユーザ ID
71 * @return ブログリスト
72 */
73 public List<Blog> findByOwnerId(int ownerId) {
74 return blogDao.findByOwnerId(ownerId);
75 }
76
77 /**
78 * 匿名ユーザに公開しているブログを取得します。返り値のリストは登録日の降順。
79 *
80 * @return ブログリスト
81 */
82 public List<Blog> findPublicBlogs() {
83 return blogDao.findPublicBlogs();
84 }
85
86 /**
87 * 匿名ユーザに公開しているブログを取得します。
88 *
89 * @param max 最大件数
90 * @return ブログリスト
91 */
92 public List<Blog> findPublicBlogsRandomly(int max) {
93 return blogDao.findPublicBlogsRandomly(max);
94 }
95
96 /**
97 * ブログコメントを e-メールへ転送する設定になっているかどうか。
98 *
99 * @param userId ユーザ ID
100 * @return 転送を行う設定になっている場合は <code>true</code> 、なっていないなら
101 * <code>false</code>
102 */
103 public boolean isBlogCommentForwarding(int userId) {
104 return emailForwardingTable.find(userId, EmailForwarding.BLOG_COMMENT);
105 }
106
107 public void setBlogDao(BlogDao blogDao) {
108 this.blogDao = blogDao;
109 }
110
111 public void setEmailForwardingTable(
112 EmailForwardingTable emailForwardingTable) {
113 this.emailForwardingTable = emailForwardingTable;
114 }
115 }