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.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.io.Serializable;
021    
022    import java.util.ArrayList;
023    import java.util.Collection;
024    import java.util.HashMap;
025    import java.util.List;
026    import java.util.Locale;
027    import java.util.Map;
028    
029    /**
030     * @author Zsolt Berentey
031     */
032    public class SocialActivityDefinition implements Serializable {
033    
034            public void addCounter(
035                    SocialActivityCounterDefinition activityCounterDefinition) {
036    
037                    _activityCounterDefinitions.put(
038                            activityCounterDefinition.getName(), activityCounterDefinition);
039            }
040    
041            @Override
042            public SocialActivityDefinition clone() {
043                    SocialActivityDefinition activityDefinition =
044                            new SocialActivityDefinition();
045    
046                    for (SocialActivityCounterDefinition activityCounterDefinition :
047                                    _activityCounterDefinitions.values()) {
048    
049                            activityDefinition.addCounter(activityCounterDefinition.clone());
050                    }
051    
052                    List<SocialAchievement> achievements =
053                            activityDefinition.getAchievements();
054    
055                    achievements.addAll(_achievements);
056    
057                    activityDefinition.setActivityProcessor(_activityProcessor);
058                    activityDefinition.setActivityType(_activityType);
059                    activityDefinition.setCountersEnabled(_countersEnabled);
060                    activityDefinition.setLanguageKey(_languageKey);
061                    activityDefinition.setLogActivity(_logActivity);
062                    activityDefinition.setModelName(_modelName);
063    
064                    return activityDefinition;
065            }
066    
067            @Override
068            public boolean equals(Object obj) {
069                    if (this == obj) {
070                            return true;
071                    }
072    
073                    if (!(obj instanceof SocialActivityDefinition)) {
074                            return false;
075                    }
076    
077                    SocialActivityDefinition activityDefinition =
078                            (SocialActivityDefinition)obj;
079    
080                    if ((activityDefinition != null) &&
081                            Validator.equals(
082                                    _achievements, activityDefinition.getAchievements()) &&
083                            Validator.equals(
084                                    _activityCounterDefinitions,
085                                    activityDefinition._activityCounterDefinitions) &&
086                            Validator.equals(
087                                    _activityProcessor,
088                                    activityDefinition.getActivityProcessor()) &&
089                            Validator.equals(
090                                    _activityType, activityDefinition.getActivityType()) &&
091                            Validator.equals(
092                                    _countersEnabled, activityDefinition.isCountersEnabled()) &&
093                            Validator.equals(
094                                    _languageKey, activityDefinition.getLanguageKey()) &&
095                            Validator.equals(
096                                    _logActivity, activityDefinition.isLogActivity()) &&
097                            Validator.equals(_modelName, activityDefinition.getModelName())) {
098    
099                            return true;
100                    }
101    
102                    return false;
103            }
104    
105            public List<SocialAchievement> getAchievements() {
106                    return _achievements;
107            }
108    
109            public SocialActivityCounterDefinition getActivityCounterDefinition(
110                    String name) {
111    
112                    return _activityCounterDefinitions.get(name);
113            }
114    
115            public Collection<SocialActivityCounterDefinition>
116                    getActivityCounterDefinitions() {
117    
118                    return _activityCounterDefinitions.values();
119            }
120    
121            public SocialActivityProcessor getActivityProcessor() {
122                    return _activityProcessor;
123            }
124    
125            public int getActivityType() {
126                    return _activityType;
127            }
128    
129            public String getLanguageKey() {
130                    return _languageKey;
131            }
132    
133            public String getModelName() {
134                    return _modelName;
135            }
136    
137            public String getName(Locale locale) {
138                    return LanguageUtil.get(
139                            locale, "social.activity." + _modelName + "." + _languageKey);
140            }
141    
142            public boolean isCountersEnabled() {
143                    return _countersEnabled;
144            }
145    
146            public boolean isLogActivity() {
147                    return _logActivity;
148            }
149    
150            public void setActivityProcessor(
151                    SocialActivityProcessor activityProcessor) {
152    
153                    _activityProcessor = activityProcessor;
154            }
155    
156            public void setActivityType(int activityKey) {
157                    _activityType = activityKey;
158            }
159    
160            public void setCounters(
161                    List<SocialActivityCounterDefinition> activityCounterDefinitions) {
162    
163                    _activityCounterDefinitions.clear();
164    
165                    for (SocialActivityCounterDefinition activityCounterDefinition :
166                                    activityCounterDefinitions) {
167    
168                            _activityCounterDefinitions.put(
169                                    activityCounterDefinition.getName(), activityCounterDefinition);
170                    }
171            }
172    
173            public void setCountersEnabled(boolean enabled) {
174                    _countersEnabled = enabled;
175            }
176    
177            public void setLanguageKey(String languageKey) {
178                    _languageKey = languageKey;
179            }
180    
181            public void setLogActivity(boolean logActivity) {
182                    _logActivity = logActivity;
183            }
184    
185            public void setModelName(String modelName) {
186                    _modelName = modelName;
187            }
188    
189            private List<SocialAchievement> _achievements =
190                    new ArrayList<SocialAchievement>();
191            private Map<String, SocialActivityCounterDefinition>
192                    _activityCounterDefinitions =
193                            new HashMap<String, SocialActivityCounterDefinition>();
194            private SocialActivityProcessor _activityProcessor;
195            private int _activityType;
196            private boolean _countersEnabled = true;
197            private String _languageKey;
198            private boolean _logActivity;
199            private String _modelName;
200    
201    }