001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            @Override
032            @Transactional(propagation = Propagation.REQUIRES_NEW)
033            public SocialActivityLimit addActivityLimit(
034                            long userId, long groupId, long classNameId, long classPK,
035                            int activityType, String activityCounterName, int limitPeriod)
036                    throws PortalException, SystemException {
037    
038                    SocialActivityLimit activityLimit =
039                            socialActivityLimitPersistence.fetchByG_U_C_C_A_A(
040                                    groupId, userId, classNameId, classPK, activityType,
041                                    activityCounterName, false);
042    
043                    if (activityLimit != null) {
044                            return activityLimit;
045                    }
046    
047                    User user = userPersistence.findByPrimaryKey(userId);
048    
049                    long activityLimitId = counterLocalService.increment();
050    
051                    activityLimit = socialActivityLimitPersistence.create(activityLimitId);
052    
053                    activityLimit.setGroupId(groupId);
054                    activityLimit.setCompanyId(user.getCompanyId());
055                    activityLimit.setUserId(userId);
056                    activityLimit.setClassNameId(classNameId);
057                    activityLimit.setClassPK(classPK);
058                    activityLimit.setActivityType(activityType);
059                    activityLimit.setActivityCounterName(activityCounterName);
060                    activityLimit.setCount(limitPeriod, 0);
061    
062                    socialActivityLimitPersistence.update(activityLimit);
063    
064                    return activityLimit;
065            }
066    
067            @Override
068            public SocialActivityLimit fetchActivityLimit(
069                            long groupId, long userId, long classNameId, long classPK,
070                            int activityType, String activityCounterName)
071                    throws SystemException {
072    
073                    return socialActivityLimitPersistence.fetchByG_U_C_C_A_A(
074                            groupId, userId, classNameId, classPK, activityType,
075                            activityCounterName);
076            }
077    
078    }