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.PricingType;
8 import com.atlassian.marketplace.client.api.UriTemplate;
9 import com.atlassian.marketplace.client.api.VendorId;
10
11 import com.google.common.base.Function;
12 import com.google.common.collect.ImmutableMap;
13
14 import static com.atlassian.marketplace.client.model.Links.REST_TYPE;
15 import static com.atlassian.marketplace.client.model.Links.WEB_TYPE;
16 import static com.google.common.collect.Iterables.transform;
17
18 /**
19 * Properties that exist in both {@link Addon} and {@link AddonSummary}.
20 * @since 2.0.0
21 */
22 public abstract class AddonBase implements Entity
23 {
24 Links _links;
25 String name;
26 String key;
27 AddonStatus status;
28 Option<String> summary;
29 Option<String> tagLine;
30 @ReadOnly Option<Integer> cloudFreeUsers;
31
32 @RequiredLink(rel = "self") URI selfUri;
33 @RequiredLink(rel = "alternate") URI alternateUri;
34 @RequiredLink(rel = "vendor") URI vendorUri;
35
36 @Override
37 public Links getLinks()
38 {
39 return _links;
40 }
41
42 @Override
43 public URI getSelfUri()
44 {
45 return selfUri;
46 }
47
48 /**
49 * The address of a Marketplace page that shows details of the add-on.
50 */
51 public URI getAlternateUri()
52 {
53 return alternateUri;
54 }
55
56 /**
57 * A unique resource identifier for the add-on's vendor.
58 * @see #getVendor()
59 * @see com.atlassian.marketplace.client.api.Vendors#getById(VendorId)
60 * @see ModelBuilders.AddonBuilder#vendor(VendorId)
61 */
62 public VendorId getVendorId()
63 {
64 return VendorId.fromUri(vendorUri);
65 }
66
67 /**
68 * The name of the add-on.
69 * @see ModelBuilders.AddonBuilder#name(String)
70 */
71 public String getName()
72 {
73 return name;
74 }
75
76 /**
77 * The unique key of the add-on.
78 * @see com.atlassian.marketplace.client.api.Addons#getByKey
79 * @see ModelBuilders.AddonBuilder#key(String)
80 */
81 public String getKey()
82 {
83 return key;
84 }
85
86 /**
87 * Indicates whether the add-on is public, private, or pending approval.
88 * @see ModelBuilders.AddonBuilder#status(AddonStatus)
89 */
90 public AddonStatus getStatus()
91 {
92 return status;
93 }
94
95 /**
96 * Summary of the add-on's functionality. This is optional for private add-ons.
97 * @see ModelBuilders.AddonBuilder#summary(Option)
98 */
99 public Option<String> getSummary()
100 {
101 return summary;
102 }
103
104 /**
105 * A short phrase that summarizes what the add-on does. This is optional for private add-ons.
106 * @see ModelBuilders.AddonBuilder#tagLine(Option)
107 */
108 public Option<String> getTagLine()
109 {
110 return tagLine;
111 }
112
113 /**
114 * If there is an introductory free tier for this add-on, the maximum number of users allowed for free.
115 */
116 public Option<Integer> getCloudFreeUsers()
117 {
118 return cloudFreeUsers;
119 }
120
121 /**
122 * Returns a resource URI for retrieving the add-on's current pricing. You can instead access
123 * pricing directly with {@link com.atlassian.marketplace.client.api.Addons#getPricing(String, PricingType)};
124 * use {@code getPricingUri} only if you need to pass the resource link to other code, for instance in order
125 * to get pricing asynchronously from the front end.
126 * @param pricingType specifies whether to query Cloud or Server pricing
127 * @return link to the pricing resource, if pricing is available for the specified hosting type; otherwise
128 * {@link Option#none()}
129 */
130 public Option<URI> getPricingUri(final PricingType pricingType)
131 {
132 return getLinks().getUriTemplate("pricing", REST_TYPE).map(new Function<UriTemplate, URI>()
133 {
134 public URI apply(UriTemplate t)
135 {
136 return t.resolve(ImmutableMap.of("cloudOrServer", pricingType.getKey(),
137 "liveOrPending", "live"));
138 }
139 });
140 }
141
142 /**
143 * The address of a Marketplace page that shows details of the add-on's pricing.
144 */
145 public Option<URI> getPricingDetailsPageUri()
146 {
147 return getLinks().getUri("pricing", WEB_TYPE);
148 }
149
150 /**
151 * The address of a Marketplace page that shows details of the add-on's reviews.
152 */
153 public Option<URI> getReviewDetailsPageUri()
154 {
155 return getLinks().getUri("reviews", WEB_TYPE);
156 }
157
158 /**
159 * Same as {@link #getCategories()}, but returns only the {@link AddonCategoryId}
160 * rather than the rest of the category description.
161 * @see ModelBuilders.AddonBuilder#categories(Iterable)
162 */
163 public Iterable<AddonCategoryId> getCategoryIds()
164 {
165 return transform(getLinks().getLinks("categories"), new Function<Link, AddonCategoryId>()
166 {
167 public AddonCategoryId apply(Link l)
168 {
169 return AddonCategoryId.fromUri(l.getUri());
170 }
171 });
172 }
173
174 /**
175 * Returns summaries of all logical categories that this add-on belongs to. These are assigned
176 * by the vendor.
177 * @see AddonVersionBase#getFunctionalCategories()
178 * @see #getCategoryIds()
179 */
180 public abstract Iterable<AddonCategorySummary> getCategories();
181
182 /**
183 * Summary information about the add-on's download/install counts.
184 */
185 public abstract AddonDistributionSummary getDistribution();
186
187 /**
188 * The add-on logo.
189 * @see ModelBuilders.AddonBuilder#logo
190 */
191 public abstract Option<ImageInfo> getLogo();
192
193 /**
194 * Summary information about the add-on's reviews.
195 */
196 public abstract AddonReviewsSummary getReviews();
197
198 /**
199 * Summary information about the add-on's vendor.
200 * @see #getVendorId()
201 */
202 public abstract Option<VendorSummary> getVendor();
203 }