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