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