1
22
23 package com.liferay.portal.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.model.Subscription;
28 import com.liferay.portal.model.User;
29 import com.liferay.portal.model.impl.SubscriptionImpl;
30 import com.liferay.portal.service.base.SubscriptionLocalServiceBaseImpl;
31 import com.liferay.portal.util.PortalUtil;
32
33 import java.util.Date;
34 import java.util.List;
35
36
43 public class SubscriptionLocalServiceImpl
44 extends SubscriptionLocalServiceBaseImpl {
45
46 public Subscription addSubscription(
47 long userId, String className, long classPK)
48 throws PortalException, SystemException {
49
50 return addSubscription(
51 userId, className, classPK, SubscriptionImpl.FREQUENCY_INSTANT);
52 }
53
54 public Subscription addSubscription(
55 long userId, String className, long classPK, String frequency)
56 throws PortalException, SystemException {
57
58 User user = userPersistence.findByPrimaryKey(userId);
59 long classNameId = PortalUtil.getClassNameId(className);
60 Date now = new Date();
61
62 long subscriptionId = counterLocalService.increment();
63
64 Subscription subscription = subscriptionPersistence.create(
65 subscriptionId);
66
67 subscription.setCompanyId(user.getCompanyId());
68 subscription.setUserId(user.getUserId());
69 subscription.setUserName(user.getFullName());
70 subscription.setCreateDate(now);
71 subscription.setModifiedDate(now);
72 subscription.setClassNameId(classNameId);
73 subscription.setClassPK(classPK);
74 subscription.setFrequency(frequency);
75
76 subscriptionPersistence.update(subscription, false);
77
78 return subscription;
79 }
80
81 public void deleteSubscription(long subscriptionId)
82 throws PortalException, SystemException {
83
84 subscriptionPersistence.remove(subscriptionId);
85 }
86
87 public void deleteSubscription(
88 long userId, String className, long classPK)
89 throws PortalException, SystemException {
90
91 User user = userPersistence.findByPrimaryKey(userId);
92 long classNameId = PortalUtil.getClassNameId(className);
93
94 subscriptionPersistence.removeByC_U_C_C(
95 user.getCompanyId(), userId, classNameId, classPK);
96 }
97
98 public void deleteSubscriptions(long userId) throws SystemException {
99 subscriptionPersistence.removeByUserId(userId);
100 }
101
102 public void deleteSubscriptions(
103 long companyId, String className, long classPK)
104 throws SystemException {
105
106 long classNameId = PortalUtil.getClassNameId(className);
107
108 subscriptionPersistence.removeByC_C_C(companyId, classNameId, classPK);
109 }
110
111 public Subscription getSubscription(
112 long companyId, long userId, String className, long classPK)
113 throws PortalException, SystemException {
114
115 long classNameId = PortalUtil.getClassNameId(className);
116
117 return subscriptionPersistence.findByC_U_C_C(
118 companyId, userId, classNameId, classPK);
119 }
120
121 public List<Subscription> getSubscriptions(
122 long companyId, String className, long classPK)
123 throws SystemException {
124
125 long classNameId = PortalUtil.getClassNameId(className);
126
127 return subscriptionPersistence.findByC_C_C(
128 companyId, classNameId, classPK);
129 }
130
131 public boolean isSubscribed(
132 long companyId, long userId, String className, long classPK)
133 throws SystemException {
134
135 long classNameId = PortalUtil.getClassNameId(className);
136
137 Subscription subscription = subscriptionPersistence.fetchByC_U_C_C(
138 companyId, userId, classNameId, classPK);
139
140 if (subscription != null) {
141 return true;
142 }
143 else {
144 return false;
145 }
146 }
147
148 }