diff --git a/src/main/java/com/crowdin/client/translationmemory/TranslationMemoryApi.java b/src/main/java/com/crowdin/client/translationmemory/TranslationMemoryApi.java index 822f61ed5..e7242639d 100644 --- a/src/main/java/com/crowdin/client/translationmemory/TranslationMemoryApi.java +++ b/src/main/java/com/crowdin/client/translationmemory/TranslationMemoryApi.java @@ -334,6 +334,21 @@ public ResponseObject editTmSegment(Long tmId, Long segmentId, List

+ *

  • API Documentation
  • + *
  • API Enterprise Documentation
  • + * + */ + public ResponseList batchOperationsTmSegment(Long tmId, List request) throws HttpException, HttpBadRequestException { + String url = formUrl_tmSegments(tmId); + TmSegmentResponseList responseList = this.httpClient.patch(url, request, new HttpRequestConfig(), TmSegmentResponseList.class); + return TmSegmentResponseList.to(responseList); + } + // private String formUrl_tmSegments(Long tmId) { diff --git a/src/test/java/com/crowdin/client/translationmemory/TranslationMemorySegmentsApiTest.java b/src/test/java/com/crowdin/client/translationmemory/TranslationMemorySegmentsApiTest.java index 7b250d9ad..bdeb068f8 100644 --- a/src/test/java/com/crowdin/client/translationmemory/TranslationMemorySegmentsApiTest.java +++ b/src/test/java/com/crowdin/client/translationmemory/TranslationMemorySegmentsApiTest.java @@ -24,10 +24,13 @@ public class TranslationMemorySegmentsApiTest extends TestClient { private final Long tm2Id = 2L; private final Long tm3Id = 3L; private final Long segmentId = 1L; + private final Long recordId = 1L; private final Long tmsId = 4L; private final Long tms2Id = 5L; + private final String recordText = "Перекладений текст 2"; + @Override public List getMocks() { return Arrays.asList( @@ -89,6 +92,14 @@ public List getMocks() { HttpPatch.METHOD_NAME, "api/translationmemory/segments/editTmSegmentRequest.json", "api/translationmemory/segments/commonResponses_single.json" + ), + + // BATCH OPERATIONS + RequestMock.build( + formUrl_tmSegments(tmsId), + HttpPatch.METHOD_NAME, + "api/translationmemory/segments/batchTmSegmentRequest.json", + "api/translationmemory/segments/batchTmSegmentResponse.json" ) ); } @@ -204,6 +215,46 @@ public void editTmSegment() { assertTmSegment(response.getData()); } + @Test + public void batchOperationsTmSegment() { + List request = new ArrayList() {{ + add(new PatchRequest() {{ + setOp(PatchOperation.ADD); + setPath("/-"); + setValue(new CreateTmSegmentRequest() {{ + setRecords(singletonList(new TmSegmentRecordForm() {{ + setLanguageId("uk"); + setText("Перекладений текст"); + }})); + }}); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.ADD); + setPath("/" + segmentId + "/records/-"); + setValue(new TmSegmentRecordForm() {{ + setLanguageId("uk"); + setText("Перекладений текст"); + }}); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.REMOVE); + setPath("/" + segmentId); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.REMOVE); + setPath("/" + segmentId + "/records/" + recordId); + }}); + add(new PatchRequest() {{ + setOp(PatchOperation.REPLACE); + setPath("/" + segmentId + "/records/" + recordId + "/text"); + setValue(recordText); + }}); + }}; + + ResponseList response = this.getTranslationMemoryApi().batchOperationsTmSegment(tmsId, request); + assertTmSegment(response.getData().get(0).getData()); + } + @SneakyThrows private static void assertTmSegment(TmSegment tmSegment) { assertNotNull(tmSegment); diff --git a/src/test/resources/api/translationmemory/segments/batchTmSegmentRequest.json b/src/test/resources/api/translationmemory/segments/batchTmSegmentRequest.json new file mode 100644 index 000000000..e76e84209 --- /dev/null +++ b/src/test/resources/api/translationmemory/segments/batchTmSegmentRequest.json @@ -0,0 +1,35 @@ +[ + { + "op": "add", + "path": "/-", + "value": { + "records": [ + { + "languageId": "uk", + "text": "Перекладений текст" + } + ] + } + }, + { + "op": "add", + "path": "/1/records/-", + "value": { + "languageId": "uk", + "text": "Перекладений текст" + } + }, + { + "op": "remove", + "path": "/1" + }, + { + "op": "remove", + "path": "/1/records/1" + }, + { + "op": "replace", + "path": "/1/records/1/text", + "value": "Перекладений текст 2" + } +] \ No newline at end of file diff --git a/src/test/resources/api/translationmemory/segments/batchTmSegmentResponse.json b/src/test/resources/api/translationmemory/segments/batchTmSegmentResponse.json new file mode 100644 index 000000000..e2a765f49 --- /dev/null +++ b/src/test/resources/api/translationmemory/segments/batchTmSegmentResponse.json @@ -0,0 +1,21 @@ +{ + "data": [ + { + "data": { + "id": 4, + "records": [ + { + "id": 1, + "languageId": "uk", + "text": "Перекладений текст", + "usageCount": 13, + "createdBy": 1, + "updatedBy": 1, + "createdAt": "2019-09-16T13:48:04+00:00", + "updatedAt": "2019-09-16T13:48:04+00:00" + } + ] + } + } + ] +} \ No newline at end of file