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