001    /**
002     * Copyright (c) 2000-2012 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.social.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.portlet.social.model.SocialActivity;
021    import com.liferay.portlet.social.model.SocialActivitySet;
022    import com.liferay.portlet.social.service.base.SocialActivitySetLocalServiceBaseImpl;
023    
024    /**
025     * @author Matthew Kong
026     */
027    public class SocialActivitySetLocalServiceImpl
028            extends SocialActivitySetLocalServiceBaseImpl {
029    
030            public SocialActivitySet addActivitySet(
031                            long userId, long activityId, String className, long classPK,
032                            int type)
033                    throws PortalException, SystemException {
034    
035                    // Activity set
036    
037                    User user = userPersistence.findByPrimaryKey(userId);
038                    SocialActivity activity = socialActivityPersistence.findByPrimaryKey(
039                            activityId);
040    
041                    long activitySetId = counterLocalService.increment();
042    
043                    SocialActivitySet activitySet = socialActivitySetPersistence.create(
044                            activitySetId);
045    
046                    activitySet.setGroupId(activity.getGroupId());
047                    activitySet.setCompanyId(user.getCompanyId());
048                    activitySet.setUserId(userId);
049                    activitySet.setCreateDate(activity.getCreateDate());
050                    activitySet.setModifiedDate(activity.getCreateDate());
051                    activitySet.setClassName(className);
052                    activitySet.setClassPK(classPK);
053                    activitySet.setType(type);
054                    activitySet.setActivityCount(1);
055    
056                    socialActivitySetPersistence.update(activitySet);
057    
058                    // Activity
059    
060                    activity.setActivitySetId(activitySetId);
061    
062                    socialActivityPersistence.update(activity);
063    
064                    return activitySet;
065            }
066    
067    }