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.kernel.transaction.Propagation;
020    import com.liferay.portal.kernel.transaction.Transactional;
021    import com.liferay.portal.model.User;
022    import com.liferay.portlet.social.model.SocialActivityLimit;
023    import com.liferay.portlet.social.service.base.SocialActivityLimitLocalServiceBaseImpl;
024    
025    /**
026     * @author Zsolt Berentey
027     */
028    public class SocialActivityLimitLocalServiceImpl
029            extends SocialActivityLimitLocalServiceBaseImpl {
030    
031            @Transactional(
032                    propagation = Propagation.REQUIRES_NEW,
033                    rollbackFor = {PortalException.class, SystemException.class})
034            public SocialActivityLimit addActivityLimit(
035                            long userId, long groupId, long classNameId, long classPK,
036                            int activityType, String activityCounterName, int limitPeriod)
037                    throws PortalException, SystemException {
038    
039                    User user = userPersistence.findByPrimaryKey(userId);
040    
041                    long activityLimitId = counterLocalService.increment();
042    
043                    SocialActivityLimit activityLimit =
044                            socialActivityLimitPersistence.create(activityLimitId);
045    
046                    activityLimit.setGroupId(groupId);
047                    activityLimit.setCompanyId(user.getCompanyId());
048                    activityLimit.setUserId(userId);
049                    activityLimit.setClassNameId(classNameId);
050                    activityLimit.setClassPK(classPK);
051                    activityLimit.setActivityType(activityType);
052                    activityLimit.setActivityCounterName(activityCounterName);
053                    activityLimit.setCount(limitPeriod, 0);
054    
055                    socialActivityLimitPersistence.update(activityLimit, false);
056    
057                    return activityLimit;
058            }
059    
060    }