Skip to content

Commit 1981038

Browse files
author
”Andrei”
committed
feat: add support for string comments attachments
* Added an additional class to model the attachment; * Modified existing classes: StringComment and AddStringCommentRequest to contain a list of attachments; * Implemented the method to delete an attachment from a string comment; * Fixed a typo in the batch operations method (PATCH) to correctly redirect the user to documentation; * Modified JSON response files to mirror the attachment addition; * Tested the newly added method and added additional asserts in existing tests to ensure correct functionality after adding attachments;
1 parent 4b25348 commit 1981038

11 files changed

Lines changed: 164 additions & 16 deletions

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.crowdin.client.core.CrowdinApi;
44
import com.crowdin.client.core.http.HttpRequestConfig;
5+
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
6+
import com.crowdin.client.core.http.exceptions.HttpException;
57
import com.crowdin.client.core.model.*;
68
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
79
import com.crowdin.client.stringcomments.model.IssueStatus;
@@ -146,13 +148,27 @@ public ResponseObject<StringComment> editStringComment(Long projectId, Long stri
146148
* @param request request object
147149
* @return list of updated string comment objects
148150
* @see <ul>
149-
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/String-Comments/operation/api.projects.comments.batchPatch" target="_blank"><b>API Documentation</b></a></li>
150-
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Comments/operation/api.projects.comments.batchPatch" target="_blank"><b>Enterprise API Documentation</b></a></li>
151+
* <li><a href="https://support.crowdin.com/developer/api/v2/#operation/api.projects.comments.batchPatch" target="_blank"><b>API Documentation</b></a></li>
152+
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#operation/api.projects.comments.batchPatch" target="_blank"><b>Enterprise API Documentation</b></a></li>
151153
* </ul>
152154
*/
153155
public ResponseList<StringComment> stringCommentBatchOperations(Long projectId, List<PatchRequest> request) {
154156
String builtUrl = String.format("%s/projects/%d/comments", this.url, projectId);
155157
StringCommentResponseList response = this.httpClient.patch(builtUrl, request, new HttpRequestConfig(), StringCommentResponseList.class);
156158
return StringCommentResponseList.to(response);
157159
}
160+
161+
/**
162+
* @param projectId project identifier
163+
* @param commentId comment identifier
164+
* @param attachmentId attachment identifier
165+
* @see <ul>
166+
* <li><a href="https://support.crowdin.com/developer/api/v2/#operation/api.projects.comments.attachments.delete" target="_blank"><b>API Documentation</b></a></li>
167+
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#operation/api.projects.comments.attachments.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
168+
* </ul>
169+
*/
170+
public void deleteAttachmentFromStringComment(Long projectId, Long commentId, Long attachmentId) throws HttpException, HttpBadRequestException {
171+
String builtUrl = String.format("%s/projects/%d/comments/%d/attachments/%d", this.url, projectId, commentId, attachmentId);
172+
this.httpClient.delete(builtUrl, new HttpRequestConfig(), Void.class);
173+
}
158174
}

src/main/java/com/crowdin/client/stringcomments/model/AddStringCommentRequest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import lombok.Data;
44

5+
import java.util.List;
6+
57
@Data
68
public class AddStringCommentRequest {
79

@@ -11,4 +13,5 @@ public class AddStringCommentRequest {
1113
private Type type;
1214
private String issueType;
1315
private IssueStatus issueStatus;
16+
private List<Attachment> attachments;
1417
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.crowdin.client.stringcomments.model;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class Attachment {
7+
private Long id;
8+
private String name;
9+
private String mime;
10+
private Long size;
11+
private String category;
12+
private String thumbnailUrl;
13+
private String url;
14+
private String downloadUrl;
15+
}

src/main/java/com/crowdin/client/stringcomments/model/StringComment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.Data;
44

55
import java.util.Date;
6+
import java.util.List;
67

78
@Data
89
public class StringComment {
@@ -18,6 +19,7 @@ public class StringComment {
1819
private String issueType;
1920
private IssueStatus issueStatus;
2021
private Date createdAt;
22+
private List<Attachment> attachments;
2123

2224
@Data
2325
public static class User {

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.crowdin.client.framework.RequestMock;
55
import com.crowdin.client.framework.TestClient;
66
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
7+
import com.crowdin.client.stringcomments.model.Attachment;
78
import com.crowdin.client.stringcomments.model.IssueStatus;
89
import com.crowdin.client.stringcomments.model.StringComment;
910
import com.crowdin.client.stringcomments.model.Type;
@@ -23,10 +24,12 @@ public class StringCommentsApiTest extends TestClient {
2324
private final Long projectId = 8L;
2425
private final Long project2Id = 9L;
2526
private final Long project3Id = 10L;
26-
private final Long stringId = 64L;
27+
private final Long stringId = 1L;
2728
private final Long stringCommentId = 512L;
29+
private final Long attachmentId = 123L;
30+
private final Long attachmentId2 = 10L;
2831

29-
private final String text = "some issue";
32+
private final String text = "some issue with translation";
3033
private final String targetLanguageId = "en";
3134
private final Type type = Type.ISSUE;
3235
private final String issueType = "translation_mistake";
@@ -58,7 +61,8 @@ public List<RequestMock> getMocks() {
5861
HttpPatch.METHOD_NAME,
5962
"api/stringcomments/stringCommentBatchOperationsRequest.json",
6063
"api/stringcomments/stringCommentBatchOperationsResponse.json"
61-
)
64+
),
65+
RequestMock.build(String.format("%s/projects/%d/comments/%d/attachments/%d", this.url, projectId, stringCommentId, attachmentId), HttpDelete.METHOD_NAME)
6266
);
6367
}
6468

@@ -68,6 +72,7 @@ public void listStringCommentsTest() {
6872
assertNotNull(responseList);
6973
assertNotNull(responseList.getData());
7074
assertEquals(1, responseList.getData().size(), "Size of list should be 1");
75+
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
7176
}
7277

7378
@Test
@@ -85,6 +90,7 @@ public void listStringCommentsTest_orderByNull() {
8590
assertNotNull(responseList);
8691
assertNotNull(responseList.getData());
8792
assertEquals(1, responseList.getData().size(), "Size of list should be 1");
93+
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
8894
}
8995

9096
@Test
@@ -108,6 +114,7 @@ public void listStringCommentsTest_orderByIdNull() {
108114

109115
assertEquals(2, responseList.getData().get(0).getData().getId(), "Id of list should be 2");
110116
assertEquals(3, responseList.getData().get(1).getData().getId(), "Id of list should be 3");
117+
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
111118
}
112119

113120
@Test
@@ -132,6 +139,7 @@ public void listStringCommentsTest_orderByIdAsc() {
132139

133140
assertEquals(2, responseList.getData().get(0).getData().getId(), "Id of list should be 2");
134141
assertEquals(3, responseList.getData().get(1).getData().getId(), "Id of list should be 3");
142+
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
135143
}
136144

137145
@Test
@@ -156,28 +164,37 @@ public void listStringCommentsTest_orderByIdDesc() {
156164

157165
assertEquals(3, responseList.getData().get(0).getData().getId(), "Id of list should be 3");
158166
assertEquals(2, responseList.getData().get(1).getData().getId(), "Id of list should be 2");
167+
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
159168
}
160169

161170
@Test
162171
public void addStringCommentTest() {
172+
Attachment attachment = new Attachment();
173+
attachment.setId(attachmentId);
174+
List<Attachment> attachments = Collections.singletonList(attachment);
175+
163176
AddStringCommentRequest request = new AddStringCommentRequest() {{
164177
setText(text);
165178
setTargetLanguageId(targetLanguageId);
166179
setStringId(stringId);
167180
setType(type);
168181
setIssueType(issueType);
169-
setIssueStatus(issueStatus);
182+
setAttachments(attachments);
170183
}};
171184
ResponseObject<StringComment> response = this.getStringCommentsApi().addStringComment(projectId, request);
172185
assertNotNull(response);
173186
assertNotNull(response.getData());
187+
188+
assertEquals(attachmentId2, response.getData().getAttachments().get(0).getId());
174189
}
175190

176191
@Test
177192
public void getStringCommentTest() {
178193
ResponseObject<StringComment> response = this.getStringCommentsApi().getStringComment(projectId, stringCommentId);
179194
assertNotNull(response);
180195
assertNotNull(response.getData());
196+
197+
assertEquals(attachmentId2, response.getData().getAttachments().get(0).getId());
181198
}
182199

183200
@Test
@@ -197,6 +214,7 @@ public void editStringCommentTest() {
197214
assertNotNull(response);
198215
assertNotNull(response.getData());
199216

217+
assertEquals(attachmentId2, response.getData().getAttachments().get(0).getId());
200218
}
201219

202220
@Test
@@ -234,5 +252,11 @@ public void stringCommentBatchOperationsTest(){
234252
assertNotNull(response.getData());
235253

236254
assertEquals(IssueStatus.UNRESOLVED, response.getData().get(0).getData().getIssueStatus());
255+
assertEquals(attachmentId2, response.getData().get(0).getData().getAttachments().get(0).getId());
256+
}
257+
258+
@Test
259+
public void deleteAttachmentFromStringCommentTest() {
260+
this.getStringCommentsApi().deleteAttachmentFromStringComment(projectId, stringCommentId, attachmentId);
237261
}
238262
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
2-
"text": "some issue",
2+
"stringId": 1,
3+
"text": "some issue with translation",
34
"targetLanguageId": "en",
4-
"stringId": 64,
55
"type": "issue",
66
"issueType": "translation_mistake",
7-
"issueStatus": "resolved"
7+
"attachments": [
8+
{
9+
"id": 123
10+
}
11+
]
812
}

src/test/resources/api/stringcomments/listStringCommentsResponse.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@
2525
"type": "issue",
2626
"issueType": "source_mistake",
2727
"issueStatus": "unresolved",
28-
"createdAt": "2019-09-20T11:05:24+00:00"
28+
"createdAt": "2019-09-20T11:05:24+00:00",
29+
"attachments": [
30+
{
31+
"id": 10,
32+
"name": "screenshot.png",
33+
"mime": "image/png",
34+
"size": 12345,
35+
"category": "image",
36+
"thumbnailUrl": "https://example.com/thumbnail.png",
37+
"url": "https://example.com/original.png",
38+
"downloadUrl": "https://example.com/raw.png"
39+
}
40+
]
2941
}
3042
}
3143
],

src/test/resources/api/stringcomments/listStringCommentsResponseOrderByIdAsc.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@
2525
"type": "issue",
2626
"issueType": "source_mistake",
2727
"issueStatus": "unresolved",
28-
"createdAt": "2019-09-20T11:05:24+00:00"
28+
"createdAt": "2019-09-20T11:05:24+00:00",
29+
"attachments": [
30+
{
31+
"id": 10,
32+
"name": "screenshot.png",
33+
"mime": "image/png",
34+
"size": 12345,
35+
"category": "image",
36+
"thumbnailUrl": "https://example.com/thumbnail.png",
37+
"url": "https://example.com/original.png",
38+
"downloadUrl": "https://example.com/raw.png"
39+
}
40+
]
2941
}
3042
},
3143
{
@@ -53,7 +65,19 @@
5365
"type": "issue",
5466
"issueType": "source_mistake",
5567
"issueStatus": "unresolved",
56-
"createdAt": "2019-09-20T11:05:24+00:00"
68+
"createdAt": "2019-09-20T11:05:24+00:00",
69+
"attachments": [
70+
{
71+
"id": 10,
72+
"name": "screenshot.png",
73+
"mime": "image/png",
74+
"size": 12345,
75+
"category": "image",
76+
"thumbnailUrl": "https://example.com/thumbnail.png",
77+
"url": "https://example.com/original.png",
78+
"downloadUrl": "https://example.com/raw.png"
79+
}
80+
]
5781
}
5882
}
5983
],

src/test/resources/api/stringcomments/listStringCommentsResponseOrderByIdDesc.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@
2525
"type": "issue",
2626
"issueType": "source_mistake",
2727
"issueStatus": "unresolved",
28-
"createdAt": "2019-09-20T11:05:24+00:00"
28+
"createdAt": "2019-09-20T11:05:24+00:00",
29+
"attachments": [
30+
{
31+
"id": 10,
32+
"name": "screenshot.png",
33+
"mime": "image/png",
34+
"size": 12345,
35+
"category": "image",
36+
"thumbnailUrl": "https://example.com/thumbnail.png",
37+
"url": "https://example.com/original.png",
38+
"downloadUrl": "https://example.com/raw.png"
39+
}
40+
]
2941
}
3042
},
3143
{
@@ -53,7 +65,19 @@
5365
"type": "issue",
5466
"issueType": "source_mistake",
5567
"issueStatus": "unresolved",
56-
"createdAt": "2019-09-20T11:05:24+00:00"
68+
"createdAt": "2019-09-20T11:05:24+00:00",
69+
"attachments": [
70+
{
71+
"id": 10,
72+
"name": "screenshot.png",
73+
"mime": "image/png",
74+
"size": 12345,
75+
"category": "image",
76+
"thumbnailUrl": "https://example.com/thumbnail.png",
77+
"url": "https://example.com/original.png",
78+
"downloadUrl": "https://example.com/raw.png"
79+
}
80+
]
5781
}
5882
}
5983
],

src/test/resources/api/stringcomments/stringCommentBatchOperationsResponse.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@
3434
"avatarUrl": ""
3535
},
3636
"resolvedAt": "2019-09-20T11:05:24+00:00",
37-
"createdAt": "2019-09-20T11:05:24+00:00"
37+
"createdAt": "2019-09-20T11:05:24+00:00",
38+
"attachments": [
39+
{
40+
"id": 10,
41+
"name": "screenshot.png",
42+
"mime": "image/png",
43+
"size": 12345,
44+
"category": "image",
45+
"thumbnailUrl": "https://example.com/thumbnail.png",
46+
"url": "https://example.com/original.png",
47+
"downloadUrl": "https://example.com/raw.png"
48+
}
49+
]
3850
}
3951
}
4052
]

0 commit comments

Comments
 (0)