community.entryCreate-flow のコントローラロジックをリファクタリングしました。
@@ -53,6 +53,9 @@ | ||
53 | 53 | /** 最終更新日時 */ |
54 | 54 | private transient Date lastUpdateDate; |
55 | 55 | |
56 | + /** スレッドリスト */ | |
57 | + private transient List<Thread> threads; | |
58 | + | |
56 | 59 | /** コミュニティデータアクセスオブジェクト */ |
57 | 60 | private transient CommunityDao communityDao; |
58 | 61 |
@@ -296,17 +299,34 @@ | ||
296 | 299 | return doChangeTo(clazz); |
297 | 300 | } |
298 | 301 | |
299 | - /** | |
300 | - * スレッドを取得します。指定したスレッドがこのコミュニティに存在しない場合は <code>null</code> を | |
301 | - * 返します。 | |
302 | - * | |
303 | - * @param threadId スレッド ID | |
304 | - * @return スレッド | |
305 | - */ | |
306 | - public Thread findThread(int threadId) { | |
307 | - return communityDao.findThread(this.id, threadId); | |
302 | + @Override | |
303 | + public Thread getThread() { | |
304 | + List<Thread> threads = communityDao.findThreads(id); | |
305 | + if (threads.isEmpty()) { | |
306 | + return null; | |
307 | + } else { | |
308 | + return threads.get(0); | |
309 | + } | |
308 | 310 | } |
309 | 311 | |
312 | + @Override | |
313 | + public Thread getThread(Integer threadId) { | |
314 | + if (threadId == null) { | |
315 | + return getThread(); | |
316 | + } else { | |
317 | + return communityDao.findThread(this.id, threadId); | |
318 | + } | |
319 | + } | |
320 | + | |
321 | + @Override | |
322 | + public List<Thread> getThreads() { | |
323 | + if (this.threads == null && getId() != null | |
324 | + && getCommunityDao() != null) { | |
325 | + this.threads = getCommunityDao().findThreads(getId()); | |
326 | + } | |
327 | + return threads; | |
328 | + } | |
329 | + | |
310 | 330 | /** |
311 | 331 | * 削除可能であるかどうかを判定します。このメソッドが <code>true</code> を返す場合、データの整合 |
312 | 332 | * 性に違反することなくこのコミュニティを削除できます。 |
@@ -29,9 +29,6 @@ | ||
29 | 29 | /** シリアル番号 */ |
30 | 30 | private static final long serialVersionUID = -5904029361837475679L; |
31 | 31 | |
32 | - /** スレッドリスト */ | |
33 | - private transient List<Thread> threads; | |
34 | - | |
35 | 32 | public MultiThreadCommunity() { |
36 | 33 | super(); |
37 | 34 | } |
@@ -127,12 +124,4 @@ | ||
127 | 124 | thread.store(); |
128 | 125 | getCommunityDao().registerThread(getId(), thread.getId()); |
129 | 126 | } |
130 | - | |
131 | - public List<Thread> getThreads() { | |
132 | - if (this.threads == null && getId() != null | |
133 | - && getCommunityDao() != null) { | |
134 | - this.threads = getCommunityDao().findThreads(getId()); | |
135 | - } | |
136 | - return threads; | |
137 | - } | |
138 | 127 | } |
@@ -82,6 +82,25 @@ | ||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | + * コミュニティを投稿権限で取得します。 | |
86 | + * | |
87 | + * @param id ID | |
88 | + * @param user ユーザ | |
89 | + * @return コミュニティ | |
90 | + * @throws AccessDeniedException アクセス拒否 | |
91 | + */ | |
92 | + public Community findForPost(int id, User user) | |
93 | + throws AccessDeniedException { | |
94 | + Community c = find(id); | |
95 | + if (c == null) { | |
96 | + return null; | |
97 | + } else { | |
98 | + c.postAccess(user); | |
99 | + return c; | |
100 | + } | |
101 | + } | |
102 | + | |
103 | + /** | |
85 | 104 | * コードを引数として渡し、完全なコミュニティオブジェクトを取得します。 |
86 | 105 | * |
87 | 106 | * @param code コード |
@@ -130,6 +149,25 @@ | ||
130 | 149 | } |
131 | 150 | |
132 | 151 | /** |
152 | + * 指定したコードを持つコミュニティを投稿権限で取得します。 | |
153 | + * | |
154 | + * @param code コード | |
155 | + * @param user ユーザ | |
156 | + * @return コミュニティ | |
157 | + * @throws AccessDeniedException アクセス拒否 | |
158 | + */ | |
159 | + public Community findByCodeForPost(String code, User user) | |
160 | + throws AccessDeniedException { | |
161 | + Community c = findByCode(code); | |
162 | + if (c == null) { | |
163 | + return null; | |
164 | + } else { | |
165 | + c.postAccess(user); | |
166 | + return c; | |
167 | + } | |
168 | + } | |
169 | + | |
170 | + /** | |
133 | 171 | * コミュニティリストを記事の最終更新日時の降順で取得します。返されるコミュニティには最終更新日時が設 |
134 | 172 | * 定されている状態になります。 |
135 | 173 | * |
@@ -152,6 +152,7 @@ | ||
152 | 152 | return super.getLastUpdateDate(); |
153 | 153 | } |
154 | 154 | |
155 | + @Override | |
155 | 156 | public Thread getThread() { |
156 | 157 | if (thread == null && getCommunityDao() != null && getId() != null) { |
157 | 158 | List<Thread> threads = getCommunityDao().findThreads(getId()); |
@@ -1,6 +1,7 @@ | ||
1 | 1 | package org.unitedfront2.domain.communication; |
2 | 2 | |
3 | 3 | import java.util.Date; |
4 | +import java.util.List; | |
4 | 5 | |
5 | 6 | import org.unitedfront2.domain.Deletable; |
6 | 7 | import org.unitedfront2.domain.Identifiable; |
@@ -155,6 +156,29 @@ | ||
155 | 156 | */ |
156 | 157 | boolean canPost(User user); |
157 | 158 | |
159 | + /** | |
160 | + * スレッドを一つ取得します。 | |
161 | + * | |
162 | + * @return スレッド | |
163 | + */ | |
164 | + Thread getThread(); | |
165 | + | |
166 | + /** | |
167 | + * 指定したスレッドを取得します。引数に <code>null</code> が指定された場合は任意のスレッド | |
168 | + * を返します。 | |
169 | + * | |
170 | + * @param id スレッド ID | |
171 | + * @return スレッド | |
172 | + */ | |
173 | + Thread getThread(Integer id); | |
174 | + | |
175 | + /** | |
176 | + * 全てのスレッドを取得します。 | |
177 | + * | |
178 | + * @return スレッドのリスト | |
179 | + */ | |
180 | + List<Thread> getThreads(); | |
181 | + | |
158 | 182 | Integer getId(); |
159 | 183 | |
160 | 184 | void setId(Integer id); |
@@ -1,43 +0,0 @@ | ||
1 | -package org.unitedfront2.web.controller.community; | |
2 | - | |
3 | -import org.springframework.beans.factory.annotation.Autowired; | |
4 | -import org.springframework.stereotype.Repository; | |
5 | -import org.springframework.webflow.action.AbstractAction; | |
6 | -import org.springframework.webflow.execution.Event; | |
7 | -import org.springframework.webflow.execution.RequestContext; | |
8 | -import org.unitedfront2.domain.communication.Community; | |
9 | -import org.unitedfront2.domain.communication.CommunityTable; | |
10 | -import org.unitedfront2.domain.communication.Thread; | |
11 | -import org.unitedfront2.web.WebUtils; | |
12 | -import org.unitedfront2.web.controller.message.FormAction; | |
13 | - | |
14 | -/** | |
15 | - * 記事投稿用のアクションクラスです。 | |
16 | - * | |
17 | - * @author kurokkie | |
18 | - * | |
19 | - */ | |
20 | -@Repository(value = "communityEntryCreateAction") | |
21 | -public class EntryCreateAction extends AbstractAction { | |
22 | - | |
23 | - /** コミュニティテーブル */ | |
24 | - @Autowired | |
25 | - private CommunityTable communityTable; | |
26 | - | |
27 | - @Override | |
28 | - protected Event doExecute(RequestContext context) { | |
29 | - Community c = Utils.findCommunityAndPostAccess(context, this, | |
30 | - communityTable, "communityCode"); | |
31 | - Thread t = Utils.findThread(context, this, c, "threadId"); | |
32 | - | |
33 | - context.getFlowScope().put("community", c); | |
34 | - context.getFlowScope().put( | |
35 | - org.unitedfront2.web.controller.thread.EntryFormAction | |
36 | - .THREAD_ID_PARAM_NAME, t.getId()); | |
37 | - context.getFlowScope().put(FormAction.SUBJECT_DISABLED_PARAM_NAME, | |
38 | - true); | |
39 | - context.getFlowScope().put("isAnonymous", | |
40 | - WebUtils.findUser(context) == null); | |
41 | - return success(); | |
42 | - } | |
43 | -} |
@@ -270,7 +270,7 @@ | ||
270 | 270 | int threadId = context.getRequestParameters().getRequiredInteger( |
271 | 271 | threadIdParamName); |
272 | 272 | MultiThreadCommunity c = (MultiThreadCommunity) community; |
273 | - Thread t = c.findThread(threadId); | |
273 | + Thread t = c.getThread(threadId); | |
274 | 274 | if (t == null) { |
275 | 275 | String message = "The community '" + community.getCode() |
276 | 276 | + "' doesn't have the thread '" + threadId + "'."; |
@@ -309,7 +309,7 @@ | ||
309 | 309 | throw new org.unitedfront2.web.BadRequestException(e); |
310 | 310 | } |
311 | 311 | MultiThreadCommunity c = (MultiThreadCommunity) community; |
312 | - Thread t = c.findThread(threadId); | |
312 | + Thread t = c.getThread(threadId); | |
313 | 313 | if (t == null) { |
314 | 314 | String message = "The community '" + community.getCode() |
315 | 315 | + "' doesn't have the thread '" + threadId + "'."; |
@@ -399,7 +399,7 @@ | ||
399 | 399 | int threadId = context.getRequestParameters().getRequiredInteger( |
400 | 400 | threadIdParamName); |
401 | 401 | MultiThreadCommunity c = (MultiThreadCommunity) community; |
402 | - Thread t = c.findThread(threadId); | |
402 | + Thread t = c.getThread(threadId); | |
403 | 403 | if (t == null) { |
404 | 404 | String message = "The thread " + threadId |
405 | 405 | + " not found in this community '" + community.getCode() |
@@ -4,12 +4,13 @@ | ||
4 | 4 | xsi:schemaLocation="http://www.springframework.org/schema/webflow |
5 | 5 | http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> |
6 | 6 | |
7 | - <decision-state id="anonymousOrNot"> | |
8 | - <on-entry> | |
9 | - <evaluate expression="communityEntryCreateAction"/> | |
10 | - </on-entry> | |
11 | - <if test="flowScope.isAnonymous" then="captcha" else="form"/> | |
12 | - </decision-state> | |
7 | + <on-start> | |
8 | + <set name="requestScope.communityCode" value="requestParameters.communityCode"/> | |
9 | + <set name="requestScope.threadId" value="requestParameters.threadId" type="int"/> | |
10 | + <set name="requestScope.user" value="externalContext.requestMap._user"/> | |
11 | + <set name="flowScope.community" value="communityTable.findByCodeForPost(communityCode, user)"/> | |
12 | + <set name="flowScope.thread" value="community.getThread(threadId)"/> | |
13 | + </on-start> | |
13 | 14 | |
14 | 15 | <subflow-state id="captcha" subflow="captcha-sub-flow"> |
15 | 16 | <transition on="finish" to="form"/> |
@@ -16,8 +17,8 @@ | ||
16 | 17 | </subflow-state> |
17 | 18 | |
18 | 19 | <subflow-state id="form" subflow="thread.entryForm-sub-flow"> |
19 | - <input name="threadId" required="true"/> | |
20 | - <input name="subjectDisabled" required="true"/> | |
20 | + <input name="threadId" value="thread.id" required="true"/> | |
21 | + <input name="subjectDisabled" value="true"/> | |
21 | 22 | <transition on="finish" to="finish"/> |
22 | 23 | </subflow-state> |
23 | 24 |
@@ -27,6 +28,6 @@ | ||
27 | 28 | </decision-state> |
28 | 29 | |
29 | 30 | <end-state id="singleThreadFinish" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/index.html"/> |
30 | - <end-state id="multiThreadFinish" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/${flowScope.threadId}/index.html"/> | |
31 | + <end-state id="multiThreadFinish" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/${flowScope.thread.id}/index.html"/> | |
31 | 32 | |
32 | 33 | </flow> |