This repository was archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAbstractBaseRequestChain.java
231 lines (197 loc) · 6.46 KB
/
AbstractBaseRequestChain.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package io.rocketbase.toggl.report;
import io.rocketbase.toggl.report.model.Billable;
import io.rocketbase.toggl.report.model.DisplayHours;
import org.springframework.core.ParameterizedTypeReference;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* Created by marten on 07.03.17.
*/
public abstract class AbstractBaseRequestChain<T, R> extends ExecutableRequestChain<R> {
protected static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
protected static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
protected final String path;
public AbstractBaseRequestChain(RequestContext context, String path, ParameterizedTypeReference<R> typeReference) {
super(context, path, typeReference);
this.path = path;
}
public T since(Date since) {
super.getUriBuilder()
.addParameter("since", DATE_FORMAT.format(since));
return (T) this;
}
public T since(LocalDateTime since) {
super.getUriBuilder()
.addParameter("since", since.format(DATE_TIME_FORMATTER));
return (T) this;
}
/**
* not allowed in weekly report use since for 7 days starting from...
*/
public T until(Date until) {
super.getUriBuilder()
.addParameter("until", DATE_FORMAT.format(until));
return (T) this;
}
/**
* not allowed in weekly report use since for 7 days starting from...
*/
public T until(LocalDateTime until) {
super.getUriBuilder()
.addParameter("until", until.format(DATE_TIME_FORMATTER));
return (T) this;
}
public T billable(Billable billable) {
super.getUriBuilder()
.addParameter("billable",
billable.name()
.toLowerCase());
return (T) this;
}
public T clientIds(String... ids) {
return clientIds(Arrays.asList(ids));
}
/**
* 0 if you want to filter out time entries without a client
*/
public T clientIds(List<String> ids) {
super.getUriBuilder()
.addParameter("client_ids",
String.join(",", ids));
return (T) this;
}
public T projectIds(String... ids) {
return projectIds(Arrays.asList(ids));
}
/**
* 0 if you want to filter out time entries without a project
*/
public T projectIds(List<String> ids) {
super.getUriBuilder()
.addParameter("project_ids",
String.join(",", ids));
return (T) this;
}
public T userIds(String... ids) {
return userIds(Arrays.asList(ids));
}
public T userIds(List<String> ids) {
super.getUriBuilder()
.addParameter("user_ids",
String.join(",", ids));
return (T) this;
}
public T membersOfGroupIds(String... ids) {
return membersOfGroupIds(Arrays.asList(ids));
}
/**
* This limits provided user_ids to the provided group members
*/
public T membersOfGroupIds(List<String> ids) {
super.getUriBuilder()
.addParameter("members_of_group_ids",
String.join(",", ids));
return (T) this;
}
public T orMembersOfGroupIds(String... ids) {
return orMembersOfGroupIds(Arrays.asList(ids));
}
/**
* This extends provided user_ids with the provided group members
*/
public T orMembersOfGroupIds(List<String> ids) {
super.getUriBuilder()
.addParameter("or_members_of_group_ids",
String.join(",", ids));
return (T) this;
}
public T tagIds(String... ids) {
return tagIds(Arrays.asList(ids));
}
/**
* 0 if you want to filter out time entries without a tag
*/
public T tagIds(List<String> ids) {
super.getUriBuilder()
.addParameter("tag_ids",
String.join(",", ids));
return (T) this;
}
public T taskIds(String... ids) {
return tagIds(Arrays.asList(ids));
}
/**
* 0 if you want to filter out time entries without a task
*/
public T taskIds(List<String> ids) {
super.getUriBuilder()
.addParameter("task_ids",
String.join(",", ids));
return (T) this;
}
public T timeEntryIds(String... ids) {
return tagIds(Arrays.asList(ids));
}
public T timeEntryIds(List<String> ids) {
super.getUriBuilder()
.addParameter("time_entry_ids",
String.join(",", ids));
return (T) this;
}
public T description(String description) {
super.getUriBuilder()
.addParameter("description", description);
return (T) this;
}
public T withoutDescription(boolean withoutDescription) {
super.getUriBuilder()
.addParameter("without_description", withoutDescription ? "true" : "false");
return (T) this;
}
/**
* date/description/duration/user
*/
public T orderField(String orderField) {
super.getUriBuilder()
.addParameter("order_field", orderField);
return (T) this;
}
/**
* on for descending and off for ascending order
*/
public T orderDesc(boolean orderDesc) {
super.getUriBuilder()
.addParameter("order_desc", orderDesc ? "on" : "off");
return (T) this;
}
/**
* default off
*/
public T distinctRates(boolean distinctRates) {
super.getUriBuilder()
.addParameter("distinct_rates", distinctRates ? "on" : "off");
return (T) this;
}
/**
* default off, rounds time according to workspace settings
*/
public T rounding(boolean rounding) {
super.getUriBuilder()
.addParameter("rounding", rounding ? "on" : "off");
return (T) this;
}
/**
* display hours with minutes or as a decimal number, default minutes
*/
public T displayHours(DisplayHours displayHours) {
super.getUriBuilder()
.addParameter("display_hours",
displayHours.name()
.toLowerCase());
return (T) this;
}
}