001    /**
002     * Copyright (c) 2000-2011 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.model;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.io.Serializable;
021    
022    /**
023     * @author Zsolt Berentey
024     */
025    public class SocialActivityCounterDefinition implements Serializable {
026    
027            @Override
028            public SocialActivityCounterDefinition clone() {
029                    SocialActivityCounterDefinition activityCounterDefinition =
030                            new SocialActivityCounterDefinition();
031    
032                    activityCounterDefinition.setIncrement(_increment);
033                    activityCounterDefinition.setLimitValue(_limitValue);
034                    activityCounterDefinition.setLimitPeriod(_limitPeriod);
035                    activityCounterDefinition.setName(_name);
036                    activityCounterDefinition.setOwnerType(_ownerType);
037    
038                    return activityCounterDefinition;
039            }
040    
041            public boolean equals(
042                    SocialActivityCounterDefinition activityCounterDefinition) {
043    
044                    if (Validator.equals(
045                                    _increment, activityCounterDefinition._increment) &&
046                            Validator.equals(
047                                    _limitValue, activityCounterDefinition._limitValue) &&
048                            Validator.equals(
049                                    _limitPeriod, activityCounterDefinition._limitPeriod) &&
050                            Validator.equals(_name, activityCounterDefinition._name) &&
051                            Validator.equals(
052                                    _ownerType, activityCounterDefinition._ownerType)) {
053    
054                            return true;
055                    }
056    
057                    return false;
058            }
059    
060            public int getIncrement() {
061                    return _increment;
062            }
063    
064            public String getKey() {
065                    return _name.concat(StringPool.SLASH).concat(
066                            String.valueOf(_ownerType));
067            }
068    
069            public int getLimitPeriod() {
070                    return _limitPeriod;
071            }
072    
073            public int getLimitValue() {
074                    return _limitValue;
075            }
076    
077            public String getName() {
078                    return _name;
079            }
080    
081            public int getOwnerType() {
082                    return _ownerType;
083            }
084    
085            public void setIncrement(int increment) {
086                    _increment = increment;
087            }
088    
089            public void setLimitPeriod(int limitPeriod) {
090                    _limitPeriod = limitPeriod;
091            }
092    
093            public void setLimitPeriod(String limitPeriod) {
094                    if (limitPeriod.equalsIgnoreCase("day")) {
095                            setLimitPeriod(_LIMIT_PERIOD_DAY);
096                    }
097                    else if (limitPeriod.equalsIgnoreCase("lifetime")) {
098                            setLimitPeriod(_LIMIT_PERIOD_LIFETIME);
099                    }
100                    else {
101                            setLimitPeriod(_LIMIT_PERIOD_PERIOD);
102                    }
103            }
104    
105            public void setLimitValue(int limitValue) {
106                    _limitValue = limitValue;
107            }
108    
109            public void setName(String name) {
110                    _name = name;
111            }
112    
113            public void setOwnerType(int ownerType) {
114                    _ownerType = ownerType;
115            }
116    
117            public void setOwnerType(String ownerType) {
118                    if (ownerType.equalsIgnoreCase("actor")) {
119                            setOwnerType(SocialActivityCounterConstants.TYPE_ACTOR);
120                    }
121                    else if (ownerType.equalsIgnoreCase("asset")) {
122                            setOwnerType(SocialActivityCounterConstants.TYPE_ASSET);
123                    }
124                    else if (ownerType.equalsIgnoreCase("creator")) {
125                            setOwnerType(SocialActivityCounterConstants.TYPE_CREATOR);
126                    }
127            }
128    
129            private static final int _LIMIT_PERIOD_DAY = 1;
130    
131            private static final int _LIMIT_PERIOD_LIFETIME = 2;
132    
133            private static final int _LIMIT_PERIOD_PERIOD = 3;
134    
135            private int _increment;
136            private int _limitPeriod;
137            private int _limitValue;
138            private String _name;
139            private int _ownerType;
140    
141    }