View Javadoc

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   * Information about a specific version of a {@link Product}.
21   * @since 2.0.0
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       * The version string, e.g. "1.0".
54       */
55      public String getName()
56      {
57          return name;
58      }
59      
60      /**
61       * The unique integer that identifies this version and defines its ordering relative to other versions.
62       */
63      public int getBuildNumber()
64      {
65          return buildNumber;
66      }
67      
68      /**
69       * Indicates whether the version is free or paid via Atlassian.
70       */
71      public PaymentModel getPaymentModel()
72      {
73          return paymentModel;
74      }
75      
76      public LocalDate getReleaseDate()
77      {
78          return releaseDate;
79      }
80      
81      /**
82       * Returns a list of {@link VersionCompatibility} objects representing each of the
83       * {@link Application}s the product version is compatible with, and the compatible
84       * application version range.
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 }