--- /dev/null
+/**\r
+ * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.\r
+ *\r
+ * This library is free software; you can redistribute it and/or modify it under\r
+ * the terms of the GNU Lesser General Public License as published by the Free\r
+ * Software Foundation; either version 2.1 of the License, or (at your option)\r
+ * any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\r
+ * details.\r
+ */\r
+\r
+package com.liferay.portlet.social.service.impl;\r
+\r
+import com.liferay.portal.kernel.dao.orm.QueryUtil;\r
+import com.liferay.portal.kernel.exception.PortalException;\r
+import com.liferay.portal.kernel.exception.SystemException;\r
+import com.liferay.portal.kernel.lar.ImportExportThreadLocal;\r
+import com.liferay.portal.kernel.messaging.async.Async;\r
+import com.liferay.portal.model.Group;\r
+import com.liferay.portal.model.Layout;\r
+import com.liferay.portal.model.User;\r
+import com.liferay.portal.util.PortalUtil;\r
+import com.liferay.portlet.asset.model.AssetEntry;\r
+import com.liferay.portlet.social.NoSuchActivityException;\r
+import com.liferay.portlet.social.model.SocialActivity;\r
+import com.liferay.portlet.social.model.SocialActivityDefinition;\r
+import com.liferay.portlet.social.service.base.SocialActivityLocalServiceBaseImpl;\r
+import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+/**\r
+ * The social activity local service. This service provides the means to record\r
+ * and list social activities in groups and organizations.\r
+ *\r
+ * <p>\r
+ * Social activities are identified by their type and the type of asset they are\r
+ * done on. Each activity records the exact time of the action as well as human\r
+ * readable information needed for activity feeds.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Most of the <i>get-</i> methods in this service order activities in\r
+ * descending order by their execution times, so the most recent activities are\r
+ * listed first.\r
+ * </p>\r
+ *\r
+ * @author Brian Wing Shun Chan\r
+ */\r
+public class SocialActivityLocalServiceImpl\r
+ extends SocialActivityLocalServiceBaseImpl {\r
+\r
+ /**\r
+ * Records an activity with the given time in the database.\r
+ *\r
+ * <p>\r
+ * This method records a social activity done on an asset, identified by its\r
+ * class name and class primary key, in the database. Additional information\r
+ * (such as the original message ID for a reply to a forum post) is passed\r
+ * in via the <code>extraData</code> in JSON format. For activities\r
+ * affecting another user, a mirror activity is generated that describes the\r
+ * action from the user's point of view. The target user's ID is passed in\r
+ * via the <code>receiverUserId</code>.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Example for a mirrored activity:<br> When a user replies to a message\r
+ * boards post, the reply action is stored in the database with the\r
+ * <code>receiverUserId</code> being the ID of the author of the original\r
+ * message. The <code>extraData</code> contains the ID of the original\r
+ * message in JSON format. A mirror activity is generated with the values of\r
+ * the <code>userId</code> and the <code>receiverUserId</code> swapped. This\r
+ * mirror activity basically describes a "replied to" event.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Mirror activities are most often used in relation to friend requests and\r
+ * activities.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the acting user\r
+ * @param groupId the primary key of the group\r
+ * @param createDate the activity's date\r
+ * @param className the target asset's class name\r
+ * @param classPK the primary key of the target asset\r
+ * @param type the activity's type\r
+ * @param extraData any extra data regarding the activity\r
+ * @param receiverUserId the primary key of the receiving user\r
+ * @throws PortalException if the user or group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void addActivity(\r
+ long userId, long groupId, Date createDate, String className,\r
+ long classPK, int type, String extraData, long receiverUserId)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ if (ImportExportThreadLocal.isImportInProcess()) {\r
+ return;\r
+ }\r
+\r
+ User user = userPersistence.findByPrimaryKey(userId);\r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ if (groupId > 0) {\r
+ Group group = groupLocalService.getGroup(groupId);\r
+\r
+ if (group.isLayout()) {\r
+ Layout layout = layoutLocalService.getLayout(\r
+ group.getClassPK());\r
+\r
+ groupId = layout.getGroupId();\r
+ }\r
+ }\r
+\r
+ SocialActivity activity = socialActivityPersistence.create(0);\r
+\r
+ activity.setGroupId(groupId);\r
+ activity.setCompanyId(user.getCompanyId());\r
+ activity.setUserId(user.getUserId());\r
+ activity.setCreateDate(createDate.getTime());\r
+ activity.setMirrorActivityId(0);\r
+ activity.setClassNameId(classNameId);\r
+ activity.setClassPK(classPK);\r
+ activity.setType(type);\r
+ activity.setExtraData(extraData);\r
+ activity.setReceiverUserId(receiverUserId);\r
+\r
+ AssetEntry assetEntry = assetEntryPersistence.fetchByC_C(\r
+ classNameId, classPK);\r
+\r
+ activity.setAssetEntry(assetEntry);\r
+\r
+ SocialActivity mirrorActivity = null;\r
+\r
+ if ((receiverUserId > 0) && (userId != receiverUserId)) {\r
+ mirrorActivity = socialActivityPersistence.create(0);\r
+\r
+ mirrorActivity.setGroupId(groupId);\r
+ mirrorActivity.setCompanyId(user.getCompanyId());\r
+ mirrorActivity.setUserId(receiverUserId);\r
+ mirrorActivity.setCreateDate(createDate.getTime());\r
+ mirrorActivity.setClassNameId(classNameId);\r
+ mirrorActivity.setClassPK(classPK);\r
+ mirrorActivity.setType(type);\r
+ mirrorActivity.setExtraData(extraData);\r
+ mirrorActivity.setReceiverUserId(user.getUserId());\r
+ mirrorActivity.setAssetEntry(assetEntry);\r
+ }\r
+\r
+ socialActivityLocalService.addActivity(activity, mirrorActivity);\r
+ }\r
+\r
+ /**\r
+ * Records an activity in the database, using a time based on the current\r
+ * time in an attempt to make the activity's time unique.\r
+ *\r
+ * @param userId the primary key of the acting user\r
+ * @param groupId the primary key of the group\r
+ * @param className the target asset's class name\r
+ * @param classPK the primary key of the target asset\r
+ * @param type the activity's type\r
+ * @param extraData any extra data regarding the activity\r
+ * @param receiverUserId the primary key of the receiving user\r
+ * @throws PortalException if the user or group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void addActivity(\r
+ long userId, long groupId, String className, long classPK, int type,\r
+ String extraData, long receiverUserId)\r
+ throws PortalException, SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ if (ImportExportThreadLocal.isImportInProcess()) {\r
+ return;\r
+ }\r
+\r
+ Date createDate = new Date();\r
+\r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ while (true) {\r
+ SocialActivity socialActivity =\r
+ socialActivityPersistence.fetchByG_U_CD_C_C_T_R(\r
+ groupId, userId, createDate.getTime(), classNameId, classPK,\r
+ type, receiverUserId);\r
+\r
+ if (socialActivity != null) {\r
+ createDate = new Date(createDate.getTime() + 1);\r
+ }\r
+ else {\r
+ break;\r
+ }\r
+ }\r
+\r
+ addActivity(\r
+ userId, groupId, createDate, className, classPK, type, extraData,\r
+ receiverUserId);\r
+ }\r
+\r
+ @Async\r
+ public void addActivity(\r
+ SocialActivity activity, SocialActivity mirrorActivity)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ if (ImportExportThreadLocal.isImportInProcess()) {\r
+ return;\r
+ }\r
+\r
+ if ((activity.getActivityId() > 0) ||\r
+ ((mirrorActivity != null) &&\r
+ (mirrorActivity.getActivityId() > 0))) {\r
+\r
+ throw new PortalException(\r
+ "Activity and mirror activity must not have primary keys set");\r
+ }\r
+\r
+ SocialActivityDefinition activityDefinition =\r
+ socialActivitySettingLocalService.getActivityDefinition(\r
+ activity.getGroupId(), activity.getClassName(),\r
+ activity.getType());\r
+\r
+ if (((activityDefinition == null) && (activity.getType() < 10000)) ||\r
+ ((activityDefinition != null) &&\r
+ activityDefinition.isLogActivity())) {\r
+\r
+ long activityId = counterLocalService.increment(\r
+ SocialActivity.class.getName());\r
+\r
+ activity.setActivityId(activityId);\r
+\r
+ socialActivityPersistence.update(activity, false);\r
+\r
+ if (mirrorActivity != null) {\r
+ long mirrorActivityId = counterLocalService.increment(\r
+ SocialActivity.class.getName());\r
+\r
+ mirrorActivity.setActivityId(mirrorActivityId);\r
+ mirrorActivity.setMirrorActivityId(activity.getPrimaryKey());\r
+\r
+ socialActivityPersistence.update(mirrorActivity, false);\r
+ }\r
+ }\r
+\r
+ socialActivityCounterLocalService.addActivityCounters(activity);\r
+ }\r
+\r
+ /**\r
+ * Records an activity in the database, but only if there isn't already an\r
+ * activity with the same parameters.\r
+ *\r
+ * <p>\r
+ * For the main functionality see {@link #addActivity(long, long, Date,\r
+ * String, long, int, String, long)}\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the acting user\r
+ * @param groupId the primary key of the group\r
+ * @param createDate the activity's date\r
+ * @param className the target asset's class name\r
+ * @param classPK the primary key of the target asset\r
+ * @param type the activity's type\r
+ * @param extraData any extra data regarding the activity\r
+ * @param receiverUserId the primary key of the receiving user\r
+ * @throws PortalException if the user or group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void addUniqueActivity(\r
+ long userId, long groupId, Date createDate, String className,\r
+ long classPK, int type, String extraData, long receiverUserId)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ SocialActivity socialActivity =\r
+ socialActivityPersistence.fetchByG_U_CD_C_C_T_R(\r
+ groupId, userId, createDate.getTime(), classNameId, classPK,\r
+ type, receiverUserId);\r
+\r
+ if (socialActivity != null) {\r
+ return;\r
+ }\r
+\r
+ addActivity(\r
+ userId, groupId, createDate, className, classPK, type, extraData,\r
+ receiverUserId);\r
+ }\r
+\r
+ /**\r
+ * Records an activity with the current time in the database, but only if\r
+ * there isn't one with the same parameters.\r
+ *\r
+ * <p>\r
+ * For the main functionality see {@link #addActivity(long, long, Date,\r
+ * String, long, int, String, long)}\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the acting user\r
+ * @param groupId the primary key of the group\r
+ * @param className the target asset's class name\r
+ * @param classPK the primary key of the target asset\r
+ * @param type the activity's type\r
+ * @param extraData any extra data regarding the activity\r
+ * @param receiverUserId the primary key of the receiving user\r
+ * @throws PortalException if the user or group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void addUniqueActivity(\r
+ long userId, long groupId, String className, long classPK, int type,\r
+ String extraData, long receiverUserId)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ int count = socialActivityPersistence.countByG_U_C_C_T_R(\r
+ groupId, userId, classNameId, classPK, type, receiverUserId);\r
+\r
+ if (count > 0) {\r
+ return;\r
+ }\r
+\r
+ addActivity(\r
+ userId, groupId, new Date(), className, classPK, type, extraData,\r
+ receiverUserId);\r
+ }\r
+\r
+ /**\r
+ * Removes stored activities for the asset identified by the class name ID\r
+ * and class primary key.\r
+ *\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void deleteActivities(AssetEntry assetEntry)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ socialActivityPersistence.removeByC_C(\r
+ assetEntry.getClassNameId(), assetEntry.getClassPK());\r
+\r
+ socialActivityCounterLocalService.deleteActivityCounters(assetEntry);\r
+ }\r
+\r
+ /**\r
+ * Removes stored activities for the asset identified by the class name and\r
+ * class primary key.\r
+ *\r
+ * @param className the target asset's class name\r
+ * @param classPK the primary key of the target asset\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void deleteActivities(String className, long classPK)\r
+ throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ socialActivityPersistence.removeByC_C(classNameId, classPK);\r
+ }\r
+\r
+ /**\r
+ * Removes the stored activity from the database.\r
+ *\r
+ * @param activityId the primary key of the stored activity\r
+ * @throws PortalException if the activity could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void deleteActivity(long activityId)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ SocialActivity activity = socialActivityPersistence.findByPrimaryKey(\r
+ activityId);\r
+\r
+ deleteActivity(activity);\r
+ }\r
+\r
+ /**\r
+ * Removes the stored activity and its mirror activity from the database.\r
+ *\r
+ * @param activity the activity to be removed\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void deleteActivity(SocialActivity activity) throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ socialActivityPersistence.remove(activity);\r
+\r
+ try {\r
+ socialActivityPersistence.removeByMirrorActivityId(\r
+ activity.getActivityId());\r
+ }\r
+ catch (NoSuchActivityException nsae) {\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Removes the user's stored activities from the database.\r
+ *\r
+ * <p>\r
+ * This method removes all activities where the user is either the actor or\r
+ * the receiver.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void deleteUserActivities(long userId) throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return;\r
+ }\r
+ \r
+ List<SocialActivity> activities =\r
+ socialActivityPersistence.findByUserId(\r
+ userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);\r
+\r
+ for (SocialActivity activity : activities) {\r
+ socialActivityPersistence.remove(activity);\r
+ }\r
+\r
+ activities = socialActivityPersistence.findByReceiverUserId(\r
+ userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);\r
+\r
+ for (SocialActivity activity : activities) {\r
+ socialActivityPersistence.remove(activity);\r
+ }\r
+\r
+ socialActivityCounterLocalService.deleteActivityCounters(\r
+ PortalUtil.getClassNameId(User.class.getName()), userId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done on assets identified by the\r
+ * class name ID.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param classNameId the target asset's class name ID\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getActivities(\r
+ long classNameId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityPersistence.findByClassNameId(\r
+ classNameId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done on the asset identified by the\r
+ * class name ID and class primary key that are mirrors of the activity\r
+ * identified by the mirror activity ID.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param mirrorActivityId the primary key of the mirror activity\r
+ * @param classNameId the target asset's class name ID\r
+ * @param classPK the primary key of the target asset\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getActivities(\r
+ long mirrorActivityId, long classNameId, long classPK, int start,\r
+ int end)\r
+ throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+\r
+ return socialActivityPersistence.findByM_C_C(\r
+ mirrorActivityId, classNameId, classPK, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done on the asset identified by the\r
+ * class name and the class primary key that are mirrors of the activity\r
+ * identified by the mirror activity ID.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param mirrorActivityId the primary key of the mirror activity\r
+ * @param className the target asset's class name\r
+ * @param classPK the primary key of the target asset\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getActivities(\r
+ long mirrorActivityId, String className, long classPK, int start,\r
+ int end)\r
+ throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+\r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ return getActivities(\r
+ mirrorActivityId, classNameId, classPK, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done on assets identified by the\r
+ * class name.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param className the target asset's class name\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getActivities(\r
+ String className, int start, int end)\r
+ throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+\r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ return getActivities(classNameId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done on assets identified by the class\r
+ * name ID.\r
+ *\r
+ * @param classNameId the target asset's class name ID\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getActivitiesCount(long classNameId) throws SystemException {\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityPersistence.countByClassNameId(classNameId);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done on the asset identified by the\r
+ * class name ID and class primary key that are mirrors of the activity\r
+ * identified by the mirror activity ID.\r
+ *\r
+ * @param mirrorActivityId the primary key of the mirror activity\r
+ * @param classNameId the target asset's class name ID\r
+ * @param classPK the primary key of the target asset\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getActivitiesCount(\r
+ long mirrorActivityId, long classNameId, long classPK)\r
+ throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+\r
+ return socialActivityPersistence.countByM_C_C(\r
+ mirrorActivityId, classNameId, classPK);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done on the asset identified by the\r
+ * class name and class primary key that are mirrors of the activity\r
+ * identified by the mirror activity ID.\r
+ *\r
+ * @param mirrorActivityId the primary key of the mirror activity\r
+ * @param className the target asset's class name\r
+ * @param classPK the primary key of the target asset\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getActivitiesCount(\r
+ long mirrorActivityId, String className, long classPK)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ return getActivitiesCount(mirrorActivityId, classNameId, classPK);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done on assets identified by class name.\r
+ *\r
+ * @param className the target asset's class name\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getActivitiesCount(String className) throws SystemException {\r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return getActivitiesCount(classNameId);\r
+ }\r
+\r
+ /**\r
+ * Returns the activity identified by its primary key.\r
+ *\r
+ * @param activityId the primary key of the activity\r
+ * @return Returns the activity\r
+ * @throws PortalException if the activity could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public SocialActivity getActivity(long activityId)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return null;\r
+ }\r
+ \r
+ return socialActivityPersistence.findByPrimaryKey(activityId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done in the group.\r
+ *\r
+ * <p>\r
+ * This method only finds activities without mirrors.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getGroupActivities(\r
+ long groupId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByGroupId(groupId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done in the group.\r
+ *\r
+ * <p>\r
+ * This method only counts activities without mirrors.\r
+ * </p>\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getGroupActivitiesCount(long groupId) throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityFinder.countByGroupId(groupId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of activities done by users that are members of the\r
+ * group.\r
+ *\r
+ * <p>\r
+ * This method only finds activities without mirrors.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getGroupUsersActivities(\r
+ long groupId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByGroupUsers(groupId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done by users that are members of the\r
+ * group.\r
+ *\r
+ * <p>\r
+ * This method only counts activities without mirrors.\r
+ * </p>\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getGroupUsersActivitiesCount(long groupId)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ return socialActivityFinder.countByGroupUsers(groupId);\r
+ }\r
+\r
+ /**\r
+ * Returns the activity that has the mirror activity.\r
+ *\r
+ * @param mirrorActivityId the primary key of the mirror activity\r
+ * @return Returns the mirror activity\r
+ * @throws PortalException if the mirror activity could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public SocialActivity getMirrorActivity(long mirrorActivityId)\r
+ throws PortalException, SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return null;\r
+ }\r
+ \r
+ return socialActivityPersistence.findByMirrorActivityId(\r
+ mirrorActivityId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done in the organization. This\r
+ * method only finds activities without mirrors.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param organizationId the primary key of the organization\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getOrganizationActivities(\r
+ long organizationId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByOrganizationId(\r
+ organizationId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done in the organization. This method\r
+ * only counts activities without mirrors.\r
+ *\r
+ * @param organizationId the primary key of the organization\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getOrganizationActivitiesCount(long organizationId)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityFinder.countByOrganizationId(organizationId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done by users of the organization.\r
+ * This method only finds activities without mirrors.\r
+ *\r
+ * <p>\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param organizationId the primary key of the organization\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getOrganizationUsersActivities(\r
+ long organizationId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByOrganizationUsers(\r
+ organizationId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done by users of the organization. This\r
+ * method only counts activities without mirrors.\r
+ *\r
+ * @param organizationId the primary key of the organization\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getOrganizationUsersActivitiesCount(long organizationId)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityFinder.countByOrganizationUsers(organizationId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done by users in a relationship\r
+ * with the user identified by the user ID.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <>0</code> refers\r
+ * to the first result in the set. Setting both <code>start</code> and\r
+ * <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getRelationActivities(\r
+ long userId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByRelation(userId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done by users in a relationship of\r
+ * type <code>type</code> with the user identified by <code>userId</code>.\r
+ * This method only finds activities without mirrors.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param type the relationship type\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getRelationActivities(\r
+ long userId, int type, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByRelationType(\r
+ userId, type, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done by users in a relationship with the\r
+ * user identified by userId.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getRelationActivitiesCount(long userId) throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityFinder.countByRelation(userId);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done by users in a relationship of type\r
+ * <code>type</code> with the user identified by <code>userId</code>. This\r
+ * method only counts activities without mirrors.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param type the relationship type\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getRelationActivitiesCount(long userId, int type)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityFinder.countByRelationType(userId, type);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done by the user.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getUserActivities(\r
+ long userId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityPersistence.findByUserId(userId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done by the user.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getUserActivitiesCount(long userId) throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityPersistence.countByUserId(userId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done in the user's groups. This\r
+ * method only finds activities without mirrors.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getUserGroupsActivities(\r
+ long userId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByUserGroups(userId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done in user's groups. This method only\r
+ * counts activities without mirrors.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getUserGroupsActivitiesCount(long userId)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityFinder.countByUserGroups(userId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the activities done in the user's groups and\r
+ * organizations. This method only finds activities without mirrors.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getUserGroupsAndOrganizationsActivities(\r
+ long userId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByUserGroupsAndOrganizations(\r
+ userId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done in user's groups and organizations.\r
+ * This method only counts activities without mirrors.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getUserGroupsAndOrganizationsActivitiesCount(long userId)\r
+ throws SystemException {\r
+ \r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+\r
+ return socialActivityFinder.countByUserGroupsAndOrganizations(userId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all activities done in the user's organizations. This\r
+ * method only finds activities without mirrors.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param start the lower bound of the range of results\r
+ * @param end the upper bound of the range of results (not inclusive)\r
+ * @return the range of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<SocialActivity> getUserOrganizationsActivities(\r
+ long userId, int start, int end)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return new ArrayList<SocialActivity>();\r
+ }\r
+ \r
+ return socialActivityFinder.findByUserOrganizations(userId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of activities done in the user's organizations. This\r
+ * method only counts activities without mirrors.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @return the number of matching activities\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getUserOrganizationsActivitiesCount(long userId)\r
+ throws SystemException {\r
+\r
+ if(!ENTMainUtilsLocalServiceUtil.getEntSocialActivityEnabled()){\r
+ return 0;\r
+ }\r
+ \r
+ return socialActivityFinder.countByUserOrganizations(userId);\r
+ }\r
+\r
+}
\ No newline at end of file