1 package com.atlassian.marketplace.client.model;
2
3 import java.net.URI;
4
5 import com.atlassian.fugue.Option;
6 import com.atlassian.marketplace.client.api.ApplicationKey;
7 import com.atlassian.marketplace.client.api.HostingType;
8
9 import com.google.common.base.Predicate;
10 import com.google.common.collect.ImmutableList;
11
12 import org.joda.time.LocalDate;
13
14 import static com.atlassian.fugue.Option.none;
15 import static com.atlassian.fugue.Option.some;
16 import static com.google.common.base.Predicates.equalTo;
17 import static com.google.common.collect.Iterables.any;
18
19
20
21
22
23 public final class ProductVersion
24 {
25 Links _links;
26 Embedded _embedded;
27 String name;
28 int buildNumber;
29 PaymentModel paymentModel;
30 LocalDate releaseDate;
31 ImmutableList<VersionCompatibility> compatibilities;
32
33 public Option<URI> getArtifactUri()
34 {
35 for (ArtifactInfo a: _embedded.artifact)
36 {
37 return some(a.getBinaryUri());
38 }
39 return none();
40 }
41
42 public Option<URI> getLearnMoreUri()
43 {
44 return _links.getUri("view");
45 }
46
47 public Option<URI> getReleaseNotesUri()
48 {
49 return _links.getUri("releaseNotes");
50 }
51
52
53
54
55 public String getName()
56 {
57 return name;
58 }
59
60
61
62
63 public int getBuildNumber()
64 {
65 return buildNumber;
66 }
67
68
69
70
71 public PaymentModel getPaymentModel()
72 {
73 return paymentModel;
74 }
75
76 public LocalDate getReleaseDate()
77 {
78 return releaseDate;
79 }
80
81
82
83
84
85
86 public Iterable<VersionCompatibility> getCompatibilities()
87 {
88 return compatibilities;
89 }
90
91 public boolean isCompatibleWith(final ApplicationKey application, final HostingType hosting, final int buildNumber)
92 {
93 return any(compatibilities, new Predicate<VersionCompatibility>()
94 {
95 public boolean apply(VersionCompatibility vc)
96 {
97 return vc.isCompatibleWith(equalTo(application), hosting, buildNumber);
98 }
99 });
100 }
101
102 static final class Embedded
103 {
104 Option<ArtifactInfo> artifact;
105 }
106 }