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