• R/O
  • SSH
  • HTTPS

pal: Commit


Commit MetaInfo

Revision1768 (tree)
Zeit2009-02-15 16:55:16
Autorshinsuke

Log Message

fixed category handling.

Ändern Zusammenfassung

Diff

--- notepad/trunk/src/main/java/jp/sf/pal/notepad/service/NotepadService.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/service/NotepadService.java (revision 1768)
@@ -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.notepad.common.dxo.PagerDxo;
1011 import jp.sf.pal.notepad.common.util.PagingResultBeanWrapper;
1112 import jp.sf.pal.notepad.db.allcommon.cbean.PagingResultBean;
13+import jp.sf.pal.notepad.db.allcommon.cbean.UnionQuery;
1214 import jp.sf.pal.notepad.db.cbean.NotepadCB;
1315 import jp.sf.pal.notepad.db.cbean.UserInfoCB;
1416 import jp.sf.pal.notepad.db.exbhv.NotepadBhv;
@@ -53,8 +55,17 @@
5355 }
5456 }
5557
56- public List<Notepad> getNotepadList(NotepadPager notepadPager) {
58+ public List<Notepad> getNotepadList(final NotepadPager notepadPager) {
59+ return getNotepadList(notepadPager, false);
60+ }
5761
62+ public List<Notepad> getNotepadList(final NotepadPager notepadPager,
63+ boolean permission) {
64+ if (!permission && notepadPager.getCreatedBy() == null) {
65+ // no permission
66+ return new ArrayList<Notepad>();
67+ }
68+
5869 HotdeployUtil.rebuildValue(notepadPager);
5970
6071 NotepadCB cb = new NotepadCB();
@@ -69,24 +80,46 @@
6980
7081 if (notepadPager.getCreatedBy() != null) {
7182 if (notepadPager.getCategoryId() != null) {
83+ cb.query().setCategoryId_Equal(notepadPager.getCategoryId());
84+
7285 NotepadCategory notepadCategory = categoryService
7386 .getCategory(notepadPager.getCategoryId());
74- if (NotepadConstants.DEFAULT_CATEGORY.equals(notepadCategory
87+ if (NotepadConstants.PRIVATE_CATEGORY.equals(notepadCategory
7588 .getType())) {
7689 cb.query().setCreatedBy_Equal(notepadPager.getCreatedBy());
77- } else if (NotepadConstants.PRIVATE_CATEGORY
90+ cb.query().queryNotepadCategory().setCreatedBy_Equal(
91+ notepadPager.getCreatedBy());
92+ } else if (NotepadConstants.PUBLIC_CATEGORY
7893 .equals(notepadCategory.getType())) {
79- cb.query().setCreatedBy_Equal(notepadPager.getCreatedBy());
94+ cb.query().queryNotepadCategory().setType_Equal(
95+ NotepadConstants.PUBLIC_CATEGORY);
96+ } else if (NotepadConstants.SHARED_CATEGORY
97+ .equals(notepadCategory.getType())) {
98+ cb.query().queryNotepadCategory().setType_Equal(
99+ NotepadConstants.SHARED_CATEGORY);
80100 }
81101 } else {
102+ // All
82103 cb.query().setCreatedBy_Equal(notepadPager.getCreatedBy());
104+ cb.unionAll(new UnionQuery<NotepadCB>() {
105+ public void query(NotepadCB unionCB) {
106+ unionCB.query().setDeletedBy_IsNull();
107+ List<String> typeList = new ArrayList<String>();
108+ typeList.add(NotepadConstants.PUBLIC_CATEGORY);
109+ typeList.add(NotepadConstants.SHARED_CATEGORY);
110+ unionCB.query().queryNotepadCategory().setType_InScope(
111+ typeList);
112+ unionCB.query().setCreatedBy_NotEqual(
113+ notepadPager.getCreatedBy());
114+ }
115+ });
83116 }
84- }
85- if (notepadPager.getCategoryId() != null) {
117+ } else if (notepadPager.getCategoryId() != null) {
86118 cb.query().setCategoryId_Equal(notepadPager.getCategoryId());
87119 }
88120 cb.query().setDeletedBy_IsNull();
89121
122+ cb.query().addOrderBy_CategoryId_Asc();
90123 cb.query().addOrderBy_SortOrder_Asc();
91124
92125 PagingResultBean<Notepad> messageList = notepadBhv.selectPage(cb);
@@ -111,6 +144,7 @@
111144
112145 cb.query().setId_Equal(id);
113146 return notepadBhv.selectEntity(cb);
147+ // need to check a permission of this entity.
114148 }
115149
116150 public void store(Notepad notepad) {
@@ -177,10 +211,6 @@
177211 cb.query().setSortOrder_GreaterEqual(notepad.getSortOrder());
178212 cb.query().addOrderBy_SortOrder_Asc();
179213 cb.query().setCategoryId_Equal(notepad.getCategoryId());
180- if (NotepadConstants.DEFAULT_CATEGORY.equals(notepad
181- .getNotepadCategory().getType())) {
182- cb.query().setCreatedBy_Equal(notepad.getCreatedBy());
183- }
184214 List<Notepad> notepadList = notepadBhv.selectPage(cb);
185215 if (notepadList != null && !notepadList.isEmpty()) {
186216 Notepad targetNotepad = notepadList.get(0);
@@ -210,10 +240,6 @@
210240 cb.query().setSortOrder_LessEqual(notepad.getSortOrder());
211241 cb.query().addOrderBy_SortOrder_Desc();
212242 cb.query().setCategoryId_Equal(notepad.getCategoryId());
213- if (NotepadConstants.DEFAULT_CATEGORY.equals(notepad
214- .getNotepadCategory().getType())) {
215- cb.query().setCreatedBy_Equal(notepad.getCreatedBy());
216- }
217243 List<Notepad> notepadList = notepadBhv.selectPage(cb);
218244 if (notepadList != null && !notepadList.isEmpty()) {
219245 Notepad targetNotepad = notepadList.get(0);
--- notepad/trunk/src/main/java/jp/sf/pal/notepad/service/CategoryService.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/service/CategoryService.java (revision 1768)
@@ -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<NotepadCategory> getCategoryList(CategoryPager categoryPager) {
53+ return getCategoryList(categoryPager, false);
54+ }
5255
56+ public List<NotepadCategory> getCategoryList(CategoryPager categoryPager,
57+ boolean permission) {
58+ if (!permission && categoryPager.getCreatedBy() == null) {
59+ // no permission
60+ return new ArrayList<NotepadCategory>();
61+ }
62+
5363 HotdeployUtil.rebuildValue(categoryPager);
5464
5565 NotepadCategoryCB cb = new NotepadCategoryCB();
@@ -86,6 +96,7 @@
8696
8797 cb.query().setId_Equal(id);
8898 return notepadCategoryBhv.selectEntity(cb);
99+ // need to check a permission of this entity.
89100 }
90101
91102 public void store(NotepadCategory category) {
@@ -227,8 +238,10 @@
227238 cb.unionAll(new UnionQuery<NotepadCategoryCB>() {
228239 public void query(NotepadCategoryCB unionCB) {
229240 unionCB.query().setDeletedBy_IsNull();
230- unionCB.query()
231- .setType_Equal(NotepadConstants.PRIVATE_CATEGORY);
241+ List<String> typeList = new ArrayList<String>();
242+ typeList.add(NotepadConstants.PRIVATE_CATEGORY);
243+ typeList.add(NotepadConstants.PUBLIC_CATEGORY);
244+ unionCB.query().setType_InScope(typeList);
232245 unionCB.query().setCreatedBy_Equal(createdBy);
233246 }
234247 });
--- notepad/trunk/src/main/java/jp/sf/pal/notepad/NotepadConstants.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/NotepadConstants.java (revision 1768)
@@ -18,10 +18,6 @@
1818
1919 public static final String FALSE = "F";
2020
21- public static final Integer DEFAULT_CATEGORY_ID = Integer.valueOf(1);
22-
23- public static final String DEFAULT_CATEGORY = "D";
24-
2521 public static final String PUBLIC_CATEGORY = "P";
2622
2723 public static final String PRIVATE_CATEGORY = "R";
--- notepad/trunk/src/main/java/jp/sf/pal/notepad/action/admin/NotepadAction.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/action/admin/NotepadAction.java (revision 1768)
@@ -52,7 +52,7 @@
5252 // page navi
5353 notepadPager.setCreatedBy(null);
5454 notepadPager.setCategoryId(null);
55- notepadItems = notepadService.getNotepadList(notepadPager);
55+ notepadItems = notepadService.getNotepadList(notepadPager, true);
5656
5757 return "index.jsp";
5858 }
@@ -211,12 +211,7 @@
211211 private void loadLink() {
212212 Long linkId = Long.parseLong(notepadForm.id);
213213
214- Notepad link = notepadService.getNotepad(linkId);
215- if (link == null) {
216- // throw an exception
217- throw new ActionMessagesException("errors.could_not_find_notepad",
218- new Object[] { linkId });
219- }
214+ Notepad link = getNotepad(linkId);
220215 notepadDxo.convertFromNotepadToForm(link, notepadForm);
221216
222217 }
@@ -225,7 +220,7 @@
225220 Notepad link;
226221 if (notepadForm.mode == NotepadConstants.EDIT_MODE) {
227222 Long linkId = Long.parseLong(notepadForm.id);
228- link = notepadService.getNotepad(linkId);
223+ link = getNotepad(linkId);
229224 link.setUpdatedBy(request.getRemoteUser());
230225 } else {
231226 link = new Notepad();
@@ -238,6 +233,16 @@
238233 return link;
239234 }
240235
236+ private Notepad getNotepad(Long id) {
237+ Notepad notepad = notepadService.getNotepad(id);
238+ if (notepad == null) {
239+ // throw an exception
240+ throw new ActionMessagesException("errors.could_not_find_notepad",
241+ new Object[] { id });
242+ }
243+ return notepad;
244+ }
245+
241246 private void loadListPageParameters() {
242247 }
243248
--- notepad/trunk/src/main/java/jp/sf/pal/notepad/action/admin/CategoryAction.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/action/admin/CategoryAction.java (revision 1768)
@@ -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- NotepadCategory category = categoryService.getCategory(Integer
143+ NotepadCategory category = getNotepadCategory(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 NotepadUtil.addMessage(request, "success.move_category_up");
@@ -164,12 +160,8 @@
164160 if (categoryForm.id == null) {
165161 throw new ActionMessagesException("errors.invalid.id");
166162 }
167- NotepadCategory category = categoryService.getCategory(Integer
163+ NotepadCategory category = getNotepadCategory(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 NotepadUtil.addMessage(request, "success.move_category_down");
@@ -240,12 +232,7 @@
240232 private void loadCategory() {
241233 Integer categoryId = Integer.parseInt(categoryForm.id);
242234
243- NotepadCategory 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+ NotepadCategory category = getNotepadCategory(categoryId);
249236 categoryDxo.convertFromCategoryToForm(category, categoryForm);
250237
251238 }
@@ -254,7 +241,7 @@
254241 NotepadCategory category;
255242 if (categoryForm.mode == NotepadConstants.EDIT_MODE) {
256243 Integer categoryId = Integer.parseInt(categoryForm.id);
257- category = categoryService.getCategory(categoryId);
244+ category = getNotepadCategory(categoryId);
258245 category.setUpdatedBy(request.getRemoteUser());
259246 } else {
260247 category = new NotepadCategory();
@@ -268,6 +255,15 @@
268255
269256 }
270257
258+ private NotepadCategory getNotepadCategory(Integer id) {
259+ NotepadCategory category = categoryService.getCategory(id);
260+ if (category == null) {
261+ throw new ActionMessagesException("errors.could_not_find_category",
262+ new Object[] { id });
263+ }
264+ return category;
265+ }
266+
271267 /**
272268 * @return the request
273269 */
--- notepad/trunk/src/main/java/jp/sf/pal/notepad/action/user/NotepadAction.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/action/user/NotepadAction.java (revision 1768)
@@ -111,6 +111,11 @@
111111
112112 @Execute(validator = false, input = "error.jsp")
113113 public String createpage() {
114+ List<NotepadCategory> categoryList = getEditableCategoryItems();
115+ if (categoryList == null || categoryList.isEmpty()) {
116+ throw new ActionMessagesException("errors.need_to_create_category");
117+ }
118+
114119 // page navi
115120 notepadForm.initialize();
116121 notepadForm.mode = NotepadConstants.CREATE_MODE;
@@ -155,12 +160,7 @@
155160 if (notepadForm.id == null) {
156161 throw new ActionMessagesException("errors.invalid.id");
157162 }
158- Notepad notepad = notepadService.getNotepad(Long
159- .parseLong(notepadForm.id));
160- if (notepad == null) {
161- throw new ActionMessagesException("errors.could_not_find_notepad",
162- new Object[] { notepadForm.id });
163- }
163+ Notepad notepad = getNotepad(Long.parseLong(notepadForm.id));
164164 try {
165165 notepadService.moveDown(notepad);
166166 NotepadUtil.addMessage(request, "success.move_notepad_down");
@@ -178,12 +178,7 @@
178178 if (notepadForm.id == null) {
179179 throw new ActionMessagesException("errors.invalid.id");
180180 }
181- Notepad notepad = notepadService.getNotepad(Long
182- .parseLong(notepadForm.id));
183- if (notepad == null) {
184- throw new ActionMessagesException("errors.could_not_find_notepad",
185- new Object[] { notepadForm.id });
186- }
181+ Notepad notepad = getNotepad(Long.parseLong(notepadForm.id));
187182 try {
188183 notepadService.moveUp(notepad);
189184 NotepadUtil.addMessage(request, "success.move_notepad_up");
@@ -259,12 +254,7 @@
259254 private void loadNotepad() {
260255 Long notepadId = Long.parseLong(notepadForm.id);
261256
262- Notepad notepad = notepadService.getNotepad(notepadId);
263- if (notepad == null) {
264- // throw an exception
265- throw new ActionMessagesException("errors.could_not_find_notepad",
266- new Object[] { notepadId });
267- }
257+ Notepad notepad = getNotepad(notepadId);
268258 notepadDxo.convertFromNotepadToForm(notepad, notepadForm);
269259
270260 }
@@ -273,7 +263,7 @@
273263 Notepad notepad;
274264 if (notepadForm.mode == NotepadConstants.EDIT_MODE) {
275265 Long notepadId = Long.parseLong(notepadForm.id);
276- notepad = notepadService.getNotepad(notepadId);
266+ notepad = getNotepad(notepadId);
277267 notepad.setUpdatedBy(request.getRemoteUser());
278268 } else {
279269 notepad = new Notepad();
@@ -306,8 +296,7 @@
306296 String type = notepadForm.type;
307297 if (type != null) {
308298 if (NotepadConstants.PRIVATE_CATEGORY.equals(type)
309- || NotepadConstants.PUBLIC_CATEGORY.equals(type)
310- || NotepadConstants.DEFAULT_CATEGORY.equals(type)) {
299+ || NotepadConstants.PUBLIC_CATEGORY.equals(type)) {
311300 String userId = request.getRemoteUser();
312301 if (userId != null && userId.equals(notepadForm.createdBy)) {
313302 return true;
@@ -319,6 +308,31 @@
319308 return false;
320309 }
321310
311+ private Notepad getNotepad(Long id) {
312+ Notepad notepad = notepadService.getNotepad(id);
313+ if (notepad == null) {
314+ // throw an exception
315+ throw new ActionMessagesException("errors.could_not_find_notepad",
316+ new Object[] { id });
317+ }
318+ if (notepad.getCategoryId() == null
319+ || NotepadConstants.PRIVATE_CATEGORY.equals(notepad
320+ .getNotepadCategory().getType())) {
321+ if (!notepad.getCreatedBy().equals(getUserId())) {
322+ throw new ActionMessagesException(
323+ "errors.no_permission_for_notepad", new Object[] { id });
324+ }
325+ return notepad;
326+ } else if (NotepadConstants.PUBLIC_CATEGORY.equals(notepad
327+ .getNotepadCategory().getType())
328+ || NotepadConstants.SHARED_CATEGORY.equals(notepad
329+ .getNotepadCategory().getType())) {
330+ return notepad;
331+ }
332+ throw new ActionMessagesException("errors.illegal_state_for_notepad",
333+ new Object[] { id });
334+ }
335+
322336 public String getUserId() {
323337 return request.getRemoteUser();
324338 }
--- notepad/trunk/src/main/java/jp/sf/pal/notepad/action/user/CategoryAction.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/action/user/CategoryAction.java (revision 1768)
@@ -140,12 +140,8 @@
140140 if (categoryForm.id == null) {
141141 throw new ActionMessagesException("errors.invalid.id");
142142 }
143- NotepadCategory category = categoryService.getCategory(Integer
143+ NotepadCategory category = getNotepadCategory(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 NotepadUtil.addMessage(request, "success.move_category_down");
@@ -164,12 +160,8 @@
164160 if (categoryForm.id == null) {
165161 throw new ActionMessagesException("errors.invalid.id");
166162 }
167- NotepadCategory category = categoryService.getCategory(Integer
163+ NotepadCategory category = getNotepadCategory(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 NotepadUtil.addMessage(request, "success.move_category_up");
@@ -240,12 +232,7 @@
240232 private void loadCategory() {
241233 Integer categoryId = Integer.parseInt(categoryForm.id);
242234
243- NotepadCategory 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+ NotepadCategory category = getNotepadCategory(categoryId);
249236 categoryDxo.convertFromCategoryToForm(category, categoryForm);
250237
251238 }
@@ -254,7 +241,7 @@
254241 NotepadCategory category;
255242 if (categoryForm.mode == NotepadConstants.EDIT_MODE) {
256243 Integer categoryId = Integer.parseInt(categoryForm.id);
257- category = categoryService.getCategory(categoryId);
244+ category = getNotepadCategory(categoryId);
258245 category.setUpdatedBy(request.getRemoteUser());
259246 } else {
260247 category = new NotepadCategory();
@@ -268,6 +255,24 @@
268255
269256 }
270257
258+ private NotepadCategory getNotepadCategory(Integer id) {
259+ NotepadCategory category = categoryService.getCategory(id);
260+ if (category == null) {
261+ throw new ActionMessagesException("errors.could_not_find_category",
262+ new Object[] { id });
263+ }
264+ if (!category.getCreatedBy().equals(getUserId())) {
265+ throw new ActionMessagesException(
266+ "errors.no_permission_for_notepadcategory",
267+ new Object[] { id });
268+ }
269+ return category;
270+ }
271+
272+ private String getUserId() {
273+ return request.getRemoteUser();
274+ }
275+
271276 /**
272277 * @return the request
273278 */
--- notepad/trunk/src/main/java/jp/sf/pal/notepad/pager/NotepadPager.java (revision 1767)
+++ notepad/trunk/src/main/java/jp/sf/pal/notepad/pager/NotepadPager.java (revision 1768)
@@ -1,6 +1,5 @@
11 package jp.sf.pal.notepad.pager;
22
3-import jp.sf.pal.notepad.NotepadConstants;
43 import jp.sf.pal.notepad.common.pager.DefaultPager;
54
65 public class NotepadPager extends DefaultPager {
@@ -13,7 +12,7 @@
1312
1413 public NotepadPager() {
1514 createdBy = null;
16- categoryId = NotepadConstants.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