001 /** 002 * Copyright (c) 2000-2012 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) && (activity.getType() < 10000)) || 225 ((activityDefinition != null) && 226 activityDefinition.isLogActivity())) { 227 228 long activityId = counterLocalService.increment( 229 SocialActivity.class.getName()); 230 231 activity.setActivityId(activityId); 232 233 socialActivityPersistence.update(activity, false); 234 235 if (mirrorActivity != null) { 236 long mirrorActivityId = counterLocalService.increment( 237 SocialActivity.class.getName()); 238 239 mirrorActivity.setActivityId(mirrorActivityId); 240 mirrorActivity.setMirrorActivityId(activity.getPrimaryKey()); 241 242 socialActivityPersistence.update(mirrorActivity, false); 243 } 244 } 245 246 socialActivityCounterLocalService.addActivityCounters(activity); 247 } 248 249 /** 250 * Records an activity in the database, but only if there isn't already an 251 * activity with the same parameters. 252 * 253 * <p> 254 * For the main functionality see {@link #addActivity(long, long, Date, 255 * String, long, int, String, long)} 256 * </p> 257 * 258 * @param userId the primary key of the acting user 259 * @param groupId the primary key of the group 260 * @param createDate the activity's date 261 * @param className the target asset's class name 262 * @param classPK the primary key of the target asset 263 * @param type the activity's type 264 * @param extraData any extra data regarding the activity 265 * @param receiverUserId the primary key of the receiving user 266 * @throws PortalException if the user or group could not be found 267 * @throws SystemException if a system exception occurred 268 */ 269 public void addUniqueActivity( 270 long userId, long groupId, Date createDate, String className, 271 long classPK, int type, String extraData, long receiverUserId) 272 throws PortalException, SystemException { 273 274 long classNameId = PortalUtil.getClassNameId(className); 275 276 SocialActivity socialActivity = 277 socialActivityPersistence.fetchByG_U_CD_C_C_T_R( 278 groupId, userId, createDate.getTime(), classNameId, classPK, 279 type, receiverUserId); 280 281 if (socialActivity != null) { 282 return; 283 } 284 285 addActivity( 286 userId, groupId, createDate, className, classPK, type, extraData, 287 receiverUserId); 288 } 289 290 /** 291 * Records an activity with the current time in the database, but only if 292 * there isn't one with the same parameters. 293 * 294 * <p> 295 * For the main functionality see {@link #addActivity(long, long, Date, 296 * String, long, int, String, long)} 297 * </p> 298 * 299 * @param userId the primary key of the acting user 300 * @param groupId the primary key of the group 301 * @param className the target asset's class name 302 * @param classPK the primary key of the target asset 303 * @param type the activity's type 304 * @param extraData any extra data regarding the activity 305 * @param receiverUserId the primary key of the receiving user 306 * @throws PortalException if the user or group could not be found 307 * @throws SystemException if a system exception occurred 308 */ 309 public void addUniqueActivity( 310 long userId, long groupId, String className, long classPK, int type, 311 String extraData, long receiverUserId) 312 throws PortalException, SystemException { 313 314 long classNameId = PortalUtil.getClassNameId(className); 315 316 int count = socialActivityPersistence.countByG_U_C_C_T_R( 317 groupId, userId, classNameId, classPK, type, receiverUserId); 318 319 if (count > 0) { 320 return; 321 } 322 323 addActivity( 324 userId, groupId, new Date(), className, classPK, type, extraData, 325 receiverUserId); 326 } 327 328 /** 329 * Removes stored activities for the asset identified by the class name ID 330 * and class primary key. 331 * 332 * @throws SystemException if a system exception occurred 333 */ 334 public void deleteActivities(AssetEntry assetEntry) 335 throws PortalException, SystemException { 336 337 socialActivityPersistence.removeByC_C( 338 assetEntry.getClassNameId(), assetEntry.getClassPK()); 339 340 socialActivityCounterLocalService.deleteActivityCounters(assetEntry); 341 } 342 343 /** 344 * Removes stored activities for the asset identified by the class name and 345 * class primary key. 346 * 347 * @param className the target asset's class name 348 * @param classPK the primary key of the target asset 349 * @throws SystemException if a system exception occurred 350 */ 351 public void deleteActivities(String className, long classPK) 352 throws SystemException { 353 354 long classNameId = PortalUtil.getClassNameId(className); 355 356 socialActivityPersistence.removeByC_C(classNameId, classPK); 357 } 358 359 /** 360 * Removes the stored activity from the database. 361 * 362 * @param activityId the primary key of the stored activity 363 * @throws PortalException if the activity could not be found 364 * @throws SystemException if a system exception occurred 365 */ 366 public void deleteActivity(long activityId) 367 throws PortalException, SystemException { 368 369 SocialActivity activity = socialActivityPersistence.findByPrimaryKey( 370 activityId); 371 372 deleteActivity(activity); 373 } 374 375 /** 376 * Removes the stored activity and its mirror activity from the database. 377 * 378 * @param activity the activity to be removed 379 * @throws SystemException if a system exception occurred 380 */ 381 public void deleteActivity(SocialActivity activity) throws SystemException { 382 socialActivityPersistence.remove(activity); 383 384 try { 385 socialActivityPersistence.removeByMirrorActivityId( 386 activity.getActivityId()); 387 } 388 catch (NoSuchActivityException nsae) { 389 } 390 } 391 392 /** 393 * Removes the user's stored activities from the database. 394 * 395 * <p> 396 * This method removes all activities where the user is either the actor or 397 * the receiver. 398 * </p> 399 * 400 * @param userId the primary key of the user 401 * @throws SystemException if a system exception occurred 402 */ 403 public void deleteUserActivities(long userId) throws SystemException { 404 List<SocialActivity> activities = 405 socialActivityPersistence.findByUserId( 406 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 407 408 for (SocialActivity activity : activities) { 409 socialActivityPersistence.remove(activity); 410 } 411 412 activities = socialActivityPersistence.findByReceiverUserId( 413 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); 414 415 for (SocialActivity activity : activities) { 416 socialActivityPersistence.remove(activity); 417 } 418 419 socialActivityCounterLocalService.deleteActivityCounters( 420 PortalUtil.getClassNameId(User.class.getName()), userId); 421 } 422 423 /** 424 * Returns a range of all the activities done on assets identified by the 425 * class name ID. 426 * 427 * <p> 428 * Useful when paginating results. Returns a maximum of <code>end - 429 * start</code> instances. <code>start</code> and <code>end</code> are not 430 * primary keys, they are indexes in the result set. Thus, <code>0</code> 431 * refers to the first result in the set. Setting both <code>start</code> 432 * and <code>end</code> to {@link 433 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 434 * result set. 435 * </p> 436 * 437 * @param classNameId the target asset's class name ID 438 * @param start the lower bound of the range of results 439 * @param end the upper bound of the range of results (not inclusive) 440 * @return the range of matching activities 441 * @throws SystemException if a system exception occurred 442 */ 443 public List<SocialActivity> getActivities( 444 long classNameId, int start, int end) 445 throws SystemException { 446 447 return socialActivityPersistence.findByClassNameId( 448 classNameId, start, end); 449 } 450 451 /** 452 * Returns a range of all the activities done on the asset identified by the 453 * class name ID and class primary key that are mirrors of the activity 454 * identified by the mirror activity ID. 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 462 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 463 * result set. 464 * </p> 465 * 466 * @param mirrorActivityId the primary key of the mirror activity 467 * @param classNameId the target asset's class name ID 468 * @param classPK the primary key of the target asset 469 * @param start the lower bound of the range of results 470 * @param end the upper bound of the range of results (not inclusive) 471 * @return the range of matching activities 472 * @throws SystemException if a system exception occurred 473 */ 474 public List<SocialActivity> getActivities( 475 long mirrorActivityId, long classNameId, long classPK, int start, 476 int end) 477 throws SystemException { 478 479 return socialActivityPersistence.findByM_C_C( 480 mirrorActivityId, classNameId, classPK, start, end); 481 } 482 483 /** 484 * Returns a range of all the activities done on the asset identified by the 485 * class name and the class primary key that are mirrors of the activity 486 * identified by the mirror activity ID. 487 * 488 * <p> 489 * Useful when paginating results. Returns a maximum of <code>end - 490 * start</code> instances. <code>start</code> and <code>end</code> are not 491 * primary keys, they are indexes in the result set. Thus, <code>0</code> 492 * refers to the first result in the set. Setting both <code>start</code> 493 * and <code>end</code> to {@link 494 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 495 * result set. 496 * </p> 497 * 498 * @param mirrorActivityId the primary key of the mirror activity 499 * @param className the target asset's class name 500 * @param classPK the primary key of the target asset 501 * @param start the lower bound of the range of results 502 * @param end the upper bound of the range of results (not inclusive) 503 * @return the range of matching activities 504 * @throws SystemException if a system exception occurred 505 */ 506 public List<SocialActivity> getActivities( 507 long mirrorActivityId, String className, long classPK, int start, 508 int end) 509 throws SystemException { 510 511 long classNameId = PortalUtil.getClassNameId(className); 512 513 return getActivities( 514 mirrorActivityId, classNameId, classPK, start, end); 515 } 516 517 /** 518 * Returns a range of all the activities done on assets identified by the 519 * class name. 520 * 521 * <p> 522 * Useful when paginating results. Returns a maximum of <code>end - 523 * start</code> instances. <code>start</code> and <code>end</code> are not 524 * primary keys, they are indexes in the result set. Thus, <code>0</code> 525 * refers to the first result in the set. Setting both <code>start</code> 526 * and <code>end</code> to {@link 527 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 528 * result set. 529 * </p> 530 * 531 * @param className the target asset's class name 532 * @param start the lower bound of the range of results 533 * @param end the upper bound of the range of results (not inclusive) 534 * @return the range of matching activities 535 * @throws SystemException if a system exception occurred 536 */ 537 public List<SocialActivity> getActivities( 538 String className, int start, int end) 539 throws SystemException { 540 541 long classNameId = PortalUtil.getClassNameId(className); 542 543 return getActivities(classNameId, start, end); 544 } 545 546 /** 547 * Returns the number of activities done on assets identified by the class 548 * name ID. 549 * 550 * @param classNameId the target asset's class name ID 551 * @return the number of matching activities 552 * @throws SystemException if a system exception occurred 553 */ 554 public int getActivitiesCount(long classNameId) throws SystemException { 555 return socialActivityPersistence.countByClassNameId(classNameId); 556 } 557 558 /** 559 * Returns the number of activities done on the asset identified by the 560 * class name ID and class primary key that are mirrors of the activity 561 * identified by the mirror activity ID. 562 * 563 * @param mirrorActivityId the primary key of the mirror activity 564 * @param classNameId the target asset's class name ID 565 * @param classPK the primary key of the target asset 566 * @return the number of matching activities 567 * @throws SystemException if a system exception occurred 568 */ 569 public int getActivitiesCount( 570 long mirrorActivityId, long classNameId, long classPK) 571 throws SystemException { 572 573 return socialActivityPersistence.countByM_C_C( 574 mirrorActivityId, classNameId, classPK); 575 } 576 577 /** 578 * Returns the number of activities done on the asset identified by the 579 * class name and class primary key that are mirrors of the activity 580 * identified by the mirror activity ID. 581 * 582 * @param mirrorActivityId the primary key of the mirror activity 583 * @param className the target asset's class name 584 * @param classPK the primary key of the target asset 585 * @return the number of matching activities 586 * @throws SystemException if a system exception occurred 587 */ 588 public int getActivitiesCount( 589 long mirrorActivityId, String className, long classPK) 590 throws SystemException { 591 592 long classNameId = PortalUtil.getClassNameId(className); 593 594 return getActivitiesCount(mirrorActivityId, classNameId, classPK); 595 } 596 597 /** 598 * Returns the number of activities done on assets identified by class 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 full 638 * 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 full 684 * 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 full 744 * 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 full 786 * 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> refers 825 * to the first result in the set. Setting both <code>start</code> and 826 * <code>end</code> to {@link 827 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 828 * 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 full 856 * 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 the 876 * 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 full 912 * 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 full 950 * 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 full 991 * 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 organizations. 1010 * 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 full 1033 * 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 }