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