Skip to content

Commit 56279ac

Browse files
committed
wip: fifth part of orderBy implementation in list methods
1 parent 23d2923 commit 56279ac

4 files changed

Lines changed: 259 additions & 12 deletions

File tree

src/main/java/com/crowdin/client/stringcomments/StringCommentsApi.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
import com.crowdin.client.core.CrowdinApi;
44
import com.crowdin.client.core.http.HttpRequestConfig;
5-
import com.crowdin.client.core.model.ClientConfig;
6-
import com.crowdin.client.core.model.Credentials;
7-
import com.crowdin.client.core.model.PatchRequest;
8-
import com.crowdin.client.core.model.ResponseList;
9-
import com.crowdin.client.core.model.ResponseObject;
5+
import com.crowdin.client.core.model.*;
106
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
117
import com.crowdin.client.stringcomments.model.IssueStatus;
128
import com.crowdin.client.stringcomments.model.StringComment;
@@ -56,6 +52,36 @@ public ResponseList<StringComment> listStringComments(Long projectId, Long strin
5652
return StringCommentResponseList.to(response);
5753
}
5854

55+
/**
56+
* @param projectId project identifier
57+
* @param stringId string Identifier
58+
* @param limit maximum number of items to retrieve (default 25)
59+
* @param offset starting offset in the collection (default 0)
60+
* @param type defines string comment type
61+
* @param issueType defines issue type
62+
* @param issueStatus defines issue resolution status
63+
* @param orderBy list of OrderByField
64+
* @return list of string comments
65+
* @see <ul>
66+
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.comments.getMany" target="_blank"><b>API Documentation</b></a></li>
67+
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.comments.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
68+
* </ul>
69+
*/
70+
public ResponseList<StringComment> listStringComments(Long projectId, Long stringId, Integer limit, Integer offset, Type type, String issueType, IssueStatus issueStatus, List<OrderByField> orderBy) {
71+
String builtUrl = String.format("%s/projects/%d/comments", this.url, projectId);
72+
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
73+
"limit", Optional.ofNullable(limit),
74+
"offset", Optional.ofNullable(offset),
75+
"type", Optional.ofNullable(type),
76+
"stringId", Optional.ofNullable(stringId),
77+
"issueType", Optional.ofNullable(issueType),
78+
"issueStatus", Optional.ofNullable(issueStatus),
79+
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
80+
);
81+
StringCommentResponseList response = this.httpClient.get(builtUrl, new HttpRequestConfig(queryParams), StringCommentResponseList.class);
82+
return StringCommentResponseList.to(response);
83+
}
84+
5985
/**
6086
* @param projectId project identifier
6187
* @param request request object

src/test/java/com/crowdin/client/stringcomments/StringCommentsApiTest.java

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.crowdin.client.stringcomments;
22

3-
import com.crowdin.client.core.model.PatchOperation;
4-
import com.crowdin.client.core.model.PatchRequest;
5-
import com.crowdin.client.core.model.ResponseList;
6-
import com.crowdin.client.core.model.ResponseObject;
3+
import com.crowdin.client.core.model.*;
74
import com.crowdin.client.framework.RequestMock;
85
import com.crowdin.client.framework.TestClient;
96
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
@@ -16,16 +13,16 @@
1613
import org.apache.http.client.methods.HttpPost;
1714
import org.junit.jupiter.api.Test;
1815

19-
import java.util.ArrayList;
20-
import java.util.Arrays;
21-
import java.util.List;
16+
import java.util.*;
2217

2318
import static org.junit.jupiter.api.Assertions.assertEquals;
2419
import static org.junit.jupiter.api.Assertions.assertNotNull;
2520

2621
public class StringCommentsApiTest extends TestClient {
2722

2823
private final Long projectId = 8L;
24+
private final Long project2Id = 9L;
25+
private final Long project3Id = 10L;
2926
private final Long stringId = 64L;
3027
private final Long stringCommentId = 512L;
3128

@@ -41,6 +38,14 @@ public List<RequestMock> getMocks() {
4138
return Arrays.asList(
4239
RequestMock.build(String.format("%s/projects/%d/comments", this.url, projectId), HttpGet.METHOD_NAME,
4340
"api/stringcomments/listStringCommentsResponse.json"),
41+
RequestMock.build(String.format("%s/projects/%d/comments", this.url, project2Id), HttpGet.METHOD_NAME,
42+
"api/stringcomments/listStringCommentsResponseOrderByIdAsc.json", new HashMap<String, String>() {{
43+
put("orderBy", "id%20asc");
44+
}}),
45+
RequestMock.build(String.format("%s/projects/%d/comments", this.url, project3Id), HttpGet.METHOD_NAME,
46+
"api/stringcomments/listStringCommentsResponseOrderByIdDesc.json", new HashMap<String, String>(){{
47+
put("orderBy", "id%20desc");
48+
}}),
4449
RequestMock.build(String.format("%s/projects/%d/comments", this.url, projectId), HttpPost.METHOD_NAME,
4550
"api/stringcomments/addStringCommentRequest.json", "api/stringcomments/stringCommentResponse.json"),
4651
RequestMock.build(String.format("%s/projects/%d/comments/%d", this.url, projectId, stringCommentId), HttpGet.METHOD_NAME,
@@ -65,6 +70,94 @@ public void listStringCommentsTest() {
6570
assertEquals(1, responseList.getData().size(), "Size of list should be 1");
6671
}
6772

73+
@Test
74+
public void listStringCommentsTest_orderByNull() {
75+
ResponseList<StringComment> responseList = this.getStringCommentsApi().listStringComments(
76+
projectId,
77+
null,
78+
null,
79+
null,
80+
null,
81+
null,
82+
null,
83+
null
84+
);
85+
assertNotNull(responseList);
86+
assertNotNull(responseList.getData());
87+
assertEquals(1, responseList.getData().size(), "Size of list should be 1");
88+
}
89+
90+
@Test
91+
public void listStringCommentsTest_orderByIdNull() {
92+
OrderByField orderById = new OrderByField();
93+
orderById.setFieldName("id");
94+
95+
ResponseList<StringComment> responseList = this.getStringCommentsApi().listStringComments(
96+
project2Id,
97+
null,
98+
null,
99+
null,
100+
null,
101+
null,
102+
null,
103+
Collections.singletonList(orderById)
104+
);
105+
assertNotNull(responseList);
106+
assertNotNull(responseList.getData());
107+
assertEquals(2, responseList.getData().size(), "Size of list should be 1");
108+
109+
assertEquals(2, responseList.getData().get(0).getData().getId(), "Id of list should be 2");
110+
assertEquals(3, responseList.getData().get(1).getData().getId(), "Id of list should be 3");
111+
}
112+
113+
@Test
114+
public void listStringCommentsTest_orderByIdAsc() {
115+
OrderByField orderById = new OrderByField();
116+
orderById.setFieldName("id");
117+
orderById.setOrderBy(SortOrder.ASC);
118+
119+
ResponseList<StringComment> responseList = this.getStringCommentsApi().listStringComments(
120+
project2Id,
121+
null,
122+
null,
123+
null,
124+
null,
125+
null,
126+
null,
127+
Collections.singletonList(orderById)
128+
);
129+
assertNotNull(responseList);
130+
assertNotNull(responseList.getData());
131+
assertEquals(2, responseList.getData().size(), "Size of list should be 1");
132+
133+
assertEquals(2, responseList.getData().get(0).getData().getId(), "Id of list should be 2");
134+
assertEquals(3, responseList.getData().get(1).getData().getId(), "Id of list should be 3");
135+
}
136+
137+
@Test
138+
public void listStringCommentsTest_orderByIdDesc() {
139+
OrderByField orderById = new OrderByField();
140+
orderById.setFieldName("id");
141+
orderById.setOrderBy(SortOrder.DESC);
142+
143+
ResponseList<StringComment> responseList = this.getStringCommentsApi().listStringComments(
144+
project3Id,
145+
null,
146+
null,
147+
null,
148+
null,
149+
null,
150+
null,
151+
Collections.singletonList(orderById)
152+
);
153+
assertNotNull(responseList);
154+
assertNotNull(responseList.getData());
155+
assertEquals(2, responseList.getData().size(), "Size of list should be 1");
156+
157+
assertEquals(3, responseList.getData().get(0).getData().getId(), "Id of list should be 3");
158+
assertEquals(2, responseList.getData().get(1).getData().getId(), "Id of list should be 2");
159+
}
160+
68161
@Test
69162
public void addStringCommentTest() {
70163
AddStringCommentRequest request = new AddStringCommentRequest() {{
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"data": [
3+
{
4+
"data": {
5+
"id": 2,
6+
"text": "@BeMyEyes Please provide more details on where the text will be used",
7+
"userId": 6,
8+
"stringId": 742,
9+
"user": {
10+
"id": 12,
11+
"username": "john_smith",
12+
"fullName": "John Smith",
13+
"avatarUrl": ""
14+
},
15+
"string": {
16+
"id": 123,
17+
"text": "HTML page example",
18+
"type": "text",
19+
"hasPlurals": false,
20+
"isIcu": false,
21+
"context": "Document Title\\r\\nXPath: /html/head/title",
22+
"fileId": 22
23+
},
24+
"languageId": "bg",
25+
"type": "issue",
26+
"issueType": "source_mistake",
27+
"issueStatus": "unresolved",
28+
"createdAt": "2019-09-20T11:05:24+00:00"
29+
}
30+
},
31+
{
32+
"data": {
33+
"id": 3,
34+
"text": "@BeMyEyes Please provide more details on where the text will be used",
35+
"userId": 6,
36+
"stringId": 742,
37+
"user": {
38+
"id": 12,
39+
"username": "john_smith",
40+
"fullName": "John Smith",
41+
"avatarUrl": ""
42+
},
43+
"string": {
44+
"id": 123,
45+
"text": "HTML page example",
46+
"type": "text",
47+
"hasPlurals": false,
48+
"isIcu": false,
49+
"context": "Document Title\\r\\nXPath: /html/head/title",
50+
"fileId": 22
51+
},
52+
"languageId": "bg",
53+
"type": "issue",
54+
"issueType": "source_mistake",
55+
"issueStatus": "unresolved",
56+
"createdAt": "2019-09-20T11:05:24+00:00"
57+
}
58+
}
59+
],
60+
"pagination": {
61+
"offset": 0,
62+
"limit": 25
63+
}
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"data": [
3+
{
4+
"data": {
5+
"id": 3,
6+
"text": "@BeMyEyes Please provide more details on where the text will be used",
7+
"userId": 6,
8+
"stringId": 742,
9+
"user": {
10+
"id": 12,
11+
"username": "john_smith",
12+
"fullName": "John Smith",
13+
"avatarUrl": ""
14+
},
15+
"string": {
16+
"id": 123,
17+
"text": "HTML page example",
18+
"type": "text",
19+
"hasPlurals": false,
20+
"isIcu": false,
21+
"context": "Document Title\\r\\nXPath: /html/head/title",
22+
"fileId": 22
23+
},
24+
"languageId": "bg",
25+
"type": "issue",
26+
"issueType": "source_mistake",
27+
"issueStatus": "unresolved",
28+
"createdAt": "2019-09-20T11:05:24+00:00"
29+
}
30+
},
31+
{
32+
"data": {
33+
"id": 2,
34+
"text": "@BeMyEyes Please provide more details on where the text will be used",
35+
"userId": 6,
36+
"stringId": 742,
37+
"user": {
38+
"id": 12,
39+
"username": "john_smith",
40+
"fullName": "John Smith",
41+
"avatarUrl": ""
42+
},
43+
"string": {
44+
"id": 123,
45+
"text": "HTML page example",
46+
"type": "text",
47+
"hasPlurals": false,
48+
"isIcu": false,
49+
"context": "Document Title\\r\\nXPath: /html/head/title",
50+
"fileId": 22
51+
},
52+
"languageId": "bg",
53+
"type": "issue",
54+
"issueType": "source_mistake",
55+
"issueStatus": "unresolved",
56+
"createdAt": "2019-09-20T11:05:24+00:00"
57+
}
58+
}
59+
],
60+
"pagination": {
61+
"offset": 0,
62+
"limit": 25
63+
}
64+
}

0 commit comments

Comments
 (0)