View Javadoc

1   package org.unitedfront2.domain.communication;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   import org.unitedfront2.domain.DomainFactory;
6   import org.unitedfront2.domain.User;
7   import org.unitedfront2.domain.accesscontrol.AccessDeniedException;
8   
9   /**
10   * ブログ記事のファクトリクラスです。
11   *
12   * @author kurokkie
13   *
14   */
15  public class BlogEntryTable {
16  
17      /** ログ */
18      protected final Log logger = LogFactory.getLog(getClass());
19  
20      /** メッセージテーブル */
21      private MessageTable messageTable;
22  
23      /** ドメインファクトリ */
24      private DomainFactory domainFactory;
25  
26      /**
27       * ブログ記事を取得します。
28       *
29       * @param id ブログ記事 ID
30       * @return ブログ記事、見つからなければ <code>null</code>
31       */
32      public BlogEntry find(int id) {
33          Message entry = messageTable.find(id);
34          if (entry == null) {
35              return null;
36          }
37          return domainFactory.prototype(new BlogEntry(entry), BlogEntry.class);
38      }
39  
40      /**
41       * ブログ記事を参照権限で取得します。
42       *
43       * @param id ブログ記事 ID
44       * @param user ユーザ
45       * @return ブログ記事
46       * @throws AccessDeniedException アクセス拒否
47       */
48      public BlogEntry findForRead(int id, User user)
49          throws AccessDeniedException {
50          BlogEntry entry = find(id);
51          if (entry == null) {
52              return null;
53          } else {
54              entry.readAccess(user);
55              return entry;
56          }
57      }
58  
59      /**
60       * ブログ記事を編集権限で取得します。
61       *
62       * @param id ブログ記事 ID
63       * @param user ユーザ
64       * @return ブログ記事
65       * @throws AccessDeniedException アクセス拒否
66       */
67      public BlogEntry findForWrite(int id, User user)
68          throws AccessDeniedException {
69          BlogEntry entry = find(id);
70          if (entry == null) {
71              return null;
72          } else {
73              entry.writeAccess(user);
74              return entry;
75          }
76      }
77  
78      /**
79       * 指定した記事コードを持つブログ記事を取得します。
80       *
81       * @param code 記事コード(メッセージコード)
82       * @return ブログ記事、見つからなければ <code>null</code>
83       */
84      public BlogEntry findByCode(String code) {
85          Message entry = messageTable.findByCode(code);
86          if (entry == null) {
87              return null;
88          }
89          return domainFactory.prototype(new BlogEntry(entry), BlogEntry.class);
90      }
91  
92      /**
93       * 指定した記事コードを持つブログ記事を参照権限で取得します。
94       *
95       * @param id ブログ記事 ID
96       * @param user ユーザ
97       * @return ブログ記事
98       * @throws AccessDeniedException アクセス拒否
99       */
100     public BlogEntry findByCodeForRead(String code, User user)
101         throws AccessDeniedException {
102         BlogEntry entry = findByCode(code);
103         if (entry == null) {
104             return null;
105         } else {
106             entry.readAccess(user);
107             return entry;
108         }
109     }
110 
111     /**
112      * 指定した記事コードを持つブログ記事を編集権限で取得します。
113      *
114      * @param id ブログ記事 ID
115      * @param user ユーザ
116      * @return ブログ記事
117      * @throws AccessDeniedException アクセス拒否
118      */
119     public BlogEntry findByCodeForWrite(String code, User user)
120         throws AccessDeniedException {
121         BlogEntry entry = findByCode(code);
122         if (entry == null) {
123             return null;
124         } else {
125             entry.writeAccess(user);
126             return entry;
127         }
128     }
129 
130     public void setMessageTable(MessageTable messageTable) {
131         this.messageTable = messageTable;
132     }
133 
134     public void setDomainFactory(DomainFactory domainFactory) {
135         this.domainFactory = domainFactory;
136     }
137 }