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.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.setLimitEnabled(_limitEnabled);
040                    activityCounterDefinition.setLimitPeriod(_limitPeriod);
041                    activityCounterDefinition.setLimitValue(_limitValue);
042                    activityCounterDefinition.setName(_name);
043                    activityCounterDefinition.setOwnerType(_ownerType);
044                    activityCounterDefinition.setPeriodLength(_periodLength);
045                    activityCounterDefinition.setTransient(_transient);
046    
047                    return activityCounterDefinition;
048            }
049    
050            public boolean equals(
051                    SocialActivityCounterDefinition activityCounterDefinition) {
052    
053                    if (Validator.isNotNull(activityCounterDefinition) &&
054                            Validator.equals(_enabled, activityCounterDefinition._enabled) &&
055                            Validator.equals(
056                                    _increment, activityCounterDefinition._increment) &&
057                            Validator.equals(
058                                    _limitEnabled, activityCounterDefinition._limitEnabled) &&
059                            Validator.equals(
060                                    _limitPeriod, activityCounterDefinition._limitPeriod) &&
061                            Validator.equals(
062                                    _limitValue, activityCounterDefinition._limitValue) &&
063                            Validator.equals(_name, activityCounterDefinition._name) &&
064                            Validator.equals(
065                                    _ownerType, activityCounterDefinition._ownerType) &&
066                            Validator.equals(
067                                    _periodLength, activityCounterDefinition._periodLength) &&
068                            Validator.equals(
069                                    _transient, activityCounterDefinition._transient)) {
070    
071                            return true;
072                    }
073    
074                    return false;
075            }
076    
077            public int getIncrement() {
078                    return _increment;
079            }
080    
081            public String getKey() {
082                    return _name.concat(StringPool.SLASH).concat(
083                            String.valueOf(_ownerType));
084            }
085    
086            public int getLimitPeriod() {
087                    return _limitPeriod;
088            }
089    
090            public int getLimitValue() {
091                    return _limitValue;
092            }
093    
094            public String getName() {
095                    return _name;
096            }
097    
098            public int getOwnerType() {
099                    return _ownerType;
100            }
101    
102            public int getPeriodLength() {
103                    return _periodLength;
104            }
105    
106            public boolean isEnabled() {
107                    return _enabled;
108            }
109    
110            public boolean isLimitEnabled() {
111                    return _limitEnabled;
112            }
113    
114            public boolean isTransient() {
115                    return _transient;
116            }
117    
118            public void setEnabled(boolean enabled) {
119                    _enabled = enabled;
120            }
121    
122            public void setIncrement(int increment) {
123                    _increment = increment;
124            }
125    
126            public void setLimitEnabled(boolean limitEnabled) {
127                    _limitEnabled = limitEnabled;
128            }
129    
130            public void setLimitPeriod(int limitPeriod) {
131                    _limitPeriod = limitPeriod;
132            }
133    
134            public void setLimitPeriod(String limitPeriod) {
135                    if (limitPeriod.equalsIgnoreCase("day")) {
136                            setLimitPeriod(LIMIT_PERIOD_DAY);
137                    }
138                    else if (limitPeriod.equalsIgnoreCase("lifetime")) {
139                            setLimitPeriod(LIMIT_PERIOD_LIFETIME);
140                    }
141                    else {
142                            setLimitPeriod(LIMIT_PERIOD_PERIOD);
143                    }
144            }
145    
146            public void setLimitValue(int limitValue) {
147                    _limitValue = limitValue;
148            }
149    
150            public void setName(String name) {
151                    _name = name;
152            }
153    
154            public void setOwnerType(int ownerType) {
155                    _ownerType = ownerType;
156            }
157    
158            public void setOwnerType(String ownerType) {
159                    if (ownerType.equalsIgnoreCase("actor")) {
160                            setOwnerType(SocialActivityCounterConstants.TYPE_ACTOR);
161                    }
162                    else if (ownerType.equalsIgnoreCase("asset")) {
163                            setOwnerType(SocialActivityCounterConstants.TYPE_ASSET);
164                    }
165                    else if (ownerType.equalsIgnoreCase("creator")) {
166                            setOwnerType(SocialActivityCounterConstants.TYPE_CREATOR);
167                    }
168            }
169    
170            public void setPeriodLength(int periodLength) {
171                    _periodLength = periodLength;
172            }
173    
174            public void setTransient(boolean transientCounter) {
175                    _transient = transientCounter;
176            }
177    
178            private boolean _enabled = true;
179            private int _increment = 1;
180            private boolean _limitEnabled = true;
181            private int _limitPeriod = LIMIT_PERIOD_DAY;
182            private int _limitValue;
183            private String _name;
184            private int _ownerType;
185            private int _periodLength =
186                    SocialActivityCounterConstants.PERIOD_LENGTH_SYSTEM;
187            private boolean _transient;
188    
189    }