• R/O
  • SSH
  • HTTPS

pal: Commit


Commit MetaInfo

Revision1765 (tree)
Zeit2009-02-15 09:52:50
Autorshinsuke

Log Message

modified category handling.

Ändern Zusammenfassung

Diff

--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/service/CategoryService.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/service/CategoryService.java (revision 1765)
@@ -2,6 +2,7 @@
22
33 import java.io.Serializable;
44 import java.sql.Timestamp;
5+import java.util.ArrayList;
56 import java.util.Date;
67 import java.util.List;
78
@@ -49,7 +50,16 @@
4950 }
5051
5152 public List<BookmarkCategory> getCategoryList(CategoryPager categoryPager) {
53+ return getCategoryList(categoryPager, false);
54+ }
5255
56+ public List<BookmarkCategory> getCategoryList(CategoryPager categoryPager,
57+ boolean permission) {
58+ if (!permission && categoryPager.getCreatedBy() == null) {
59+ // no permission
60+ return new ArrayList<BookmarkCategory>();
61+ }
62+
5363 HotdeployUtil.rebuildValue(categoryPager);
5464
5565 BookmarkCategoryCB cb = new BookmarkCategoryCB();
@@ -86,6 +96,7 @@
8696
8797 cb.query().setId_Equal(id);
8898 return bookmarkCategoryBhv.selectEntity(cb);
99+ // need to check a permission of this entity.
89100 }
90101
91102 public void store(BookmarkCategory category) {
@@ -203,14 +214,16 @@
203214
204215 cb.query().setDeletedBy_IsNull();
205216 cb.query().setType_NotEqual(BookmarkConstants.PRIVATE_CATEGORY);
206- cb.unionAll(new UnionQuery<BookmarkCategoryCB>() {
207- public void query(BookmarkCategoryCB unionCB) {
208- unionCB.query().setDeletedBy_IsNull();
209- unionCB.query().setType_Equal(
210- BookmarkConstants.PRIVATE_CATEGORY);
211- unionCB.query().setCreatedBy_Equal(createdBy);
212- }
213- });
217+ if (createdBy != null) {
218+ cb.unionAll(new UnionQuery<BookmarkCategoryCB>() {
219+ public void query(BookmarkCategoryCB unionCB) {
220+ unionCB.query().setDeletedBy_IsNull();
221+ unionCB.query().setType_Equal(
222+ BookmarkConstants.PRIVATE_CATEGORY);
223+ unionCB.query().setCreatedBy_Equal(createdBy);
224+ }
225+ });
226+ }
214227 cb.query().addOrderBy_Type_Asc();
215228 cb.query().addOrderBy_SortOrder_Asc();
216229
@@ -226,14 +239,6 @@
226239
227240 cb.query().setDeletedBy_IsNull();
228241 cb.query().setCreatedBy_Equal(createdBy);
229- cb.unionAll(new UnionQuery<BookmarkCategoryCB>() {
230- public void query(BookmarkCategoryCB unionCB) {
231- unionCB.query().setDeletedBy_IsNull();
232- unionCB.query().setType_Equal(
233- BookmarkConstants.DEFAULT_CATEGORY);
234- unionCB.query().setCreatedBy_NotEqual(createdBy);
235- }
236- });
237242 cb.query().addOrderBy_Type_Asc();
238243 cb.query().addOrderBy_SortOrder_Asc();
239244
--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/service/LinkService.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/service/LinkService.java (revision 1765)
@@ -2,6 +2,7 @@
22
33 import java.io.Serializable;
44 import java.sql.Timestamp;
5+import java.util.ArrayList;
56 import java.util.Date;
67 import java.util.List;
78
@@ -9,6 +10,7 @@
910 import jp.sf.pal.bookmark.common.dxo.PagerDxo;
1011 import jp.sf.pal.bookmark.common.util.PagingResultBeanWrapper;
1112 import jp.sf.pal.bookmark.db.allcommon.cbean.PagingResultBean;
13+import jp.sf.pal.bookmark.db.allcommon.cbean.UnionQuery;
1214 import jp.sf.pal.bookmark.db.cbean.BookmarkLinkCB;
1315 import jp.sf.pal.bookmark.db.cbean.UserInfoCB;
1416 import jp.sf.pal.bookmark.db.exbhv.BookmarkLinkBhv;
@@ -51,7 +53,16 @@
5153 }
5254
5355 public List<BookmarkLink> getLinkList(LinkPager linkPager) {
56+ return getLinkList(linkPager, false);
57+ }
5458
59+ public List<BookmarkLink> getLinkList(final LinkPager linkPager,
60+ boolean permission) {
61+ if (!permission && linkPager.getCreatedBy() == null) {
62+ // no permission
63+ return new ArrayList<BookmarkLink>();
64+ }
65+
5566 HotdeployUtil.rebuildValue(linkPager);
5667
5768 BookmarkLinkCB cb = new BookmarkLinkCB();
@@ -66,20 +77,34 @@
6677
6778 if (linkPager.getCreatedBy() != null) {
6879 if (linkPager.getCategoryId() != null) {
80+ cb.query().setCategoryId_Equal(linkPager.getCategoryId());
81+
6982 BookmarkCategory bookmarkCategory = categoryService
7083 .getCategory(linkPager.getCategoryId());
71- if (BookmarkConstants.DEFAULT_CATEGORY.equals(bookmarkCategory
84+ if (BookmarkConstants.PRIVATE_CATEGORY.equals(bookmarkCategory
7285 .getType())) {
7386 cb.query().setCreatedBy_Equal(linkPager.getCreatedBy());
74- } else if (BookmarkConstants.PRIVATE_CATEGORY
87+ cb.query().queryBookmarkCategory().setCreatedBy_Equal(
88+ linkPager.getCreatedBy());
89+ } else if (BookmarkConstants.PUBLIC_CATEGORY
7590 .equals(bookmarkCategory.getType())) {
76- cb.query().setCreatedBy_Equal(linkPager.getCreatedBy());
91+ cb.query().queryBookmarkCategory().setType_Equal(
92+ BookmarkConstants.PUBLIC_CATEGORY);
7793 }
7894 } else {
95+ // All links
7996 cb.query().setCreatedBy_Equal(linkPager.getCreatedBy());
97+ cb.unionAll(new UnionQuery<BookmarkLinkCB>() {
98+ public void query(BookmarkLinkCB unionCB) {
99+ unionCB.query().setDeletedBy_IsNull();
100+ unionCB.query().queryBookmarkCategory().setType_Equal(
101+ BookmarkConstants.PUBLIC_CATEGORY);
102+ unionCB.query().setCreatedBy_NotEqual(
103+ linkPager.getCreatedBy());
104+ }
105+ });
80106 }
81- }
82- if (linkPager.getCategoryId() != null) {
107+ } else if (linkPager.getCategoryId() != null) {
83108 cb.query().setCategoryId_Equal(linkPager.getCategoryId());
84109 }
85110 cb.query().setDeletedBy_IsNull();
@@ -108,6 +133,7 @@
108133
109134 cb.query().setId_Equal(id);
110135 return bookmarkLinkBhv.selectEntity(cb);
136+ // need to check a permission of this entity.
111137 }
112138
113139 public void store(BookmarkLink link) {
--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/BookmarkConstants.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/BookmarkConstants.java (revision 1765)
@@ -18,11 +18,6 @@
1818
1919 public static final String FALSE = "F";
2020
21- // TODO remove
22- public static final Integer DEFAULT_CATEGORY_ID = Integer.valueOf(1);
23-
24- public static final String DEFAULT_CATEGORY = "D";
25-
2621 public static final String PUBLIC_CATEGORY = "P";
2722
2823 public static final String PRIVATE_CATEGORY = "R";
--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/admin/CategoryAction.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/admin/CategoryAction.java (revision 1765)
@@ -48,7 +48,7 @@
4848 protected String displayList() {
4949 // page navi
5050 categoryPager.setCreatedBy(null);
51- categoryItems = categoryService.getCategoryList(categoryPager);
51+ categoryItems = categoryService.getCategoryList(categoryPager, true);
5252 return "index.jsp";
5353 }
5454
@@ -140,12 +140,8 @@
140140 if (categoryForm.id == null) {
141141 throw new ActionMessagesException("errors.invalid.id");
142142 }
143- BookmarkCategory category = categoryService.getCategory(Integer
143+ BookmarkCategory category = getBookmarkCategory(Integer
144144 .parseInt(categoryForm.id));
145- if (category == null) {
146- throw new ActionMessagesException("errors.could_not_find_category",
147- new Object[] { categoryForm.id });
148- }
149145 try {
150146 categoryService.moveDown(category);
151147 BookmarkUtil.addMessage(request, "success.move_category_up");
@@ -164,12 +160,8 @@
164160 if (categoryForm.id == null) {
165161 throw new ActionMessagesException("errors.invalid.id");
166162 }
167- BookmarkCategory category = categoryService.getCategory(Integer
163+ BookmarkCategory category = getBookmarkCategory(Integer
168164 .parseInt(categoryForm.id));
169- if (category == null) {
170- throw new ActionMessagesException("errors.could_not_find_category",
171- new Object[] { categoryForm.id });
172- }
173165 try {
174166 categoryService.moveUp(category);
175167 BookmarkUtil.addMessage(request, "success.move_category_down");
@@ -240,12 +232,7 @@
240232 private void loadCategory() {
241233 Integer categoryId = Integer.parseInt(categoryForm.id);
242234
243- BookmarkCategory category = categoryService.getCategory(categoryId);
244- if (category == null) {
245- // throw an exception
246- throw new ActionMessagesException("errors.could_not_find_category",
247- new Object[] { categoryId });
248- }
235+ BookmarkCategory category = getBookmarkCategory(categoryId);
249236 categoryDxo.convertFromCategoryToForm(category, categoryForm);
250237
251238 }
@@ -254,7 +241,7 @@
254241 BookmarkCategory category;
255242 if (categoryForm.mode == BookmarkConstants.EDIT_MODE) {
256243 Integer categoryId = Integer.parseInt(categoryForm.id);
257- category = categoryService.getCategory(categoryId);
244+ category = getBookmarkCategory(categoryId);
258245 category.setUpdatedBy(request.getRemoteUser());
259246 } else {
260247 category = new BookmarkCategory();
@@ -268,6 +255,16 @@
268255
269256 }
270257
258+ private BookmarkCategory getBookmarkCategory(Integer id) {
259+ BookmarkCategory category = categoryService.getCategory(id);
260+ if (category == null) {
261+ throw new ActionMessagesException("errors.could_not_find_category",
262+ new Object[] { categoryForm.id });
263+ }
264+
265+ return category;
266+ }
267+
271268 /**
272269 * @return the request
273270 */
--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/admin/LinkAction.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/admin/LinkAction.java (revision 1765)
@@ -52,7 +52,7 @@
5252 // page navi
5353 linkPager.setCreatedBy(null);
5454 linkPager.setCategoryId(null);
55- linkItems = linkService.getLinkList(linkPager);
55+ linkItems = linkService.getLinkList(linkPager, true);
5656
5757 return "index.jsp";
5858 }
@@ -208,15 +208,19 @@
208208 }
209209 }
210210
211+ private BookmarkLink getBookmarkLink(Long id) {
212+ BookmarkLink link = linkService.getLink(id);
213+ if (link == null) {
214+ throw new ActionMessagesException("errors.could_not_find_link",
215+ new Object[] { linkForm.id });
216+ }
217+ return link;
218+ }
219+
211220 private void loadLink() {
212221 Long linkId = Long.parseLong(linkForm.id);
213222
214- BookmarkLink link = linkService.getLink(linkId);
215- if (link == null) {
216- // throw an exception
217- throw new ActionMessagesException("errors.could_not_find_link",
218- new Object[] { linkId });
219- }
223+ BookmarkLink link = getBookmarkLink(linkId);
220224 linkDxo.convertFromLinkToForm(link, linkForm);
221225
222226 }
@@ -225,7 +229,7 @@
225229 BookmarkLink link;
226230 if (linkForm.mode == BookmarkConstants.EDIT_MODE) {
227231 Long linkId = Long.parseLong(linkForm.id);
228- link = linkService.getLink(linkId);
232+ link = getBookmarkLink(linkId);
229233 link.setUpdatedBy(request.getRemoteUser());
230234 } else {
231235 link = new BookmarkLink();
--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/user/CategoryAction.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/user/CategoryAction.java (revision 1765)
@@ -140,12 +140,8 @@
140140 if (categoryForm.id == null) {
141141 throw new ActionMessagesException("errors.invalid.id");
142142 }
143- BookmarkCategory category = categoryService.getCategory(Integer
143+ BookmarkCategory category = getBookmarkCategory(Integer
144144 .parseInt(categoryForm.id));
145- if (category == null) {
146- throw new ActionMessagesException("errors.could_not_find_category",
147- new Object[] { categoryForm.id });
148- }
149145 try {
150146 categoryService.moveDown(category);
151147 BookmarkUtil.addMessage(request, "success.move_category_down");
@@ -164,12 +160,8 @@
164160 if (categoryForm.id == null) {
165161 throw new ActionMessagesException("errors.invalid.id");
166162 }
167- BookmarkCategory category = categoryService.getCategory(Integer
163+ BookmarkCategory category = getBookmarkCategory(Integer
168164 .parseInt(categoryForm.id));
169- if (category == null) {
170- throw new ActionMessagesException("errors.could_not_find_category",
171- new Object[] { categoryForm.id });
172- }
173165 try {
174166 categoryService.moveUp(category);
175167 BookmarkUtil.addMessage(request, "success.move_category_up");
@@ -240,12 +232,7 @@
240232 private void loadCategory() {
241233 Integer categoryId = Integer.parseInt(categoryForm.id);
242234
243- BookmarkCategory category = categoryService.getCategory(categoryId);
244- if (category == null) {
245- // throw an exception
246- throw new ActionMessagesException("errors.could_not_find_category",
247- new Object[] { categoryId });
248- }
235+ BookmarkCategory category = getBookmarkCategory(categoryId);
249236 categoryDxo.convertFromCategoryToForm(category, categoryForm);
250237
251238 }
@@ -254,7 +241,7 @@
254241 BookmarkCategory category;
255242 if (categoryForm.mode == BookmarkConstants.EDIT_MODE) {
256243 Integer categoryId = Integer.parseInt(categoryForm.id);
257- category = categoryService.getCategory(categoryId);
244+ category = getBookmarkCategory(categoryId);
258245 category.setUpdatedBy(request.getRemoteUser());
259246 } else {
260247 category = new BookmarkCategory();
@@ -268,6 +255,24 @@
268255
269256 }
270257
258+ private BookmarkCategory getBookmarkCategory(Integer id) {
259+ BookmarkCategory category = categoryService.getCategory(id);
260+ if (category == null) {
261+ throw new ActionMessagesException("errors.could_not_find_category",
262+ new Object[] { categoryForm.id });
263+ }
264+ if (!category.getCreatedBy().equals(getUserId())) {
265+ throw new ActionMessagesException(
266+ "errors.no_permission_for_bookmarkcategory",
267+ new Object[] { categoryForm.id });
268+ }
269+ return category;
270+ }
271+
272+ private String getUserId() {
273+ return request.getRemoteUser();
274+ }
275+
271276 /**
272277 * @return the request
273278 */
--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/user/LinkAction.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/action/user/LinkAction.java (revision 1765)
@@ -111,6 +111,11 @@
111111
112112 @Execute(validator = false, input = "error.jsp")
113113 public String createpage() {
114+ List<BookmarkCategory> categoryList = getEditableCategoryItems();
115+ if (categoryList == null || categoryList.isEmpty()) {
116+ throw new ActionMessagesException("errors.need_to_create_category");
117+ }
118+
114119 // page navi
115120 linkForm.initialize();
116121 linkForm.mode = BookmarkConstants.CREATE_MODE;
@@ -155,11 +160,7 @@
155160 if (linkForm.id == null) {
156161 throw new ActionMessagesException("errors.invalid.id");
157162 }
158- BookmarkLink link = linkService.getLink(Long.parseLong(linkForm.id));
159- if (link == null) {
160- throw new ActionMessagesException("errors.could_not_find_link",
161- new Object[] { linkForm.id });
162- }
163+ BookmarkLink link = getBookmarkLink(Long.parseLong(linkForm.id));
163164 try {
164165 linkService.moveDown(link);
165166 BookmarkUtil.addMessage(request, "success.move_link_down");
@@ -177,11 +178,7 @@
177178 if (linkForm.id == null) {
178179 throw new ActionMessagesException("errors.invalid.id");
179180 }
180- BookmarkLink link = linkService.getLink(Long.parseLong(linkForm.id));
181- if (link == null) {
182- throw new ActionMessagesException("errors.could_not_find_link",
183- new Object[] { linkForm.id });
184- }
181+ BookmarkLink link = getBookmarkLink(Long.parseLong(linkForm.id));
185182 try {
186183 linkService.moveUp(link);
187184 BookmarkUtil.addMessage(request, "success.move_link_up");
@@ -257,12 +254,7 @@
257254 private void loadLink() {
258255 Long linkId = Long.parseLong(linkForm.id);
259256
260- BookmarkLink link = linkService.getLink(linkId);
261- if (link == null) {
262- // throw an exception
263- throw new ActionMessagesException("errors.could_not_find_link",
264- new Object[] { linkId });
265- }
257+ BookmarkLink link = getBookmarkLink(linkId);
266258 linkDxo.convertFromLinkToForm(link, linkForm);
267259
268260 }
@@ -271,7 +263,7 @@
271263 BookmarkLink link;
272264 if (linkForm.mode == BookmarkConstants.EDIT_MODE) {
273265 Long linkId = Long.parseLong(linkForm.id);
274- link = linkService.getLink(linkId);
266+ link = getBookmarkLink(linkId);
275267 link.setUpdatedBy(request.getRemoteUser());
276268 } else {
277269 link = new BookmarkLink();
@@ -307,14 +299,9 @@
307299 public boolean isEditable() {
308300 String type = linkForm.categoryType;
309301 if (type != null) {
310- String userId = request.getRemoteUser();
311- if (BookmarkConstants.DEFAULT_CATEGORY.equals(type)) {
312- if (userId != null && userId.equals(linkForm.createdBy)) {
313- return true;
314- }
315- }
316302 String createdBy = linkForm.categoryCreatedBy;
317303 if (createdBy != null) {
304+ String userId = request.getRemoteUser();
318305 if (userId != null && userId.equals(createdBy)) {
319306 return true;
320307 }
@@ -324,6 +311,29 @@
324311 return false;
325312 }
326313
314+ private BookmarkLink getBookmarkLink(Long id) {
315+ BookmarkLink link = linkService.getLink(id);
316+ if (link == null) {
317+ throw new ActionMessagesException("errors.could_not_find_link",
318+ new Object[] { linkForm.id });
319+ }
320+ if (link.getCategoryId() == null
321+ || BookmarkConstants.PRIVATE_CATEGORY.equals(link
322+ .getBookmarkCategory().getType())) {
323+ if (!link.getCreatedBy().equals(getUserId())) {
324+ throw new ActionMessagesException(
325+ "errors.no_permission_for_bookmarklink",
326+ new Object[] { id });
327+ }
328+ return link;
329+ } else if (BookmarkConstants.PUBLIC_CATEGORY.equals(link
330+ .getBookmarkCategory().getType())) {
331+ return link;
332+ }
333+ throw new ActionMessagesException(
334+ "errors.illegal_state_for_bookmaklink", new Object[] { id });
335+ }
336+
327337 /**
328338 * @return the request
329339 */
--- bookmark/trunk/src/main/java/jp/sf/pal/bookmark/pager/LinkPager.java (revision 1764)
+++ bookmark/trunk/src/main/java/jp/sf/pal/bookmark/pager/LinkPager.java (revision 1765)
@@ -1,6 +1,5 @@
11 package jp.sf.pal.bookmark.pager;
22
3-import jp.sf.pal.bookmark.BookmarkConstants;
43 import jp.sf.pal.bookmark.common.pager.DefaultPager;
54
65 public class LinkPager extends DefaultPager {
@@ -13,7 +12,7 @@
1312
1413 public LinkPager() {
1514 createdBy = null;
16- categoryId = BookmarkConstants.DEFAULT_CATEGORY_ID;
15+ categoryId = null;
1716 }
1817
1918 protected int getDefaultPageSize() {
@@ -25,7 +24,13 @@
2524 }
2625
2726 public void setCategoryId(Integer categoryId) {
28- this.categoryId = categoryId;
27+ if (categoryId != null) {
28+ if (categoryId.intValue() > 0) {
29+ this.categoryId = categoryId;
30+ return;
31+ }
32+ }
33+ this.categoryId = null;
2934 }
3035
3136 public String getCreatedBy() {
Show on old repository browser