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.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.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 (ExportImportThreadLocal.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 (ExportImportThreadLocal.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 (ExportImportThreadLocal.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            public SocialActivity fetchFirstActivity(
429                            String className, long classPK, int type)
430                    throws SystemException {
431    
432                    long classNameId = PortalUtil.getClassNameId(className);
433    
434                    return socialActivityPersistence.fetchByC_C_T_First(
435                            classNameId, classPK, type, null);
436            }
437    
438            /**
439             * Returns a range of all the activities done on assets identified by the
440             * class name ID.
441             *
442             * <p>
443             * Useful when paginating results. Returns a maximum of <code>end -
444             * start</code> instances. <code>start</code> and <code>end</code> are not
445             * primary keys, they are indexes in the result set. Thus, <code>0</code>
446             * refers to the first result in the set. Setting both <code>start</code>
447             * and <code>end</code> to {@link
448             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
449             * result set.
450             * </p>
451             *
452             * @param  classNameId the target asset's class name ID
453             * @param  start the lower bound of the range of results
454             * @param  end the upper bound of the range of results (not inclusive)
455             * @return the range of matching activities
456             * @throws SystemException if a system exception occurred
457             */
458            public List<SocialActivity> getActivities(
459                            long classNameId, int start, int end)
460                    throws SystemException {
461    
462                    return socialActivityPersistence.findByClassNameId(
463                            classNameId, start, end);
464            }
465    
466            /**
467             * Returns a range of all the activities done on the asset identified by the
468             * class name ID and class primary key that are mirrors of the activity
469             * identified by the mirror activity ID.
470             *
471             * <p>
472             * Useful when paginating results. Returns a maximum of <code>end -
473             * start</code> instances. <code>start</code> and <code>end</code> are not
474             * primary keys, they are indexes in the result set. Thus, <code>0</code>
475             * refers to the first result in the set. Setting both <code>start</code>
476             * and <code>end</code> to {@link
477             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
478             * result set.
479             * </p>
480             *
481             * @param  mirrorActivityId the primary key of the mirror activity
482             * @param  classNameId the target asset's class name ID
483             * @param  classPK the primary key of the target asset
484             * @param  start the lower bound of the range of results
485             * @param  end the upper bound of the range of results (not inclusive)
486             * @return the range of matching activities
487             * @throws SystemException if a system exception occurred
488             */
489            public List<SocialActivity> getActivities(
490                            long mirrorActivityId, long classNameId, long classPK, int start,
491                            int end)
492                    throws SystemException {
493    
494                    return socialActivityPersistence.findByM_C_C(
495                            mirrorActivityId, classNameId, classPK, start, end);
496            }
497    
498            /**
499             * Returns a range of all the activities done on the asset identified by the
500             * class name and the class primary key that are mirrors of the activity
501             * identified by the mirror activity ID.
502             *
503             * <p>
504             * Useful when paginating results. Returns a maximum of <code>end -
505             * start</code> instances. <code>start</code> and <code>end</code> are not
506             * primary keys, they are indexes in the result set. Thus, <code>0</code>
507             * refers to the first result in the set. Setting both <code>start</code>
508             * and <code>end</code> to {@link
509             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
510             * result set.
511             * </p>
512             *
513             * @param  mirrorActivityId the primary key of the mirror activity
514             * @param  className the target asset's class name
515             * @param  classPK the primary key of the target asset
516             * @param  start the lower bound of the range of results
517             * @param  end the upper bound of the range of results (not inclusive)
518             * @return the range of matching activities
519             * @throws SystemException if a system exception occurred
520             */
521            public List<SocialActivity> getActivities(
522                            long mirrorActivityId, String className, long classPK, int start,
523                            int end)
524                    throws SystemException {
525    
526                    long classNameId = PortalUtil.getClassNameId(className);
527    
528                    return getActivities(
529                            mirrorActivityId, classNameId, classPK, start, end);
530            }
531    
532            /**
533             * Returns a range of all the activities done on assets identified by the
534             * class name.
535             *
536             * <p>
537             * Useful when paginating results. Returns a maximum of <code>end -
538             * start</code> instances. <code>start</code> and <code>end</code> are not
539             * primary keys, they are indexes in the result set. Thus, <code>0</code>
540             * refers to the first result in the set. Setting both <code>start</code>
541             * and <code>end</code> to {@link
542             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
543             * result set.
544             * </p>
545             *
546             * @param  className the target asset's class name
547             * @param  start the lower bound of the range of results
548             * @param  end the upper bound of the range of results (not inclusive)
549             * @return the range of matching activities
550             * @throws SystemException if a system exception occurred
551             */
552            public List<SocialActivity> getActivities(
553                            String className, int start, int end)
554                    throws SystemException {
555    
556                    long classNameId = PortalUtil.getClassNameId(className);
557    
558                    return getActivities(classNameId, start, end);
559            }
560    
561            /**
562             * Returns the number of activities done on assets identified by the class
563             * name ID.
564             *
565             * @param  classNameId the target asset's class name ID
566             * @return the number of matching activities
567             * @throws SystemException if a system exception occurred
568             */
569            public int getActivitiesCount(long classNameId) throws SystemException {
570                    return socialActivityPersistence.countByClassNameId(classNameId);
571            }
572    
573            /**
574             * Returns the number of activities done on the asset identified by the
575             * class name ID and class primary key that are mirrors of the activity
576             * identified by the mirror activity ID.
577             *
578             * @param  mirrorActivityId the primary key of the mirror activity
579             * @param  classNameId the target asset's class name ID
580             * @param  classPK the primary key of the target asset
581             * @return the number of matching activities
582             * @throws SystemException if a system exception occurred
583             */
584            public int getActivitiesCount(
585                            long mirrorActivityId, long classNameId, long classPK)
586                    throws SystemException {
587    
588                    return socialActivityPersistence.countByM_C_C(
589                            mirrorActivityId, classNameId, classPK);
590            }
591    
592            /**
593             * Returns the number of activities done on the asset identified by the
594             * class name and class primary key that are mirrors of the activity
595             * identified by the mirror activity ID.
596             *
597             * @param  mirrorActivityId the primary key of the mirror activity
598             * @param  className the target asset's class name
599             * @param  classPK the primary key of the target asset
600             * @return the number of matching activities
601             * @throws SystemException if a system exception occurred
602             */
603            public int getActivitiesCount(
604                            long mirrorActivityId, String className, long classPK)
605                    throws SystemException {
606    
607                    long classNameId = PortalUtil.getClassNameId(className);
608    
609                    return getActivitiesCount(mirrorActivityId, classNameId, classPK);
610            }
611    
612            /**
613             * Returns the number of activities done on assets identified by class name.
614             *
615             * @param  className the target asset's class name
616             * @return the number of matching activities
617             * @throws SystemException if a system exception occurred
618             */
619            public int getActivitiesCount(String className) throws SystemException {
620                    long classNameId = PortalUtil.getClassNameId(className);
621    
622                    return getActivitiesCount(classNameId);
623            }
624    
625            /**
626             * Returns the activity identified by its primary key.
627             *
628             * @param  activityId the primary key of the activity
629             * @return Returns the activity
630             * @throws PortalException if the activity could not be found
631             * @throws SystemException if a system exception occurred
632             */
633            public SocialActivity getActivity(long activityId)
634                    throws PortalException, SystemException {
635    
636                    return socialActivityPersistence.findByPrimaryKey(activityId);
637            }
638    
639            public List<SocialActivity> getActivitySetActivities(
640                            long activitySetId, int start, int end)
641                    throws SystemException {
642    
643                    return socialActivityPersistence.findByActivitySetId(
644                            activitySetId, start, end);
645            }
646    
647            /**
648             * Returns a range of all the activities done in the group.
649             *
650             * <p>
651             * This method only finds activities without mirrors.
652             * </p>
653             *
654             * <p>
655             * Useful when paginating results. Returns a maximum of <code>end -
656             * start</code> instances. <code>start</code> and <code>end</code> are not
657             * primary keys, they are indexes in the result set. Thus, <code>0</code>
658             * refers to the first result in the set. Setting both <code>start</code>
659             * and <code>end</code> to {@link
660             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
661             * result set.
662             * </p>
663             *
664             * @param  groupId the primary key of the group
665             * @param  start the lower bound of the range of results
666             * @param  end the upper bound of the range of results (not inclusive)
667             * @return the range of matching activities
668             * @throws SystemException if a system exception occurred
669             */
670            public List<SocialActivity> getGroupActivities(
671                            long groupId, int start, int end)
672                    throws SystemException {
673    
674                    return socialActivityFinder.findByGroupId(groupId, start, end);
675            }
676    
677            /**
678             * Returns the number of activities done in the group.
679             *
680             * <p>
681             * This method only counts activities without mirrors.
682             * </p>
683             *
684             * @param  groupId the primary key of the group
685             * @return the number of matching activities
686             * @throws SystemException if a system exception occurred
687             */
688            public int getGroupActivitiesCount(long groupId) throws SystemException {
689                    return socialActivityFinder.countByGroupId(groupId);
690            }
691    
692            /**
693             * Returns a range of activities done by users that are members of the
694             * group.
695             *
696             * <p>
697             * This method only finds activities without mirrors.
698             * </p>
699             *
700             * <p>
701             * Useful when paginating results. Returns a maximum of <code>end -
702             * start</code> instances. <code>start</code> and <code>end</code> are not
703             * primary keys, they are indexes in the result set. Thus, <code>0</code>
704             * refers to the first result in the set. Setting both <code>start</code>
705             * and <code>end</code> to {@link
706             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
707             * result set.
708             * </p>
709             *
710             * @param  groupId the primary key of the group
711             * @param  start the lower bound of the range of results
712             * @param  end the upper bound of the range of results (not inclusive)
713             * @return the range of matching activities
714             * @throws SystemException if a system exception occurred
715             */
716            public List<SocialActivity> getGroupUsersActivities(
717                            long groupId, int start, int end)
718                    throws SystemException {
719    
720                    return socialActivityFinder.findByGroupUsers(groupId, start, end);
721            }
722    
723            /**
724             * Returns the number of activities done by users that are members of the
725             * group.
726             *
727             * <p>
728             * This method only counts activities without mirrors.
729             * </p>
730             *
731             * @param  groupId the primary key of the group
732             * @return the number of matching activities
733             * @throws SystemException if a system exception occurred
734             */
735            public int getGroupUsersActivitiesCount(long groupId)
736                    throws SystemException {
737    
738                    return socialActivityFinder.countByGroupUsers(groupId);
739            }
740    
741            /**
742             * Returns the activity that has the mirror activity.
743             *
744             * @param  mirrorActivityId the primary key of the mirror activity
745             * @return Returns the mirror activity
746             * @throws PortalException if the mirror activity could not be found
747             * @throws SystemException if a system exception occurred
748             */
749            public SocialActivity getMirrorActivity(long mirrorActivityId)
750                    throws PortalException, SystemException {
751    
752                    return socialActivityPersistence.findByMirrorActivityId(
753                            mirrorActivityId);
754            }
755    
756            /**
757             * Returns a range of all the activities done in the organization. This
758             * method only finds activities without mirrors.
759             *
760             * <p>
761             * Useful when paginating results. Returns a maximum of <code>end -
762             * start</code> instances. <code>start</code> and <code>end</code> are not
763             * primary keys, they are indexes in the result set. Thus, <code>0</code>
764             * refers to the first result in the set. Setting both <code>start</code>
765             * and <code>end</code> to {@link
766             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
767             * result set.
768             * </p>
769             *
770             * @param  organizationId the primary key of the organization
771             * @param  start the lower bound of the range of results
772             * @param  end the upper bound of the range of results (not inclusive)
773             * @return the range of matching activities
774             * @throws SystemException if a system exception occurred
775             */
776            public List<SocialActivity> getOrganizationActivities(
777                            long organizationId, int start, int end)
778                    throws SystemException {
779    
780                    return socialActivityFinder.findByOrganizationId(
781                            organizationId, start, end);
782            }
783    
784            /**
785             * Returns the number of activities done in the organization. This method
786             * only counts activities without mirrors.
787             *
788             * @param  organizationId the primary key of the organization
789             * @return the number of matching activities
790             * @throws SystemException if a system exception occurred
791             */
792            public int getOrganizationActivitiesCount(long organizationId)
793                    throws SystemException {
794    
795                    return socialActivityFinder.countByOrganizationId(organizationId);
796            }
797    
798            /**
799             * Returns a range of all the activities done by users of the organization.
800             * This method only finds activities without mirrors.
801             *
802             * <p>
803             * Useful when paginating results. Returns a maximum of <code>end -
804             * start</code> instances. <code>start</code> and <code>end</code> are not
805             * primary keys, they are indexes in the result set. Thus, <code>0</code>
806             * refers to the first result in the set. Setting both <code>start</code>
807             * and <code>end</code> to {@link
808             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
809             * result set.
810             * </p>
811             *
812             * @param  organizationId the primary key of the organization
813             * @param  start the lower bound of the range of results
814             * @param  end the upper bound of the range of results (not inclusive)
815             * @return the range of matching activities
816             * @throws SystemException if a system exception occurred
817             */
818            public List<SocialActivity> getOrganizationUsersActivities(
819                            long organizationId, int start, int end)
820                    throws SystemException {
821    
822                    return socialActivityFinder.findByOrganizationUsers(
823                            organizationId, start, end);
824            }
825    
826            /**
827             * Returns the number of activities done by users of the organization. This
828             * method only counts activities without mirrors.
829             *
830             * @param  organizationId the primary key of the organization
831             * @return the number of matching activities
832             * @throws SystemException if a system exception occurred
833             */
834            public int getOrganizationUsersActivitiesCount(long organizationId)
835                    throws SystemException {
836    
837                    return socialActivityFinder.countByOrganizationUsers(organizationId);
838            }
839    
840            /**
841             * Returns a range of all the activities done by users in a relationship
842             * with the user identified by the user ID.
843             *
844             * <p>
845             * Useful when paginating results. Returns a maximum of <code>end -
846             * start</code> instances. <code>start</code> and <code>end</code> are not
847             * primary keys, they are indexes in the result set. Thus, <>0</code> refers
848             * to the first result in the set. Setting both <code>start</code> and
849             * <code>end</code> to {@link
850             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
851             * result set.
852             * </p>
853             *
854             * @param  userId the primary key of the user
855             * @param  start the lower bound of the range of results
856             * @param  end the upper bound of the range of results (not inclusive)
857             * @return the range of matching activities
858             * @throws SystemException if a system exception occurred
859             */
860            public List<SocialActivity> getRelationActivities(
861                            long userId, int start, int end)
862                    throws SystemException {
863    
864                    return socialActivityFinder.findByRelation(userId, start, end);
865            }
866    
867            /**
868             * Returns a range of all the activities done by users in a relationship of
869             * type <code>type</code> with the user identified by <code>userId</code>.
870             * This method only finds activities without mirrors.
871             *
872             * <p>
873             * Useful when paginating results. Returns a maximum of <code>end -
874             * start</code> instances. <code>start</code> and <code>end</code> are not
875             * primary keys, they are indexes in the result set. Thus, <code>0</code>
876             * refers to the first result in the set. Setting both <code>start</code>
877             * and <code>end</code> to {@link
878             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
879             * result set.
880             * </p>
881             *
882             * @param  userId the primary key of the user
883             * @param  type the relationship type
884             * @param  start the lower bound of the range of results
885             * @param  end the upper bound of the range of results (not inclusive)
886             * @return the range of matching activities
887             * @throws SystemException if a system exception occurred
888             */
889            public List<SocialActivity> getRelationActivities(
890                            long userId, int type, int start, int end)
891                    throws SystemException {
892    
893                    return socialActivityFinder.findByRelationType(
894                            userId, type, start, end);
895            }
896    
897            /**
898             * Returns the number of activities done by users in a relationship with the
899             * user identified by userId.
900             *
901             * @param  userId the primary key of the user
902             * @return the number of matching activities
903             * @throws SystemException if a system exception occurred
904             */
905            public int getRelationActivitiesCount(long userId) throws SystemException {
906                    return socialActivityFinder.countByRelation(userId);
907            }
908    
909            /**
910             * Returns the number of activities done by users in a relationship of type
911             * <code>type</code> with the user identified by <code>userId</code>. This
912             * method only counts activities without mirrors.
913             *
914             * @param  userId the primary key of the user
915             * @param  type the relationship type
916             * @return the number of matching activities
917             * @throws SystemException if a system exception occurred
918             */
919            public int getRelationActivitiesCount(long userId, int type)
920                    throws SystemException {
921    
922                    return socialActivityFinder.countByRelationType(userId, type);
923            }
924    
925            /**
926             * Returns a range of all the activities done by the user.
927             *
928             * <p>
929             * Useful when paginating results. Returns a maximum of <code>end -
930             * start</code> instances. <code>start</code> and <code>end</code> are not
931             * primary keys, they are indexes in the result set. Thus, <code>0</code>
932             * refers to the first result in the set. Setting both <code>start</code>
933             * and <code>end</code> to {@link
934             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
935             * result set.
936             * </p>
937             *
938             * @param  userId the primary key of the user
939             * @param  start the lower bound of the range of results
940             * @param  end the upper bound of the range of results (not inclusive)
941             * @return the range of matching activities
942             * @throws SystemException if a system exception occurred
943             */
944            public List<SocialActivity> getUserActivities(
945                            long userId, int start, int end)
946                    throws SystemException {
947    
948                    return socialActivityPersistence.findByUserId(userId, start, end);
949            }
950    
951            /**
952             * Returns the number of activities done by the user.
953             *
954             * @param  userId the primary key of the user
955             * @return the number of matching activities
956             * @throws SystemException if a system exception occurred
957             */
958            public int getUserActivitiesCount(long userId) throws SystemException {
959                    return socialActivityPersistence.countByUserId(userId);
960            }
961    
962            /**
963             * Returns a range of all the activities done in the user's groups. This
964             * method only finds activities without mirrors.
965             *
966             * <p>
967             * Useful when paginating results. Returns a maximum of <code>end -
968             * start</code> instances. <code>start</code> and <code>end</code> are not
969             * primary keys, they are indexes in the result set. Thus, <code>0</code>
970             * refers to the first result in the set. Setting both <code>start</code>
971             * and <code>end</code> to {@link
972             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
973             * result set.
974             * </p>
975             *
976             * @param  userId the primary key of the user
977             * @param  start the lower bound of the range of results
978             * @param  end the upper bound of the range of results (not inclusive)
979             * @return the range of matching activities
980             * @throws SystemException if a system exception occurred
981             */
982            public List<SocialActivity> getUserGroupsActivities(
983                            long userId, int start, int end)
984                    throws SystemException {
985    
986                    return socialActivityFinder.findByUserGroups(userId, start, end);
987            }
988    
989            /**
990             * Returns the number of activities done in user's groups. This method only
991             * counts activities without mirrors.
992             *
993             * @param  userId the primary key of the user
994             * @return the number of matching activities
995             * @throws SystemException if a system exception occurred
996             */
997            public int getUserGroupsActivitiesCount(long userId)
998                    throws SystemException {
999    
1000                    return socialActivityFinder.countByUserGroups(userId);
1001            }
1002    
1003            /**
1004             * Returns a range of all the activities done in the user's groups and
1005             * organizations. This method only finds activities without mirrors.
1006             *
1007             * <p>
1008             * Useful when paginating results. Returns a maximum of <code>end -
1009             * start</code> instances. <code>start</code> and <code>end</code> are not
1010             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1011             * refers to the first result in the set. Setting both <code>start</code>
1012             * and <code>end</code> to {@link
1013             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1014             * result set.
1015             * </p>
1016             *
1017             * @param  userId the primary key of the user
1018             * @param  start the lower bound of the range of results
1019             * @param  end the upper bound of the range of results (not inclusive)
1020             * @return the range of matching activities
1021             * @throws SystemException if a system exception occurred
1022             */
1023            public List<SocialActivity> getUserGroupsAndOrganizationsActivities(
1024                            long userId, int start, int end)
1025                    throws SystemException {
1026    
1027                    return socialActivityFinder.findByUserGroupsAndOrganizations(
1028                            userId, start, end);
1029            }
1030    
1031            /**
1032             * Returns the number of activities done in user's groups and organizations.
1033             * This method only counts activities without mirrors.
1034             *
1035             * @param  userId the primary key of the user
1036             * @return the number of matching activities
1037             * @throws SystemException if a system exception occurred
1038             */
1039            public int getUserGroupsAndOrganizationsActivitiesCount(long userId)
1040                    throws SystemException {
1041    
1042                    return socialActivityFinder.countByUserGroupsAndOrganizations(userId);
1043            }
1044    
1045            /**
1046             * Returns a range of all activities done in the user's organizations. This
1047             * method only finds activities without mirrors.
1048             *
1049             * <p>
1050             * Useful when paginating results. Returns a maximum of <code>end -
1051             * start</code> instances. <code>start</code> and <code>end</code> are not
1052             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1053             * refers to the first result in the set. Setting both <code>start</code>
1054             * and <code>end</code> to {@link
1055             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1056             * result set.
1057             * </p>
1058             *
1059             * @param  userId the primary key of the user
1060             * @param  start the lower bound of the range of results
1061             * @param  end the upper bound of the range of results (not inclusive)
1062             * @return the range of matching activities
1063             * @throws SystemException if a system exception occurred
1064             */
1065            public List<SocialActivity> getUserOrganizationsActivities(
1066                            long userId, int start, int end)
1067                    throws SystemException {
1068    
1069                    return socialActivityFinder.findByUserOrganizations(userId, start, end);
1070            }
1071    
1072            /**
1073             * Returns the number of activities done in the user's organizations. This
1074             * method only counts activities without mirrors.
1075             *
1076             * @param  userId the primary key of the user
1077             * @return the number of matching activities
1078             * @throws SystemException if a system exception occurred
1079             */
1080            public int getUserOrganizationsActivitiesCount(long userId)
1081                    throws SystemException {
1082    
1083                    return socialActivityFinder.countByUserOrganizations(userId);
1084            }
1085    
1086    }