001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.impl;
022:
023: import com.liferay.portal.NoSuchSubscriptionException;
024: import com.liferay.portal.PortalException;
025: import com.liferay.portal.SystemException;
026: import com.liferay.portal.model.Subscription;
027: import com.liferay.portal.model.User;
028: import com.liferay.portal.model.impl.SubscriptionImpl;
029: import com.liferay.portal.service.base.SubscriptionLocalServiceBaseImpl;
030: import com.liferay.portal.util.PortalUtil;
031:
032: import java.util.Date;
033: import java.util.List;
034:
035: /**
036: * <a href="SubscriptionLocalServiceImpl.java.html"><b><i>View Source</i></b>
037: * </a>
038: *
039: * @author Charles May
040: *
041: */
042: public class SubscriptionLocalServiceImpl extends
043: SubscriptionLocalServiceBaseImpl {
044:
045: public Subscription addSubscription(long userId, String className,
046: long classPK) throws PortalException, SystemException {
047:
048: return addSubscription(userId, className, classPK,
049: SubscriptionImpl.FREQUENCY_INSTANT);
050: }
051:
052: public Subscription addSubscription(long userId, String className,
053: long classPK, String frequency) throws PortalException,
054: SystemException {
055:
056: User user = userPersistence.findByPrimaryKey(userId);
057: long classNameId = PortalUtil.getClassNameId(className);
058: Date now = new Date();
059:
060: long subscriptionId = counterLocalService.increment();
061:
062: Subscription subscription = subscriptionPersistence
063: .create(subscriptionId);
064:
065: subscription.setCompanyId(user.getCompanyId());
066: subscription.setUserId(user.getUserId());
067: subscription.setUserName(user.getFullName());
068: subscription.setCreateDate(now);
069: subscription.setModifiedDate(now);
070: subscription.setClassNameId(classNameId);
071: subscription.setClassPK(classPK);
072: subscription.setFrequency(frequency);
073:
074: subscriptionPersistence.update(subscription);
075:
076: return subscription;
077: }
078:
079: public void deleteSubscription(long subscriptionId)
080: throws PortalException, SystemException {
081:
082: subscriptionPersistence.remove(subscriptionId);
083: }
084:
085: public void deleteSubscription(long userId, String className,
086: long classPK) throws PortalException, SystemException {
087:
088: User user = userPersistence.findByPrimaryKey(userId);
089: long classNameId = PortalUtil.getClassNameId(className);
090:
091: subscriptionPersistence.removeByC_U_C_C(user.getCompanyId(),
092: userId, classNameId, classPK);
093: }
094:
095: public void deleteSubscriptions(long userId) throws SystemException {
096: subscriptionPersistence.removeByUserId(userId);
097: }
098:
099: public void deleteSubscriptions(long companyId, String className,
100: long classPK) throws SystemException {
101:
102: long classNameId = PortalUtil.getClassNameId(className);
103:
104: subscriptionPersistence.removeByC_C_C(companyId, classNameId,
105: classPK);
106: }
107:
108: public Subscription getSubscription(long companyId, long userId,
109: String className, long classPK) throws PortalException,
110: SystemException {
111:
112: long classNameId = PortalUtil.getClassNameId(className);
113:
114: return subscriptionPersistence.findByC_U_C_C(companyId, userId,
115: classNameId, classPK);
116: }
117:
118: public List getSubscriptions(long companyId, String className,
119: long classPK) throws PortalException, SystemException {
120:
121: long classNameId = PortalUtil.getClassNameId(className);
122:
123: return subscriptionPersistence.findByC_C_C(companyId,
124: classNameId, classPK);
125: }
126:
127: public boolean isSubscribed(long companyId, long userId,
128: String className, long classPK) throws PortalException,
129: SystemException {
130:
131: long classNameId = PortalUtil.getClassNameId(className);
132:
133: try {
134: subscriptionPersistence.findByC_U_C_C(companyId, userId,
135: classNameId, classPK);
136:
137: return true;
138: } catch (NoSuchSubscriptionException nsse) {
139: return false;
140: }
141: }
142:
143: }
|