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