001 /** 002 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 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.exception.SystemException; 020 import com.liferay.portal.kernel.lar.ImportExportThreadLocal; 021 import com.liferay.portal.kernel.messaging.async.Async; 022 import com.liferay.portal.model.Group; 023 import com.liferay.portal.model.Layout; 024 import com.liferay.portal.model.User; 025 import com.liferay.portal.util.PortalUtil; 026 import com.liferay.portlet.asset.model.AssetEntry; 027 import com.liferay.portlet.social.NoSuchActivityException; 028 import com.liferay.portlet.social.model.SocialActivity; 029 import com.liferay.portlet.social.model.SocialActivityDefinition; 030 import com.liferay.portlet.social.service.base.SocialActivityLocalServiceBaseImpl; 031 032 import java.util.Date; 033 import java.util.List; 034 035 /** 036 * The social activity local service. This service provides the means to record 037 * and list social activities in groups and organizations. 038 * 039 * <p> 040 * Social activities are identified by their type and the type of asset they 041 * are done on. Each activity records the exact time of the action as well as 042 * human readable information needed for activity feeds. 043 * </p> 044 * 045 * <p> 046 * Most of the <i>get-</i> methods in this service order activities in 047 * descending order by their execution times, so the most recent activities are 048 * listed first. 049 * </p> 050 * 051 * @author Brian Wing Shun Chan 052 */ 053 public class SocialActivityLocalServiceImpl 054 extends SocialActivityLocalServiceBaseImpl { 055 056 /** 057 * Records an activity with the given time in the database. 058 * 059 * <p> 060 * This method records a social activity done on an asset, identified by 061 * its class name and class primary key, in the database. Additional 062 * information (such as the original message ID for a reply to a forum 063 * post) is passed in via the <code>extraData</code> in JSON format. For 064 * activities affecting another user, a mirror activity is generated that 065 * describes the action from the user's point of view. The target user's ID 066 * is passed in via the <code>receiverUserId</code>. 067 * </p> 068 * 069 * <p> 070 * Example for a mirrored activity:<br> When a user replies to a message 071 * boards post, the reply action is stored in the database with the 072 * <code>receiverUserId</code> being the ID of the author of the original 073 * message. The <code>extraData</code> contains the ID of the original 074 * message in JSON format. A mirror activity is generated with the values 075 * of the <code>userId</code> and the <code>receiverUserId</code> swapped. 076 * This mirror activity basically describes a "replied to" event. 077 * </p> 078 * 079 * <p> 080 * Mirror activities are most often used in relation to friend requests and 081 * activities. 082 * </p> 083 * 084 * @param userId the primary key of the acting user 085 * @param groupId the primary key of the group 086 * @param createDate the activity's date 087 * @param className the target asset's class name 088 * @param classPK the primary key of the target asset 089 * @param type the activity's type 090 * @param extraData any extra data regarding the activity 091 * @param receiverUserId the primary key of the receiving user 092 * @throws PortalException if the user or group could not be found 093 * @throws SystemException if a system exception occurred 094 */ 095 public void addActivity( 096 long userId, long groupId, Date createDate, String className, 097 long classPK, int type, String extraData, long receiverUserId) 098 throws PortalException, SystemException { 099 100 if (ImportExportThreadLocal.isImportInProcess()) { 101 return; 102 } 103 104 User user = userPersistence.findByPrimaryKey(userId); 105 long classNameId = PortalUtil.getClassNameId(className); 106 107 if (groupId > 0) { 108 Group group = groupLocalService.getGroup(groupId); 109 110 if (group.isLayout()) { 111 Layout layout = layoutLocalService.getLayout( 112 group.getClassPK()); 113 114 groupId = layout.getGroupId(); 115 } 116 } 117 118 SocialActivity activity = socialActivityPersistence.create(0); 119 120 activity.setGroupId(groupId); 121 activity.setCompanyId(user.getCompanyId()); 122 activity.setUserId(user.getUserId()); 123 activity.setCreateDate(createDate.getTime()); 124 activity.setMirrorActivityId(0); 125 activity.setClassNameId(classNameId); 126 activity.setClassPK(classPK); 127 activity.setType(type); 128 activity.setExtraData(extraData); 129 activity.setReceiverUserId(receiverUserId); 130 131 AssetEntry assetEntry = assetEntryPersistence.fetchByC_C( 132 classNameId, classPK); 133 134 activity.setAssetEntry(assetEntry); 135 136 SocialActivity mirrorActivity = null; 137 138 if ((receiverUserId > 0) && (userId != receiverUserId)) { 139 mirrorActivity = socialActivityPersistence.create(0); 140 141 mirrorActivity.setGroupId(groupId); 142 mirrorActivity.setCompanyId(user.getCompanyId()); 143 mirrorActivity.setUserId(receiverUserId); 144 mirrorActivity.setCreateDate(createDate.getTime()); 145 mirrorActivity.setClassNameId(classNameId); 146 mirrorActivity.setClassPK(classPK); 147 mirrorActivity.setType(type); 148 mirrorActivity.setExtraData(extraData); 149 mirrorActivity.setReceiverUserId(user.getUserId()); 150 mirrorActivity.setAssetEntry(assetEntry); 151 } 152 153 socialActivityLocalService.addActivity(activity, mirrorActivity); 154 } 155 156 /** 157 * Records an activity in the database, using a time based on the current 158 * time in an attempt to make the activity's time unique. 159 * 160 * @param userId the primary key of the acting user 161 * @param groupId the primary key of the group 162 * @param className the target asset's class name 163 * @param classPK the primary key of the target asset 164 * @param type the activity's type 165 * @param extraData any extra data regarding the activity 166 * @param receiverUserId the primary key of the receiving user 167 * @throws PortalException if the user or group could not be found 168 * @throws SystemException if a system exception occurred 169 */ 170 public void addActivity( 171 long userId, long groupId, String className, long classPK, int type, 172 String extraData, long receiverUserId) 173 throws PortalException, SystemException { 174 175 if (ImportExportThreadLocal.isImportInProcess()) { 176 return; 177 } 178 179 Date createDate = new Date(); 180 181 long classNameId = PortalUtil.getClassNameId(className); 182 183 while (true) { 184 SocialActivity socialActivity = 185 socialActivityPersistence.fetchByG_U_CD_C_C_T_R( 186 groupId, userId, createDate.getTime(), classNameId, classPK, 187 type, receiverUserId); 188 189 if (socialActivity != null) { 190 createDate = new Date(createDate.getTime() + 1); 191 } 192 else { 193 break; 194 } 195 } 196 197 addActivity( 198 userId, groupId, createDate, className, classPK, type, extraData, 199 receiverUserId); 200 } 201 202 @Async 203 public void addActivity( 204 SocialActivity activity, SocialActivity mirrorActivity) 205 throws PortalException, SystemException { 206 207 if (ImportExportThreadLocal.isImportInProcess()) { 208 return; 209 } 210 211 if ((activity.getActivityId() > 0) || 212 ((mirrorActivity != null) && 213 (mirrorActivity.getActivityId() > 0))) { 214 215 throw new PortalException( 216 "Activity and mirror activity must not have primary keys set"); 217 } 218 219 SocialActivityDefinition activityDefinition = 220 socialActivitySettingLocalService.getActivityDefinition( 221 activity.getGroupId(), activity.getClassName(), 222 activity.getType()); 223 224 if ((activityDefinition == null) || 225 activityDefinition.isLogActivity()) { 226 227 long activityId = counterLocalService.increment( 228 SocialActivity.class.getName()); 229 230 activity.setActivityId(activityId); 231 232 socialActivityPersistence.update(activity, false); 233 234 if (mirrorActivity != null) { 235 long mirrorActivityId = counterLocalService.increment( 236 SocialActivity.class.getName()); 237 238 mirrorActivity.setActivityId(mirrorActivityId); 239 mirrorActivity.setMirrorActivityId(activity.getPrimaryKey()); 240 241 socialActivityPersistence.update(mirrorActivity, false); 242 } 243 } 244 245 socialActivityCounterLocalService.addActivityCounters(activity); 246 } 247 248 /** 249 * Records an activity in the database, but only if there isn't already an 250 * activity with the same parameters. 251 * 252 * <p> 253 * For the main functionality see {@link #addActivity(long, long, Date, 254 * String, long, int, String, long)} 255 * </p> 256 * 257 * @param userId the primary key of the acting user 258 * @param groupId the primary key of the group 259 * @param createDate the activity's date 260 * @param className the target asset's class name 261 * @param classPK the primary key of the target asset 262 * @param type the activity's type 263 * @param extraData any extra data regarding the activity 264 * @param receiverUserId the primary key of the receiving user 265 * @throws PortalException if the user or group could not be found 266 * @throws SystemException if a system exception occurred 267 */ 268 public void addUniqueActivity( 269 long userId, long groupId, Date createDate, String className, 270 long classPK, int type, String extraData, long receiverUserId) 271 throws PortalException, SystemException { 272 273 long classNameId = PortalUtil.getClassNameId(className); 274 275 SocialActivity socialActivity = 276 socialActivityPersistence.fetchByG_U_CD_C_C_T_R( 277 groupId, userId, createDate.getTime(), classNameId, classPK, 278 type, receiverUserId); 279 280 if (socialActivity != null) { 281 return; 282 } 283 284 addActivity( 285 userId, groupId, createDate, className, classPK, type, extraData, 286 receiverUserId); 287 } 288 289 /** 290 * Records an activity with the current time in the database, but only if 291 * there isn't one with the same parameters. 292 * 293 * <p> 294 * For the main functionality see {@link #addActivity(long, long, Date, 295 * String, long, int, String, long)} 296 * </p> 297 * 298 * @param userId the primary key of the acting user 299 * @param groupId the primary key of the group 300 * @param className the target asset's class name 301 * @param classPK the primary key of the target asset 302 * @param type the activity's type 303 * @param extraData any extra data regarding the activity 304 * @param receiverUserId the primary key of the receiving user 305 * @throws PortalException if the user or group could not be found 306 * @throws SystemException if a system exception occurred 307 */ 308 public void addUniqueActivity( 309 long userId, long groupId, String className, long classPK, int type, 310 String extraData, long receiverUserId) 311 throws PortalException, SystemException { 312 313 long classNameId = PortalUtil.getClassNameId(className); 314 315 int count = socialActivityPersistence.countByG_U_C_C_T_R( 316 groupId, userId, classNameId, classPK, type, receiverUserId); 317 318 if (count > 0) { 319 return; 320 } 321 322 addActivity( 323 userId, groupId, new Date(), className, classPK, type, extraData, 324 receiverUserId); 325 } 326 327 /** 328 * Removes stored activities for the asset identified by the class name ID 329 * and class primary key. 330 * 331 * @throws SystemException if a system exception occurred 332 */ 333 public void deleteActivities(AssetEntry assetEntry) 334 throws PortalException, SystemException { 335 336 socialActivityPersistence.removeByC_C( 337 assetEntry.getClassNameId(), assetEntry.getClassPK()); 338 339 socialActivityCounterLocalService.deleteActivityCounters(assetEntry); 340 } 341 342 /** 343 * Removes stored activities for the asset identified by the class name and 344 * class primary key. 345 * 346 * @param className the target asset's class name 347 * @param classPK the primary key of the target asset 348 * @throws SystemException if a system exception occurred 349 */ 350 public void deleteActivities(String className, long classPK) 351 throws SystemException { 352 353 long classNameId = PortalUtil.getClassNameId(className); 354 355 socialActivityPersistence.removeByC_C(classNameId, classPK); 356 } 357 358 /** 359 * Removes the stored activity from the database. 360 * 361 * @param activityId the primary key of the stored activity 362 * @throws PortalException if the activity could not be found 363 * @throws SystemException if a system exception occurred 364 */ 365 public void deleteActivity(long activityId) 366 throws PortalException, SystemException { 367 368 SocialActivity activity = socialActivityPersistence.findByPrimaryKey( 369 activityId); 370 371 deleteActivity(activity); 372 } 373 374 /** 375 * Removes the stored activity and its mirror activity from the database. 376 * 377 * @param activity the activity to be removed 378 * @throws SystemException if a system exception occurred 379 */ 380 public void deleteActivity(SocialActivity activity) throws SystemException { 381 socialActivityPersistence.remove(activity); 382 383 try { 384 socialActivityPersistence.removeByMirrorActivityId( 385 activity.getActivityId()); 386 } 387 catch (NoSuchActivityException nsae) { 388 } 389 } 390 391 /** 392 * Removes the user's stored activities from the database. 393 * 394 * <p> 395 * This method removes all activities where the user is either the actor or 396 * the receiver. 397 * </p> 398 * 399 * @param userId the primary key of the user 400 * @throws SystemException if a system exception occurred 401 */ 402 public void deleteUserActivities(long userId) throws SystemException { 403 List<SocialActivity> activities = 404 socialActivityPersistence.findByUserId( 405 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 406 407 for (SocialActivity activity : activities) { 408 socialActivityPersistence.remove(activity); 409 } 410 411 activities = socialActivityPersistence.findByReceiverUserId( 412 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 413 414 for (SocialActivity activity : activities) { 415 socialActivityPersistence.remove(activity); 416 } 417 418 socialActivityCounterLocalService.deleteActivityCounters( 419 PortalUtil.getClassNameId(User.class.getName()), userId); 420 } 421 422 /** 423 * Returns a range of all the activities done on assets identified by the 424 * class name ID. 425 * 426 * <p> 427 * Useful when paginating results. Returns a maximum of <code>end - 428 * start</code> instances. <code>start</code> and <code>end</code> are not 429 * primary keys, they are indexes in the result set. Thus, <code>0</code> 430 * refers to the first result in the set. Setting both <code>start</code> 431 * and <code>end</code> to {@link 432 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 433 * full result set. 434 * </p> 435 * 436 * @param classNameId the target asset's class name ID 437 * @param start the lower bound of the range of results 438 * @param end the upper bound of the range of results (not inclusive) 439 * @return the range of matching activities 440 * @throws SystemException if a system exception occurred 441 */ 442 public List<SocialActivity> getActivities( 443 long classNameId, int start, int end) 444 throws SystemException { 445 446 return socialActivityPersistence.findByClassNameId( 447 classNameId, start, end); 448 } 449 450 /** 451 * Returns a range of all the activities done on the asset identified by 452 * the class name ID and class primary key that are mirrors of the activity 453 * identified by the mirror activity ID. 454 * 455 * <p> 456 * Useful when paginating results. Returns a maximum of <code>end - 457 * start</code> instances. <code>start</code> and <code>end</code> are not 458 * primary keys, they are indexes in the result set. Thus, <code>0</code> 459 * refers to the first result in the set. Setting both <code>start</code> 460 * and <code>end</code> to {@link 461 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 462 * full result set. 463 * </p> 464 * 465 * @param mirrorActivityId the primary key of the mirror activity 466 * @param classNameId the target asset's class name ID 467 * @param classPK the primary key of the target asset 468 * @param start the lower bound of the range of results 469 * @param end the upper bound of the range of results (not inclusive) 470 * @return the range of matching activities 471 * @throws SystemException if a system exception occurred 472 */ 473 public List<SocialActivity> getActivities( 474 long mirrorActivityId, long classNameId, long classPK, int start, 475 int end) 476 throws SystemException { 477 478 return socialActivityPersistence.findByM_C_C( 479 mirrorActivityId, classNameId, classPK, start, end); 480 } 481 482 /** 483 * Returns a range of all the activities done on the asset identified by 484 * the class name and the class primary key that are mirrors of the 485 * activity identified by the mirror activity ID. 486 * 487 * <p> 488 * Useful when paginating results. Returns a maximum of <code>end - 489 * start</code> instances. <code>start</code> and <code>end</code> are not 490 * primary keys, they are indexes in the result set. Thus, <code>0</code> 491 * refers to the first result in the set. Setting both <code>start</code> 492 * and <code>end</code> to {@link 493 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 494 * full result set. 495 * </p> 496 * 497 * @param mirrorActivityId the primary key of the mirror activity 498 * @param className the target asset's class name 499 * @param classPK the primary key of the target asset 500 * @param start the lower bound of the range of results 501 * @param end the upper bound of the range of results (not inclusive) 502 * @return the range of matching activities 503 * @throws SystemException if a system exception occurred 504 */ 505 public List<SocialActivity> getActivities( 506 long mirrorActivityId, String className, long classPK, int start, 507 int end) 508 throws SystemException { 509 510 long classNameId = PortalUtil.getClassNameId(className); 511 512 return getActivities( 513 mirrorActivityId, classNameId, classPK, start, end); 514 } 515 516 /** 517 * Returns a range of all the activities done on assets identified by the 518 * class name. 519 * 520 * <p> 521 * Useful when paginating results. Returns a maximum of <code>end - 522 * start</code> instances. <code>start</code> and <code>end</code> are not 523 * primary keys, they are indexes in the result set. Thus, <code>0</code> 524 * refers to the first result in the set. Setting both <code>start</code> 525 * and <code>end</code> to {@link 526 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 527 * full result set. 528 * </p> 529 * 530 * @param className the target asset's class name 531 * @param start the lower bound of the range of results 532 * @param end the upper bound of the range of results (not inclusive) 533 * @return the range of matching activities 534 * @throws SystemException if a system exception occurred 535 */ 536 public List<SocialActivity> getActivities( 537 String className, int start, int end) 538 throws SystemException { 539 540 long classNameId = PortalUtil.getClassNameId(className); 541 542 return getActivities(classNameId, start, end); 543 } 544 545 /** 546 * Returns the number of activities done on assets identified by the class 547 * name ID. 548 * 549 * @param classNameId the target asset's class name ID 550 * @return the number of matching activities 551 * @throws SystemException if a system exception occurred 552 */ 553 public int getActivitiesCount(long classNameId) throws SystemException { 554 return socialActivityPersistence.countByClassNameId(classNameId); 555 } 556 557 /** 558 * Returns the number of activities done on the asset identified by the 559 * class name ID and class primary key that are mirrors of the activity 560 * identified by the mirror activity ID. 561 * 562 * @param mirrorActivityId the primary key of the mirror activity 563 * @param classNameId the target asset's class name ID 564 * @param classPK the primary key of the target asset 565 * @return the number of matching activities 566 * @throws SystemException if a system exception occurred 567 */ 568 public int getActivitiesCount( 569 long mirrorActivityId, long classNameId, long classPK) 570 throws SystemException { 571 572 return socialActivityPersistence.countByM_C_C( 573 mirrorActivityId, classNameId, classPK); 574 } 575 576 /** 577 * Returns the number of activities done on the asset identified by the 578 * class name and class primary key that are mirrors of the activity 579 * identified by the mirror activity ID. 580 * 581 * @param mirrorActivityId the primary key of the mirror activity 582 * @param className the target asset's class name 583 * @param classPK the primary key of the target asset 584 * @return the number of matching activities 585 * @throws SystemException if a system exception occurred 586 */ 587 public int getActivitiesCount( 588 long mirrorActivityId, String className, long classPK) 589 throws SystemException { 590 591 long classNameId = PortalUtil.getClassNameId(className); 592 593 return getActivitiesCount(mirrorActivityId, classNameId, classPK); 594 } 595 596 /** 597 * Returns the number of activities done on assets identified by class 598 * name. 599 * 600 * @param className the target asset's class name 601 * @return the number of matching activities 602 * @throws SystemException if a system exception occurred 603 */ 604 public int getActivitiesCount(String className) throws SystemException { 605 long classNameId = PortalUtil.getClassNameId(className); 606 607 return getActivitiesCount(classNameId); 608 } 609 610 /** 611 * Returns the activity identified by its primary key. 612 * 613 * @param activityId the primary key of the activity 614 * @return Returns the activity 615 * @throws PortalException if the activity could not be found 616 * @throws SystemException if a system exception occurred 617 */ 618 public SocialActivity getActivity(long activityId) 619 throws PortalException, SystemException { 620 621 return socialActivityPersistence.findByPrimaryKey(activityId); 622 } 623 624 /** 625 * Returns a range of all the activities done in the group. 626 * 627 * <p> 628 * This method only finds activities without mirrors. 629 * </p> 630 * 631 * <p> 632 * Useful when paginating results. Returns a maximum of <code>end - 633 * start</code> instances. <code>start</code> and <code>end</code> are not 634 * primary keys, they are indexes in the result set. Thus, <code>0</code> 635 * refers to the first result in the set. Setting both <code>start</code> 636 * and <code>end</code> to {@link 637 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 638 * full result set. 639 * </p> 640 * 641 * @param groupId the primary key of the group 642 * @param start the lower bound of the range of results 643 * @param end the upper bound of the range of results (not inclusive) 644 * @return the range of matching activities 645 * @throws SystemException if a system exception occurred 646 */ 647 public List<SocialActivity> getGroupActivities( 648 long groupId, int start, int end) 649 throws SystemException { 650 651 return socialActivityFinder.findByGroupId(groupId, start, end); 652 } 653 654 /** 655 * Returns the number of activities done in the group. 656 * 657 * <p> 658 * This method only counts activities without mirrors. 659 * </p> 660 * 661 * @param groupId the primary key of the group 662 * @return the number of matching activities 663 * @throws SystemException if a system exception occurred 664 */ 665 public int getGroupActivitiesCount(long groupId) throws SystemException { 666 return socialActivityFinder.countByGroupId(groupId); 667 } 668 669 /** 670 * Returns a range of activities done by users that are members of the 671 * group. 672 * 673 * <p> 674 * This method only finds activities without mirrors. 675 * </p> 676 * 677 * <p> 678 * Useful when paginating results. Returns a maximum of <code>end - 679 * start</code> instances. <code>start</code> and <code>end</code> are not 680 * primary keys, they are indexes in the result set. Thus, <code>0</code> 681 * refers to the first result in the set. Setting both <code>start</code> 682 * and <code>end</code> to {@link 683 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 684 * full result set. 685 * </p> 686 * 687 * @param groupId the primary key of the group 688 * @param start the lower bound of the range of results 689 * @param end the upper bound of the range of results (not inclusive) 690 * @return the range of matching activities 691 * @throws SystemException if a system exception occurred 692 */ 693 public List<SocialActivity> getGroupUsersActivities( 694 long groupId, int start, int end) 695 throws SystemException { 696 697 return socialActivityFinder.findByGroupUsers(groupId, start, end); 698 } 699 700 /** 701 * Returns the number of activities done by users that are members of the 702 * group. 703 * 704 * <p> 705 * This method only counts activities without mirrors. 706 * </p> 707 * 708 * @param groupId the primary key of the group 709 * @return the number of matching activities 710 * @throws SystemException if a system exception occurred 711 */ 712 public int getGroupUsersActivitiesCount(long groupId) 713 throws SystemException { 714 715 return socialActivityFinder.countByGroupUsers(groupId); 716 } 717 718 /** 719 * Returns the activity that has the mirror activity. 720 * 721 * @param mirrorActivityId the primary key of the mirror activity 722 * @return Returns the mirror activity 723 * @throws PortalException if the mirror activity could not be found 724 * @throws SystemException if a system exception occurred 725 */ 726 public SocialActivity getMirrorActivity(long mirrorActivityId) 727 throws PortalException, SystemException { 728 729 return socialActivityPersistence.findByMirrorActivityId( 730 mirrorActivityId); 731 } 732 733 /** 734 * Returns a range of all the activities done in the organization. This 735 * method only finds activities without mirrors. 736 * 737 * <p> 738 * Useful when paginating results. Returns a maximum of <code>end - 739 * start</code> instances. <code>start</code> and <code>end</code> are not 740 * primary keys, they are indexes in the result set. Thus, <code>0</code> 741 * refers to the first result in the set. Setting both <code>start</code> 742 * and <code>end</code> to {@link 743 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 744 * full result set. 745 * </p> 746 * 747 * @param organizationId the primary key of the organization 748 * @param start the lower bound of the range of results 749 * @param end the upper bound of the range of results (not inclusive) 750 * @return the range of matching activities 751 * @throws SystemException if a system exception occurred 752 */ 753 public List<SocialActivity> getOrganizationActivities( 754 long organizationId, int start, int end) 755 throws SystemException { 756 757 return socialActivityFinder.findByOrganizationId( 758 organizationId, start, end); 759 } 760 761 /** 762 * Returns the number of activities done in the organization. This method 763 * only counts activities without mirrors. 764 * 765 * @param organizationId the primary key of the organization 766 * @return the number of matching activities 767 * @throws SystemException if a system exception occurred 768 */ 769 public int getOrganizationActivitiesCount(long organizationId) 770 throws SystemException { 771 772 return socialActivityFinder.countByOrganizationId(organizationId); 773 } 774 775 /** 776 * Returns a range of all the activities done by users of the organization. 777 * This method only finds activities without mirrors. 778 * 779 * <p> 780 * Useful when paginating results. Returns a maximum of <code>end - 781 * start</code> instances. <code>start</code> and <code>end</code> are not 782 * primary keys, they are indexes in the result set. Thus, <code>0</code> 783 * refers to the first result in the set. Setting both <code>start</code> 784 * and <code>end</code> to {@link 785 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 786 * full result set. 787 * </p> 788 * 789 * @param organizationId the primary key of the organization 790 * @param start the lower bound of the range of results 791 * @param end the upper bound of the range of results (not inclusive) 792 * @return the range of matching activities 793 * @throws SystemException if a system exception occurred 794 */ 795 public List<SocialActivity> getOrganizationUsersActivities( 796 long organizationId, int start, int end) 797 throws SystemException { 798 799 return socialActivityFinder.findByOrganizationUsers( 800 organizationId, start, end); 801 } 802 803 /** 804 * Returns the number of activities done by users of the organization. This 805 * method only counts activities without mirrors. 806 * 807 * @param organizationId the primary key of the organization 808 * @return the number of matching activities 809 * @throws SystemException if a system exception occurred 810 */ 811 public int getOrganizationUsersActivitiesCount(long organizationId) 812 throws SystemException { 813 814 return socialActivityFinder.countByOrganizationUsers(organizationId); 815 } 816 817 /** 818 * Returns a range of all the activities done by users in a relationship 819 * with the user identified by the user ID. 820 * 821 * <p> 822 * Useful when paginating results. Returns a maximum of <code>end - 823 * start</code> instances. <code>start</code> and <code>end</code> are not 824 * primary keys, they are indexes in the result set. Thus, <>0</code> 825 * refers to the first result in the set. Setting both <code>start</code> 826 * and <code>end</code> to {@link 827 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 828 * full result set. 829 * </p> 830 * 831 * @param userId the primary key of the user 832 * @param start the lower bound of the range of results 833 * @param end the upper bound of the range of results (not inclusive) 834 * @return the range of matching activities 835 * @throws SystemException if a system exception occurred 836 */ 837 public List<SocialActivity> getRelationActivities( 838 long userId, int start, int end) 839 throws SystemException { 840 841 return socialActivityFinder.findByRelation(userId, start, end); 842 } 843 844 /** 845 * Returns a range of all the activities done by users in a relationship of 846 * type <code>type</code> with the user identified by <code>userId</code>. 847 * This method only finds activities without mirrors. 848 * 849 * <p> 850 * Useful when paginating results. Returns a maximum of <code>end - 851 * start</code> instances. <code>start</code> and <code>end</code> are not 852 * primary keys, they are indexes in the result set. Thus, <code>0</code> 853 * refers to the first result in the set. Setting both <code>start</code> 854 * and <code>end</code> to {@link 855 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 856 * full result set. 857 * </p> 858 * 859 * @param userId the primary key of the user 860 * @param type the relationship type 861 * @param start the lower bound of the range of results 862 * @param end the upper bound of the range of results (not inclusive) 863 * @return the range of matching activities 864 * @throws SystemException if a system exception occurred 865 */ 866 public List<SocialActivity> getRelationActivities( 867 long userId, int type, int start, int end) 868 throws SystemException { 869 870 return socialActivityFinder.findByRelationType( 871 userId, type, start, end); 872 } 873 874 /** 875 * Returns the number of activities done by users in a relationship with 876 * the user identified by userId. 877 * 878 * @param userId the primary key of the user 879 * @return the number of matching activities 880 * @throws SystemException if a system exception occurred 881 */ 882 public int getRelationActivitiesCount(long userId) throws SystemException { 883 return socialActivityFinder.countByRelation(userId); 884 } 885 886 /** 887 * Returns the number of activities done by users in a relationship of type 888 * <code>type</code> with the user identified by <code>userId</code>. This 889 * method only counts activities without mirrors. 890 * 891 * @param userId the primary key of the user 892 * @param type the relationship type 893 * @return the number of matching activities 894 * @throws SystemException if a system exception occurred 895 */ 896 public int getRelationActivitiesCount(long userId, int type) 897 throws SystemException { 898 899 return socialActivityFinder.countByRelationType(userId, type); 900 } 901 902 /** 903 * Returns a range of all the activities done by the user. 904 * 905 * <p> 906 * Useful when paginating results. Returns a maximum of <code>end - 907 * start</code> instances. <code>start</code> and <code>end</code> are not 908 * primary keys, they are indexes in the result set. Thus, <code>0</code> 909 * refers to the first result in the set. Setting both <code>start</code> 910 * and <code>end</code> to {@link 911 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 912 * full result set. 913 * </p> 914 * 915 * @param userId the primary key of the user 916 * @param start the lower bound of the range of results 917 * @param end the upper bound of the range of results (not inclusive) 918 * @return the range of matching activities 919 * @throws SystemException if a system exception occurred 920 */ 921 public List<SocialActivity> getUserActivities( 922 long userId, int start, int end) 923 throws SystemException { 924 925 return socialActivityPersistence.findByUserId(userId, start, end); 926 } 927 928 /** 929 * Returns the number of activities done by the user. 930 * 931 * @param userId the primary key of the user 932 * @return the number of matching activities 933 * @throws SystemException if a system exception occurred 934 */ 935 public int getUserActivitiesCount(long userId) throws SystemException { 936 return socialActivityPersistence.countByUserId(userId); 937 } 938 939 /** 940 * Returns a range of all the activities done in the user's groups. This 941 * method only finds activities without mirrors. 942 * 943 * <p> 944 * Useful when paginating results. Returns a maximum of <code>end - 945 * start</code> instances. <code>start</code> and <code>end</code> are not 946 * primary keys, they are indexes in the result set. Thus, <code>0</code> 947 * refers to the first result in the set. Setting both <code>start</code> 948 * and <code>end</code> to {@link 949 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 950 * full result set. 951 * </p> 952 * 953 * @param userId the primary key of the user 954 * @param start the lower bound of the range of results 955 * @param end the upper bound of the range of results (not inclusive) 956 * @return the range of matching activities 957 * @throws SystemException if a system exception occurred 958 */ 959 public List<SocialActivity> getUserGroupsActivities( 960 long userId, int start, int end) 961 throws SystemException { 962 963 return socialActivityFinder.findByUserGroups(userId, start, end); 964 } 965 966 /** 967 * Returns the number of activities done in user's groups. This method only 968 * counts activities without mirrors. 969 * 970 * @param userId the primary key of the user 971 * @return the number of matching activities 972 * @throws SystemException if a system exception occurred 973 */ 974 public int getUserGroupsActivitiesCount(long userId) 975 throws SystemException { 976 977 return socialActivityFinder.countByUserGroups(userId); 978 } 979 980 /** 981 * Returns a range of all the activities done in the user's groups and 982 * organizations. This method only finds activities without mirrors. 983 * 984 * <p> 985 * Useful when paginating results. Returns a maximum of <code>end - 986 * start</code> instances. <code>start</code> and <code>end</code> are not 987 * primary keys, they are indexes in the result set. Thus, <code>0</code> 988 * refers to the first result in the set. Setting both <code>start</code> 989 * and <code>end</code> to {@link 990 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 991 * full result set. 992 * </p> 993 * 994 * @param userId the primary key of the user 995 * @param start the lower bound of the range of results 996 * @param end the upper bound of the range of results (not inclusive) 997 * @return the range of matching activities 998 * @throws SystemException if a system exception occurred 999 */ 1000 public List<SocialActivity> getUserGroupsAndOrganizationsActivities( 1001 long userId, int start, int end) 1002 throws SystemException { 1003 1004 return socialActivityFinder.findByUserGroupsAndOrganizations( 1005 userId, start, end); 1006 } 1007 1008 /** 1009 * Returns the number of activities done in user's groups and 1010 * organizations. This method only counts activities without mirrors. 1011 * 1012 * @param userId the primary key of the user 1013 * @return the number of matching activities 1014 * @throws SystemException if a system exception occurred 1015 */ 1016 public int getUserGroupsAndOrganizationsActivitiesCount(long userId) 1017 throws SystemException { 1018 1019 return socialActivityFinder.countByUserGroupsAndOrganizations(userId); 1020 } 1021 1022 /** 1023 * Returns a range of all activities done in the user's organizations. This 1024 * method only finds activities without mirrors. 1025 * 1026 * <p> 1027 * Useful when paginating results. Returns a maximum of <code>end - 1028 * start</code> instances. <code>start</code> and <code>end</code> are not 1029 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1030 * refers to the first result in the set. Setting both <code>start</code> 1031 * and <code>end</code> to {@link 1032 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the 1033 * full result set. 1034 * </p> 1035 * 1036 * @param userId the primary key of the user 1037 * @param start the lower bound of the range of results 1038 * @param end the upper bound of the range of results (not inclusive) 1039 * @return the range of matching activities 1040 * @throws SystemException if a system exception occurred 1041 */ 1042 public List<SocialActivity> getUserOrganizationsActivities( 1043 long userId, int start, int end) 1044 throws SystemException { 1045 1046 return socialActivityFinder.findByUserOrganizations(userId, start, end); 1047 } 1048 1049 /** 1050 * Returns the number of activities done in the user's organizations. This 1051 * method only counts activities without mirrors. 1052 * 1053 * @param userId the primary key of the user 1054 * @return the number of matching activities 1055 * @throws SystemException if a system exception occurred 1056 */ 1057 public int getUserOrganizationsActivitiesCount(long userId) 1058 throws SystemException { 1059 1060 return socialActivityFinder.countByUserOrganizations(userId); 1061 } 1062 1063 }