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 @@ -114,4 +114,19 @@ public ResponseObject<StringComment> 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 <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>
* </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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 <ul>
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/String-Translations/operation/api.projects.approvals.patch" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Translations/operation/api.projects.approvals.patch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<Approval> approvalBatchOperations(Long projectId, List<PatchRequest> 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 <ul>
* <li><a href="https://support.crowdin.com/developer/api/v2/#tag/String-Translations/operation/api.projects.translations.patch" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Translations/operation/api.projects.translations.patch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<StringTranslation> translationBatchOperations(Long projectId, List<PatchRequest> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public List<RequestMock> 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"
)
);
}

Expand Down Expand Up @@ -99,4 +105,41 @@ public void editStringCommentTest() {
assertNotNull(response.getData());

}

@Test
public void stringCommentBatchOperationsTest(){
List<PatchRequest> request = new ArrayList<PatchRequest>() {{
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<StringComment> response = this.getStringCommentsApi().stringCommentBatchOperations(projectId, request);
assertNotNull(response);
assertNotNull(response.getData());

assertEquals(IssueStatus.UNRESOLVED, response.getData().get(0).getData().getIssueStatus());
}
}
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -51,7 +50,20 @@ public List<RequestMock> 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"
)
);
}

Expand Down Expand Up @@ -189,4 +201,55 @@ public void cancelVoteTest() {
this.getStringTranslationsApi().cancelVote(projectId, voteId);
}

@Test
public void approvalBatchOperationsTest() {
List<PatchRequest> request = new ArrayList<PatchRequest>() {{
add(new PatchRequest() {{
setOp(PatchOperation.ADD);
setPath("/-");
setValue(new AddApprovalRequest() {{
setTranslationId(200L);
}});
}});
add(new PatchRequest() {{
setOp(PatchOperation.REMOVE);
setPath("/2815");
}});
}};

ResponseList<Approval> 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<PatchRequest> request = new ArrayList<PatchRequest>() {{
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<StringTranslation> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"op": "add",
"path": "/-",
"value": {
"translationId": 200
}
},
{
"op": "remove",
"path": "/2815"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"op": "add",
"path": "/-",
"value": {
"stringId": 35434,
"languageId": "fr",
"text": "Цю стрічку перекладено",
"pluralCategoryName": "few",
"addToTm": false
}
},
{
"op": "remove",
"path": "/2815"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Loading