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.messageboards.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.model.User;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.messageboards.model.MBDiscussion;
021    import com.liferay.portlet.messageboards.service.base.MBDiscussionLocalServiceBaseImpl;
022    
023    import java.util.Date;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class MBDiscussionLocalServiceImpl
029            extends MBDiscussionLocalServiceBaseImpl {
030    
031            @Override
032            public MBDiscussion addDiscussion(
033                            long userId, long groupId, long classNameId, long classPK,
034                            long threadId, ServiceContext serviceContext)
035                    throws PortalException {
036    
037                    User user = userPersistence.findByPrimaryKey(userId);
038                    Date now = new Date();
039    
040                    long discussionId = counterLocalService.increment();
041    
042                    MBDiscussion discussion = mbDiscussionPersistence.create(discussionId);
043    
044                    discussion.setUuid(serviceContext.getUuid());
045                    discussion.setGroupId(groupId);
046                    discussion.setCompanyId(serviceContext.getCompanyId());
047                    discussion.setUserId(userId);
048                    discussion.setUserName(user.getFullName());
049                    discussion.setCreateDate(serviceContext.getCreateDate(now));
050                    discussion.setModifiedDate(serviceContext.getModifiedDate(now));
051                    discussion.setClassNameId(classNameId);
052                    discussion.setClassPK(classPK);
053                    discussion.setThreadId(threadId);
054    
055                    mbDiscussionPersistence.update(discussion);
056    
057                    return discussion;
058            }
059    
060            /**
061             * @deprecated As of 7.0.0, replaced by {@link #addDiscussion(long, long,
062             *             long, long, long, ServiceContext)}
063             */
064            @Deprecated
065            @Override
066            public MBDiscussion addDiscussion(
067                            long userId, long classNameId, long classPK, long threadId,
068                            ServiceContext serviceContext)
069                    throws PortalException {
070    
071                    return addDiscussion(
072                            userId, serviceContext.getScopeGroupId(), classNameId, classPK,
073                            threadId, serviceContext);
074            }
075    
076            @Override
077            public MBDiscussion fetchDiscussion(long discussionId) {
078                    return mbDiscussionPersistence.fetchByPrimaryKey(discussionId);
079            }
080    
081            @Override
082            public MBDiscussion fetchDiscussion(String className, long classPK) {
083                    long classNameId = classNameLocalService.getClassNameId(className);
084    
085                    return mbDiscussionPersistence.fetchByC_C(classNameId, classPK);
086            }
087    
088            @Override
089            public MBDiscussion getDiscussion(long discussionId)
090                    throws PortalException {
091    
092                    return mbDiscussionPersistence.findByPrimaryKey(discussionId);
093            }
094    
095            @Override
096            public MBDiscussion getDiscussion(String className, long classPK)
097                    throws PortalException {
098    
099                    long classNameId = classNameLocalService.getClassNameId(className);
100    
101                    return mbDiscussionPersistence.findByC_C(classNameId, classPK);
102            }
103    
104            @Override
105            public MBDiscussion getThreadDiscussion(long threadId)
106                    throws PortalException {
107    
108                    return mbDiscussionPersistence.findByThreadId(threadId);
109            }
110    
111            @Override
112            public void subscribeDiscussion(
113                            long userId, long groupId, String className, long classPK)
114                    throws PortalException {
115    
116                    subscriptionLocalService.addSubscription(
117                            userId, groupId, className, classPK);
118            }
119    
120            @Override
121            public void unsubscribeDiscussion(
122                            long userId, String className, long classPK)
123                    throws PortalException {
124    
125                    subscriptionLocalService.deleteSubscription(userId, className, classPK);
126            }
127    
128    }