Kaynağa Gözat

Improve client

ext.rascm 4 yıl önce
ebeveyn
işleme
e0dc55ee1f

+ 1 - 1
build.gradle

@@ -15,7 +15,7 @@ dependencies {
15 15
     compile fileTree(dir: 'libs', include: '*.jar')
16 16
     compile 'io.github.openfeign:feign-core:11.1'
17 17
     compile 'io.github.openfeign:feign-httpclient:11.1'
18
-    compile 'io.github.openfeign:feign-gson:11.1'
18
+    compile 'io.github.openfeign:feign-jackson-jaxb:11.1'
19 19
 
20 20
     compileOnly 'org.projectlombok:lombok:1.18.20'
21 21
     annotationProcessor 'org.projectlombok:lombok:1.18.20'

+ 2 - 2
src/main/java/com/armstrongconsulting/acprotasks/AcproRepository.java

@@ -56,8 +56,8 @@ public class AcproRepository extends BaseRepository
56 56
         {
57 57
             apiKey = AcproConnector.getClient(getUrl()).getApiKey(getUsername(), getPassword(), 28800);
58 58
         }
59
-        return AcproConnector.getClient(getUrl()).getItems(query, offset, limit, apiKey).stream().peek(a -> logger.warn(a.toString())).map(AcproTask::new)
60
-            .toArray(AcproTask[]::new);
59
+        return new Task[0];/*AcproConnector.getClient(getUrl()).getItems(query, offset, limit, apiKey).stream().peek(a -> logger.warn(a.toString())).map(AcproTask::new)
60
+            .toArray(AcproTask[]::new);*/
61 61
     }
62 62
 
63 63
     @Override

+ 2 - 2
src/main/java/com/armstrongconsulting/acprotasks/AcproTask.java

@@ -7,7 +7,7 @@ import javax.swing.*;
7 7
 import org.jetbrains.annotations.NotNull;
8 8
 import org.jetbrains.annotations.Nullable;
9 9
 
10
-import com.armstrongconsulting.acprotasks.client.model.AcproItem;
10
+import com.armstrongconsulting.acprotasks.client.model.Item;
11 11
 import com.intellij.tasks.Comment;
12 12
 import com.intellij.tasks.Task;
13 13
 import com.intellij.tasks.TaskType;
@@ -20,7 +20,7 @@ public class AcproTask extends Task
20 20
     private String summary;
21 21
     private String description;
22 22
 
23
-    public AcproTask(AcproItem item)
23
+    public AcproTask(Item item)
24 24
     {
25 25
         this.id = String.valueOf(item.getId());
26 26
         this.summary = item.getTitle();

+ 3 - 5
src/main/java/com/armstrongconsulting/acprotasks/client/AcproClient.java

@@ -1,13 +1,12 @@
1 1
 package com.armstrongconsulting.acprotasks.client;
2 2
 
3
-import java.util.List;
4
-
5
-import com.armstrongconsulting.acprotasks.client.model.AcproItem;
3
+import com.armstrongconsulting.acprotasks.client.model.Items;
6 4
 
7 5
 import feign.Headers;
8 6
 import feign.Param;
9 7
 import feign.RequestLine;
10 8
 
9
+@Headers("Accept: application/json")
11 10
 public interface AcproClient
12 11
 {
13 12
     @RequestLine("GET /api_key?user={user}&password={password}&expires_after_seconds={expires_after_seconds}")
@@ -15,7 +14,6 @@ public interface AcproClient
15 14
         @Param("expires_after_seconds") Integer timeToLive);
16 15
 
17 16
     @RequestLine("GET /items?q=title:{title}&start={offset}&count={limit}&api_key={apiKey}")
18
-    @Headers("Accept: application/json")
19
-    List<AcproItem> getItems(@Param("title") String titleContains, @Param("offset") Integer offset,
17
+    Items getItems(@Param("title") String titleContains, @Param("offset") Integer offset,
20 18
         @Param("limit") Integer limit, @Param("apiKey") String apiKey);
21 19
 }

+ 4 - 4
src/main/java/com/armstrongconsulting/acprotasks/client/AcproConnector.java

@@ -4,9 +4,9 @@ import com.sun.istack.NotNull;
4 4
 
5 5
 import feign.Feign;
6 6
 import feign.Logger;
7
-import feign.gson.GsonDecoder;
8
-import feign.gson.GsonEncoder;
9 7
 import feign.httpclient.ApacheHttpClient;
8
+import feign.jackson.jaxb.JacksonJaxbJsonDecoder;
9
+import feign.jackson.jaxb.JacksonJaxbJsonEncoder;
10 10
 
11 11
 public class AcproConnector
12 12
 {
@@ -21,8 +21,8 @@ public class AcproConnector
21 21
 
22 22
         return Feign.builder()
23 23
             .client(new ApacheHttpClient())
24
-            .encoder(new GsonEncoder())
25
-            .decoder(new GsonDecoder())
24
+            .encoder(new JacksonJaxbJsonEncoder())
25
+            .decoder(new JacksonJaxbJsonDecoder())
26 26
             .logger(new Logger.JavaLogger(AcproClient.class))
27 27
             .logLevel(Logger.Level.FULL)
28 28
             .target(AcproClient.class, url);

+ 0 - 13
src/main/java/com/armstrongconsulting/acprotasks/client/model/AcproItem.java

@@ -1,13 +0,0 @@
1
-package com.armstrongconsulting.acprotasks.client.model;
2
-
3
-import lombok.Data;
4
-import lombok.ToString;
5
-
6
-@Data
7
-@ToString
8
-public class AcproItem
9
-{
10
-    private Long id;
11
-    private String title;
12
-    private String description;
13
-}

+ 297 - 0
src/main/java/com/armstrongconsulting/acprotasks/client/model/Item.java

@@ -0,0 +1,297 @@
1
+package com.armstrongconsulting.acprotasks.client.model;
2
+
3
+import com.fasterxml.jackson.annotation.JsonInclude;
4
+import com.fasterxml.jackson.annotation.JsonProperty;
5
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6
+
7
+@JsonInclude(JsonInclude.Include.NON_NULL)
8
+@JsonPropertyOrder({
9
+    "actualHours",
10
+    "attachments",
11
+    "created",
12
+    "createdBy",
13
+    "createdBy_firstname",
14
+    "createdBy_lastname",
15
+    "description",
16
+    "estimateHours",
17
+    "id",
18
+    "lastChanged",
19
+    "lastChangedBy",
20
+    "lastChangedBy_firstname",
21
+    "lastChangedBy_lastname",
22
+    "project",
23
+    "project_name",
24
+    "status",
25
+    "title",
26
+    "unreadByAssignee",
27
+    "urgency"
28
+})
29
+public class Item
30
+{
31
+    @JsonProperty("actualHours")
32
+    private Integer actualHours;
33
+    @JsonProperty("attachments")
34
+    private Integer attachments;
35
+    @JsonProperty("created")
36
+    private String created;
37
+    @JsonProperty("createdBy")
38
+    private Integer createdBy;
39
+    @JsonProperty("createdBy_firstname")
40
+    private String createdByFirstname;
41
+    @JsonProperty("createdBy_lastname")
42
+    private String createdByLastname;
43
+    @JsonProperty("description")
44
+    private String description;
45
+    @JsonProperty("estimateHours")
46
+    private Integer estimateHours;
47
+    @JsonProperty("id")
48
+    private Integer id;
49
+    @JsonProperty("lastChanged")
50
+    private String lastChanged;
51
+    @JsonProperty("lastChangedBy")
52
+    private Integer lastChangedBy;
53
+    @JsonProperty("lastChangedBy_firstname")
54
+    private String lastChangedByFirstname;
55
+    @JsonProperty("lastChangedBy_lastname")
56
+    private String lastChangedByLastname;
57
+    @JsonProperty("project")
58
+    private Integer project;
59
+    @JsonProperty("project_name")
60
+    private String projectName;
61
+    @JsonProperty("status")
62
+    private String status;
63
+    @JsonProperty("title")
64
+    private String title;
65
+    @JsonProperty("unreadByAssignee")
66
+    private Boolean unreadByAssignee;
67
+    @JsonProperty("urgency")
68
+    private Integer urgency;
69
+
70
+    @JsonProperty("actualHours")
71
+    public Integer getActualHours()
72
+    {
73
+        return actualHours;
74
+    }
75
+
76
+    @JsonProperty("actualHours")
77
+    public void setActualHours(Integer actualHours)
78
+    {
79
+        this.actualHours = actualHours;
80
+    }
81
+
82
+    @JsonProperty("attachments")
83
+    public Integer getAttachments()
84
+    {
85
+        return attachments;
86
+    }
87
+
88
+    @JsonProperty("attachments")
89
+    public void setAttachments(Integer attachments)
90
+    {
91
+        this.attachments = attachments;
92
+    }
93
+
94
+    @JsonProperty("created")
95
+    public String getCreated()
96
+    {
97
+        return created;
98
+    }
99
+
100
+    @JsonProperty("created")
101
+    public void setCreated(String created)
102
+    {
103
+        this.created = created;
104
+    }
105
+
106
+    @JsonProperty("createdBy")
107
+    public Integer getCreatedBy()
108
+    {
109
+        return createdBy;
110
+    }
111
+
112
+    @JsonProperty("createdBy")
113
+    public void setCreatedBy(Integer createdBy)
114
+    {
115
+        this.createdBy = createdBy;
116
+    }
117
+
118
+    @JsonProperty("createdBy_firstname")
119
+    public String getCreatedByFirstname()
120
+    {
121
+        return createdByFirstname;
122
+    }
123
+
124
+    @JsonProperty("createdBy_firstname")
125
+    public void setCreatedByFirstname(String createdByFirstname)
126
+    {
127
+        this.createdByFirstname = createdByFirstname;
128
+    }
129
+
130
+    @JsonProperty("createdBy_lastname")
131
+    public String getCreatedByLastname()
132
+    {
133
+        return createdByLastname;
134
+    }
135
+
136
+    @JsonProperty("createdBy_lastname")
137
+    public void setCreatedByLastname(String createdByLastname)
138
+    {
139
+        this.createdByLastname = createdByLastname;
140
+    }
141
+
142
+    @JsonProperty("description")
143
+    public String getDescription()
144
+    {
145
+        return description;
146
+    }
147
+
148
+    @JsonProperty("description")
149
+    public void setDescription(String description)
150
+    {
151
+        this.description = description;
152
+    }
153
+
154
+    @JsonProperty("estimateHours")
155
+    public Integer getEstimateHours()
156
+    {
157
+        return estimateHours;
158
+    }
159
+
160
+    @JsonProperty("estimateHours")
161
+    public void setEstimateHours(Integer estimateHours)
162
+    {
163
+        this.estimateHours = estimateHours;
164
+    }
165
+
166
+    @JsonProperty("id")
167
+    public Integer getId()
168
+    {
169
+        return id;
170
+    }
171
+
172
+    @JsonProperty("id")
173
+    public void setId(Integer id)
174
+    {
175
+        this.id = id;
176
+    }
177
+
178
+    @JsonProperty("lastChanged")
179
+    public String getLastChanged()
180
+    {
181
+        return lastChanged;
182
+    }
183
+
184
+    @JsonProperty("lastChanged")
185
+    public void setLastChanged(String lastChanged)
186
+    {
187
+        this.lastChanged = lastChanged;
188
+    }
189
+
190
+    @JsonProperty("lastChangedBy")
191
+    public Integer getLastChangedBy()
192
+    {
193
+        return lastChangedBy;
194
+    }
195
+
196
+    @JsonProperty("lastChangedBy")
197
+    public void setLastChangedBy(Integer lastChangedBy)
198
+    {
199
+        this.lastChangedBy = lastChangedBy;
200
+    }
201
+
202
+    @JsonProperty("lastChangedBy_firstname")
203
+    public String getLastChangedByFirstname()
204
+    {
205
+        return lastChangedByFirstname;
206
+    }
207
+
208
+    @JsonProperty("lastChangedBy_firstname")
209
+    public void setLastChangedByFirstname(String lastChangedByFirstname)
210
+    {
211
+        this.lastChangedByFirstname = lastChangedByFirstname;
212
+    }
213
+
214
+    @JsonProperty("lastChangedBy_lastname")
215
+    public String getLastChangedByLastname()
216
+    {
217
+        return lastChangedByLastname;
218
+    }
219
+
220
+    @JsonProperty("lastChangedBy_lastname")
221
+    public void setLastChangedByLastname(String lastChangedByLastname)
222
+    {
223
+        this.lastChangedByLastname = lastChangedByLastname;
224
+    }
225
+
226
+    @JsonProperty("project")
227
+    public Integer getProject()
228
+    {
229
+        return project;
230
+    }
231
+
232
+    @JsonProperty("project")
233
+    public void setProject(Integer project)
234
+    {
235
+        this.project = project;
236
+    }
237
+
238
+    @JsonProperty("project_name")
239
+    public String getProjectName()
240
+    {
241
+        return projectName;
242
+    }
243
+
244
+    @JsonProperty("project_name")
245
+    public void setProjectName(String projectName)
246
+    {
247
+        this.projectName = projectName;
248
+    }
249
+
250
+    @JsonProperty("status")
251
+    public String getStatus()
252
+    {
253
+        return status;
254
+    }
255
+
256
+    @JsonProperty("status")
257
+    public void setStatus(String status)
258
+    {
259
+        this.status = status;
260
+    }
261
+
262
+    @JsonProperty("title")
263
+    public String getTitle()
264
+    {
265
+        return title;
266
+    }
267
+
268
+    @JsonProperty("title")
269
+    public void setTitle(String title)
270
+    {
271
+        this.title = title;
272
+    }
273
+
274
+    @JsonProperty("unreadByAssignee")
275
+    public Boolean getUnreadByAssignee()
276
+    {
277
+        return unreadByAssignee;
278
+    }
279
+
280
+    @JsonProperty("unreadByAssignee")
281
+    public void setUnreadByAssignee(Boolean unreadByAssignee)
282
+    {
283
+        this.unreadByAssignee = unreadByAssignee;
284
+    }
285
+
286
+    @JsonProperty("urgency")
287
+    public Integer getUrgency()
288
+    {
289
+        return urgency;
290
+    }
291
+
292
+    @JsonProperty("urgency")
293
+    public void setUrgency(Integer urgency)
294
+    {
295
+        this.urgency = urgency;
296
+    }
297
+}

+ 89 - 0
src/main/java/com/armstrongconsulting/acprotasks/client/model/Items.java

@@ -0,0 +1,89 @@
1
+package com.armstrongconsulting.acprotasks.client.model;
2
+
3
+import java.util.List;
4
+
5
+import com.fasterxml.jackson.annotation.JsonInclude;
6
+import com.fasterxml.jackson.annotation.JsonProperty;
7
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
8
+
9
+@JsonInclude(JsonInclude.Include.NON_NULL)
10
+@JsonPropertyOrder({
11
+    "@rows",
12
+    "@sort",
13
+    "@start",
14
+    "@totalNumRows",
15
+    "item"
16
+})
17
+public class Items
18
+{
19
+    @JsonProperty("@rows")
20
+    private String rows;
21
+    @JsonProperty("@sort")
22
+    private String sort;
23
+    @JsonProperty("@start")
24
+    private String start;
25
+    @JsonProperty("@totalNumRows")
26
+    private String totalNumRows;
27
+    @JsonProperty("item")
28
+    private List<Item> item = null;
29
+
30
+    @JsonProperty("@rows")
31
+    public String getRows()
32
+    {
33
+        return rows;
34
+    }
35
+
36
+    @JsonProperty("@rows")
37
+    public void setRows(String rows)
38
+    {
39
+        this.rows = rows;
40
+    }
41
+
42
+    @JsonProperty("@sort")
43
+    public String getSort()
44
+    {
45
+        return sort;
46
+    }
47
+
48
+    @JsonProperty("@sort")
49
+    public void setSort(String sort)
50
+    {
51
+        this.sort = sort;
52
+    }
53
+
54
+    @JsonProperty("@start")
55
+    public String getStart()
56
+    {
57
+        return start;
58
+    }
59
+
60
+    @JsonProperty("@start")
61
+    public void setStart(String start)
62
+    {
63
+        this.start = start;
64
+    }
65
+
66
+    @JsonProperty("@totalNumRows")
67
+    public String getTotalNumRows()
68
+    {
69
+        return totalNumRows;
70
+    }
71
+
72
+    @JsonProperty("@totalNumRows")
73
+    public void setTotalNumRows(String totalNumRows)
74
+    {
75
+        this.totalNumRows = totalNumRows;
76
+    }
77
+
78
+    @JsonProperty("item")
79
+    public List<Item> getItem()
80
+    {
81
+        return item;
82
+    }
83
+
84
+    @JsonProperty("item")
85
+    public void setItem(List<Item> item)
86
+    {
87
+        this.item = item;
88
+    }
89
+}