forked from intercom/intercom-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJob.java
More file actions
216 lines (172 loc) · 6.49 KB
/
Copy pathJob.java
File metadata and controls
216 lines (172 loc) · 6.49 KB
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
package io.intercom.api;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.google.common.collect.Maps;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class Job extends TypedData {
private static final HashMap<String, String> SENTINEL = Maps.newHashMap();
public static Job find(String id)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return find(id, SENTINEL);
}
public static Job find(String id, Map<String, String> params)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return new HttpClient(
UriBuilder.newBuilder().path("jobs").path(id).query(params).build()
).get(Job.class);
}
public static Job update(Job job)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return DataResource.post(
job,
UriBuilder.newBuilder().path("jobs").path(job.getID()).build(),
Job.class);
}
static <T extends TypedData> Job submit(List<JobItem<T>> items, List<String> bulkPaths)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return submit(items, null, bulkPaths);
}
static <T extends TypedData> Job submit(List<JobItem<T>> items, Job job, List<String> bulkPaths)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return DataResource.create(new JobItemRequest<T>(items, job), bulkPaths, Job.class);
}
static <T extends TypedData> JobItemCollection<T> listJobErrorFeed(String jobID, Class<T> c)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
final URI feedURI = UriBuilder.newBuilder()
.path("jobs")
.path(jobID)
.path("error")
.build();
final HttpClient resource = new HttpClient(feedURI);
final TypeReference<JobItemCollection<T>> typeReference =
new TypeReference<JobItemCollection<T>>() {
};
final JavaType type = MapperSupport
.objectMapper()
.getTypeFactory()
.constructParametricType(JobItemCollection.class, c);
return resource.get(type);
}
@JsonProperty("type")
private final String type = "job";
@JsonProperty("id")
private String id;
@JsonProperty("app_id")
private String appID;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("updated_at")
private long updatedAt;
@JsonProperty("completed_at")
private long completedAt;
@JsonProperty("closing_at")
private long closingAt;
@JsonProperty("name")
private String name;
@JsonProperty("state")
private String state;
@JsonProperty("tasks")
private List<JobTask> tasks;
@JsonProperty("links")
private Map<String, URI> links;
public Job() {
}
public String getType() {
return type;
}
public String getID() {
return id;
}
public Job setID(String id) {
this.id = id;
return this;
}
public long getCreatedAt() {
return createdAt;
}
public long getUpdatedAt() {
return updatedAt;
}
public long getCompletedAt() {
return completedAt;
}
public String getName() {
return name;
}
public Job setName(String name) {
this.name = name;
return this;
}
public String getState() {
return state;
}
public String getAppID() {
return appID;
}
public Map<String, URI> getLinks() {
return links;
}
public long getClosingAt() {
return closingAt;
}
public Job setClosingAt(long closingAt) {
this.closingAt = closingAt;
return this;
}
public List<JobTask> getTasks() {
return tasks;
}
@Override
public String toString() {
return "Job{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", appID='" + appID + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", completedAt=" + completedAt +
", name='" + name + '\'' +
", state='" + state + '\'' +
", links=" + links +
"} " + super.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Job job = (Job) o;
if (createdAt != job.createdAt) return false;
if (updatedAt != job.updatedAt) return false;
if (completedAt != job.completedAt) return false;
//noinspection ConstantConditions
if (type != null ? !type.equals(job.type) : job.type != null) return false;
if (id != null ? !id.equals(job.id) : job.id != null) return false;
if (appID != null ? !appID.equals(job.appID) : job.appID != null) return false;
if (name != null ? !name.equals(job.name) : job.name != null) return false;
//noinspection SimplifiableIfStatement
if (state != null ? !state.equals(job.state) : job.state != null) return false;
return !(links != null ? !links.equals(job.links) : job.links != null);
}
@Override
public int hashCode() {
@SuppressWarnings("ConstantConditions") int result = type != null ? type.hashCode() : 0;
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (appID != null ? appID.hashCode() : 0);
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32));
result = 31 * result + (int) (completedAt ^ (completedAt >>> 32));
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (state != null ? state.hashCode() : 0);
result = 31 * result + (links != null ? links.hashCode() : 0);
return result;
}
}