1 127 package com.ivata.groupware.business.library.right; 128 129 import java.io.Serializable ; 130 import java.util.Collection ; 131 import java.util.Iterator ; 132 import java.util.List ; 133 import java.util.Vector ; 134 135 import javax.mail.MethodNotSupportedException ; 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 160 public class LibraryRightsImpl implements LibraryRights, Serializable { 161 164 private QueryPersistenceManager persistenceManager; 165 166 171 public LibraryRightsImpl(QueryPersistenceManager persistenceManager) { 172 this.persistenceManager = persistenceManager; 173 } 174 175 191 public void amendAddRightsForItem(final SecuritySession securitySession, 192 final Integer id, 193 final Collection rights) 194 throws SystemException { 195 throw new SystemException(new MethodNotSupportedException ("ERROR: LibraryRightsImpl.amendAddRightsForItem is not implemented yet!")); 196 } 197 198 207 public void amendAmendRightsForItem(final SecuritySession securitySession, 208 final Integer id, 209 final Collection rights) 210 throws SystemException { 211 throw new SystemException(new MethodNotSupportedException ("ERROR: LibraryRightsImpl.amendAmendRightsForItem is not implemented yet!")); 212 } 213 214 222 public void amendAmendRightsForTopic(final SecuritySession securitySession, 223 final Integer id, 224 final Collection rights) 225 throws SystemException { 226 throw new SystemException(new MethodNotSupportedException ("ERROR: LibraryRightsImpl.amendAmendRightsForTopic is not implemented yet!")); 227 } 228 229 238 public void amendRemoveRightsForItem(final SecuritySession securitySession, 239 final Integer id, 240 final Collection rights) 241 throws SystemException { 242 throw new SystemException(new MethodNotSupportedException ("ERROR: LibraryRightsImpl.amendRemoveRightsForItem is not implemented yet!")); 243 } 244 245 253 public void amendRemoveRightsForTopic(final SecuritySession securitySession, 254 final Integer id, 255 final Collection rights) 256 throws SystemException { 257 throw new SystemException(new MethodNotSupportedException ("ERROR: LibraryRightsImpl.amendRemoveRightsForTopic is not implemented yet!")); 258 } 259 260 268 public void amendViewRightsForItem(final SecuritySession securitySession, 269 final Integer id, 270 final Collection rights) 271 throws SystemException { 272 throw new SystemException(new MethodNotSupportedException ("ERROR: LibraryRightsImpl.amendViewRightsForItem is not implemented yet!")); 273 } 274 275 282 public void amendViewRightsForTopic(final SecuritySession securitySession, 283 final Integer id, 284 final Collection rights) 285 throws SystemException { 286 throw new SystemException(new MethodNotSupportedException ("ERROR: LibraryRightsImpl.amendViewRightsForTopic is not implemented yet!")); 287 } 288 289 297 public boolean canAddComment(final SecuritySession securitySession, 298 final CommentDO comment) 299 throws SystemException { 300 return canViewInTopic(securitySession, comment.getItem().getTopic().getId()); 303 } 304 305 313 public boolean canAddTopic(final SecuritySession securitySession) 314 throws SystemException { 315 return canUser(securitySession, (Integer )null, 316 RightConstants.DETAIL_LIBRARY_TOPIC, 317 RightConstants.ACCESS_ADD); 318 } 319 320 328 public boolean canAddToTopic(final SecuritySession securitySession, 329 final Integer topicId) 330 throws SystemException { 331 return canUser(securitySession, topicId, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC, 332 RightConstants.ACCESS_ADD); 333 } 334 335 343 public boolean canAmendComment(final SecuritySession securitySession, 344 final CommentDO commentParam) 345 throws SystemException { 346 if (commentParam.getId() == null) { 348 return false; 349 } 350 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 353 CommentDO comment; 354 try { 355 comment = (CommentDO) 357 persistenceManager.findByPrimaryKey(persistenceSession, 358 CommentDO.class, commentParam.getId()); 359 } catch (Exception e) { 360 persistenceSession.cancel(); 361 throw new SystemException(e); 362 } finally { 363 persistenceSession.close(); 364 } 365 if (comment.getCreatedBy().equals(securitySession.getUser())) { 367 return true; 368 } 369 return canUser(securitySession, comment.getItem().getTopic().getId(), 371 RightConstants.DETAIL_LIBRARY_COMMENT_TOPIC, 372 RightConstants.ACCESS_AMEND); 373 } 374 375 383 public boolean canAmendInTopic(final SecuritySession securitySession, 384 final Integer topicId) 385 throws SystemException { 386 return canUser(securitySession, topicId, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC, 387 RightConstants.ACCESS_AMEND); 388 } 389 390 398 public boolean canAmendTopic(final SecuritySession securitySession, 399 final Integer id) 400 throws SystemException { 401 return canUser(securitySession, id, RightConstants.DETAIL_LIBRARY_TOPIC, 402 RightConstants.ACCESS_AMEND); 403 } 404 405 413 public boolean canRemoveComment(final SecuritySession securitySession, 414 final CommentDO commentParam) 415 throws SystemException { 416 if (commentParam.getId() == null) { 418 return false; 419 } 420 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 423 CommentDO comment; 424 try { 425 comment = (CommentDO) 427 persistenceManager.findByPrimaryKey(persistenceSession, 428 CommentDO.class, commentParam.getId()); 429 } catch (Exception e) { 430 persistenceSession.cancel(); 431 throw new SystemException(e); 432 } finally { 433 persistenceSession.close(); 434 } 435 if (comment.getCreatedBy().equals(securitySession.getUser())) { 437 return true; 438 } 439 return canUser(securitySession, comment.getItem().getTopic().getId(), 441 RightConstants.DETAIL_LIBRARY_COMMENT_TOPIC, 442 RightConstants.ACCESS_REMOVE); 443 } 444 445 453 public boolean canRemoveFromTopic(final SecuritySession securitySession, 454 final Integer topicId) 455 throws SystemException { 456 return canUser(securitySession, topicId, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC, 457 RightConstants.ACCESS_REMOVE); 458 } 459 460 461 469 public boolean canRemoveTopic(final SecuritySession securitySession, 470 final Integer id) 471 throws SystemException { 472 return canUser(securitySession, id, RightConstants.DETAIL_LIBRARY_TOPIC, 473 RightConstants.ACCESS_REMOVE); 474 } 475 487 public boolean canUser(final SecuritySession securitySession, 488 Integer integerParam, 489 final Integer detail, 490 final Integer access) 491 throws SystemException { 492 513 514 return true; 515 } 516 517 525 public boolean canViewInTopic(final SecuritySession securitySession, 526 Integer topicId) 527 throws SystemException { 528 return canUser(securitySession, topicId, 529 RightConstants.DETAIL_LIBRARY_ITEM_TOPIC, 530 RightConstants.ACCESS_VIEW); 531 } 532 541 public Collection findRightsForItemsInTopic(final SecuritySession securitySession, 542 final Integer id, 543 final Integer access) 544 throws SystemException { 545 Vector rights = new Vector (); 546 String userName = securitySession.getUser().getName(); 547 548 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 549 try { 550 List groupIdsCanViewByUser = 552 persistenceManager.find(persistenceSession, 553 "rightTargetIdByUserNameAccessDetail", 554 new Object [] { 555 userName, RightConstants.ACCESS_VIEW, 556 RightConstants.DETAIL_PERSON_GROUP_MEMBER 557 }); 558 List tmp = 560 persistenceManager.find(persistenceSession, 561 "rightByAccessDetailTargetId", 562 new Object [] { 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 groupId = right.getGroup().getId(); 569 570 if (groupIdsCanViewByUser.contains(groupId)) { 571 rights.add(groupId); 572 } 573 } 574 } catch (Exception e) { 575 persistenceSession.cancel(); 576 throw new SystemException(e); 577 } finally { 578 persistenceSession.close(); 579 } 580 return rights; 581 } 582 583 592 public Collection findRightsForTopic(final SecuritySession securitySession, 593 final Integer id, 594 final Integer access) 595 throws SystemException { 596 Vector rights = new Vector (); 597 String userName = securitySession.getUser().getName(); 598 599 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 600 try { 601 List groupIdsCanViewByUser = 603 persistenceManager.find(persistenceSession, 604 "rightTargetIdByUserNameAccessDetail", 605 new Object [] { 606 userName, RightConstants.ACCESS_VIEW, 607 RightConstants.DETAIL_LIBRARY_TOPIC 608 }); 609 List tmp = 611 persistenceManager.find(persistenceSession, 612 "rightByAccessDetailTargetId", 613 new Object [] { 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 groupId = right.getGroup().getId(); 620 621 if (groupIdsCanViewByUser.contains(groupId)) { 622 rights.add(groupId); 623 } 624 } 625 } catch (Exception e) { 626 persistenceSession.cancel(); 627 throw new SystemException(e); 628 } finally { 629 persistenceSession.close(); 630 } 631 return rights; 632 } 633 634 647 public Collection findTopicsByGroupAccess(final SecuritySession 648 securitySession, 649 final Integer groupId, 650 final Integer access) 651 throws SystemException { 652 Vector topics = new Vector (); 653 654 PersistenceSession persistenceSession = 655 persistenceManager.openSession(securitySession); 656 try { 657 GroupDO group = (GroupDO) 659 persistenceManager.findByPrimaryKey(persistenceSession, 660 GroupDO.class, groupId); 661 662 List topicIds = 664 persistenceManager.find(persistenceSession, 665 "rightTargetIdByGroupIdAccessDetail", 666 new Object [] { 667 group, access, RightConstants.DETAIL_LIBRARY_ITEM_TOPIC 668 }); 669 for (Iterator i = topicIds.iterator(); i.hasNext(); ) { 670 String topicId = (String ) i.next(); 671 TopicDO topic = (TopicDO) 672 persistenceManager.findByPrimaryKey(persistenceSession, 673 TopicDO.class, topicId); 674 topics.add(topic); 675 } 676 677 } catch (Exception e) { 678 persistenceSession.cancel(); 679 throw new SystemException(e); 680 } finally { 681 persistenceSession.close(); 682 } 683 684 return topics; 685 } 686 } 687 | Popular Tags |