1 package com.atlassian.marketplace.client.model;
2
3 import java.net.URI;
4 import java.util.Map;
5
6 import com.atlassian.fugue.Option;
7 import com.atlassian.marketplace.client.api.AddonVersionExternalLinkType;
8 import com.atlassian.marketplace.client.api.ApplicationKey;
9 import com.atlassian.marketplace.client.api.HostingType;
10 import com.atlassian.marketplace.client.api.LicenseTypeId;
11
12 import com.google.common.base.Function;
13 import com.google.common.base.Functions;
14 import com.google.common.base.Predicate;
15 import com.google.common.collect.ImmutableList;
16
17 import static com.atlassian.fugue.Option.none;
18 import static com.atlassian.fugue.Option.option;
19 import static com.atlassian.fugue.Option.some;
20 import static com.google.common.collect.Iterables.transform;
21
22
23
24
25
26
27
28 public final class AddonVersion extends AddonVersionBase
29 {
30 Embedded _embedded;
31 Integer buildNumber;
32 Option<String> youtubeId;
33 Map<String, URI> vendorLinks;
34 Option<ImmutableList<VersionCompatibility>> compatibilities;
35 TextProperties text;
36 @ReadOnly Option<LegacyProperties> legacy;
37
38 @Override
39 public Option<ArtifactInfo> getArtifactInfo()
40 {
41 return _embedded.artifact;
42 }
43
44 @Override
45 public Option<URI> getArtifactUri()
46 {
47 for (ArtifactInfo a: _embedded.artifact)
48 {
49 return some(a.getBinaryUri());
50 }
51 return none();
52 }
53
54 @Override
55 public Option<URI> getRemoteDescriptorUri()
56 {
57 for (ArtifactInfo a: _embedded.artifact)
58 {
59 return a.getRemoteDescriptorUri();
60 }
61 return none();
62 }
63
64
65
66
67
68
69
70 public int getBuildNumber()
71 {
72 return buildNumber;
73 }
74
75
76
77
78
79
80
81
82 public Iterable<VersionCompatibility> getCompatibilities()
83 {
84 return compatibilities.getOrElse(ImmutableList.<VersionCompatibility>of());
85 }
86
87
88
89
90
91
92 public Option<Iterable<VersionCompatibility>> getCompatibilitiesIfSpecified()
93 {
94 return compatibilities.map(Functions.<Iterable<VersionCompatibility>>identity());
95 }
96
97
98
99
100
101
102 public Option<URI> getExternalLinkUri(AddonVersionExternalLinkType type)
103 {
104 if (type.canSetForNewAddonVersions())
105 {
106 return option(vendorLinks.get(type.getKey()));
107 }
108 else
109 {
110 for (LegacyProperties l: legacy)
111 {
112 return option(l.vendorLinks.get(type.getKey()));
113 }
114 return none();
115 }
116 }
117
118 @Override
119 public Iterable<AddonCategorySummary> getFunctionalCategories()
120 {
121 return _embedded.functionalCategories;
122 }
123
124
125
126
127
128
129
130 public Iterable<Highlight> getHighlights()
131 {
132 return _embedded.highlights.getOrElse(ImmutableList.<Highlight>of());
133 }
134
135
136
137
138
139
140 public Option<Iterable<Highlight>> getHighlightsIfSpecified()
141 {
142 return _embedded.highlights.map(Functions.<Iterable<Highlight>>identity());
143 }
144
145
146
147
148
149
150
151 public Option<LicenseType> getLicenseType()
152 {
153 return _embedded.license;
154 }
155
156
157
158
159
160
161
162 public Option<LicenseTypeId> getLicenseTypeId()
163 {
164 for (URI u: getLinks().getUri("license"))
165 {
166 return some(LicenseTypeId.fromUri(u));
167 }
168 return none();
169 }
170
171
172
173
174
175 public Option<HtmlString> getMoreDetails()
176 {
177 return text.moreDetails;
178 }
179
180 @Override
181 public PaymentModel getPaymentModel()
182 {
183 return paymentModel;
184 }
185
186
187
188
189
190 public Option<HtmlString> getReleaseNotes()
191 {
192 return text.releaseNotes;
193 }
194
195
196
197
198
199 public Option<String> getReleaseSummary()
200 {
201 return text.releaseSummary;
202 }
203
204
205
206
207
208
209 public Iterable<Screenshot> getScreenshots()
210 {
211 return _embedded.screenshots.getOrElse(ImmutableList.<Screenshot>of());
212 }
213
214
215
216
217
218
219 public Option<Iterable<Screenshot>> getScreenshotsIfSpecified()
220 {
221 return _embedded.screenshots.map(Functions.<Iterable<Screenshot>>identity());
222 }
223
224 @Override
225 public AddonVersionStatus getStatus()
226 {
227 return status;
228 }
229
230 @Override
231 public boolean isStatic()
232 {
233 return staticAddon;
234 }
235
236
237
238
239
240 public Option<String> getYoutubeId()
241 {
242 return youtubeId;
243 }
244
245
246
247
248
249 public Iterable<ApplicationKey> getCompatibleApplications()
250 {
251 return transform(getCompatibilities(), new Function<VersionCompatibility, ApplicationKey>()
252 {
253 public ApplicationKey apply(VersionCompatibility input)
254 {
255 return input.getApplication();
256 }
257 });
258 }
259
260
261
262
263
264 public boolean isCompatibleWithApplication(ApplicationKey application)
265 {
266 for (VersionCompatibility c: getCompatibilities())
267 {
268 if (c.getApplication().equals(application))
269 {
270 return true;
271 }
272 }
273 return false;
274 }
275
276
277
278
279
280
281 public boolean isCompatibleWith(Predicate<ApplicationKey> applicationCriteria, HostingType hostingType, int build)
282 {
283 for (VersionCompatibility c: getCompatibilities())
284 {
285 if (c.isCompatibleWith(applicationCriteria, hostingType, build))
286 {
287 return true;
288 }
289 }
290 return false;
291 }
292
293 static final class Embedded
294 {
295 Option<ArtifactInfo> artifact;
296 ImmutableList<AddonCategorySummary> functionalCategories;
297 Option<ImmutableList<Highlight>> highlights;
298 Option<LicenseType> license;
299 Option<ImmutableList<Screenshot>> screenshots;
300 }
301
302 static final class LegacyProperties
303 {
304 Map<String, URI> vendorLinks;
305 }
306
307 static final class TextProperties
308 {
309 Option<String> releaseSummary;
310 Option<HtmlString> moreDetails;
311 Option<HtmlString> releaseNotes;
312 }
313 }