forked from Chavaillaz/jira-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchApi.java
155 lines (137 loc) · 5.56 KB
/
SearchApi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.chavaillaz.client.jira.api;
import static com.chavaillaz.client.jira.api.IssueApi.ALL_FIELDS;
import static java.util.Collections.emptySet;
import static java.util.Optional.empty;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.commons.lang3.StringUtils.join;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import com.chavaillaz.client.jira.api.expand.IssueExpand;
import com.chavaillaz.client.jira.domain.Filter;
import com.chavaillaz.client.jira.domain.Filters;
import com.chavaillaz.client.jira.domain.Issue;
public interface SearchApi<T extends List<? extends Issue>> extends AutoCloseable {
String URL_SEARCH = "search";
String URL_FILTERS = "filter";
String URL_FILTER = "filter/{0}";
String URL_FILTER_FAVOURITE = "filter/favourite";
/**
* Gets the issues corresponding to the given keys.
*
* @param issuesKey The list of issues key
* @return The corresponding list of issues
*/
default CompletableFuture<T> getIssues(Set<String> issuesKey) {
return getIssues(issuesKey, ALL_FIELDS);
}
/**
* Gets the issues corresponding to the given keys.
*
* @param issuesKey The list of issues key
* @param fields The list of fields to retrieve for those issues
* @return The corresponding list of issues
*/
default CompletableFuture<T> getIssues(Set<String> issuesKey, Set<String> fields) {
// Sending an empty list would make the query fails so the whole query is replaced by an empty one
// Note that an empty list cannot be returned directly as we don't know the class of the generic T
String jql = (issuesKey == null || issuesKey.isEmpty()) ? EMPTY : "issue in (" + join(issuesKey, ",") + ")";
Integer size = issuesKey == null ? 0 : issuesKey.size();
return searchIssues(jql, 0, size, emptySet(), fields);
}
/**
* Performs a search for issues.
* The page offset is 0 and the number of results returned per page is 50.
* No parameter is expanded and all navigable fields in the issues are returned.
*
* @param jql The query in Jira Query Language
* @return A {@link CompletableFuture} with the issues found
*/
default CompletableFuture<T> searchIssues(String jql) {
return searchIssues(jql, 0, 50);
}
/**
* Performs a search for issues.
* No parameter is expanded and all fields in the issues are returned.
*
* @param jql The query in Jira Query Language
* @param startAt The page offset
* @param maxResults The number of results per page
* @return A {@link CompletableFuture} with the issues found
*/
default CompletableFuture<T> searchIssues(String jql, Integer startAt, Integer maxResults) {
return searchIssues(jql, startAt, maxResults, emptySet());
}
/**
* Performs a search for issues.
* All navigable fields in the issues are returned.
*
* @param jql The query in Jira Query Language
* @param startAt The page offset
* @param maxResults The number of results per page
* @param expand The list of parameters to expand
* @return A {@link CompletableFuture} with the issues found
*/
default CompletableFuture<T> searchIssues(String jql, Integer startAt, Integer maxResults, Set<IssueExpand> expand) {
return searchIssues(jql, startAt, maxResults, expand, ALL_FIELDS);
}
/**
* Performs a search for issues.
*
* @param jql The query in Jira Query Language
* @param startAt The page offset
* @param maxResults The number of results per page
* @param expand The list of parameters to expand
* @param fields The list of fields to be present in the issues retrieved
* @return A {@link CompletableFuture} with the issues found
*/
CompletableFuture<T> searchIssues(String jql, Integer startAt, Integer maxResults, Set<IssueExpand> expand, Set<String> fields);
/**
* Creates a new search filter for the logged-in user.
*
* @param filter The filter to create
* @return A {@link CompletableFuture} with the filter created
*/
CompletableFuture<Filter> addFilter(Filter filter);
/**
* Gets a filter.
*
* @param id The filter identifier
* @return A {@link CompletableFuture} with the filter found
*/
CompletableFuture<Filter> getFilter(String id);
/**
* Gets a filter.
* Note that if the filter does not exist, an {@link Optional#empty()} will be returned.
*
* @param id The filter identifier
* @return A {@link CompletableFuture} with the corresponding optional filter
*/
default CompletableFuture<Optional<Filter>> getFilterOptional(String id) {
return getFilter(id)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Gets all favorite filters of the logged-in user.
*
* @return A {@link CompletableFuture} with the filters found
*/
CompletableFuture<Filters> getFavoriteFilters();
/**
* Updates a filter.
*
* @param id The filter identifier
* @param filter The filter to update
* @return A {@link CompletableFuture} with the updated filter
*/
CompletableFuture<Filter> updateFilter(String id, Filter filter);
/**
* Deletes a filter.
*
* @param id The filter identifier
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteFilter(String id);
}