001    /**
002     * Copyright (c) 2000-2013 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.kernel.exception.SystemException;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portal.util.PortalUtil;
022    import com.liferay.portlet.messageboards.model.MBDiscussion;
023    import com.liferay.portlet.messageboards.service.base.MBDiscussionLocalServiceBaseImpl;
024    
025    import java.util.Date;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class MBDiscussionLocalServiceImpl
031            extends MBDiscussionLocalServiceBaseImpl {
032    
033            @Override
034            public MBDiscussion addDiscussion(
035                            long userId, long classNameId, long classPK, long threadId,
036                            ServiceContext serviceContext)
037                    throws PortalException, SystemException {
038    
039                    User user = userPersistence.findByPrimaryKey(userId);
040                    long groupId = serviceContext.getScopeGroupId();
041                    Date now = new Date();
042    
043                    long discussionId = counterLocalService.increment();
044    
045                    MBDiscussion discussion = mbDiscussionPersistence.create(discussionId);
046    
047                    discussion.setUuid(serviceContext.getUuid());
048                    discussion.setGroupId(groupId);
049                    discussion.setCompanyId(serviceContext.getCompanyId());
050                    discussion.setUserId(userId);
051                    discussion.setUserName(user.getFullName());
052                    discussion.setCreateDate(serviceContext.getCreateDate(now));
053                    discussion.setModifiedDate(serviceContext.getModifiedDate(now));
054                    discussion.setClassNameId(classNameId);
055                    discussion.setClassPK(classPK);
056                    discussion.setThreadId(threadId);
057    
058                    mbDiscussionPersistence.update(discussion);
059    
060                    return discussion;
061            }
062    
063            @Override
064            public MBDiscussion fetchDiscussion(long discussionId)
065                    throws SystemException {
066    
067                    return mbDiscussionPersistence.fetchByPrimaryKey(discussionId);
068            }
069    
070            @Override
071            public MBDiscussion fetchDiscussion(String className, long classPK)
072                    throws SystemException {
073    
074                    long classNameId = PortalUtil.getClassNameId(className);
075    
076                    return mbDiscussionPersistence.fetchByC_C(classNameId, classPK);
077            }
078    
079            @Override
080            public MBDiscussion getDiscussion(long discussionId)
081                    throws PortalException, SystemException {
082    
083                    return mbDiscussionPersistence.findByPrimaryKey(discussionId);
084            }
085    
086            @Override
087            public MBDiscussion getDiscussion(String className, long classPK)
088                    throws PortalException, SystemException {
089    
090                    long classNameId = PortalUtil.getClassNameId(className);
091    
092                    return mbDiscussionPersistence.findByC_C(classNameId, classPK);
093            }
094    
095            @Override
096            public MBDiscussion getThreadDiscussion(long threadId)
097                    throws PortalException, SystemException {
098    
099                    return mbDiscussionPersistence.findByThreadId(threadId);
100            }
101    
102    }