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.portal.plugin;
016    
017    import com.liferay.portal.kernel.plugin.License;
018    import com.liferay.portal.kernel.plugin.PluginPackage;
019    import com.liferay.portal.kernel.plugin.RemotePluginPackageRepository;
020    import com.liferay.portal.kernel.plugin.Screenshot;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.kernel.util.StringBundler;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.kernel.util.Validator;
025    
026    import java.io.Serializable;
027    
028    import java.util.ArrayList;
029    import java.util.Collections;
030    import java.util.Date;
031    import java.util.List;
032    import java.util.Properties;
033    
034    import org.apache.commons.lang.builder.EqualsBuilder;
035    import org.apache.commons.lang.builder.HashCodeBuilder;
036    
037    /**
038     * @author Jorge Ferrer
039     */
040    public class PluginPackageImpl
041            implements Comparable<PluginPackage>, PluginPackage, Serializable {
042    
043            public static final String STATUS_ALL = "all";
044    
045            public static final String STATUS_INSTALLATION_IN_PROCESS =
046                    "installationInProcess";
047    
048            public static final String STATUS_NEWER_VERSION_INSTALLED =
049                    "newerVersionInstalled";
050    
051            public static final String STATUS_NOT_INSTALLED = "notInstalled";
052    
053            public static final String STATUS_NOT_INSTALLED_OR_OLDER_VERSION_INSTALLED =
054                    "notInstalledOrOlderVersionInstalled";
055    
056            public static final String STATUS_OLDER_VERSION_INSTALLED =
057                    "olderVersionInstalled";
058    
059            public static final String STATUS_SAME_VERSION_INSTALLED =
060                    "sameVersionInstalled";
061    
062            public PluginPackageImpl(String moduleId) {
063                    _moduleId = ModuleId.getInstance(moduleId);
064            }
065    
066            public int compareTo(PluginPackage pluginPackage) {
067                    return getName().compareTo(pluginPackage.getName());
068            }
069    
070            @Override
071            public boolean equals(Object obj) {
072                    if (!(obj instanceof PluginPackage)) {
073                            return false;
074                    }
075    
076                    PluginPackage pluginPackage = (PluginPackage)obj;
077    
078                    EqualsBuilder equalsBuilder = new EqualsBuilder();
079    
080                    equalsBuilder.append(getModuleId(), pluginPackage.getModuleId());
081                    equalsBuilder.append(
082                            getRepositoryURL(), pluginPackage.getRepositoryURL());
083    
084                    return equalsBuilder.isEquals();
085            }
086    
087            public String getArtifactId() {
088                    return _moduleId.getArtifactId();
089            }
090    
091            public String getArtifactURL() {
092                    return getRepositoryURL() + _moduleId.getArtifactPath();
093            }
094    
095            public String getAuthor() {
096                    return _author;
097            }
098    
099            public String getChangeLog() {
100                    return _changeLog;
101            }
102    
103            public String getContext() {
104                    return _context;
105            }
106    
107            public Properties getDeploymentSettings() {
108                    return _deploymentSettings;
109            }
110    
111            public String getDownloadURL() {
112                    String useDownloadURL = getRepository().getSettings().getProperty(
113                            RemotePluginPackageRepository.SETTING_USE_DOWNLOAD_URL);
114    
115                    if (!GetterUtil.getBoolean(useDownloadURL, true)) {
116                            return getArtifactURL();
117                    }
118    
119                    if (Validator.isNotNull(_downloadURL)) {
120                            return _downloadURL;
121                    }
122    
123                    return getArtifactURL();
124            }
125    
126            public String getGroupId() {
127                    return _moduleId.getGroupId();
128            }
129    
130            public List<License> getLicenses() {
131                    return _licenses;
132            }
133    
134            public List<String> getLiferayVersions() {
135                    return _liferayVersions;
136            }
137    
138            public String getLongDescription() {
139                    return _longDescription;
140            }
141    
142            public Date getModifiedDate() {
143                    return _modifiedDate;
144            }
145    
146            public String getModuleId() {
147                    return _moduleId.toString();
148            }
149    
150            public String getName() {
151                    return _name;
152            }
153    
154            public String getPackageId() {
155                    return _moduleId.getPackageId();
156            }
157    
158            public String getPageURL() {
159                    return _pageURL;
160            }
161    
162            public String getRecommendedDeploymentContext() {
163                    String context = _recommendedDeploymentContext;
164    
165                    if (Validator.isNull(context)) {
166                            context = _moduleId.getArtifactId();
167                    }
168    
169                    return context;
170            }
171    
172            public RemotePluginPackageRepository getRepository() {
173                    return _repository;
174            }
175    
176            public String getRepositoryURL() {
177                    if (_repository != null) {
178                            return _repository.getRepositoryURL();
179                    }
180                    else {
181                            return RemotePluginPackageRepository.LOCAL_URL;
182                    }
183            }
184    
185            public List<String> getRequiredDeploymentContexts() {
186                    return _requiredDeploymentContexts;
187            }
188    
189            public List<Screenshot> getScreenshots() {
190                    return _screenshots;
191            }
192    
193            public String getShortDescription() {
194                    return _shortDescription;
195            }
196    
197            public List<String> getTags() {
198                    return _tags;
199            }
200    
201            public List<String> getTypes() {
202                    return _types;
203            }
204    
205            public String getVersion() {
206                    return _moduleId.getVersion();
207            }
208    
209            @Override
210            public int hashCode() {
211                    HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
212    
213                    hashCodeBuilder.append(getModuleId());
214                    hashCodeBuilder.append(getRepositoryURL());
215    
216                    return hashCodeBuilder.hashCode();
217            }
218    
219            public boolean isLaterVersionThan(PluginPackage pluginPackage) {
220                    return _moduleId.isLaterVersionThan(pluginPackage.getVersion());
221            }
222    
223            public boolean isPreviousVersionThan(PluginPackage pluginPackage) {
224                    return _moduleId.isPreviousVersionThan(pluginPackage.getVersion());
225            }
226    
227            public boolean isSameVersionAs(PluginPackage pluginPackage) {
228                    return _moduleId.isSameVersionAs(pluginPackage.getVersion());
229            }
230    
231            public void setAuthor(String author) {
232                    _author = author;
233            }
234    
235            public void setChangeLog(String changeLog) {
236                    _changeLog = changeLog;
237            }
238    
239            public void setContext(String context) {
240                    _context = context;
241            }
242    
243            public void setDeploymentSettings(Properties deploymentSettings) {
244                    _deploymentSettings = deploymentSettings;
245            }
246    
247            public void setDownloadURL(String downloadURL) {
248                    _downloadURL = downloadURL;
249            }
250    
251            public void setLicenses(List<License> licenses) {
252                    _licenses = licenses;
253            }
254    
255            public void setLiferayVersions(List<String> liferayVersions) {
256                    _liferayVersions = liferayVersions;
257            }
258    
259            public void setLongDescription(String longDescription) {
260                    _longDescription = longDescription;
261            }
262    
263            public void setModifiedDate(Date modifiedDate) {
264                    _modifiedDate = modifiedDate;
265            }
266    
267            public void setName(String name) {
268                    _name = name;
269            }
270    
271            public void setPageURL(String pageURL) {
272                    _pageURL = pageURL;
273            }
274    
275            public void setRecommendedDeploymentContext(
276                    String recommendedDeploymentContext) {
277    
278                    _recommendedDeploymentContext = recommendedDeploymentContext;
279            }
280    
281            public void setRepository(RemotePluginPackageRepository repository) {
282                    _repository = repository;
283            }
284    
285            public void setRequiredDeploymentContexts(
286                    List<String> requiredDeploymentContexts) {
287    
288                    _requiredDeploymentContexts = requiredDeploymentContexts;
289            }
290    
291            public void setScreenshots(List<Screenshot> screenshots) {
292                    _screenshots = screenshots;
293            }
294    
295            public void setShortDescription(String shortDescription) {
296                    _shortDescription = shortDescription;
297            }
298    
299            public void setTags(List<String> tags) {
300                    _tags = tags;
301            }
302    
303            public void setTypes(List<String> types) {
304                    _types = types;
305            }
306    
307            @Override
308            public String toString() {
309                    StringBundler sb = new StringBundler(4);
310    
311                    sb.append(StringPool.SLASH);
312                    sb.append(_context);
313                    sb.append(StringPool.COLON);
314                    sb.append(_moduleId);
315    
316                    return sb.toString();
317            }
318    
319            private String _author;
320            private String _changeLog = StringPool.BLANK;
321            private String _context;
322            private Properties _deploymentSettings;
323            private String _downloadURL;
324            private List<License> _licenses = new ArrayList<License>();
325            private List<String> _liferayVersions = new ArrayList<String>();
326            private String _longDescription = StringPool.BLANK;
327            private Date _modifiedDate;
328            private ModuleId _moduleId;
329            private String _name;
330            private String _pageURL;
331            private String _recommendedDeploymentContext;
332            private RemotePluginPackageRepository _repository;
333            private List<String> _requiredDeploymentContexts = Collections.emptyList();
334            private List<Screenshot> _screenshots = new ArrayList<Screenshot>();
335            private String _shortDescription = StringPool.BLANK;
336            private List<String> _tags = new ArrayList<String>();
337            private List<String> _types = new ArrayList<String>();
338    
339    }