diff --git a/src/main/java/com/crowdin/client/stringcomments/StringCommentsApi.java b/src/main/java/com/crowdin/client/stringcomments/StringCommentsApi.java index 81a4061b1..ae86a185f 100644 --- a/src/main/java/com/crowdin/client/stringcomments/StringCommentsApi.java +++ b/src/main/java/com/crowdin/client/stringcomments/StringCommentsApi.java @@ -114,4 +114,19 @@ public ResponseObject editStringComment(Long projectId, Long stri StringCommentResponseObject response = this.httpClient.patch(builtUrl, request, new HttpRequestConfig(), StringCommentResponseObject.class); return ResponseObject.of(response.getData()); } + + /** + * @param projectId project identifier + * @param request request object + * @return list of updated string comment objects + * @see + */ + public ResponseList stringCommentBatchOperations(Long projectId, List 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); + } } diff --git a/src/main/java/com/crowdin/client/stringtranslations/StringTranslationsApi.java b/src/main/java/com/crowdin/client/stringtranslations/StringTranslationsApi.java index d387a7d63..d654cbfdb 100644 --- a/src/main/java/com/crowdin/client/stringtranslations/StringTranslationsApi.java +++ b/src/main/java/com/crowdin/client/stringtranslations/StringTranslationsApi.java @@ -7,6 +7,7 @@ import com.crowdin.client.core.model.*; import com.crowdin.client.stringtranslations.model.*; +import java.util.List; import java.util.Map; import java.util.Optional; @@ -133,6 +134,32 @@ public void removeApproval(Long projectId, Long approvalId) throws HttpException this.httpClient.delete(this.url + "/projects/" + projectId + "/approvals/" + approvalId, new HttpRequestConfig(), Void.class); } + /** + * @param projectId project identifier + * @see + */ + public ResponseList approvalBatchOperations(Long projectId, List request) { + String url = this.url + "/projects/" + projectId + "/approvals"; + ApprovalResponseList response = this.httpClient.patch(url, request, new HttpRequestConfig(), ApprovalResponseList.class); + return ApprovalResponseList.to(response); + } + + /** + * @param projectId project identifier + * @see + */ + public ResponseList translationBatchOperations(Long projectId, List request) { + String url = this.url + "/projects/" + projectId + "/translations"; + StringTranslationResponseList response = this.httpClient.patch(url, request, new HttpRequestConfig(), StringTranslationResponseList.class); + return StringTranslationResponseList.to(response); + } + /** * @param projectId project identifier * @param languageId language identifier diff --git a/src/test/java/com/crowdin/client/stringcomments/StringCommentsApiTest.java b/src/test/java/com/crowdin/client/stringcomments/StringCommentsApiTest.java index 08dc560e6..a8f3c313a 100644 --- a/src/test/java/com/crowdin/client/stringcomments/StringCommentsApiTest.java +++ b/src/test/java/com/crowdin/client/stringcomments/StringCommentsApiTest.java @@ -47,7 +47,13 @@ public List getMocks() { "api/stringcomments/stringCommentResponse.json"), RequestMock.build(String.format("%s/projects/%d/comments/%d", this.url, projectId, stringCommentId), HttpDelete.METHOD_NAME), RequestMock.build(String.format("%s/projects/%d/comments/%d", this.url, projectId, stringCommentId), HttpPatch.METHOD_NAME, - "api/stringcomments/editStringCommentRequest.json", "api/stringcomments/stringCommentResponse.json") + "api/stringcomments/editStringCommentRequest.json", "api/stringcomments/stringCommentResponse.json"), + RequestMock.build( + String.format("%s/projects/%d/comments", this.url, projectId), + HttpPatch.METHOD_NAME, + "api/stringcomments/stringCommentBatchOperationsRequest.json", + "api/stringcomments/stringCommentBatchOperationsResponse.json" + ) ); } @@ -99,4 +105,41 @@ public void editStringCommentTest() { assertNotNull(response.getData()); } + + @Test + public void stringCommentBatchOperationsTest(){ + List request = new ArrayList() {{ + add(new PatchRequest() {{ + setOp(PatchOperation.REPLACE); + setPath("/2814/text"); + setValue("some issue edited"); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.REPLACE); + setPath("/2814/issueStatus"); + setValue(IssueStatus.RESOLVED); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.ADD); + setPath("/-"); + setValue(new AddStringCommentRequest() {{ + setText("some issue"); + setStringId(1L); + setType(Type.ISSUE); + setTargetLanguageId("en"); + setIssueType("translation_mistake"); + }}); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.REMOVE); + setPath("/2815"); + }}); + }}; + + ResponseList response = this.getStringCommentsApi().stringCommentBatchOperations(projectId, request); + assertNotNull(response); + assertNotNull(response.getData()); + + assertEquals(IssueStatus.UNRESOLVED, response.getData().get(0).getData().getIssueStatus()); + } } diff --git a/src/test/java/com/crowdin/client/stringtranslations/StringTranslationsApiTest.java b/src/test/java/com/crowdin/client/stringtranslations/StringTranslationsApiTest.java index fdb409777..5d6996434 100644 --- a/src/test/java/com/crowdin/client/stringtranslations/StringTranslationsApiTest.java +++ b/src/test/java/com/crowdin/client/stringtranslations/StringTranslationsApiTest.java @@ -1,22 +1,21 @@ package com.crowdin.client.stringtranslations; +import com.crowdin.client.core.model.PatchOperation; +import com.crowdin.client.core.model.PatchRequest; import com.crowdin.client.core.model.ResponseList; import com.crowdin.client.core.model.ResponseObject; import com.crowdin.client.framework.RequestMock; import com.crowdin.client.framework.TestClient; import com.crowdin.client.stringtranslations.model.*; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.*; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Collections; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class StringTranslationsApiTest extends TestClient { @@ -51,7 +50,20 @@ public List getMocks() { RequestMock.build(this.url + "/projects/" + projectId + "/votes", HttpPost.METHOD_NAME, "api/stringtranslations/addVoteRequest.json", "api/stringtranslations/vote.json"), RequestMock.build(this.url + "/projects/" + projectId + "/votes/" + voteId, HttpGet.METHOD_NAME, "api/stringtranslations/vote.json"), RequestMock.build(this.url + "/projects/" + projectId + "/votes/" + voteId, HttpDelete.METHOD_NAME), - RequestMock.build(String.format("%s/projects/%d/translations/alignment", this.url, projectId), HttpPost.METHOD_NAME, "api/stringtranslations/alignTranslationRequest.json", "api/stringtranslations/alignTranslationResponse.json") + RequestMock.build(String.format("%s/projects/%d/translations/alignment", this.url, projectId), HttpPost.METHOD_NAME, "api/stringtranslations/alignTranslationRequest.json", "api/stringtranslations/alignTranslationResponse.json"), + + RequestMock.build( + this.url + "/projects/" + projectId + "/approvals", + HttpPatch.METHOD_NAME, + "api/stringtranslations/approvalBatchOperationsRequest.json", + "api/stringtranslations/approvalBatchOperationsResponse.json" + ), + RequestMock.build( + this.url + "/projects/" + projectId + "/translations", + HttpPatch.METHOD_NAME, + "api/stringtranslations/translationBatchOperationsRequest.json", + "api/stringtranslations/translationBatchOperationsResponse.json" + ) ); } @@ -189,4 +201,55 @@ public void cancelVoteTest() { this.getStringTranslationsApi().cancelVote(projectId, voteId); } + @Test + public void approvalBatchOperationsTest() { + List request = new ArrayList() {{ + add(new PatchRequest() {{ + setOp(PatchOperation.ADD); + setPath("/-"); + setValue(new AddApprovalRequest() {{ + setTranslationId(200L); + }}); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.REMOVE); + setPath("/2815"); + }}); + }}; + + ResponseList response = this.getStringTranslationsApi().approvalBatchOperations(projectId, request); + assertNotNull(response); + assertNotNull(response.getData()); + + assertEquals("uk", response.getData().get(0).getData().getLanguageId()); + assertEquals(190695, response.getData().get(0).getData().getTranslationId()); + } + + @Test + public void translationBatchOperationsTest() { + List request = new ArrayList() {{ + add(new PatchRequest() {{ + setOp(PatchOperation.ADD); + setPath("/-"); + setValue(new AddStringTranslationRequest() {{ + setStringId(35434L); + setLanguageId("fr"); + setText("Цю стрічку перекладено"); + setPluralCategoryName(PluralCategoryName.FEW); + setAddToTm(false); + }}); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.REMOVE); + setPath("/2815"); + }}); + }}; + + ResponseList response = this.getStringTranslationsApi().translationBatchOperations(projectId, request); + assertNotNull(response); + assertNotNull(response.getData()); + + assertEquals(190695, response.getData().get(0).getData().getId()); + assertEquals("tm", response.getData().get(0).getData().getProvider()); + } } diff --git a/src/test/resources/api/stringcomments/stringCommentBatchOperationsRequest.json b/src/test/resources/api/stringcomments/stringCommentBatchOperationsRequest.json new file mode 100644 index 000000000..b340cb6a9 --- /dev/null +++ b/src/test/resources/api/stringcomments/stringCommentBatchOperationsRequest.json @@ -0,0 +1,27 @@ +[ + { + "op": "replace", + "path": "/2814/text", + "value": "some issue edited" + }, + { + "op": "replace", + "path": "/2814/issueStatus", + "value": "resolved" + }, + { + "op": "add", + "path": "/-", + "value": { + "text": "some issue", + "stringId": 1, + "type": "issue", + "targetLanguageId": "en", + "issueType": "translation_mistake" + } + }, + { + "op": "remove", + "path": "/2815" + } +] \ No newline at end of file diff --git a/src/test/resources/api/stringcomments/stringCommentBatchOperationsResponse.json b/src/test/resources/api/stringcomments/stringCommentBatchOperationsResponse.json new file mode 100644 index 000000000..1730b96da --- /dev/null +++ b/src/test/resources/api/stringcomments/stringCommentBatchOperationsResponse.json @@ -0,0 +1,41 @@ +{ + "data": [ + { + "data": { + "id": 2, + "text": "@BeMyEyes Please provide more details on where the text will be used", + "userId": 6, + "stringId": 742, + "user": { + "id": 12, + "username": "john_smith", + "fullName": "John Smith", + "avatarUrl": "" + }, + "string": { + "id": 742, + "text": "HTML page example", + "type": "text", + "hasPlurals": false, + "isIcu": false, + "context": "Document Title\\r\\nXPath: /html/head/title", + "fileId": 22 + }, + "projectId": 1, + "languageId": "bg", + "type": "issue", + "issueType": "source_mistake", + "issueStatus": "unresolved", + "resolverId": 12, + "resolver": { + "id": 12, + "username": "john_smith", + "fullName": "John Smith", + "avatarUrl": "" + }, + "resolvedAt": "2019-09-20T11:05:24+00:00", + "createdAt": "2019-09-20T11:05:24+00:00" + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/api/stringtranslations/approvalBatchOperationsRequest.json b/src/test/resources/api/stringtranslations/approvalBatchOperationsRequest.json new file mode 100644 index 000000000..3ab803c45 --- /dev/null +++ b/src/test/resources/api/stringtranslations/approvalBatchOperationsRequest.json @@ -0,0 +1,13 @@ +[ + { + "op": "add", + "path": "/-", + "value": { + "translationId": 200 + } + }, + { + "op": "remove", + "path": "/2815" + } +] \ No newline at end of file diff --git a/src/test/resources/api/stringtranslations/approvalBatchOperationsResponse.json b/src/test/resources/api/stringtranslations/approvalBatchOperationsResponse.json new file mode 100644 index 000000000..e9a2ac82b --- /dev/null +++ b/src/test/resources/api/stringtranslations/approvalBatchOperationsResponse.json @@ -0,0 +1,19 @@ +{ + "data": [ + { + "data": { + "id": 190695, + "user": { + "id": 19, + "username": "john_doe", + "fullName": "John Smith", + "avatarUrl": "" + }, + "translationId": 190695, + "stringId": 2345, + "languageId": "uk", + "createdAt": "2019-09-19T12:42:12+00:00" + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/api/stringtranslations/translationBatchOperationsRequest.json b/src/test/resources/api/stringtranslations/translationBatchOperationsRequest.json new file mode 100644 index 000000000..7fcf90ebf --- /dev/null +++ b/src/test/resources/api/stringtranslations/translationBatchOperationsRequest.json @@ -0,0 +1,17 @@ +[ + { + "op": "add", + "path": "/-", + "value": { + "stringId": 35434, + "languageId": "fr", + "text": "Цю стрічку перекладено", + "pluralCategoryName": "few", + "addToTm": false + } + }, + { + "op": "remove", + "path": "/2815" + } +] \ No newline at end of file diff --git a/src/test/resources/api/stringtranslations/translationBatchOperationsResponse.json b/src/test/resources/api/stringtranslations/translationBatchOperationsResponse.json new file mode 100644 index 000000000..8e00ee231 --- /dev/null +++ b/src/test/resources/api/stringtranslations/translationBatchOperationsResponse.json @@ -0,0 +1,21 @@ +{ + "data": [ + { + "data": { + "id": 190695, + "text": "Цю стрічку перекладено", + "pluralCategoryName": "few", + "user": { + "id": 19, + "username": "john_doe", + "fullName": "John Smith", + "avatarUrl": "" + }, + "rating": 10, + "provider": "tm", + "isPreTranslated": true, + "createdAt": "2019-09-23T11:26:54+00:00" + } + } + ] +} \ No newline at end of file