Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.http.HttpRequestConfig;
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
import com.crowdin.client.core.http.exceptions.HttpException;
import com.crowdin.client.core.model.*;
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
import com.crowdin.client.stringcomments.model.IssueStatus;
Expand Down Expand Up @@ -146,13 +148,27 @@ public ResponseObject<StringComment> editStringComment(Long projectId, Long stri
* @param request request object
* @return list of updated string comment objects
* @see <ul>
* <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>
* <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>
* <li><a href="https://support.crowdin.com/developer/api/v2/#operation/api.projects.comments.batchPatch" target="_blank"><b>API Documentation</b></a></li>
* <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>
* </ul>
*/
public ResponseList<StringComment> stringCommentBatchOperations(Long projectId, List<PatchRequest> request) {
String builtUrl = String.format("%s/projects/%d/comments", this.url, projectId);
StringCommentResponseList response = this.httpClient.patch(builtUrl, request, new HttpRequestConfig(), StringCommentResponseList.class);
return StringCommentResponseList.to(response);
}

/**
* @param projectId project identifier
* @param commentId comment identifier
* @param attachmentId attachment identifier
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/api/v2/#operation/api.projects.comments.attachments.delete" target="_blank"><b>API Documentation</b></a></li>
* <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>
* </ul>
*/
public void deleteAttachmentFromStringComment(Long projectId, Long commentId, Long attachmentId) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/comments/%d/attachments/%d", this.url, projectId, commentId, attachmentId);
this.httpClient.delete(builtUrl, new HttpRequestConfig(), Void.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.Data;

import java.util.List;

@Data
public class AddStringCommentRequest {

Expand All @@ -11,4 +13,5 @@ public class AddStringCommentRequest {
private Type type;
private String issueType;
private IssueStatus issueStatus;
private List<Attachment> attachments;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.crowdin.client.stringcomments.model;

import lombok.Data;

@Data
public class Attachment {
private Long id;
private String name;
private String mime;
private Long size;
private String category;
private String thumbnailUrl;
private String url;
private String downloadUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class StringComment {
Expand All @@ -18,6 +19,7 @@ public class StringComment {
private String issueType;
private IssueStatus issueStatus;
private Date createdAt;
private List<Attachment> attachments;

@Data
public static class User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.crowdin.client.framework.RequestMock;
import com.crowdin.client.framework.TestClient;
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
import com.crowdin.client.stringcomments.model.Attachment;
import com.crowdin.client.stringcomments.model.IssueStatus;
import com.crowdin.client.stringcomments.model.StringComment;
import com.crowdin.client.stringcomments.model.Type;
Expand All @@ -23,10 +24,12 @@ public class StringCommentsApiTest extends TestClient {
private final Long projectId = 8L;
private final Long project2Id = 9L;
private final Long project3Id = 10L;
private final Long stringId = 64L;
private final Long stringId = 1L;
private final Long stringCommentId = 512L;
private final Long attachmentId = 123L;
private final Long attachmentId2 = 10L;

private final String text = "some issue";
private final String text = "some issue with translation";
private final String targetLanguageId = "en";
private final Type type = Type.ISSUE;
private final String issueType = "translation_mistake";
Expand Down Expand Up @@ -58,7 +61,8 @@ public List<RequestMock> getMocks() {
HttpPatch.METHOD_NAME,
"api/stringcomments/stringCommentBatchOperationsRequest.json",
"api/stringcomments/stringCommentBatchOperationsResponse.json"
)
),
RequestMock.build(String.format("%s/projects/%d/comments/%d/attachments/%d", this.url, projectId, stringCommentId, attachmentId), HttpDelete.METHOD_NAME)
);
}

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

@Test
Expand All @@ -85,6 +90,7 @@ public void listStringCommentsTest_orderByNull() {
assertNotNull(responseList);
assertNotNull(responseList.getData());
assertEquals(1, responseList.getData().size(), "Size of list should be 1");
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
}

@Test
Expand All @@ -108,6 +114,7 @@ public void listStringCommentsTest_orderByIdNull() {

assertEquals(2, responseList.getData().get(0).getData().getId(), "Id of list should be 2");
assertEquals(3, responseList.getData().get(1).getData().getId(), "Id of list should be 3");
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
}

@Test
Expand All @@ -132,6 +139,7 @@ public void listStringCommentsTest_orderByIdAsc() {

assertEquals(2, responseList.getData().get(0).getData().getId(), "Id of list should be 2");
assertEquals(3, responseList.getData().get(1).getData().getId(), "Id of list should be 3");
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
}

@Test
Expand All @@ -156,28 +164,37 @@ public void listStringCommentsTest_orderByIdDesc() {

assertEquals(3, responseList.getData().get(0).getData().getId(), "Id of list should be 3");
assertEquals(2, responseList.getData().get(1).getData().getId(), "Id of list should be 2");
assertEquals(attachmentId2, responseList.getData().get(0).getData().getAttachments().get(0).getId());
}

@Test
public void addStringCommentTest() {
Attachment attachment = new Attachment();
attachment.setId(attachmentId);
List<Attachment> attachments = Collections.singletonList(attachment);

AddStringCommentRequest request = new AddStringCommentRequest() {{
setText(text);
setTargetLanguageId(targetLanguageId);
setStringId(stringId);
setType(type);
setIssueType(issueType);
setIssueStatus(issueStatus);
setAttachments(attachments);
}};
ResponseObject<StringComment> response = this.getStringCommentsApi().addStringComment(projectId, request);
assertNotNull(response);
assertNotNull(response.getData());

assertEquals(attachmentId2, response.getData().getAttachments().get(0).getId());
}

@Test
public void getStringCommentTest() {
ResponseObject<StringComment> response = this.getStringCommentsApi().getStringComment(projectId, stringCommentId);
assertNotNull(response);
assertNotNull(response.getData());

assertEquals(attachmentId2, response.getData().getAttachments().get(0).getId());
}

@Test
Expand All @@ -197,6 +214,7 @@ public void editStringCommentTest() {
assertNotNull(response);
assertNotNull(response.getData());

assertEquals(attachmentId2, response.getData().getAttachments().get(0).getId());
}

@Test
Expand Down Expand Up @@ -234,5 +252,11 @@ public void stringCommentBatchOperationsTest(){
assertNotNull(response.getData());

assertEquals(IssueStatus.UNRESOLVED, response.getData().get(0).getData().getIssueStatus());
assertEquals(attachmentId2, response.getData().get(0).getData().getAttachments().get(0).getId());
}

@Test
public void deleteAttachmentFromStringCommentTest() {
this.getStringCommentsApi().deleteAttachmentFromStringComment(projectId, stringCommentId, attachmentId);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"text": "some issue",
"stringId": 1,
"text": "some issue with translation",
"targetLanguageId": "en",
"stringId": 64,
"type": "issue",
"issueType": "translation_mistake",
"issueStatus": "resolved"
"attachments": [
{
"id": 123
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@
"type": "issue",
"issueType": "source_mistake",
"issueStatus": "unresolved",
"createdAt": "2019-09-20T11:05:24+00:00"
"createdAt": "2019-09-20T11:05:24+00:00",
"attachments": [
{
"id": 10,
"name": "screenshot.png",
"mime": "image/png",
"size": 12345,
"category": "image",
"thumbnailUrl": "https://example.com/thumbnail.png",
"url": "https://example.com/original.png",
"downloadUrl": "https://example.com/raw.png"
}
]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@
"type": "issue",
"issueType": "source_mistake",
"issueStatus": "unresolved",
"createdAt": "2019-09-20T11:05:24+00:00"
"createdAt": "2019-09-20T11:05:24+00:00",
"attachments": [
{
"id": 10,
"name": "screenshot.png",
"mime": "image/png",
"size": 12345,
"category": "image",
"thumbnailUrl": "https://example.com/thumbnail.png",
"url": "https://example.com/original.png",
"downloadUrl": "https://example.com/raw.png"
}
]
}
},
{
Expand Down Expand Up @@ -53,7 +65,19 @@
"type": "issue",
"issueType": "source_mistake",
"issueStatus": "unresolved",
"createdAt": "2019-09-20T11:05:24+00:00"
"createdAt": "2019-09-20T11:05:24+00:00",
"attachments": [
{
"id": 10,
"name": "screenshot.png",
"mime": "image/png",
"size": 12345,
"category": "image",
"thumbnailUrl": "https://example.com/thumbnail.png",
"url": "https://example.com/original.png",
"downloadUrl": "https://example.com/raw.png"
}
]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@
"type": "issue",
"issueType": "source_mistake",
"issueStatus": "unresolved",
"createdAt": "2019-09-20T11:05:24+00:00"
"createdAt": "2019-09-20T11:05:24+00:00",
"attachments": [
{
"id": 10,
"name": "screenshot.png",
"mime": "image/png",
"size": 12345,
"category": "image",
"thumbnailUrl": "https://example.com/thumbnail.png",
"url": "https://example.com/original.png",
"downloadUrl": "https://example.com/raw.png"
}
]
}
},
{
Expand Down Expand Up @@ -53,7 +65,19 @@
"type": "issue",
"issueType": "source_mistake",
"issueStatus": "unresolved",
"createdAt": "2019-09-20T11:05:24+00:00"
"createdAt": "2019-09-20T11:05:24+00:00",
"attachments": [
{
"id": 10,
"name": "screenshot.png",
"mime": "image/png",
"size": 12345,
"category": "image",
"thumbnailUrl": "https://example.com/thumbnail.png",
"url": "https://example.com/original.png",
"downloadUrl": "https://example.com/raw.png"
}
]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@
"avatarUrl": ""
},
"resolvedAt": "2019-09-20T11:05:24+00:00",
"createdAt": "2019-09-20T11:05:24+00:00"
"createdAt": "2019-09-20T11:05:24+00:00",
"attachments": [
{
"id": 10,
"name": "screenshot.png",
"mime": "image/png",
"size": 12345,
"category": "image",
"thumbnailUrl": "https://example.com/thumbnail.png",
"url": "https://example.com/original.png",
"downloadUrl": "https://example.com/raw.png"
}
]
}
}
]
Expand Down
14 changes: 13 additions & 1 deletion src/test/resources/api/stringcomments/stringCommentResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
"type": "issue",
"issueType": "source_mistake",
"issueStatus": "unresolved",
"createdAt": "2019-09-20T11:05:24+00:00"
"createdAt": "2019-09-20T11:05:24+00:00",
"attachments": [
{
"id": 10,
"name": "screenshot.png",
"mime": "image/png",
"size": 12345,
"category": "image",
"thumbnailUrl": "https://example.com/thumbnail.png",
"url": "https://example.com/original.png",
"downloadUrl": "https://example.com/raw.png"
}
]
}
}