001    /**
002     * Copyright (c) 2000-present 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.util.StringPool;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.security.permission.PermissionChecker;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portal.util.PropsValues;
025    import com.liferay.portlet.social.model.SocialActivity;
026    import com.liferay.portlet.social.model.SocialActivityInterpreter;
027    import com.liferay.portlet.social.model.impl.SocialActivityInterpreterImpl;
028    import com.liferay.portlet.social.service.base.SocialActivityServiceBaseImpl;
029    
030    import java.util.ArrayList;
031    import java.util.List;
032    
033    /**
034     * Provides the remote service for accessing social activities. Its methods
035     * include permission checks.
036     *
037     * @author Zsolt Berentey
038     */
039    public class SocialActivityServiceImpl extends SocialActivityServiceBaseImpl {
040    
041            /**
042             * Returns a range of all the activities done on assets identified by the
043             * class name ID.
044             *
045             * <p>
046             * Useful when paginating results. Returns a maximum of <code>end -
047             * start</code> instances. <code>start</code> and <code>end</code> are not
048             * primary keys, they are indexes in the result set. Thus, <code>0</code>
049             * refers to the first result in the set. Setting both <code>start</code>
050             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
051             * result set.
052             * </p>
053             *
054             * @param  classNameId the target asset's class name ID
055             * @param  start the lower bound of the range of results
056             * @param  end the upper bound of the range of results (not inclusive)
057             * @return the range of matching activities
058             */
059            @Override
060            public List<SocialActivity> getActivities(
061                            long classNameId, int start, int end)
062                    throws PortalException {
063    
064                    List<SocialActivity> activities =
065                            socialActivityLocalService.getActivities(
066                                    classNameId, 0,
067                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
068    
069                    return filterActivities(activities, start, end);
070            }
071    
072            /**
073             * Returns a range of all the activities done on the asset identified by the
074             * class name ID and class primary key that are mirrors of the activity
075             * identified by the mirror activity ID.
076             *
077             * <p>
078             * Useful when paginating results. Returns a maximum of <code>end -
079             * start</code> instances. <code>start</code> and <code>end</code> are not
080             * primary keys, they are indexes in the result set. Thus, <code>0</code>
081             * refers to the first result in the set. Setting both <code>start</code>
082             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
083             * result set.
084             * </p>
085             *
086             * @param  mirrorActivityId the primary key of the mirror activity
087             * @param  classNameId the target asset's class name ID
088             * @param  classPK the primary key of the target asset
089             * @param  start the lower bound of the range of results
090             * @param  end the upper bound of the range of results (not inclusive)
091             * @return the range of matching activities
092             */
093            @Override
094            public List<SocialActivity> getActivities(
095                            long mirrorActivityId, long classNameId, long classPK, int start,
096                            int end)
097                    throws PortalException {
098    
099                    List<SocialActivity> activities =
100                            socialActivityLocalService.getActivities(
101                                    mirrorActivityId, classNameId, classPK, 0,
102                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
103    
104                    return filterActivities(activities, start, end);
105            }
106    
107            /**
108             * Returns a range of all the activities done on the asset identified by the
109             * class name and the class primary key that are mirrors of the activity
110             * identified by the mirror activity ID.
111             *
112             * <p>
113             * Useful when paginating results. Returns a maximum of <code>end -
114             * start</code> instances. <code>start</code> and <code>end</code> are not
115             * primary keys, they are indexes in the result set. Thus, <code>0</code>
116             * refers to the first result in the set. Setting both <code>start</code>
117             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
118             * result set.
119             * </p>
120             *
121             * @param  mirrorActivityId the primary key of the mirror activity
122             * @param  className the target asset's class name
123             * @param  classPK the primary key of the target asset
124             * @param  start the lower bound of the range of results
125             * @param  end the upper bound of the range of results (not inclusive)
126             * @return the range of matching activities
127             */
128            @Override
129            public List<SocialActivity> getActivities(
130                            long mirrorActivityId, String className, long classPK, int start,
131                            int end)
132                    throws PortalException {
133    
134                    long classNameId = classNameLocalService.getClassNameId(className);
135    
136                    List<SocialActivity> activities =
137                            socialActivityLocalService.getActivities(
138                                    mirrorActivityId, classNameId, classPK, 0,
139                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
140    
141                    return filterActivities(activities, start, end);
142            }
143    
144            /**
145             * Returns a range of all the activities done on assets identified by the
146             * class name.
147             *
148             * <p>
149             * Useful when paginating results. Returns a maximum of <code>end -
150             * start</code> instances. <code>start</code> and <code>end</code> are not
151             * primary keys, they are indexes in the result set. Thus, <code>0</code>
152             * refers to the first result in the set. Setting both <code>start</code>
153             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
154             * result set.
155             * </p>
156             *
157             * @param  className the target asset's class name
158             * @param  start the lower bound of the range of results
159             * @param  end the upper bound of the range of results (not inclusive)
160             * @return the range of matching activities
161             */
162            @Override
163            public List<SocialActivity> getActivities(
164                            String className, int start, int end)
165                    throws PortalException {
166    
167                    long classNameId = classNameLocalService.getClassNameId(className);
168    
169                    List<SocialActivity> activities =
170                            socialActivityLocalService.getActivities(
171                                    classNameId, 0,
172                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
173    
174                    return filterActivities(activities, start, end);
175            }
176    
177            /**
178             * Returns the number of activities done on assets identified by the class
179             * name ID.
180             *
181             * @param  classNameId the target asset's class name ID
182             * @return the number of matching activities
183             */
184            @Override
185            public int getActivitiesCount(long classNameId) {
186                    return socialActivityLocalService.getActivitiesCount(classNameId);
187            }
188    
189            /**
190             * Returns the number of activities done on the asset identified by the
191             * class name ID and class primary key that are mirrors of the activity
192             * identified by the mirror activity ID.
193             *
194             * @param  mirrorActivityId the primary key of the mirror activity
195             * @param  classNameId the target asset's class name ID
196             * @param  classPK the primary key of the target asset
197             * @return the number of matching activities
198             */
199            @Override
200            public int getActivitiesCount(
201                    long mirrorActivityId, long classNameId, long classPK) {
202    
203                    return socialActivityLocalService.getActivitiesCount(
204                            mirrorActivityId, classNameId, classPK);
205            }
206    
207            /**
208             * Returns the number of activities done on the asset identified by the
209             * class name and class primary key that are mirrors of the activity
210             * identified by the mirror activity ID.
211             *
212             * @param  mirrorActivityId the primary key of the mirror activity
213             * @param  className the target asset's class name
214             * @param  classPK the primary key of the target asset
215             * @return the number of matching activities
216             */
217            @Override
218            public int getActivitiesCount(
219                    long mirrorActivityId, String className, long classPK) {
220    
221                    long classNameId = classNameLocalService.getClassNameId(className);
222    
223                    return getActivitiesCount(mirrorActivityId, classNameId, classPK);
224            }
225    
226            /**
227             * Returns the number of activities done on assets identified by class name.
228             *
229             * @param  className the target asset's class name
230             * @return the number of matching activities
231             */
232            @Override
233            public int getActivitiesCount(String className) {
234                    long classNameId = classNameLocalService.getClassNameId(className);
235    
236                    return getActivitiesCount(classNameId);
237            }
238    
239            /**
240             * Returns the activity identified by its primary key.
241             *
242             * @param  activityId the primary key of the activity
243             * @return Returns the activity
244             */
245            @Override
246            public SocialActivity getActivity(long activityId) throws PortalException {
247                    SocialActivity activity = socialActivityLocalService.getActivity(
248                            activityId);
249    
250                    List<SocialActivityInterpreter> activityInterpreters =
251                            socialActivityInterpreterLocalService.getActivityInterpreters(
252                                    StringPool.BLANK);
253    
254                    if (!hasPermission(activity, activityInterpreters)) {
255                            throw new PrincipalException.MustHavePermission(
256                                    0, SocialActivity.class.getName(), activityId);
257                    }
258    
259                    return activity;
260            }
261    
262            @Override
263            public List<SocialActivity> getActivitySetActivities(
264                            long activitySetId, int start, int end)
265                    throws PortalException {
266    
267                    List<SocialActivity> activities =
268                            socialActivityLocalService.getActivitySetActivities(
269                                    activitySetId, start, end);
270    
271                    return filterActivities(activities, start, end);
272            }
273    
274            /**
275             * Returns a range of all the activities done in the group.
276             *
277             * <p>
278             * This method only finds activities without mirrors.
279             * </p>
280             *
281             * <p>
282             * Useful when paginating results. Returns a maximum of <code>end -
283             * start</code> instances. <code>start</code> and <code>end</code> are not
284             * primary keys, they are indexes in the result set. Thus, <code>0</code>
285             * refers to the first result in the set. Setting both <code>start</code>
286             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
287             * result set.
288             * </p>
289             *
290             * @param  groupId the primary key of the group
291             * @param  start the lower bound of the range of results
292             * @param  end the upper bound of the range of results (not inclusive)
293             * @return the range of matching activities
294             */
295            @Override
296            public List<SocialActivity> getGroupActivities(
297                            long groupId, int start, int end)
298                    throws PortalException {
299    
300                    List<SocialActivity> activities =
301                            socialActivityLocalService.getGroupActivities(
302                                    groupId, 0,
303                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
304    
305                    return filterActivities(activities, start, end);
306            }
307    
308            /**
309             * Returns the number of activities done in the group.
310             *
311             * <p>
312             * This method only counts activities without mirrors.
313             * </p>
314             *
315             * @param  groupId the primary key of the group
316             * @return the number of matching activities
317             */
318            @Override
319            public int getGroupActivitiesCount(long groupId) {
320                    return socialActivityLocalService.getGroupActivitiesCount(groupId);
321            }
322    
323            /**
324             * Returns a range of activities done by users that are members of the
325             * group.
326             *
327             * <p>
328             * This method only finds activities without mirrors.
329             * </p>
330             *
331             * <p>
332             * Useful when paginating results. Returns a maximum of <code>end -
333             * start</code> instances. <code>start</code> and <code>end</code> are not
334             * primary keys, they are indexes in the result set. Thus, <code>0</code>
335             * refers to the first result in the set. Setting both <code>start</code>
336             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
337             * result set.
338             * </p>
339             *
340             * @param  groupId the primary key of the group
341             * @param  start the lower bound of the range of results
342             * @param  end the upper bound of the range of results (not inclusive)
343             * @return the range of matching activities
344             */
345            @Override
346            public List<SocialActivity> getGroupUsersActivities(
347                            long groupId, int start, int end)
348                    throws PortalException {
349    
350                    List<SocialActivity> activities =
351                            socialActivityLocalService.getGroupUsersActivities(
352                                    groupId, 0,
353                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
354    
355                    return filterActivities(activities, start, end);
356            }
357    
358            /**
359             * Returns the number of activities done by users that are members of the
360             * group.
361             *
362             * <p>
363             * This method only counts activities without mirrors.
364             * </p>
365             *
366             * @param  groupId the primary key of the group
367             * @return the number of matching activities
368             */
369            @Override
370            public int getGroupUsersActivitiesCount(long groupId) {
371                    return socialActivityLocalService.getGroupUsersActivitiesCount(groupId);
372            }
373    
374            /**
375             * Returns the activity that has the mirror activity.
376             *
377             * @param  mirrorActivityId the primary key of the mirror activity
378             * @return Returns the mirror activity
379             */
380            @Override
381            public SocialActivity getMirrorActivity(long mirrorActivityId)
382                    throws PortalException {
383    
384                    SocialActivity activity = socialActivityLocalService.getMirrorActivity(
385                            mirrorActivityId);
386    
387                    List<SocialActivityInterpreter> activityInterpreters =
388                            socialActivityInterpreterLocalService.getActivityInterpreters(
389                                    StringPool.BLANK);
390    
391                    if (!hasPermission(activity, activityInterpreters)) {
392                            throw new PrincipalException.MustHavePermission(
393                                    0, SocialActivity.class.getName(), mirrorActivityId);
394                    }
395    
396                    return activity;
397            }
398    
399            /**
400             * Returns a range of all the activities done in the organization. This
401             * method only finds activities without mirrors.
402             *
403             * <p>
404             * Useful when paginating results. Returns a maximum of <code>end -
405             * start</code> instances. <code>start</code> and <code>end</code> are not
406             * primary keys, they are indexes in the result set. Thus, <code>0</code>
407             * refers to the first result in the set. Setting both <code>start</code>
408             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
409             * result set.
410             * </p>
411             *
412             * @param  organizationId the primary key of the organization
413             * @param  start the lower bound of the range of results
414             * @param  end the upper bound of the range of results (not inclusive)
415             * @return the range of matching activities
416             */
417            @Override
418            public List<SocialActivity> getOrganizationActivities(
419                            long organizationId, int start, int end)
420                    throws PortalException {
421    
422                    List<SocialActivity> activities =
423                            socialActivityLocalService.getOrganizationActivities(
424                                    organizationId, 0,
425                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
426    
427                    return filterActivities(activities, start, end);
428            }
429    
430            /**
431             * Returns the number of activities done in the organization. This method
432             * only counts activities without mirrors.
433             *
434             * @param  organizationId the primary key of the organization
435             * @return the number of matching activities
436             */
437            @Override
438            public int getOrganizationActivitiesCount(long organizationId) {
439                    return socialActivityLocalService.getOrganizationActivitiesCount(
440                            organizationId);
441            }
442    
443            /**
444             * Returns a range of all the activities done by users of the organization.
445             * This method only finds activities without mirrors.
446             *
447             * <p>
448             * Useful when paginating results. Returns a maximum of <code>end -
449             * start</code> instances. <code>start</code> and <code>end</code> are not
450             * primary keys, they are indexes in the result set. Thus, <code>0</code>
451             * refers to the first result in the set. Setting both <code>start</code>
452             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
453             * result set.
454             * </p>
455             *
456             * @param  organizationId the primary key of the organization
457             * @param  start the lower bound of the range of results
458             * @param  end the upper bound of the range of results (not inclusive)
459             * @return the range of matching activities
460             */
461            @Override
462            public List<SocialActivity> getOrganizationUsersActivities(
463                            long organizationId, int start, int end)
464                    throws PortalException {
465    
466                    List<SocialActivity> activities =
467                            socialActivityLocalService.getOrganizationUsersActivities(
468                                    organizationId, 0,
469                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
470    
471                    return filterActivities(activities, start, end);
472            }
473    
474            /**
475             * Returns the number of activities done by users of the organization. This
476             * method only counts activities without mirrors.
477             *
478             * @param  organizationId the primary key of the organization
479             * @return the number of matching activities
480             */
481            @Override
482            public int getOrganizationUsersActivitiesCount(long organizationId) {
483                    return socialActivityLocalService.getOrganizationUsersActivitiesCount(
484                            organizationId);
485            }
486    
487            /**
488             * Returns a range of all the activities done by users in a relationship
489             * with the user identified by the user ID.
490             *
491             * <p>
492             * Useful when paginating results. Returns a maximum of <code>end -
493             * start</code> instances. <code>start</code> and <code>end</code> are not
494             * primary keys, they are indexes in the result set. Thus, <>0</code> refers
495             * to the first result in the set. Setting both <code>start</code> and
496             * <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result
497             * set.
498             * </p>
499             *
500             * @param  userId the primary key of the user
501             * @param  start the lower bound of the range of results
502             * @param  end the upper bound of the range of results (not inclusive)
503             * @return the range of matching activities
504             */
505            @Override
506            public List<SocialActivity> getRelationActivities(
507                            long userId, int start, int end)
508                    throws PortalException {
509    
510                    List<SocialActivity> activities =
511                            socialActivityLocalService.getRelationActivities(
512                                    userId, 0,
513                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
514    
515                    return filterActivities(activities, start, end);
516            }
517    
518            /**
519             * Returns a range of all the activities done by users in a relationship of
520             * type <code>type</code> with the user identified by <code>userId</code>.
521             * This method only finds activities without mirrors.
522             *
523             * <p>
524             * Useful when paginating results. Returns a maximum of <code>end -
525             * start</code> instances. <code>start</code> and <code>end</code> are not
526             * primary keys, they are indexes in the result set. Thus, <code>0</code>
527             * refers to the first result in the set. Setting both <code>start</code>
528             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
529             * result set.
530             * </p>
531             *
532             * @param  userId the primary key of the user
533             * @param  type the relationship type
534             * @param  start the lower bound of the range of results
535             * @param  end the upper bound of the range of results (not inclusive)
536             * @return the range of matching activities
537             */
538            @Override
539            public List<SocialActivity> getRelationActivities(
540                            long userId, int type, int start, int end)
541                    throws PortalException {
542    
543                    List<SocialActivity> activities =
544                            socialActivityLocalService.getRelationActivities(
545                                    userId, type, 0,
546                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
547    
548                    return filterActivities(activities, start, end);
549            }
550    
551            /**
552             * Returns the number of activities done by users in a relationship with the
553             * user identified by userId.
554             *
555             * @param  userId the primary key of the user
556             * @return the number of matching activities
557             */
558            @Override
559            public int getRelationActivitiesCount(long userId) {
560                    return socialActivityLocalService.getRelationActivitiesCount(userId);
561            }
562    
563            /**
564             * Returns the number of activities done by users in a relationship of type
565             * <code>type</code> with the user identified by <code>userId</code>. This
566             * method only counts activities without mirrors.
567             *
568             * @param  userId the primary key of the user
569             * @param  type the relationship type
570             * @return the number of matching activities
571             */
572            @Override
573            public int getRelationActivitiesCount(long userId, int type) {
574                    return socialActivityLocalService.getRelationActivitiesCount(
575                            userId, type);
576            }
577    
578            /**
579             * Returns a range of all the activities done by the user.
580             *
581             * <p>
582             * Useful when paginating results. Returns a maximum of <code>end -
583             * start</code> instances. <code>start</code> and <code>end</code> are not
584             * primary keys, they are indexes in the result set. Thus, <code>0</code>
585             * refers to the first result in the set. Setting both <code>start</code>
586             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
587             * result set.
588             * </p>
589             *
590             * @param  userId the primary key of the user
591             * @param  start the lower bound of the range of results
592             * @param  end the upper bound of the range of results (not inclusive)
593             * @return the range of matching activities
594             */
595            @Override
596            public List<SocialActivity> getUserActivities(
597                            long userId, int start, int end)
598                    throws PortalException {
599    
600                    List<SocialActivity> activities =
601                            socialActivityLocalService.getUserActivities(
602                                    userId, 0,
603                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
604    
605                    return filterActivities(activities, start, end);
606            }
607    
608            /**
609             * Returns the number of activities done by the user.
610             *
611             * @param  userId the primary key of the user
612             * @return the number of matching activities
613             */
614            @Override
615            public int getUserActivitiesCount(long userId) {
616                    return socialActivityLocalService.getUserActivitiesCount(userId);
617            }
618    
619            /**
620             * Returns a range of all the activities done in the user's groups. This
621             * method only finds activities without mirrors.
622             *
623             * <p>
624             * Useful when paginating results. Returns a maximum of <code>end -
625             * start</code> instances. <code>start</code> and <code>end</code> are not
626             * primary keys, they are indexes in the result set. Thus, <code>0</code>
627             * refers to the first result in the set. Setting both <code>start</code>
628             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
629             * result set.
630             * </p>
631             *
632             * @param  userId the primary key of the user
633             * @param  start the lower bound of the range of results
634             * @param  end the upper bound of the range of results (not inclusive)
635             * @return the range of matching activities
636             */
637            @Override
638            public List<SocialActivity> getUserGroupsActivities(
639                            long userId, int start, int end)
640                    throws PortalException {
641    
642                    List<SocialActivity> activities =
643                            socialActivityLocalService.getUserGroupsActivities(
644                                    userId, 0,
645                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
646    
647                    return filterActivities(activities, start, end);
648            }
649    
650            /**
651             * Returns the number of activities done in user's groups. This method only
652             * counts activities without mirrors.
653             *
654             * @param  userId the primary key of the user
655             * @return the number of matching activities
656             */
657            @Override
658            public int getUserGroupsActivitiesCount(long userId) {
659                    return socialActivityLocalService.getUserGroupsActivitiesCount(userId);
660            }
661    
662            /**
663             * Returns a range of all the activities done in the user's groups and
664             * organizations. This method only finds activities without mirrors.
665             *
666             * <p>
667             * Useful when paginating results. Returns a maximum of <code>end -
668             * start</code> instances. <code>start</code> and <code>end</code> are not
669             * primary keys, they are indexes in the result set. Thus, <code>0</code>
670             * refers to the first result in the set. Setting both <code>start</code>
671             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
672             * result set.
673             * </p>
674             *
675             * @param  userId the primary key of the user
676             * @param  start the lower bound of the range of results
677             * @param  end the upper bound of the range of results (not inclusive)
678             * @return the range of matching activities
679             */
680            @Override
681            public List<SocialActivity> getUserGroupsAndOrganizationsActivities(
682                            long userId, int start, int end)
683                    throws PortalException {
684    
685                    List<SocialActivity> activities =
686                            socialActivityLocalService.getUserGroupsAndOrganizationsActivities(
687                                    userId, 0,
688                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
689    
690                    return filterActivities(activities, start, end);
691            }
692    
693            /**
694             * Returns the number of activities done in user's groups and organizations.
695             * This method only counts activities without mirrors.
696             *
697             * @param  userId the primary key of the user
698             * @return the number of matching activities
699             */
700            @Override
701            public int getUserGroupsAndOrganizationsActivitiesCount(long userId) {
702                    return socialActivityLocalService.
703                            getUserGroupsAndOrganizationsActivitiesCount(userId);
704            }
705    
706            /**
707             * Returns a range of all activities done in the user's organizations. This
708             * method only finds activities without mirrors.
709             *
710             * <p>
711             * Useful when paginating results. Returns a maximum of <code>end -
712             * start</code> instances. <code>start</code> and <code>end</code> are not
713             * primary keys, they are indexes in the result set. Thus, <code>0</code>
714             * refers to the first result in the set. Setting both <code>start</code>
715             * and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
716             * result set.
717             * </p>
718             *
719             * @param  userId the primary key of the user
720             * @param  start the lower bound of the range of results
721             * @param  end the upper bound of the range of results (not inclusive)
722             * @return the range of matching activities
723             */
724            @Override
725            public List<SocialActivity> getUserOrganizationsActivities(
726                            long userId, int start, int end)
727                    throws PortalException {
728    
729                    List<SocialActivity> activities =
730                            socialActivityLocalService.getUserOrganizationsActivities(
731                                    userId, 0,
732                                    end + PropsValues.SOCIAL_ACTIVITY_FILTER_SEARCH_LIMIT);
733    
734                    return filterActivities(activities, start, end);
735            }
736    
737            /**
738             * Returns the number of activities done in the user's organizations. This
739             * method only counts activities without mirrors.
740             *
741             * @param  userId the primary key of the user
742             * @return the number of matching activities
743             */
744            @Override
745            public int getUserOrganizationsActivitiesCount(long userId) {
746                    return socialActivityLocalService.getUserOrganizationsActivitiesCount(
747                            userId);
748            }
749    
750            protected List<SocialActivity> filterActivities(
751                            List<SocialActivity> activities, int start, int end)
752                    throws PortalException {
753    
754                    List<SocialActivity> filteredActivities = new ArrayList<>();
755    
756                    List<SocialActivityInterpreter> activityInterpreters =
757                            socialActivityInterpreterLocalService.getActivityInterpreters(
758                                    StringPool.BLANK);
759    
760                    for (SocialActivity activity : activities) {
761                            if (hasPermission(activity, activityInterpreters)) {
762                                    filteredActivities.add(activity);
763                            }
764    
765                            if ((end != QueryUtil.ALL_POS) &&
766                                    (filteredActivities.size() > end)) {
767    
768                                    break;
769                            }
770                    }
771    
772                    if ((end != QueryUtil.ALL_POS) && (start != QueryUtil.ALL_POS)) {
773                            if (end > filteredActivities.size()) {
774                                    end = filteredActivities.size();
775                            }
776    
777                            if (start > filteredActivities.size()) {
778                                    start = filteredActivities.size();
779                            }
780    
781                            filteredActivities = filteredActivities.subList(start, end);
782                    }
783    
784                    return filteredActivities;
785            }
786    
787            protected boolean hasPermission(
788                            SocialActivity activity,
789                            List<SocialActivityInterpreter> activityInterpreters)
790                    throws PortalException {
791    
792                    PermissionChecker permissionChecker = getPermissionChecker();
793                    ServiceContext serviceContext = new ServiceContext();
794    
795                    for (int i = 0; i < activityInterpreters.size(); i++) {
796                            SocialActivityInterpreterImpl activityInterpreterImpl =
797                                    (SocialActivityInterpreterImpl)activityInterpreters.get(i);
798    
799                            if (activityInterpreterImpl.hasClassName(activity.getClassName())) {
800                                    try {
801                                            if (activityInterpreterImpl.hasPermission(
802                                                            permissionChecker, activity, ActionKeys.VIEW,
803                                                            serviceContext)) {
804    
805                                                    return true;
806                                            }
807                                    }
808                                    catch (Exception e) {
809                                    }
810                            }
811                    }
812    
813                    return false;
814            }
815    
816    }