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.AddonCategoryId;
7   import com.atlassian.marketplace.client.api.LicenseTypeId;
8   
9   import com.google.common.base.Function;
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.collect.Iterables.transform;
17  
18  /**
19   * Properties that exist in both {@link AddonVersion} and {@link AddonVersionSummary}.
20   * @since 2.0.0
21   */
22  public abstract class AddonVersionBase implements Entity
23  {
24      Links _links;
25      Option<String> name;
26      AddonVersionStatus status;
27      PaymentModel paymentModel;
28      boolean staticAddon;
29      boolean deployable;
30      ReleaseProperties release;
31      @ReadOnly DeploymentProperties deployment;
32      
33      @RequiredLink(rel = "self") URI selfUri;
34  
35      @Override
36      public Links getLinks()
37      {
38          return _links;
39      }
40      
41      @Override
42      public URI getSelfUri()
43      {
44          return selfUri;
45      }
46      
47      /**
48       * The version string, e.g. "1.0".  This will always have a value in versions queried from
49       * Marketplace, but can usually be omitted when creating a new version.
50       * {@see ModelBuilders.AddonVersionBuilder#name(String)}
51       */
52      public Option<String> getName()
53      {
54          return name;
55      }
56      
57      /**
58       * Indicates whether the version is free, paid via Atlassian, or paid via Vendor.
59       * {@see ModelBuilders.AddonVersionBuilder#paymentModel(PaymentModel)}
60       */
61      public PaymentModel getPaymentModel()
62      {
63          return paymentModel;
64      }
65  
66      /**
67       * Indicates whether the version is public, private, or pending approval.
68       * {@see ModelBuilders.AddonVersionBuilder#status(AddonVersionStatus)}
69       */
70      public AddonVersionStatus getStatus()
71      {
72          return status;
73      }
74  
75      /**
76       * True if this is a beta version.
77       * {@see ModelBuilders.AddonVersionBuilder#beta(boolean)}
78       */
79      public boolean isBeta()
80      {
81          return release.beta;
82      }
83  
84      /**
85       * True if this is a static add-on (Plugins 1, a deprecated add-on framework).
86       */
87      public boolean isStatic()
88      {
89          return staticAddon;
90      }
91          
92      public boolean isSupported()
93      {
94          return release.supported;
95      }
96  
97      /**
98       * True if this version can be installed directly via the Plugin Manager.
99       */
100     public boolean isDeployable()
101     {
102         return deployable;
103     }
104 
105     /**
106      * List of Atlassian Connect scopes used by the version, if it is an Atlassian Connect add-on;
107      * otherwise an empty list.
108      */
109     public Iterable<ConnectScope> getConnectScopes()
110     {
111         return deployment.permissions.getOrElse(ImmutableList.<ConnectScope>of());
112     }
113 
114     /**
115      * True if this version is compatible with Server instances.
116      */
117     public boolean isServer()
118     {
119         return deployment.server;
120     }
121 
122     /**
123      * True if this version is compatible with Cloud instances.
124      */
125     public boolean isCloud()
126     {
127         return deployment.cloud;
128     }
129 
130     /**
131      * True if automatic updates are allowed for the version. This is always true for Atlassian
132      * Connect add-ons, and is enabled selectively by Atlassian for a small subset of other add-ons.
133      */
134     public boolean isAutoUpdateAllowed()
135     {
136         return deployment.autoUpdateAllowed;
137     }
138     
139     /**
140      * True if this is an Atlassian Connect add-on.
141      */
142     public boolean isConnect()
143     {
144         return deployment.connect;
145     }
146 
147     /**
148      * True if this version is compatible with Data Center instances.
149      */
150     public boolean isDataCenterCompatible()
151     {
152         return deployment.dataCenter;
153     }
154     
155     /**
156      * The unique resource identifier for the software license type used by this version,
157      * if any. This is required for public versions, optional for private versions.
158      * @see ModelBuilders.AddonVersionBuilder#licenseTypeId(Option)
159      */
160     public Option<LicenseTypeId> getLicenseTypeId()
161     {
162         for (URI uri: getLinks().getUri("license"))
163         {
164             return some(LicenseTypeId.fromUri(uri));
165         }
166         return none();
167     }
168     
169     /**
170      * The date on which this version was released.
171      * @see ModelBuilders.AddonVersionBuilder#releaseDate(LocalDate)
172      */
173     public LocalDate getReleaseDate()
174     {
175         return release.date;
176     }
177 
178     /**
179      * The name of the person who released this version.
180      * @see ModelBuilders.AddonVersionBuilder#releasedBy(Option)
181      */
182     public Option<String> getReleasedBy()
183     {
184         return release.releasedBy;
185     }
186     
187     /**
188      * Details about the installable file for this add-on, if it has one that is hosted by
189      * Marketplace.
190      * @see ModelBuilders.AddonVersionBuilder#artifact(Option)
191      */
192     public abstract Option<ArtifactInfo> getArtifactInfo();
193     
194     /**
195      * Shortcut for getting the download URI for the add-on's installable file, if any.
196      * @see #getArtifactInfo()
197      */
198     public abstract Option<URI> getArtifactUri();
199 
200     /**
201      * Shortcut for getting the remote Atlassian Connect descriptor URI for the add-on, if any.
202      * @see #getArtifactInfo()
203      */
204     public abstract Option<URI> getRemoteDescriptorUri();
205 
206     /**
207      * Same as {@link #getFunctionalCategories()}, but returns only the {@link AddonCategoryId}
208      * rather than the rest of the category description.
209      */
210     public Iterable<AddonCategoryId> getFunctionalCategoryIds()
211     {
212         return transform(getLinks().getLinks("functionalCategories"), new Function<Link, AddonCategoryId>()
213             {
214                 public AddonCategoryId apply(Link l)
215                 {
216                     return AddonCategoryId.fromUri(l.getUri());
217                 }
218             });
219     }
220     
221     /**
222      * Returns summaries of all functional categories that this add-on version belongs to. A
223      * functional category - unlike the logical categories returned by
224      * {@link AddonBase#getCategories()} - describes a specific kind of feature integration
225      * based on the software structure of the add-on (for instance, the types of modules it
226      * provides); this is computed by Marketplace, not set by the vendor. Examples of
227      * functional categories include macros in Confluence and workflows in JIRA.
228      */
229     public abstract Iterable<AddonCategorySummary> getFunctionalCategories();
230 
231     static final class DeploymentProperties
232     {
233         Boolean server;
234         Boolean cloud;
235         Boolean connect;
236         Boolean autoUpdateAllowed;
237         Option<ImmutableList<ConnectScope>> permissions;
238         Boolean dataCenter;
239     }
240 
241     static final class ReleaseProperties
242     {
243         LocalDate date;
244         Option<String> releasedBy;
245         Boolean beta;
246         Boolean supported;
247     }
248 }