001 /** 002 * Copyright (c) 2000-2011 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.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 are 041 * done on. Each activity records the exact time of the action as well as human 042 * 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 its 061 * class name and class primary key, in the database. Additional information 062 * (such as the original message ID for a reply to a forum post) is passed 063 * in via the <code>extraData</code> in JSON format. For activities 064 * affecting another user, a mirror activity is generated that describes the 065 * action from the user's point of view. The target user's ID is passed in 066 * 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 of 075 * the <code>userId</code> and the <code>receiverUserId</code> swapped. This 076 * 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 full 433 * 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 the 452 * 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 full 462 * 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 the 484 * class name and the class primary key that are mirrors of the activity 485 * 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 full 494 * 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 full 527 * 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 name. 598 * 599 * @param className the target asset's class name 600 * @return the number of matching activities 601 * @throws SystemException if a system exception occurred 602 */ 603 public int getActivitiesCount(String className) throws SystemException { 604 long classNameId = PortalUtil.getClassNameId(className); 605 606 return getActivitiesCount(classNameId); 607 } 608 609 /** 610 * Returns the activity identified by its primary key. 611 * 612 * @param activityId the primary key of the activity 613 * @return Returns the activity 614 * @throws PortalException if the activity could not be found 615 * @throws SystemException if a system exception occurred 616 */ 617 public SocialActivity getActivity(long activityId) 618 throws PortalException, SystemException { 619 620 return socialActivityPersistence.findByPrimaryKey(activityId); 621 } 622 623 /** 624 * Returns a range of all the activities done in the group. 625 * 626 * <p> 627 * This method only finds activities without mirrors. 628 * </p> 629 * 630 * <p> 631 * Useful when paginating results. Returns a maximum of <code>end - 632 * start</code> instances. <code>start</code> and <code>end</code> are not 633 * primary keys, they are indexes in the result set. Thus, <code>0</code> 634 * refers to the first result in the set. Setting both <code>start</code> 635 * and <code>end</code> to {@link 636 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 637 * result set. 638 * </p> 639 * 640 * @param groupId the primary key of the group 641 * @param start the lower bound of the range of results 642 * @param end the upper bound of the range of results (not inclusive) 643 * @return the range of matching activities 644 * @throws SystemException if a system exception occurred 645 */ 646 public List<SocialActivity> getGroupActivities( 647 long groupId, int start, int end) 648 throws SystemException { 649 650 return socialActivityFinder.findByGroupId(groupId, start, end); 651 } 652 653 /** 654 * Returns the number of activities done in the group. 655 * 656 * <p> 657 * This method only counts activities without mirrors. 658 * </p> 659 * 660 * @param groupId the primary key of the group 661 * @return the number of matching activities 662 * @throws SystemException if a system exception occurred 663 */ 664 public int getGroupActivitiesCount(long groupId) throws SystemException { 665 return socialActivityFinder.countByGroupId(groupId); 666 } 667 668 /** 669 * Returns a range of activities done by users that are members of the 670 * group. 671 * 672 * <p> 673 * This method only finds activities without mirrors. 674 * </p> 675 * 676 * <p> 677 * Useful when paginating results. Returns a maximum of <code>end - 678 * start</code> instances. <code>start</code> and <code>end</code> are not 679 * primary keys, they are indexes in the result set. Thus, <code>0</code> 680 * refers to the first result in the set. Setting both <code>start</code> 681 * and <code>end</code> to {@link 682 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 683 * result set. 684 * </p> 685 * 686 * @param groupId the primary key of the group 687 * @param start the lower bound of the range of results 688 * @param end the upper bound of the range of results (not inclusive) 689 * @return the range of matching activities 690 * @throws SystemException if a system exception occurred 691 */ 692 public List<SocialActivity> getGroupUsersActivities( 693 long groupId, int start, int end) 694 throws SystemException { 695 696 return socialActivityFinder.findByGroupUsers(groupId, start, end); 697 } 698 699 /** 700 * Returns the number of activities done by users that are members of the 701 * group. 702 * 703 * <p> 704 * This method only counts activities without mirrors. 705 * </p> 706 * 707 * @param groupId the primary key of the group 708 * @return the number of matching activities 709 * @throws SystemException if a system exception occurred 710 */ 711 public int getGroupUsersActivitiesCount(long groupId) 712 throws SystemException { 713 714 return socialActivityFinder.countByGroupUsers(groupId); 715 } 716 717 /** 718 * Returns the activity that has the mirror activity. 719 * 720 * @param mirrorActivityId the primary key of the mirror activity 721 * @return Returns the mirror activity 722 * @throws PortalException if the mirror activity could not be found 723 * @throws SystemException if a system exception occurred 724 */ 725 public SocialActivity getMirrorActivity(long mirrorActivityId) 726 throws PortalException, SystemException { 727 728 return socialActivityPersistence.findByMirrorActivityId( 729 mirrorActivityId); 730 } 731 732 /** 733 * Returns a range of all the activities done in the organization. This 734 * method only finds activities without mirrors. 735 * 736 * <p> 737 * Useful when paginating results. Returns a maximum of <code>end - 738 * start</code> instances. <code>start</code> and <code>end</code> are not 739 * primary keys, they are indexes in the result set. Thus, <code>0</code> 740 * refers to the first result in the set. Setting both <code>start</code> 741 * and <code>end</code> to {@link 742 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 743 * result set. 744 * </p> 745 * 746 * @param organizationId the primary key of the organization 747 * @param start the lower bound of the range of results 748 * @param end the upper bound of the range of results (not inclusive) 749 * @return the range of matching activities 750 * @throws SystemException if a system exception occurred 751 */ 752 public List<SocialActivity> getOrganizationActivities( 753 long organizationId, int start, int end) 754 throws SystemException { 755 756 return socialActivityFinder.findByOrganizationId( 757 organizationId, start, end); 758 } 759 760 /** 761 * Returns the number of activities done in the organization. This method 762 * only counts activities without mirrors. 763 * 764 * @param organizationId the primary key of the organization 765 * @return the number of matching activities 766 * @throws SystemException if a system exception occurred 767 */ 768 public int getOrganizationActivitiesCount(long organizationId) 769 throws SystemException { 770 771 return socialActivityFinder.countByOrganizationId(organizationId); 772 } 773 774 /** 775 * Returns a range of all the activities done by users of the organization. 776 * This method only finds activities without mirrors. 777 * 778 * <p> 779 * Useful when paginating results. Returns a maximum of <code>end - 780 * start</code> instances. <code>start</code> and <code>end</code> are not 781 * primary keys, they are indexes in the result set. Thus, <code>0</code> 782 * refers to the first result in the set. Setting both <code>start</code> 783 * and <code>end</code> to {@link 784 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 785 * result set. 786 * </p> 787 * 788 * @param organizationId the primary key of the organization 789 * @param start the lower bound of the range of results 790 * @param end the upper bound of the range of results (not inclusive) 791 * @return the range of matching activities 792 * @throws SystemException if a system exception occurred 793 */ 794 public List<SocialActivity> getOrganizationUsersActivities( 795 long organizationId, int start, int end) 796 throws SystemException { 797 798 return socialActivityFinder.findByOrganizationUsers( 799 organizationId, start, end); 800 } 801 802 /** 803 * Returns the number of activities done by users of the organization. This 804 * method only counts activities without mirrors. 805 * 806 * @param organizationId the primary key of the organization 807 * @return the number of matching activities 808 * @throws SystemException if a system exception occurred 809 */ 810 public int getOrganizationUsersActivitiesCount(long organizationId) 811 throws SystemException { 812 813 return socialActivityFinder.countByOrganizationUsers(organizationId); 814 } 815 816 /** 817 * Returns a range of all the activities done by users in a relationship 818 * with the user identified by the user ID. 819 * 820 * <p> 821 * Useful when paginating results. Returns a maximum of <code>end - 822 * start</code> instances. <code>start</code> and <code>end</code> are not 823 * primary keys, they are indexes in the result set. Thus, <>0</code> refers 824 * to the first result in the set. Setting both <code>start</code> and 825 * <code>end</code> to {@link 826 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 827 * result set. 828 * </p> 829 * 830 * @param userId the primary key of the user 831 * @param start the lower bound of the range of results 832 * @param end the upper bound of the range of results (not inclusive) 833 * @return the range of matching activities 834 * @throws SystemException if a system exception occurred 835 */ 836 public List<SocialActivity> getRelationActivities( 837 long userId, int start, int end) 838 throws SystemException { 839 840 return socialActivityFinder.findByRelation(userId, start, end); 841 } 842 843 /** 844 * Returns a range of all the activities done by users in a relationship of 845 * type <code>type</code> with the user identified by <code>userId</code>. 846 * This method only finds activities without mirrors. 847 * 848 * <p> 849 * Useful when paginating results. Returns a maximum of <code>end - 850 * start</code> instances. <code>start</code> and <code>end</code> are not 851 * primary keys, they are indexes in the result set. Thus, <code>0</code> 852 * refers to the first result in the set. Setting both <code>start</code> 853 * and <code>end</code> to {@link 854 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 855 * result set. 856 * </p> 857 * 858 * @param userId the primary key of the user 859 * @param type the relationship type 860 * @param start the lower bound of the range of results 861 * @param end the upper bound of the range of results (not inclusive) 862 * @return the range of matching activities 863 * @throws SystemException if a system exception occurred 864 */ 865 public List<SocialActivity> getRelationActivities( 866 long userId, int type, int start, int end) 867 throws SystemException { 868 869 return socialActivityFinder.findByRelationType( 870 userId, type, start, end); 871 } 872 873 /** 874 * Returns the number of activities done by users in a relationship with the 875 * user identified by userId. 876 * 877 * @param userId the primary key of the user 878 * @return the number of matching activities 879 * @throws SystemException if a system exception occurred 880 */ 881 public int getRelationActivitiesCount(long userId) throws SystemException { 882 return socialActivityFinder.countByRelation(userId); 883 } 884 885 /** 886 * Returns the number of activities done by users in a relationship of type 887 * <code>type</code> with the user identified by <code>userId</code>. This 888 * method only counts activities without mirrors. 889 * 890 * @param userId the primary key of the user 891 * @param type the relationship type 892 * @return the number of matching activities 893 * @throws SystemException if a system exception occurred 894 */ 895 public int getRelationActivitiesCount(long userId, int type) 896 throws SystemException { 897 898 return socialActivityFinder.countByRelationType(userId, type); 899 } 900 901 /** 902 * Returns a range of all the activities done by the user. 903 * 904 * <p> 905 * Useful when paginating results. Returns a maximum of <code>end - 906 * start</code> instances. <code>start</code> and <code>end</code> are not 907 * primary keys, they are indexes in the result set. Thus, <code>0</code> 908 * refers to the first result in the set. Setting both <code>start</code> 909 * and <code>end</code> to {@link 910 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 911 * result set. 912 * </p> 913 * 914 * @param userId the primary key of the user 915 * @param start the lower bound of the range of results 916 * @param end the upper bound of the range of results (not inclusive) 917 * @return the range of matching activities 918 * @throws SystemException if a system exception occurred 919 */ 920 public List<SocialActivity> getUserActivities( 921 long userId, int start, int end) 922 throws SystemException { 923 924 return socialActivityPersistence.findByUserId(userId, start, end); 925 } 926 927 /** 928 * Returns the number of activities done by the user. 929 * 930 * @param userId the primary key of the user 931 * @return the number of matching activities 932 * @throws SystemException if a system exception occurred 933 */ 934 public int getUserActivitiesCount(long userId) throws SystemException { 935 return socialActivityPersistence.countByUserId(userId); 936 } 937 938 /** 939 * Returns a range of all the activities done in the user's groups. This 940 * method only finds activities without mirrors. 941 * 942 * <p> 943 * Useful when paginating results. Returns a maximum of <code>end - 944 * start</code> instances. <code>start</code> and <code>end</code> are not 945 * primary keys, they are indexes in the result set. Thus, <code>0</code> 946 * refers to the first result in the set. Setting both <code>start</code> 947 * and <code>end</code> to {@link 948 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 949 * result set. 950 * </p> 951 * 952 * @param userId the primary key of the user 953 * @param start the lower bound of the range of results 954 * @param end the upper bound of the range of results (not inclusive) 955 * @return the range of matching activities 956 * @throws SystemException if a system exception occurred 957 */ 958 public List<SocialActivity> getUserGroupsActivities( 959 long userId, int start, int end) 960 throws SystemException { 961 962 return socialActivityFinder.findByUserGroups(userId, start, end); 963 } 964 965 /** 966 * Returns the number of activities done in user's groups. This method only 967 * counts activities without mirrors. 968 * 969 * @param userId the primary key of the user 970 * @return the number of matching activities 971 * @throws SystemException if a system exception occurred 972 */ 973 public int getUserGroupsActivitiesCount(long userId) 974 throws SystemException { 975 976 return socialActivityFinder.countByUserGroups(userId); 977 } 978 979 /** 980 * Returns a range of all the activities done in the user's groups and 981 * organizations. This method only finds activities without mirrors. 982 * 983 * <p> 984 * Useful when paginating results. Returns a maximum of <code>end - 985 * start</code> instances. <code>start</code> and <code>end</code> are not 986 * primary keys, they are indexes in the result set. Thus, <code>0</code> 987 * refers to the first result in the set. Setting both <code>start</code> 988 * and <code>end</code> to {@link 989 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 990 * result set. 991 * </p> 992 * 993 * @param userId the primary key of the user 994 * @param start the lower bound of the range of results 995 * @param end the upper bound of the range of results (not inclusive) 996 * @return the range of matching activities 997 * @throws SystemException if a system exception occurred 998 */ 999 public List<SocialActivity> getUserGroupsAndOrganizationsActivities( 1000 long userId, int start, int end) 1001 throws SystemException { 1002 1003 return socialActivityFinder.findByUserGroupsAndOrganizations( 1004 userId, start, end); 1005 } 1006 1007 /** 1008 * Returns the number of activities done in user's groups and organizations. 1009 * This method only counts activities without mirrors. 1010 * 1011 * @param userId the primary key of the user 1012 * @return the number of matching activities 1013 * @throws SystemException if a system exception occurred 1014 */ 1015 public int getUserGroupsAndOrganizationsActivitiesCount(long userId) 1016 throws SystemException { 1017 1018 return socialActivityFinder.countByUserGroupsAndOrganizations(userId); 1019 } 1020 1021 /** 1022 * Returns a range of all activities done in the user's organizations. This 1023 * method only finds activities without mirrors. 1024 * 1025 * <p> 1026 * Useful when paginating results. Returns a maximum of <code>end - 1027 * start</code> instances. <code>start</code> and <code>end</code> are not 1028 * primary keys, they are indexes in the result set. Thus, <code>0</code> 1029 * refers to the first result in the set. Setting both <code>start</code> 1030 * and <code>end</code> to {@link 1031 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 1032 * result set. 1033 * </p> 1034 * 1035 * @param userId the primary key of the user 1036 * @param start the lower bound of the range of results 1037 * @param end the upper bound of the range of results (not inclusive) 1038 * @return the range of matching activities 1039 * @throws SystemException if a system exception occurred 1040 */ 1041 public List<SocialActivity> getUserOrganizationsActivities( 1042 long userId, int start, int end) 1043 throws SystemException { 1044 1045 return socialActivityFinder.findByUserOrganizations(userId, start, end); 1046 } 1047 1048 /** 1049 * Returns the number of activities done in the user's organizations. This 1050 * method only counts activities without mirrors. 1051 * 1052 * @param userId the primary key of the user 1053 * @return the number of matching activities 1054 * @throws SystemException if a system exception occurred 1055 */ 1056 public int getUserOrganizationsActivitiesCount(long userId) 1057 throws SystemException { 1058 1059 return socialActivityFinder.countByUserOrganizations(userId); 1060 } 1061 1062 }