001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Anahide Tchertchian
018 */
019package org.nuxeo.targetplatforms.api.impl;
020
021import java.util.ArrayList;
022import java.util.Collections;
023import java.util.Date;
024import java.util.List;
025
026import org.nuxeo.targetplatforms.api.TargetInfo;
027
028/**
029 * @since 5.7.1
030 */
031public class TargetInfoImpl implements TargetInfo {
032
033    private static final long serialVersionUID = 1L;
034
035    protected String id;
036
037    protected String name;
038
039    protected String version;
040
041    protected String refVersion;
042
043    protected String label;
044
045    protected String description;
046
047    protected String status;
048
049    protected boolean enabled = true;
050
051    protected boolean restricted = false;
052
053    protected boolean fastTrack = false;
054
055    protected boolean trial = false;
056
057    protected boolean isDefault = false;
058
059    protected Date releaseDate;
060
061    protected Date endOfAvailability;
062
063    protected String downloadLink;
064
065    protected boolean deprecated = false;
066
067    protected boolean overridden = false;
068
069    protected List<String> types;
070
071    // needed by GWT serialization
072    protected TargetInfoImpl() {
073    }
074
075    public TargetInfoImpl(String id) {
076        this.id = id;
077    }
078
079    public TargetInfoImpl(String id, String name, String version, String refVersion, String label) {
080        this(id);
081        this.name = name;
082        this.version = version;
083        this.refVersion = refVersion;
084        this.label = label;
085    }
086
087    @Override
088    public String getId() {
089        return id;
090    }
091
092    public void setId(String id) {
093        this.id = id;
094    }
095
096    @Override
097    public String getName() {
098        return name;
099    }
100
101    public void setName(String name) {
102        this.name = name;
103    }
104
105    @Override
106    public String getVersion() {
107        return version;
108    }
109
110    public void setVersion(String version) {
111        this.version = version;
112    }
113
114    @Override
115    public String getRefVersion() {
116        if (refVersion == null) {
117            return version;
118        }
119        return refVersion;
120    }
121
122    public void setRefVersion(String refVersion) {
123        this.refVersion = refVersion;
124    }
125
126    @Override
127    public String getStatus() {
128        return status;
129    }
130
131    public void setStatus(String status) {
132        this.status = status;
133    }
134
135    @Override
136    public String getLabel() {
137        return label;
138    }
139
140    public void setLabel(String label) {
141        this.label = label;
142    }
143
144    @Override
145    public String getDescription() {
146        return description;
147    }
148
149    public void setDescription(String description) {
150        this.description = description;
151    }
152
153    @Override
154    public boolean isEnabled() {
155        return enabled;
156    }
157
158    public void setEnabled(boolean enabled) {
159        this.enabled = enabled;
160    }
161
162    @Override
163    public boolean isRestricted() {
164        return restricted;
165    }
166
167    public void setRestricted(boolean restricted) {
168        this.restricted = restricted;
169    }
170
171    @Override
172    public Date getReleaseDate() {
173        return releaseDate;
174    }
175
176    public void setReleaseDate(Date releaseDate) {
177        this.releaseDate = releaseDate;
178    }
179
180    @Override
181    public Date getEndOfAvailability() {
182        return endOfAvailability;
183    }
184
185    public void setEndOfAvailability(Date endOfAvailability) {
186        this.endOfAvailability = endOfAvailability;
187    }
188
189    @Override
190    public String getDownloadLink() {
191        return downloadLink;
192    }
193
194    public void setDownloadLink(String downloadLink) {
195        this.downloadLink = downloadLink;
196    }
197
198    @Override
199    public boolean isDeprecated() {
200        return deprecated;
201    }
202
203    public void setDeprecated(boolean deprecated) {
204        this.deprecated = deprecated;
205    }
206
207    @Override
208    public boolean isTrial() {
209        return trial;
210    }
211
212    public void setTrial(boolean trial) {
213        this.trial = trial;
214    }
215
216    @Override
217    public boolean isDefault() {
218        return isDefault;
219    }
220
221    public void setDefault(boolean isDefault) {
222        this.isDefault = isDefault;
223    }
224
225    @Override
226    public boolean isFastTrack() {
227        return fastTrack;
228    }
229
230    public void setFastTrack(boolean fastTrack) {
231        this.fastTrack = fastTrack;
232    }
233
234    @Override
235    public boolean isOverridden() {
236        return overridden;
237    }
238
239    public void setOverridden(boolean overridden) {
240        this.overridden = overridden;
241    }
242
243    @Override
244    public List<String> getTypes() {
245        if (types == null) {
246            return Collections.emptyList();
247        }
248        return types;
249    }
250
251    public void setTypes(List<String> types) {
252        if (types == null) {
253            this.types = null;
254        } else {
255            this.types = new ArrayList<>(types);
256        }
257    }
258
259    @Override
260    public boolean matchesType(String type) {
261        if (types == null) {
262            return false;
263        }
264        return types.contains(type);
265    }
266
267    // Class#getSimpleName not supported by GWT
268    protected String getSimpleName() {
269        return getClass().getName().substring(getClass().getName().lastIndexOf('.') + 1);
270    }
271
272    @Override
273    public String toString() {
274        final StringBuilder buf = new StringBuilder();
275
276        buf.append(getSimpleName());
277        buf.append(" {");
278        buf.append(" id=");
279        buf.append(id);
280        buf.append(", name=");
281        buf.append(name);
282        buf.append(", version=");
283        buf.append(version);
284        buf.append(", refVersion=");
285        buf.append(refVersion);
286        buf.append(", label=");
287        buf.append(label);
288        buf.append('}');
289
290        return buf.toString();
291    }
292
293}