KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > library > right > LibraryRightsImpl


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: LibraryRightsImpl.java,v $
31  * Revision 1.4 2005/04/29 02:48:16 colinmacleod
32  * Data bugfixes.
33  * Changed primary key back to Integer.
34  *
35  * Revision 1.3 2005/04/10 20:09:45 colinmacleod
36  * Added new themes.
37  * Changed id type to String.
38  * Changed i tag to em and b tag to strong.
39  * Improved PicoContainerFactory with NanoContainer scripts.
40  *
41  * Revision 1.2 2005/04/09 17:19:46 colinmacleod
42  * Changed copyright text to GPL v2 explicitly.
43  *
44  * Revision 1.1.1.1 2005/03/10 17:51:59 colinmacleod
45  * Restructured ivata op around Hibernate/PicoContainer.
46  * Renamed ivata groupware.
47  *
48  * Revision 1.4 2004/11/12 18:16:05 colinmacleod
49  * Ordered imports.
50  *
51  * Revision 1.3 2004/11/12 15:57:16 colinmacleod
52  * Removed dependencies on SSLEXT.
53  * Moved Persistence classes to ivata masks.
54  *
55  * Revision 1.2 2004/07/18 21:57:35 colinmacleod
56  * Removed unneccesary import.
57  *
58  * Revision 1.1 2004/07/13 19:47:29 colinmacleod
59  * Moved project to POJOs from EJBs.
60  * Applied PicoContainer to services layer (replacing session EJBs).
61  * Applied Hibernate to persistence layer (replacing entity EJBs).
62  *
63  * Revision 1.2 2004/02/01 22:07:31 colinmacleod
64  * Added full names to author tags
65  *
66  * Revision 1.1.1.1 2004/01/27 20:58:40 colinmacleod
67  * Moved open portal to sourceforge.
68  *
69  * Revision 1.5 2003/11/03 11:29:44 jano
70  * commiting library,
71  * tryinjg to fix deploying problem
72  *
73  * Revision 1.4 2003/10/28 13:16:14 jano
74  * commiting library,
75  * still fixing compile and building openGroupware project
76  *
77  * Revision 1.3 2003/10/15 14:21:00 jano
78  * converting to XDoclet
79  *
80  * Revision 1.2 2003/10/15 14:16:53 colin
81  * fixing for XDoclet
82  *
83  * Revision 1.4 2003/06/02 22:18:43 colin
84  * changes for new user rights interface
85  *
86  * Revision 1.3 2003/05/12 13:47:40 colin
87  * added new methods for finding rights
88  *
89  * Revision 1.2 2003/04/09 09:02:44 jano
90  * handling data of removing user
91  *
92  * Revision 1.1 2003/02/24 19:09:22 colin
93  * moved to business
94  *
95  * Revision 1.10 2003/02/04 17:43:50 colin
96  * copyright notice
97  *
98  * Revision 1.9 2003/01/09 10:50:11 jano
99  * I need only two method for finding right for TOPIC and ITEM
100  *
101  * Revision 1.8 2003/01/08 10:40:43 jano
102  * we changed interface of libraryBeans, we are using libraryRightBean for amending rights and for finding out
103  * and we are not storing rights in TopicDO
104  *
105  * Revision 1.7 2003/01/03 17:17:11 jano
106  * fixing findr problem in canUser
107  *
108  * Revision 1.6 2003/01/02 16:39:40 jano
109  * taking VIEW of
110  *
111  * Revision 1.5 2002/12/05 16:09:38 jano
112  * fixing bug
113  *
114  * Revision 1.4 2002/11/29 13:12:36 jano
115  * if finder didn't find anytnik he didn't throe exeption so we have to check if collection is empty
116  *
117  * Revision 1.3 2002/10/09 07:39:02 jano
118  * to many imports :-)
119  *
120  * Revision 1.2 2002/08/30 09:50:19 colin
121  * changed canUser... methods to just can...
122  *
123  * Revision 1.1 2002/07/12 09:31:39 colin
124  * split library bean into library and library rights
125  * -----------------------------------------------------------------------------
126  */

127 package com.ivata.groupware.business.library.right;
128
129 import java.io.Serializable JavaDoc;
130 import java.util.Collection JavaDoc;
131 import java.util.Iterator JavaDoc;
132 import java.util.List JavaDoc;
133 import java.util.Vector JavaDoc;
134
135 import javax.mail.MethodNotSupportedException JavaDoc;
136
137 import com.ivata.groupware.admin.security.server.SecuritySession;
138 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
139 import com.ivata.groupware.business.addressbook.person.group.right.RightConstants;
140 import com.ivata.groupware.business.addressbook.person.group.right.RightDO;
141 import com.ivata.groupware.business.library.comment.CommentDO;
142 import com.ivata.groupware.business.library.topic.TopicDO;
143 import com.ivata.groupware.container.persistence.QueryPersistenceManager;
144 import com.ivata.mask.persistence.PersistenceSession;
145 import com.ivata.mask.util.SystemException;
146
147
148 /**
149  * <p>
150  * Facade to the intranet library access rights. This POJO can be
151  * used both locally and remotely to establish what users are entitled to
152  * within the library subsystem.
153  * </p>
154  *
155  * @since 2002-07-10
156  * @author Colin MacLeod
157  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
158  * @version $Revision: 1.4 $
159  */

160 public class LibraryRightsImpl implements LibraryRights, Serializable JavaDoc {
161     /**
162      * Persistence manger used to store/retrieve data objects.
163      */

164     private QueryPersistenceManager persistenceManager;
165
166     /**
167      * Construct a new library rights instance.
168      *
169      * @param persistenceManager used to store objects in db.
170      */

171     public LibraryRightsImpl(QueryPersistenceManager persistenceManager) {
172         this.persistenceManager = persistenceManager;
173     }
174
175     /**
176      * <p>
177      * This method changes ADD rights. Users in the specified groups will be
178      * able to add ITEMS with this TOPIC.
179      * </p>
180      *
181      * <p>
182      * It's works only with those groups which can be seen by the user.
183      * if I am adding ADD right for a group and the user has not VIEW right
184      * -> also create a VIEW right for that group.
185      * </p>
186      *
187      * @param id of TOPIC
188      * @param userName user vhich is goin to change rights
189      * @param rights collection of groups for which we will set up ADD right
190      */

191     public void amendAddRightsForItem(final SecuritySession securitySession,
192             final Integer JavaDoc id,
193             final Collection JavaDoc rights)
194             throws SystemException {
195         throw new SystemException(new MethodNotSupportedException JavaDoc("ERROR: LibraryRightsImpl.amendAddRightsForItem is not implemented yet!"));
196     }
197
198     /**
199      * <p>This method changing AMEND rights. Users in those groups will be able to amend ITEMS with this TOPIC.
200      * It's working only with those groups which can be see by user.
201      * if I am adding AMEND right for group and there is not VIEW right -> so create VIEW right for that group.</p>
202      *
203      * @param id of TOPIC
204      * @param userName user vhich is goin to change rights
205      * @param rights collection of groups for which we will set up AMEND right
206      */

207     public void amendAmendRightsForItem(final SecuritySession securitySession,
208             final Integer JavaDoc id,
209             final Collection JavaDoc rights)
210             throws SystemException {
211         throw new SystemException(new MethodNotSupportedException JavaDoc("ERROR: LibraryRightsImpl.amendAmendRightsForItem is not implemented yet!"));
212     }
213
214     /**
215      * <p>This method changing AMEND rights of TOPIC. It's working only with those groups which can be see by user.
216      * if I am adding AMEND right for group and there is not VIEW right -> so create VIEW right for that group.</p>
217      *
218      * @param id of TOPIC
219      * @param userName user which is chaning
220      * @param rights collection of groups for which we will set up AMEND right
221      */

222     public void amendAmendRightsForTopic(final SecuritySession securitySession,
223             final Integer JavaDoc id,
224             final Collection JavaDoc rights)
225             throws SystemException {
226         throw new SystemException(new MethodNotSupportedException JavaDoc("ERROR: LibraryRightsImpl.amendAmendRightsForTopic is not implemented yet!"));
227     }
228
229     /**
230      * <p>This method changing REMOVE rights. Users in those groups will be able to remove ITEMS with this TOPIC.
231      * It's working only with those groups which can be see by user.
232      * if I am adding REMOVE right for group and there is not VIEW right -> so create VIEW right for that group.</p>
233      *
234      * @param id of TOPIC
235      * @param userName user vhich is goin to change rights
236      * @param rights collection of groups for which we will set up REMOVE right
237      */

238     public void amendRemoveRightsForItem(final SecuritySession securitySession,
239             final Integer JavaDoc id,
240             final Collection JavaDoc rights)
241             throws SystemException {
242         throw new SystemException(new MethodNotSupportedException JavaDoc("ERROR: LibraryRightsImpl.amendRemoveRightsForItem is not implemented yet!"));
243     }
244
245     /**
246      * <p>This method changing REMOVE rights of TOPIC. It's working only with those groups which can be see by user.
247      * if I am adding REMOVE right for group and there is not VIEW right -> so create VIEW right for that group.</p>
248      *
249      * @param id of TOPIC
250      * @param userName user vhich is going to change
251      * @param rights collection of groups for which we will set up REMOVE right
252      */

253     public void amendRemoveRightsForTopic(final SecuritySession securitySession,
254             final Integer JavaDoc id,
255             final Collection JavaDoc rights)
256             throws SystemException {
257         throw new SystemException(new MethodNotSupportedException JavaDoc("ERROR: LibraryRightsImpl.amendRemoveRightsForTopic is not implemented yet!"));
258     }
259
260     /**
261      * <p>This method changing VIEW rights of ITEMS. Users in those groups will be albe to see ITEMS with this TOPIC.
262      * It's working only with those groups which can be see by user.</p>
263      *
264      * @param id of TOPIC
265      * @param userName user vhich is goin to change rights
266      * @param rights collection of groups for which we will set up VIEW right
267      */

268     public void amendViewRightsForItem(final SecuritySession securitySession,
269             final Integer JavaDoc id,
270             final Collection JavaDoc rights)
271             throws SystemException {
272         throw new SystemException(new MethodNotSupportedException JavaDoc("ERROR: LibraryRightsImpl.amendViewRightsForItem is not implemented yet!"));
273     }
274
275     /**
276      * <p>This method changing VIEW rights of TOPIC. It's working only with those groups which can be see by user.</p>
277      *
278      * @param id of TOPIC
279      * @param userName user which is changing
280      * @param rights collection of groupIds for which we will set up VIEW right
281      */

282     public void amendViewRightsForTopic(final SecuritySession securitySession,
283             final Integer JavaDoc id,
284             final Collection JavaDoc rights)
285             throws SystemException {
286         throw new SystemException(new MethodNotSupportedException JavaDoc("ERROR: LibraryRightsImpl.amendViewRightsForTopic is not implemented yet!"));
287     }
288
289     /**
290      * <p>Find out if a user is allowed to add a new comment.</p>
291      *
292      * @param userName the name of the user to check the user rights for.
293      * @param comment the comment check.
294      * @return <code>true</code> if the user is entitled to add this comment,
295      * otherwise <code>false</code>.
296      */

297     public boolean canAddComment(final SecuritySession securitySession,
298             final CommentDO comment)
299             throws SystemException {
300         // user rights for adding comments are simple: if the user can view the
301
// item this comment refers to, she can also add comments to it
302
return canViewInTopic(securitySession, comment.getItem().getTopic().getId());
303     }
304
305     /**
306      * <p>Find out if a user is allowed to add a new topic.</p>
307      *
308      * @param userName the name of the user to check the user rights for.
309      * @param topicId the unique identifier of the topic to check.
310      * @return <code>true</code> if the user is entitled to add new topics,
311      * otherwise <code>false</code>.
312      */

313     public boolean canAddTopic(final SecuritySession securitySession)
314             throws SystemException {
315         return canUser(securitySession, (Integer JavaDoc)null,
316                 RightConstants.DETAIL_LIBRARY_TOPIC,
317                 RightConstants.ACCESS_ADD);
318     }
319
320     /**
321      * <p>Find out if a user is allowed to add items to a given topic.</p>
322      *
323      * @param userName the name of the user to check the user rights for.
324      * @param topicId the unique identifier of the topic to check.
325      * @return <code>true</code> if the user is entitled to add items to the
326      * topic, otherwise <code>false</code>.
327      */

328     public boolean canAddToTopic(final SecuritySession securitySession,
329             final Integer JavaDoc topicId)
330             throws SystemException {
331         return canUser(securitySession, topicId, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC,
332                 RightConstants.ACCESS_ADD);
333     }
334
335     /**
336      * <p>Find out if a user is allowed to change an existing comment.</p>
337      *
338      * @param userName the name of the user to check the user rights for.
339      * @param commentParam the comment check.
340      * @return <code>true</code> if the user is entitled to change this comment,
341      * otherwise <code>false</code>.
342      */

343     public boolean canAmendComment(final SecuritySession securitySession,
344             final CommentDO commentParam)
345             throws SystemException {
346         // prerequisite: nobody can amend a comment with a null id
347
if (commentParam.getId() == null) {
348             return false;
349         }
350         // in order to amend a comment, the user must have sufficient rights
351
// at topic level, or be the original author of the topic
352
PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
353         CommentDO comment;
354         try {
355             // re-get the comment from the data store
356
comment = (CommentDO)
357                 persistenceManager.findByPrimaryKey(persistenceSession,
358                     CommentDO.class, commentParam.getId());
359         } catch (Exception JavaDoc e) {
360             persistenceSession.cancel();
361             throw new SystemException(e);
362         } finally {
363             persistenceSession.close();
364         }
365         // so is this the original author?
366
if (comment.getCreatedBy().equals(securitySession.getUser())) {
367             return true;
368         }
369         // if that didn't work, check the rights at topic level
370
return canUser(securitySession, comment.getItem().getTopic().getId(),
371                 RightConstants.DETAIL_LIBRARY_COMMENT_TOPIC,
372                 RightConstants.ACCESS_AMEND);
373     }
374
375     /**
376      * <p>Find out if a user is allowed to amend items in a given topic.</p>
377      *
378      * @param userName the name of the user to check the user rights for.
379      * @param topicId the unique identifier of the topic to check.
380      * @return <code>true</code> if the user is entitled to amend items in the
381      * topic, otherwise <code>false</code>.
382      */

383     public boolean canAmendInTopic(final SecuritySession securitySession,
384             final Integer JavaDoc topicId)
385             throws SystemException {
386         return canUser(securitySession, topicId, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC,
387                 RightConstants.ACCESS_AMEND);
388     }
389
390     /**
391      * <p>Find out if a user is allowed to amend an existing new topic.</p>
392      *
393      * @param userName the name of the user to check the user rights for.
394      * @param topicId the unique identifier of the topic to check.
395      * @return <code>true</code> if the user is entitled to amend the
396      * topic, otherwise <code>false</code>.
397      */

398     public boolean canAmendTopic(final SecuritySession securitySession,
399             final Integer JavaDoc id)
400             throws SystemException {
401         return canUser(securitySession, id, RightConstants.DETAIL_LIBRARY_TOPIC,
402                 RightConstants.ACCESS_AMEND);
403     }
404
405     /**
406      * <p>Find out if a user is allowed to remove an existing comment.</p>
407      *
408      * @param userName the name of the user to check the user rights for.
409      * @param commentParam the comment check.
410      * @return <code>true</code> if the user is entitled to remove this comment,
411      * otherwise <code>false</code>.
412      */

413     public boolean canRemoveComment(final SecuritySession securitySession,
414             final CommentDO commentParam)
415             throws SystemException {
416         // prerequisite: nobody can remove a comment with a null id
417
if (commentParam.getId() == null) {
418             return false;
419         }
420         // in order to remove a comment, the user must have sufficient rights
421
// at topic level, or be the original author of the topic
422
PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
423         CommentDO comment;
424         try {
425             // re-get the comment from the data store
426
comment = (CommentDO)
427                 persistenceManager.findByPrimaryKey(persistenceSession,
428                     CommentDO.class, commentParam.getId());
429         } catch (Exception JavaDoc e) {
430             persistenceSession.cancel();
431             throw new SystemException(e);
432         } finally {
433             persistenceSession.close();
434         }
435         // so is this the original author?
436
if (comment.getCreatedBy().equals(securitySession.getUser())) {
437             return true;
438         }
439         // if that didn't work, check the rights at topic level
440
return canUser(securitySession, comment.getItem().getTopic().getId(),
441                 RightConstants.DETAIL_LIBRARY_COMMENT_TOPIC,
442                 RightConstants.ACCESS_REMOVE);
443     }
444
445     /**
446      * <p>Find out if a user is allowed to remove items from a given topic.</p>
447      *
448      * @param userName the name of the user to check the user rights for.
449      * @param topicId the unique identifier of the topic to check.
450      * @return <code>true</code> if the user is entitled to remove items from
451      * the topic, otherwise <code>false</code>.
452      */

453     public boolean canRemoveFromTopic(final SecuritySession securitySession,
454             final Integer JavaDoc topicId)
455             throws SystemException {
456         return canUser(securitySession, topicId, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC,
457                 RightConstants.ACCESS_REMOVE);
458     }
459
460
461     /**
462      * <p>Find out if a user is allowed to remove a topic.</p>
463      *
464      * @param userName the name of the user to check the user rights for.
465      * @param topicId the unique identifier of the topic to check.
466      * @return <code>true</code> if the user is entitled to remove the
467      * topic, otherwise <code>false</code>.
468      */

469     public boolean canRemoveTopic(final SecuritySession securitySession,
470             final Integer JavaDoc id)
471             throws SystemException {
472         return canUser(securitySession, id, RightConstants.DETAIL_LIBRARY_TOPIC,
473                 RightConstants.ACCESS_REMOVE);
474     }
475     /**
476      * <p>Internal helper method. Find out if a user is allowed to access
477      * entries in a given group.</p>
478      *
479      * @param securitySession Security session to check the rights for.
480      * @param integerParam Unique identifier of the topic to check.
481      * @param access The access level as defined in {@link
482      * com.ivata.groupware.business.addressbook.person.group.right.RightConstants
483      * RightConstants}.
484      * @return <code>true</code> if the user is entitled to access entries in the
485      * topic, otherwise <code>false</code>.
486      */

487     public boolean canUser(final SecuritySession securitySession,
488             Integer JavaDoc integerParam,
489             final Integer JavaDoc detail,
490             final Integer JavaDoc access)
491             throws SystemException {
492 /* TODO PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
493
494         // see if we're allowed to
495         try {
496             Collection tmp = persistenceManager.find(persistenceSession,
497                 "rightByUserNameAccessDetailTargetId",
498                 new Object [] {
499                     securitySession.getUser().getName(),
500                     access,
501                     detail,
502                     topicId
503                 });
504             if (tmp.size() == 0) {
505                 return false;
506             }
507         } catch (FinderException e) {
508             // oops
509             return false;
510         }
511         // only return true if we get this far :- )
512 */

513
514         return true;
515     }
516
517     /**
518      * <p>Find out if a user is allowed to view items to a given topic.</p>
519      *
520      * @param userName the name of the user to check the user rights for.
521      * @param integerParam the unique identifier of the topic to check.
522      * @return <code>true</code> if the user is entitled to view items in the
523      * topic, otherwise <code>false</code>.
524      */

525     public boolean canViewInTopic(final SecuritySession securitySession,
526             Integer JavaDoc topicId)
527             throws SystemException {
528         return canUser(securitySession, topicId,
529                 RightConstants.DETAIL_LIBRARY_ITEM_TOPIC,
530                 RightConstants.ACCESS_VIEW);
531     }
532     /**
533      * <p>Find groups which have <code>access</code> to items with topic.
534      * Return only those groups which can be see by that user.</p>
535      *
536      * @param id of TOPIC
537      * @param userName user which is trying to find rights
538      * @param access find rights with this access
539      * @return Collection of IDS of groups which have <code>access</code> to that items wuth that topic
540      */

541     public Collection JavaDoc findRightsForItemsInTopic(final SecuritySession securitySession,
542             final Integer JavaDoc id,
543             final Integer JavaDoc access)
544             throws SystemException {
545         Vector JavaDoc rights = new Vector JavaDoc();
546         String JavaDoc userName = securitySession.getUser().getName();
547
548         PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
549         try {
550             // I will send only groupIds which user can view, no more.
551
List JavaDoc groupIdsCanViewByUser =
552                 persistenceManager.find(persistenceSession,
553                         "rightTargetIdByUserNameAccessDetail",
554                         new Object JavaDoc [] {
555                             userName, RightConstants.ACCESS_VIEW,
556                             RightConstants.DETAIL_PERSON_GROUP_MEMBER
557                         });
558             // find rights for TOPIC
559
List JavaDoc tmp =
560                 persistenceManager.find(persistenceSession,
561                         "rightByAccessDetailTargetId",
562                         new Object JavaDoc [] {
563                             access, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC, id
564                         });
565
566             for (int i = 0; i < tmp.size(); i++) {
567                 RightDO right = (RightDO) tmp.get(i);
568                 Integer JavaDoc groupId = right.getGroup().getId();
569
570                 if (groupIdsCanViewByUser.contains(groupId)) {
571                     rights.add(groupId);
572                 }
573             }
574         } catch (Exception JavaDoc e) {
575             persistenceSession.cancel();
576             throw new SystemException(e);
577         } finally {
578             persistenceSession.close();
579         }
580         return rights;
581     }
582
583     /**
584      * <p>Find groups which have <code>access</code> to topic.
585      * Return only those groups which can be see by that user.</p>
586      *
587      * @param id of TOPIC
588      * @param userName user which is trying to find rights
589      * @param access find rights with this access
590      * @return Collection of IDS of groups which have <code>access</code> to that topic
591      */

592     public Collection JavaDoc findRightsForTopic(final SecuritySession securitySession,
593             final Integer JavaDoc id,
594             final Integer JavaDoc access)
595             throws SystemException {
596         Vector JavaDoc rights = new Vector JavaDoc();
597         String JavaDoc userName = securitySession.getUser().getName();
598
599         PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
600         try {
601             // I will send only groupIds which user can view, no more.
602
List JavaDoc groupIdsCanViewByUser =
603                 persistenceManager.find(persistenceSession,
604                         "rightTargetIdByUserNameAccessDetail",
605                         new Object JavaDoc [] {
606                             userName, RightConstants.ACCESS_VIEW,
607                             RightConstants.DETAIL_LIBRARY_TOPIC
608                         });
609             // find rights for TOPIC
610
List JavaDoc tmp =
611                 persistenceManager.find(persistenceSession,
612                         "rightByAccessDetailTargetId",
613                         new Object JavaDoc [] {
614                             access, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC, id
615                         });
616
617             for (int i = 0; i < tmp.size(); i++) {
618                 RightDO right = (RightDO) tmp.get(i);
619                 Integer JavaDoc groupId = right.getGroup().getId();
620
621                 if (groupIdsCanViewByUser.contains(groupId)) {
622                     rights.add(groupId);
623                 }
624             }
625         } catch (Exception JavaDoc e) {
626             persistenceSession.cancel();
627             throw new SystemException(e);
628         } finally {
629             persistenceSession.close();
630         }
631         return rights;
632     }
633
634     /**
635      * <p>Find the unique identifiers of all library topics for which the items
636      * can be accessed by the group specified, with the access level given.</p>
637      *
638      * @param groupId unique identifier of the group for which to search for
639      * library topics.
640      * @param access the access level as defined in {@link
641      * com.ivata.groupware.business.addressbook.person.group.right.RightConstants
642      * RightConstants}.
643      * @return a <code>Collection</code> of <code>Integer</code> instances,
644      * matching all topics which can be access with this level of access
645      * by the group specified.
646      */

647     public Collection JavaDoc findTopicsByGroupAccess(final SecuritySession
648             securitySession,
649             final Integer JavaDoc groupId,
650             final Integer JavaDoc access)
651             throws SystemException {
652         Vector JavaDoc topics = new Vector JavaDoc();
653
654         PersistenceSession persistenceSession =
655                 persistenceManager.openSession(securitySession);
656         try {
657             // first find the group
658
GroupDO group = (GroupDO)
659                 persistenceManager.findByPrimaryKey(persistenceSession,
660                         GroupDO.class, groupId);
661
662             // find all the ids
663
List JavaDoc topicIds =
664                 persistenceManager.find(persistenceSession,
665                         "rightTargetIdByGroupIdAccessDetail",
666                         new Object JavaDoc [] {
667                             group, access, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC
668                         });
669             for (Iterator JavaDoc i = topicIds.iterator(); i.hasNext(); ) {
670                 String JavaDoc topicId = (String JavaDoc) i.next();
671                 TopicDO topic = (TopicDO)
672                     persistenceManager.findByPrimaryKey(persistenceSession,
673                             TopicDO.class, topicId);
674                 topics.add(topic);
675             }
676
677         } catch (Exception JavaDoc e) {
678             persistenceSession.cancel();
679             throw new SystemException(e);
680         } finally {
681             persistenceSession.close();
682         }
683
684         return topics;
685     }
686 }
687
Popular Tags