001 /** 002 * Copyright (c) 2000-present Liferay, Inc. All rights reserved. 003 * 004 * This library is free software; you can redistribute it and/or modify it under 005 * the terms of the GNU Lesser General Public License as published by the Free 006 * Software Foundation; either version 2.1 of the License, or (at your option) 007 * any later version. 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 */ 014 015 package com.liferay.portlet.social.service.impl; 016 017 import com.liferay.portal.kernel.dao.orm.QueryUtil; 018 import com.liferay.portal.kernel.exception.PortalException; 019 import com.liferay.portal.kernel.util.StringPool; 020 import com.liferay.portal.security.auth.PrincipalException; 021 import com.liferay.portal.security.permission.ActionKeys; 022 import com.liferay.portal.security.permission.PermissionChecker; 023 import com.liferay.portal.service.ServiceContext; 024 import com.liferay.portal.util.PropsValues; 025 import com.liferay.portlet.social.model.SocialActivity; 026 import com.liferay.portlet.social.model.SocialActivityInterpreter; 027 import com.liferay.portlet.social.model.impl.SocialActivityInterpreterImpl; 028 import com.liferay.portlet.social.service.base.SocialActivityServiceBaseImpl; 029 030 import java.util.ArrayList; 031 import java.util.List; 032 033 /** 034 * Provides the remote service for accessing social activities. Its methods 035 * include permission checks. 036 * 037 * @author Zsolt Berentey 038 */ 039 public class SocialActivityServiceImpl extends SocialActivityServiceBaseImpl { 040 041 /** 042 * Returns a range of all the activities done on assets identified by the 043 * class name ID. 044 * 045 * <p> 046 * Useful when paginating results. Returns a maximum of <code>end - 047 * start</code> instances. <code>start</code> and <code>end</code> are not 048 * primary keys, they are indexes in the result set. Thus, <code>0</code> 049 * refers to the first result in the set. Setting both <code>start</code> 050 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 051 * result set. 052 * </p> 053 * 054 * @param classNameId the target asset's class name ID 055 * @param start the lower bound of the range of results 056 * @param end the upper bound of the range of results (not inclusive) 057 * @return the range of matching activities 058 * @throws PortalException if a permission checker was not initialized 059 */ 060 @Override 061 public List<SocialActivity> getActivities( 062 long classNameId, int start, int end) 063 throws PortalException { 064 065 List<SocialActivity> activities = 066 socialActivityLocalService.getActivities( 067 classNameId, 0, 068 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 069 070 return filterActivities(activities, start, end); 071 } 072 073 /** 074 * Returns a range of all the activities done on the asset identified by the 075 * class name ID and class primary key that are mirrors of the activity 076 * identified by the mirror activity ID. 077 * 078 * <p> 079 * Useful when paginating results. Returns a maximum of <code>end - 080 * start</code> instances. <code>start</code> and <code>end</code> are not 081 * primary keys, they are indexes in the result set. Thus, <code>0</code> 082 * refers to the first result in the set. Setting both <code>start</code> 083 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 084 * result set. 085 * </p> 086 * 087 * @param mirrorActivityId the primary key of the mirror activity 088 * @param classNameId the target asset's class name ID 089 * @param classPK the primary key of the target asset 090 * @param start the lower bound of the range of results 091 * @param end the upper bound of the range of results (not inclusive) 092 * @return the range of matching activities 093 * @throws PortalException if a permission checker was not initialized 094 */ 095 @Override 096 public List<SocialActivity> getActivities( 097 long mirrorActivityId, long classNameId, long classPK, int start, 098 int end) 099 throws PortalException { 100 101 List<SocialActivity> activities = 102 socialActivityLocalService.getActivities( 103 mirrorActivityId, classNameId, classPK, 0, 104 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 105 106 return filterActivities(activities, start, end); 107 } 108 109 /** 110 * Returns a range of all the activities done on the asset identified by the 111 * class name and the class primary key that are mirrors of the activity 112 * identified by the mirror activity ID. 113 * 114 * <p> 115 * Useful when paginating results. Returns a maximum of <code>end - 116 * start</code> instances. <code>start</code> and <code>end</code> are not 117 * primary keys, they are indexes in the result set. Thus, <code>0</code> 118 * refers to the first result in the set. Setting both <code>start</code> 119 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 120 * result set. 121 * </p> 122 * 123 * @param mirrorActivityId the primary key of the mirror activity 124 * @param className the target asset's class name 125 * @param classPK the primary key of the target asset 126 * @param start the lower bound of the range of results 127 * @param end the upper bound of the range of results (not inclusive) 128 * @return the range of matching activities 129 * @throws PortalException if a permission checker was not initialized 130 */ 131 @Override 132 public List<SocialActivity> getActivities( 133 long mirrorActivityId, String className, long classPK, int start, 134 int end) 135 throws PortalException { 136 137 long classNameId = classNameLocalService.getClassNameId(className); 138 139 List<SocialActivity> activities = 140 socialActivityLocalService.getActivities( 141 mirrorActivityId, classNameId, classPK, 0, 142 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 143 144 return filterActivities(activities, start, end); 145 } 146 147 /** 148 * Returns a range of all the activities done on assets identified by the 149 * class name. 150 * 151 * <p> 152 * Useful when paginating results. Returns a maximum of <code>end - 153 * start</code> instances. <code>start</code> and <code>end</code> are not 154 * primary keys, they are indexes in the result set. Thus, <code>0</code> 155 * refers to the first result in the set. Setting both <code>start</code> 156 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 157 * result set. 158 * </p> 159 * 160 * @param className the target asset's class name 161 * @param start the lower bound of the range of results 162 * @param end the upper bound of the range of results (not inclusive) 163 * @return the range of matching activities 164 * @throws PortalException if a permission checker was not initialized 165 */ 166 @Override 167 public List<SocialActivity> getActivities( 168 String className, int start, int end) 169 throws PortalException { 170 171 long classNameId = classNameLocalService.getClassNameId(className); 172 173 List<SocialActivity> activities = 174 socialActivityLocalService.getActivities( 175 classNameId, 0, 176 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 177 178 return filterActivities(activities, start, end); 179 } 180 181 /** 182 * Returns the number of activities done on assets identified by the class 183 * name ID. 184 * 185 * @param classNameId the target asset's class name ID 186 * @return the number of matching activities 187 */ 188 @Override 189 public int getActivitiesCount(long classNameId) { 190 return socialActivityLocalService.getActivitiesCount(classNameId); 191 } 192 193 /** 194 * Returns the number of activities done on the asset identified by the 195 * class name ID and class primary key that are mirrors of the activity 196 * identified by the mirror activity ID. 197 * 198 * @param mirrorActivityId the primary key of the mirror activity 199 * @param classNameId the target asset's class name ID 200 * @param classPK the primary key of the target asset 201 * @return the number of matching activities 202 */ 203 @Override 204 public int getActivitiesCount( 205 long mirrorActivityId, long classNameId, long classPK) { 206 207 return socialActivityLocalService.getActivitiesCount( 208 mirrorActivityId, classNameId, classPK); 209 } 210 211 /** 212 * Returns the number of activities done on the asset identified by the 213 * class name and class primary key that are mirrors of the activity 214 * identified by the mirror activity ID. 215 * 216 * @param mirrorActivityId the primary key of the mirror activity 217 * @param className the target asset's class name 218 * @param classPK the primary key of the target asset 219 * @return the number of matching activities 220 */ 221 @Override 222 public int getActivitiesCount( 223 long mirrorActivityId, String className, long classPK) { 224 225 long classNameId = classNameLocalService.getClassNameId(className); 226 227 return getActivitiesCount(mirrorActivityId, classNameId, classPK); 228 } 229 230 /** 231 * Returns the number of activities done on assets identified by class name. 232 * 233 * @param className the target asset's class name 234 * @return the number of matching activities 235 */ 236 @Override 237 public int getActivitiesCount(String className) { 238 long classNameId = classNameLocalService.getClassNameId(className); 239 240 return getActivitiesCount(classNameId); 241 } 242 243 /** 244 * Returns the activity identified by its primary key. 245 * 246 * @param activityId the primary key of the activity 247 * @return Returns the activity 248 * @throws PortalException if the activity could not be found 249 */ 250 @Override 251 public SocialActivity getActivity(long activityId) throws PortalException { 252 SocialActivity activity = socialActivityLocalService.getActivity( 253 activityId); 254 255 List<SocialActivityInterpreter> activityInterpreters = 256 socialActivityInterpreterLocalService.getActivityInterpreters( 257 StringPool.BLANK); 258 259 if (!hasPermission(activity, activityInterpreters)) { 260 throw new PrincipalException.MustHavePermission( 261 0, SocialActivity.class.getName(), activityId); 262 } 263 264 return activity; 265 } 266 267 @Override 268 public List<SocialActivity> getActivitySetActivities( 269 long activitySetId, int start, int end) 270 throws PortalException { 271 272 List<SocialActivity> activities = 273 socialActivityLocalService.getActivitySetActivities( 274 activitySetId, start, end); 275 276 return filterActivities(activities, start, end); 277 } 278 279 /** 280 * Returns a range of all the activities done in the group. 281 * 282 * <p> 283 * This method only finds activities without mirrors. 284 * </p> 285 * 286 * <p> 287 * Useful when paginating results. Returns a maximum of <code>end - 288 * start</code> instances. <code>start</code> and <code>end</code> are not 289 * primary keys, they are indexes in the result set. Thus, <code>0</code> 290 * refers to the first result in the set. Setting both <code>start</code> 291 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 292 * result set. 293 * </p> 294 * 295 * @param groupId the primary key of the group 296 * @param start the lower bound of the range of results 297 * @param end the upper bound of the range of results (not inclusive) 298 * @return the range of matching activities 299 * @throws PortalException if a permission checker was not initialized 300 */ 301 @Override 302 public List<SocialActivity> getGroupActivities( 303 long groupId, int start, int end) 304 throws PortalException { 305 306 List<SocialActivity> activities = 307 socialActivityLocalService.getGroupActivities( 308 groupId, 0, 309 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 310 311 return filterActivities(activities, start, end); 312 } 313 314 /** 315 * Returns the number of activities done in the group. 316 * 317 * <p> 318 * This method only counts activities without mirrors. 319 * </p> 320 * 321 * @param groupId the primary key of the group 322 * @return the number of matching activities 323 */ 324 @Override 325 public int getGroupActivitiesCount(long groupId) { 326 return socialActivityLocalService.getGroupActivitiesCount(groupId); 327 } 328 329 /** 330 * Returns a range of activities done by users that are members of the 331 * group. 332 * 333 * <p> 334 * This method only finds activities without mirrors. 335 * </p> 336 * 337 * <p> 338 * Useful when paginating results. Returns a maximum of <code>end - 339 * start</code> instances. <code>start</code> and <code>end</code> are not 340 * primary keys, they are indexes in the result set. Thus, <code>0</code> 341 * refers to the first result in the set. Setting both <code>start</code> 342 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 343 * result set. 344 * </p> 345 * 346 * @param groupId the primary key of the group 347 * @param start the lower bound of the range of results 348 * @param end the upper bound of the range of results (not inclusive) 349 * @return the range of matching activities 350 * @throws PortalException if a permission checker was not initialized 351 */ 352 @Override 353 public List<SocialActivity> getGroupUsersActivities( 354 long groupId, int start, int end) 355 throws PortalException { 356 357 List<SocialActivity> activities = 358 socialActivityLocalService.getGroupUsersActivities( 359 groupId, 0, 360 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 361 362 return filterActivities(activities, start, end); 363 } 364 365 /** 366 * Returns the number of activities done by users that are members of the 367 * group. 368 * 369 * <p> 370 * This method only counts activities without mirrors. 371 * </p> 372 * 373 * @param groupId the primary key of the group 374 * @return the number of matching activities 375 */ 376 @Override 377 public int getGroupUsersActivitiesCount(long groupId) { 378 return socialActivityLocalService.getGroupUsersActivitiesCount(groupId); 379 } 380 381 /** 382 * Returns the activity that has the mirror activity. 383 * 384 * @param mirrorActivityId the primary key of the mirror activity 385 * @return Returns the mirror activity 386 * @throws PortalException if the mirror activity could not be found 387 */ 388 @Override 389 public SocialActivity getMirrorActivity(long mirrorActivityId) 390 throws PortalException { 391 392 SocialActivity activity = socialActivityLocalService.getMirrorActivity( 393 mirrorActivityId); 394 395 List<SocialActivityInterpreter> activityInterpreters = 396 socialActivityInterpreterLocalService.getActivityInterpreters( 397 StringPool.BLANK); 398 399 if (!hasPermission(activity, activityInterpreters)) { 400 throw new PrincipalException.MustHavePermission( 401 0, SocialActivity.class.getName(), mirrorActivityId); 402 } 403 404 return activity; 405 } 406 407 /** 408 * Returns a range of all the activities done in the organization. This 409 * method only finds activities without mirrors. 410 * 411 * <p> 412 * Useful when paginating results. Returns a maximum of <code>end - 413 * start</code> instances. <code>start</code> and <code>end</code> are not 414 * primary keys, they are indexes in the result set. Thus, <code>0</code> 415 * refers to the first result in the set. Setting both <code>start</code> 416 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 417 * result set. 418 * </p> 419 * 420 * @param organizationId the primary key of the organization 421 * @param start the lower bound of the range of results 422 * @param end the upper bound of the range of results (not inclusive) 423 * @return the range of matching activities 424 * @throws PortalException if a permission checker was not initialized 425 */ 426 @Override 427 public List<SocialActivity> getOrganizationActivities( 428 long organizationId, int start, int end) 429 throws PortalException { 430 431 List<SocialActivity> activities = 432 socialActivityLocalService.getOrganizationActivities( 433 organizationId, 0, 434 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 435 436 return filterActivities(activities, start, end); 437 } 438 439 /** 440 * Returns the number of activities done in the organization. This method 441 * only counts activities without mirrors. 442 * 443 * @param organizationId the primary key of the organization 444 * @return the number of matching activities 445 */ 446 @Override 447 public int getOrganizationActivitiesCount(long organizationId) { 448 return socialActivityLocalService.getOrganizationActivitiesCount( 449 organizationId); 450 } 451 452 /** 453 * Returns a range of all the activities done by users of the organization. 454 * This method only finds activities without mirrors. 455 * 456 * <p> 457 * Useful when paginating results. Returns a maximum of <code>end - 458 * start</code> instances. <code>start</code> and <code>end</code> are not 459 * primary keys, they are indexes in the result set. Thus, <code>0</code> 460 * refers to the first result in the set. Setting both <code>start</code> 461 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 462 * result set. 463 * </p> 464 * 465 * @param organizationId the primary key of the organization 466 * @param start the lower bound of the range of results 467 * @param end the upper bound of the range of results (not inclusive) 468 * @return the range of matching activities 469 * @throws PortalException if a permission checker was not initialized 470 */ 471 @Override 472 public List<SocialActivity> getOrganizationUsersActivities( 473 long organizationId, int start, int end) 474 throws PortalException { 475 476 List<SocialActivity> activities = 477 socialActivityLocalService.getOrganizationUsersActivities( 478 organizationId, 0, 479 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 480 481 return filterActivities(activities, start, end); 482 } 483 484 /** 485 * Returns the number of activities done by users of the organization. This 486 * method only counts activities without mirrors. 487 * 488 * @param organizationId the primary key of the organization 489 * @return the number of matching activities 490 */ 491 @Override 492 public int getOrganizationUsersActivitiesCount(long organizationId) { 493 return socialActivityLocalService.getOrganizationUsersActivitiesCount( 494 organizationId); 495 } 496 497 /** 498 * Returns a range of all the activities done by users in a relationship 499 * with the user identified by the user ID. 500 * 501 * <p> 502 * Useful when paginating results. Returns a maximum of <code>end - 503 * start</code> instances. <code>start</code> and <code>end</code> are not 504 * primary keys, they are indexes in the result set. Thus, <>0</code> refers 505 * to the first result in the set. Setting both <code>start</code> and 506 * <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result 507 * set. 508 * </p> 509 * 510 * @param userId the primary key of the user 511 * @param start the lower bound of the range of results 512 * @param end the upper bound of the range of results (not inclusive) 513 * @return the range of matching activities 514 * @throws PortalException if a permission checker was not initialized 515 */ 516 @Override 517 public List<SocialActivity> getRelationActivities( 518 long userId, int start, int end) 519 throws PortalException { 520 521 List<SocialActivity> activities = 522 socialActivityLocalService.getRelationActivities( 523 userId, 0, 524 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 525 526 return filterActivities(activities, start, end); 527 } 528 529 /** 530 * Returns a range of all the activities done by users in a relationship of 531 * type <code>type</code> with the user identified by <code>userId</code>. 532 * This method only finds activities without mirrors. 533 * 534 * <p> 535 * Useful when paginating results. Returns a maximum of <code>end - 536 * start</code> instances. <code>start</code> and <code>end</code> are not 537 * primary keys, they are indexes in the result set. Thus, <code>0</code> 538 * refers to the first result in the set. Setting both <code>start</code> 539 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 540 * result set. 541 * </p> 542 * 543 * @param userId the primary key of the user 544 * @param type the relationship type 545 * @param start the lower bound of the range of results 546 * @param end the upper bound of the range of results (not inclusive) 547 * @return the range of matching activities 548 * @throws PortalException if a permission checker was not initialized 549 */ 550 @Override 551 public List<SocialActivity> getRelationActivities( 552 long userId, int type, int start, int end) 553 throws PortalException { 554 555 List<SocialActivity> activities = 556 socialActivityLocalService.getRelationActivities( 557 userId, type, 0, 558 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 559 560 return filterActivities(activities, start, end); 561 } 562 563 /** 564 * Returns the number of activities done by users in a relationship with the 565 * user identified by userId. 566 * 567 * @param userId the primary key of the user 568 * @return the number of matching activities 569 */ 570 @Override 571 public int getRelationActivitiesCount(long userId) { 572 return socialActivityLocalService.getRelationActivitiesCount(userId); 573 } 574 575 /** 576 * Returns the number of activities done by users in a relationship of type 577 * <code>type</code> with the user identified by <code>userId</code>. This 578 * method only counts activities without mirrors. 579 * 580 * @param userId the primary key of the user 581 * @param type the relationship type 582 * @return the number of matching activities 583 */ 584 @Override 585 public int getRelationActivitiesCount(long userId, int type) { 586 return socialActivityLocalService.getRelationActivitiesCount( 587 userId, type); 588 } 589 590 /** 591 * Returns a range of all the activities done by the user. 592 * 593 * <p> 594 * Useful when paginating results. Returns a maximum of <code>end - 595 * start</code> instances. <code>start</code> and <code>end</code> are not 596 * primary keys, they are indexes in the result set. Thus, <code>0</code> 597 * refers to the first result in the set. Setting both <code>start</code> 598 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 599 * result set. 600 * </p> 601 * 602 * @param userId the primary key of the user 603 * @param start the lower bound of the range of results 604 * @param end the upper bound of the range of results (not inclusive) 605 * @return the range of matching activities 606 * @throws PortalException if a permission checker was not initialized 607 */ 608 @Override 609 public List<SocialActivity> getUserActivities( 610 long userId, int start, int end) 611 throws PortalException { 612 613 List<SocialActivity> activities = 614 socialActivityLocalService.getUserActivities( 615 userId, 0, 616 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 617 618 return filterActivities(activities, start, end); 619 } 620 621 /** 622 * Returns the number of activities done by the user. 623 * 624 * @param userId the primary key of the user 625 * @return the number of matching activities 626 */ 627 @Override 628 public int getUserActivitiesCount(long userId) { 629 return socialActivityLocalService.getUserActivitiesCount(userId); 630 } 631 632 /** 633 * Returns a range of all the activities done in the user's groups. This 634 * method only finds activities without mirrors. 635 * 636 * <p> 637 * Useful when paginating results. Returns a maximum of <code>end - 638 * start</code> instances. <code>start</code> and <code>end</code> are not 639 * primary keys, they are indexes in the result set. Thus, <code>0</code> 640 * refers to the first result in the set. Setting both <code>start</code> 641 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 642 * result set. 643 * </p> 644 * 645 * @param userId the primary key of the user 646 * @param start the lower bound of the range of results 647 * @param end the upper bound of the range of results (not inclusive) 648 * @return the range of matching activities 649 * @throws PortalException if a permission checker was not initialized 650 */ 651 @Override 652 public List<SocialActivity> getUserGroupsActivities( 653 long userId, int start, int end) 654 throws PortalException { 655 656 List<SocialActivity> activities = 657 socialActivityLocalService.getUserGroupsActivities( 658 userId, 0, 659 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 660 661 return filterActivities(activities, start, end); 662 } 663 664 /** 665 * Returns the number of activities done in user's groups. This method only 666 * counts activities without mirrors. 667 * 668 * @param userId the primary key of the user 669 * @return the number of matching activities 670 */ 671 @Override 672 public int getUserGroupsActivitiesCount(long userId) { 673 return socialActivityLocalService.getUserGroupsActivitiesCount(userId); 674 } 675 676 /** 677 * Returns a range of all the activities done in the user's groups and 678 * organizations. This method only finds activities without mirrors. 679 * 680 * <p> 681 * Useful when paginating results. Returns a maximum of <code>end - 682 * start</code> instances. <code>start</code> and <code>end</code> are not 683 * primary keys, they are indexes in the result set. Thus, <code>0</code> 684 * refers to the first result in the set. Setting both <code>start</code> 685 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 686 * result set. 687 * </p> 688 * 689 * @param userId the primary key of the user 690 * @param start the lower bound of the range of results 691 * @param end the upper bound of the range of results (not inclusive) 692 * @return the range of matching activities 693 * @throws PortalException if a permission checker was not initialized 694 */ 695 @Override 696 public List<SocialActivity> getUserGroupsAndOrganizationsActivities( 697 long userId, int start, int end) 698 throws PortalException { 699 700 List<SocialActivity> activities = 701 socialActivityLocalService.getUserGroupsAndOrganizationsActivities( 702 userId, 0, 703 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 704 705 return filterActivities(activities, start, end); 706 } 707 708 /** 709 * Returns the number of activities done in user's groups and organizations. 710 * This method only counts activities without mirrors. 711 * 712 * @param userId the primary key of the user 713 * @return the number of matching activities 714 */ 715 @Override 716 public int getUserGroupsAndOrganizationsActivitiesCount(long userId) { 717 return socialActivityLocalService. 718 getUserGroupsAndOrganizationsActivitiesCount(userId); 719 } 720 721 /** 722 * Returns a range of all activities done in the user's organizations. This 723 * method only finds activities without mirrors. 724 * 725 * <p> 726 * Useful when paginating results. Returns a maximum of <code>end - 727 * start</code> instances. <code>start</code> and <code>end</code> are not 728 * primary keys, they are indexes in the result set. Thus, <code>0</code> 729 * refers to the first result in the set. Setting both <code>start</code> 730 * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full 731 * result set. 732 * </p> 733 * 734 * @param userId the primary key of the user 735 * @param start the lower bound of the range of results 736 * @param end the upper bound of the range of results (not inclusive) 737 * @return the range of matching activities 738 * @throws PortalException if a permission checker was not initialized 739 */ 740 @Override 741 public List<SocialActivity> getUserOrganizationsActivities( 742 long userId, int start, int end) 743 throws PortalException { 744 745 List<SocialActivity> activities = 746 socialActivityLocalService.getUserOrganizationsActivities( 747 userId, 0, 748 end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT); 749 750 return filterActivities(activities, start, end); 751 } 752 753 /** 754 * Returns the number of activities done in the user's organizations. This 755 * method only counts activities without mirrors. 756 * 757 * @param userId the primary key of the user 758 * @return the number of matching activities 759 */ 760 @Override 761 public int getUserOrganizationsActivitiesCount(long userId) { 762 return socialActivityLocalService.getUserOrganizationsActivitiesCount( 763 userId); 764 } 765 766 protected List<SocialActivity> filterActivities( 767 List<SocialActivity> activities, int start, int end) 768 throws PortalException { 769 770 List<SocialActivity> filteredActivities = new ArrayList<>(); 771 772 List<SocialActivityInterpreter> activityInterpreters = 773 socialActivityInterpreterLocalService.getActivityInterpreters( 774 StringPool.BLANK); 775 776 for (SocialActivity activity : activities) { 777 if (hasPermission(activity, activityInterpreters)) { 778 filteredActivities.add(activity); 779 } 780 781 if ((end != QueryUtil.ALL_POS) && 782 (filteredActivities.size() > end)) { 783 784 break; 785 } 786 } 787 788 if ((end != QueryUtil.ALL_POS) && (start != QueryUtil.ALL_POS)) { 789 if (end > filteredActivities.size()) { 790 end = filteredActivities.size(); 791 } 792 793 if (start > filteredActivities.size()) { 794 start = filteredActivities.size(); 795 } 796 797 filteredActivities = filteredActivities.subList(start, end); 798 } 799 800 return filteredActivities; 801 } 802 803 protected boolean hasPermission( 804 SocialActivity activity, 805 List<SocialActivityInterpreter> activityInterpreters) 806 throws PortalException { 807 808 PermissionChecker permissionChecker = getPermissionChecker(); 809 ServiceContext serviceContext = new ServiceContext(); 810 811 for (int i = 0; i < activityInterpreters.size(); i++) { 812 SocialActivityInterpreterImpl activityInterpreterImpl = 813 (SocialActivityInterpreterImpl)activityInterpreters.get(i); 814 815 if (activityInterpreterImpl.hasClassName(activity.getClassName())) { 816 try { 817 if (activityInterpreterImpl.hasPermission( 818 permissionChecker, activity, ActionKeys.VIEW, 819 serviceContext)) { 820 821 return true; 822 } 823 } 824 catch (Exception e) { 825 } 826 } 827 } 828 829 return false; 830 } 831 832 }