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.setEnabled(_enabled);
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(_enabled, activityDefinition.isEnabled()) &&
092                            Validator.equals(
093                                    _languageKey, activityDefinition.getLanguageKey()) &&
094                            Validator.equals(
095                                    _logActivity, activityDefinition.isLogActivity()) &&
096                            Validator.equals(_modelName, activityDefinition.getModelName())) {
097    
098                            return true;
099                    }
100    
101                    return false;
102            }
103    
104            public List<SocialAchievement> getAchievements() {
105                    return _achievements;
106            }
107    
108            public SocialActivityCounterDefinition getActivityCounterDefinition(
109                    String name) {
110    
111                    return _activityCounterDefinitions.get(name);
112            }
113    
114            public Collection<SocialActivityCounterDefinition>
115                    getActivityCounterDefinitions() {
116    
117                    return _activityCounterDefinitions.values();
118            }
119    
120            public SocialActivityProcessor getActivityProcessor() {
121                    return _activityProcessor;
122            }
123    
124            public int getActivityType() {
125                    return _activityType;
126            }
127    
128            public String getLanguageKey() {
129                    return _languageKey;
130            }
131    
132            public String getModelName() {
133                    return _modelName;
134            }
135    
136            public String getName(Locale locale) {
137                    return LanguageUtil.get(
138                            locale, "social.activity." + _modelName + "." + _languageKey);
139            }
140    
141            public boolean isEnabled() {
142                    return _enabled;
143            }
144    
145            public boolean isLogActivity() {
146                    return _logActivity;
147            }
148    
149            public void setActivityProcessor(
150                    SocialActivityProcessor activityProcessor) {
151    
152                    _activityProcessor = activityProcessor;
153            }
154    
155            public void setActivityType(int activityKey) {
156                    _activityType = activityKey;
157            }
158    
159            public void setCounters(
160                    List<SocialActivityCounterDefinition> activityCounterDefinitions) {
161    
162                    _activityCounterDefinitions.clear();
163    
164                    for (SocialActivityCounterDefinition activityCounterDefinition :
165                                    activityCounterDefinitions) {
166    
167                            _activityCounterDefinitions.put(
168                                    activityCounterDefinition.getName(), activityCounterDefinition);
169                    }
170            }
171    
172            public void setEnabled(boolean enabled) {
173                    _enabled = enabled;
174            }
175    
176            public void setLanguageKey(String languageKey) {
177                    _languageKey = languageKey;
178            }
179    
180            public void setLogActivity(boolean logActivity) {
181                    _logActivity = logActivity;
182            }
183    
184            public void setModelName(String modelName) {
185                    _modelName = modelName;
186            }
187    
188            private List<SocialAchievement> _achievements =
189                    new ArrayList<SocialAchievement>();
190            private Map<String, SocialActivityCounterDefinition>
191                    _activityCounterDefinitions =
192                            new HashMap<String, SocialActivityCounterDefinition>();
193            private SocialActivityProcessor _activityProcessor;
194            private int _activityType;
195            private boolean _enabled = true;
196            private String _languageKey;
197            private boolean _logActivity;
198            private String _modelName;
199    
200    }