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