1 package com.atlassian.marketplace.client.api;
2
3 import com.atlassian.fugue.Option;
4
5 import com.google.common.base.Joiner;
6 import com.google.common.collect.Iterables;
7
8 import static com.atlassian.fugue.Option.none;
9 import static com.atlassian.fugue.Option.some;
10 import static com.google.common.collect.Iterables.concat;
11
12 /**
13 * Interfaces for common query criteria, allowing classes like {@link AddonQuery} to be treated abstractly.
14 * @since 2.0.0
15 */
16 public abstract class QueryProperties
17 {
18 private QueryProperties()
19 {
20 }
21
22 /**
23 * Interface for query criteria that include an "accessToken" parameter.
24 * @see QueryBuilderProperties.AccessToken
25 */
26 public interface AccessToken
27 {
28 /**
29 * The access token, if any, that the client is providing for the query (in order to allow
30 * access to a private listing).
31 * @see QueryBuilderProperties.AccessToken#accessToken(Option)
32 */
33 Option<String> getAccessToken();
34 }
35
36 /**
37 * Interface for query criteria that include "application" and "application build number" parameters.
38 * @see QueryBuilderProperties.ApplicationCriteria
39 */
40 public interface ApplicationCriteria
41 {
42 /**
43 * The key of the application, if any, that the client is using to restrict the query results.
44 * @see QueryBuilderProperties.ApplicationCriteria#application(Option)
45 */
46 Option<ApplicationKey> getApplication();
47
48 /**
49 * The application build number, if any, that the client is using to restrict the query results.
50 * @see QueryBuilderProperties.ApplicationCriteria#appBuildNumber(Option)
51 */
52 Option<Integer> getAppBuildNumber();
53 }
54
55 /**
56 * Interface for query criteria that include "offset" and "limit" parameters.
57 * @see QueryBuilderProperties.Bounds
58 */
59 public interface Bounds
60 {
61 /**
62 * The offset/limit parameters attached to this query.
63 * @see QueryBuilderProperties.Bounds#bounds(QueryBounds)
64 */
65 QueryBounds getBounds();
66 }
67
68 /**
69 * Interface for query criteria that include a "cost" parameter.
70 * @see QueryBuilderProperties.Cost
71 */
72 public interface Cost
73 {
74 /**
75 * The {@link Cost} filter, if any, that the client is using to restrict the query results.
76 * @see QueryBuilderProperties.Cost#cost(Option)
77 */
78 Option<com.atlassian.marketplace.client.api.Cost> getCost();
79 }
80
81 /**
82 * Interface for query criteria that include a "hosting" parameter.
83 * @see QueryBuilderProperties.Hosting
84 */
85 public interface Hosting
86 {
87 /**
88 * The hosting type that the client is using to restrict the query, if any.
89 * @see QueryBuilderProperties.Hosting#hosting(Option)
90 */
91 Option<HostingType> getHosting();
92 }
93
94 /**
95 * Interface for query criteria that include a "withVersion" parameter.
96 * @see QueryBuilderProperties.WithVersion
97 */
98 public interface WithVersion
99 {
100 /**
101 * True if the client is requesting version-level detail in the result set.
102 * @see QueryBuilderProperties.WithVersion#withVersion(boolean)
103 */
104 boolean isWithVersion();
105 }
106
107 // helper methods used internally
108
109 static String describeParams(String className, Iterable<String>... paramLists)
110 {
111 return className + "(" + Joiner.on(", ").join(concat(paramLists)) + ")";
112 }
113
114 static Iterable<String> describeOptBoolean(String name, boolean value)
115 {
116 return value ? some(name + "(true)") : Option.<String>none();
117 }
118
119 static <T extends EnumWithKey> Iterable<String> describeOptEnum(String name, Option<T> value)
120 {
121 for (T v: value)
122 {
123 return some(name + "(" + v.getKey() + ")");
124 }
125 return none();
126 }
127
128 static Iterable<String> describeValues(String name, Iterable<?> values)
129 {
130 if (!Iterables.isEmpty(values))
131 {
132 return some(name + "(" + Joiner.on(",").join(values) + ")");
133 }
134 return none();
135 }
136 }