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