• R/O
  • SSH
  • HTTPS

unitedfront2: Commit


Commit MetaInfo

Revision1182 (tree)
Time2008-12-22 02:04:25
Authorkurokkie

Log Message

community.entryCreate-flow のコントローラロジックをリファクタリングしました。

Change Summary

Incremental Difference

--- trunk/src/main/java/org/unitedfront2/domain/communication/AbstractCommunity.java (revision 1181)
+++ trunk/src/main/java/org/unitedfront2/domain/communication/AbstractCommunity.java (revision 1182)
@@ -53,6 +53,9 @@
5353 /** 最終更新日時 */
5454 private transient Date lastUpdateDate;
5555
56+ /** スレッドリスト */
57+ private transient List<Thread> threads;
58+
5659 /** コミュニティデータアクセスオブジェクト */
5760 private transient CommunityDao communityDao;
5861
@@ -296,17 +299,34 @@
296299 return doChangeTo(clazz);
297300 }
298301
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+ }
308310 }
309311
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+
310330 /**
311331 * 削除可能であるかどうかを判定します。このメソッドが <code>true</code> を返す場合、データの整合
312332 * 性に違反することなくこのコミュニティを削除できます。
--- trunk/src/main/java/org/unitedfront2/domain/communication/MultiThreadCommunity.java (revision 1181)
+++ trunk/src/main/java/org/unitedfront2/domain/communication/MultiThreadCommunity.java (revision 1182)
@@ -29,9 +29,6 @@
2929 /** シリアル番号 */
3030 private static final long serialVersionUID = -5904029361837475679L;
3131
32- /** スレッドリスト */
33- private transient List<Thread> threads;
34-
3532 public MultiThreadCommunity() {
3633 super();
3734 }
@@ -127,12 +124,4 @@
127124 thread.store();
128125 getCommunityDao().registerThread(getId(), thread.getId());
129126 }
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- }
138127 }
--- trunk/src/main/java/org/unitedfront2/domain/communication/CommunityTable.java (revision 1181)
+++ trunk/src/main/java/org/unitedfront2/domain/communication/CommunityTable.java (revision 1182)
@@ -82,6 +82,25 @@
8282 }
8383
8484 /**
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+ /**
85104 * コードを引数として渡し、完全なコミュニティオブジェクトを取得します。
86105 *
87106 * @param code コード
@@ -130,6 +149,25 @@
130149 }
131150
132151 /**
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+ /**
133171 * コミュニティリストを記事の最終更新日時の降順で取得します。返されるコミュニティには最終更新日時が設
134172 * 定されている状態になります。
135173 *
--- trunk/src/main/java/org/unitedfront2/domain/communication/SingleThreadCommunity.java (revision 1181)
+++ trunk/src/main/java/org/unitedfront2/domain/communication/SingleThreadCommunity.java (revision 1182)
@@ -152,6 +152,7 @@
152152 return super.getLastUpdateDate();
153153 }
154154
155+ @Override
155156 public Thread getThread() {
156157 if (thread == null && getCommunityDao() != null && getId() != null) {
157158 List<Thread> threads = getCommunityDao().findThreads(getId());
--- trunk/src/main/java/org/unitedfront2/domain/communication/Community.java (revision 1181)
+++ trunk/src/main/java/org/unitedfront2/domain/communication/Community.java (revision 1182)
@@ -1,6 +1,7 @@
11 package org.unitedfront2.domain.communication;
22
33 import java.util.Date;
4+import java.util.List;
45
56 import org.unitedfront2.domain.Deletable;
67 import org.unitedfront2.domain.Identifiable;
@@ -155,6 +156,29 @@
155156 */
156157 boolean canPost(User user);
157158
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+
158182 Integer getId();
159183
160184 void setId(Integer id);
--- trunk/src/main/java/org/unitedfront2/web/controller/community/EntryCreateAction.java (revision 1181)
+++ trunk/src/main/java/org/unitedfront2/web/controller/community/EntryCreateAction.java (nonexistent)
@@ -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-}
--- trunk/src/main/java/org/unitedfront2/web/controller/community/Utils.java (revision 1181)
+++ trunk/src/main/java/org/unitedfront2/web/controller/community/Utils.java (revision 1182)
@@ -270,7 +270,7 @@
270270 int threadId = context.getRequestParameters().getRequiredInteger(
271271 threadIdParamName);
272272 MultiThreadCommunity c = (MultiThreadCommunity) community;
273- Thread t = c.findThread(threadId);
273+ Thread t = c.getThread(threadId);
274274 if (t == null) {
275275 String message = "The community '" + community.getCode()
276276 + "' doesn't have the thread '" + threadId + "'.";
@@ -309,7 +309,7 @@
309309 throw new org.unitedfront2.web.BadRequestException(e);
310310 }
311311 MultiThreadCommunity c = (MultiThreadCommunity) community;
312- Thread t = c.findThread(threadId);
312+ Thread t = c.getThread(threadId);
313313 if (t == null) {
314314 String message = "The community '" + community.getCode()
315315 + "' doesn't have the thread '" + threadId + "'.";
@@ -399,7 +399,7 @@
399399 int threadId = context.getRequestParameters().getRequiredInteger(
400400 threadIdParamName);
401401 MultiThreadCommunity c = (MultiThreadCommunity) community;
402- Thread t = c.findThread(threadId);
402+ Thread t = c.getThread(threadId);
403403 if (t == null) {
404404 String message = "The thread " + threadId
405405 + " not found in this community '" + community.getCode()
--- trunk/src/main/webapp/WEB-INF/view/community/community.entryCreate-flow.xml (revision 1181)
+++ trunk/src/main/webapp/WEB-INF/view/community/community.entryCreate-flow.xml (revision 1182)
@@ -4,12 +4,13 @@
44 xsi:schemaLocation="http://www.springframework.org/schema/webflow
55 http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
66
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>
1314
1415 <subflow-state id="captcha" subflow="captcha-sub-flow">
1516 <transition on="finish" to="form"/>
@@ -16,8 +17,8 @@
1617 </subflow-state>
1718
1819 <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"/>
2122 <transition on="finish" to="finish"/>
2223 </subflow-state>
2324
@@ -27,6 +28,6 @@
2728 </decision-state>
2829
2930 <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"/>
3132
3233 </flow>
Show on old repository browser