From 9859d564f413a342c96fc7cb036ecd0a618dc75a Mon Sep 17 00:00:00 2001 From: alubenskyi Date: Mon, 18 Nov 2024 18:33:17 +0200 Subject: [PATCH 1/3] update job batches sdk --- .../v2/pto/ContentAssignmentPTO.java | 18 +++++ .../api/jobbatches/v2/pto/WorkflowPTO.java | 4 ++ .../api/jobbatches/v2/JobBatchesApiTest.java | 71 ++++++++++++++++--- 3 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/ContentAssignmentPTO.java diff --git a/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/ContentAssignmentPTO.java b/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/ContentAssignmentPTO.java new file mode 100644 index 00000000..7137da1e --- /dev/null +++ b/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/ContentAssignmentPTO.java @@ -0,0 +1,18 @@ +package com.smartling.api.jobbatches.v2.pto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ContentAssignmentPTO +{ + private String workflowStepUid; + private List userUids; +} diff --git a/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java b/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java index 824cf8e7..e7d470b3 100644 --- a/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java +++ b/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java @@ -5,6 +5,8 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + @Data @NoArgsConstructor @AllArgsConstructor @@ -13,4 +15,6 @@ public class WorkflowPTO { private String targetLocaleId; private String workflowUid; + private String contentAssignmentStrategy; + private List contentAssignments; } diff --git a/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java b/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java index 4e581386..5983e63c 100644 --- a/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java +++ b/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java @@ -1,15 +1,6 @@ package com.smartling.api.jobbatches.v2; -import com.smartling.api.jobbatches.v2.pto.BatchItemStatus; -import com.smartling.api.jobbatches.v2.pto.BatchStatus; -import com.smartling.api.jobbatches.v2.pto.BatchStatusResponsePTO; -import com.smartling.api.jobbatches.v2.pto.CancelBatchActionRequestPTO; -import com.smartling.api.jobbatches.v2.pto.CreateBatchRequestPTO; -import com.smartling.api.jobbatches.v2.pto.CreateBatchResponsePTO; -import com.smartling.api.jobbatches.v2.pto.CreateJobRequestPTO; -import com.smartling.api.jobbatches.v2.pto.CreateJobResponsePTO; -import com.smartling.api.jobbatches.v2.pto.RegisterBatchActionRequestPTO; -import com.smartling.api.jobbatches.v2.pto.WorkflowPTO; +import com.smartling.api.jobbatches.v2.pto.*; import com.smartling.api.v2.client.ClientConfiguration; import com.smartling.api.v2.client.DefaultClientConfiguration; import com.smartling.api.v2.client.auth.BearerAuthStaticTokenFilter; @@ -81,7 +72,7 @@ public void testCreateBatch() throws Exception + "\"translationJobUid\":\"jobUid\"," + "\"authorize\":true," + "\"fileUris\":[\"fileUri.json\"]," - + "\"localeWorkflows\":[{\"targetLocaleId\":\"fr-FR\",\"workflowUid\":\"workflowUid\"}]" + + "\"localeWorkflows\":[{\"targetLocaleId\":\"fr-FR\",\"workflowUid\":\"workflowUid\",\"contentAssignmentStrategy\":null,\"contentAssignments\":null}]" + "}"; CreateBatchRequestPTO requestBody = CreateBatchRequestPTO.builder() @@ -105,6 +96,64 @@ public void testCreateBatch() throws Exception assertTrue(request.getPath().startsWith(("/job-batches-api/v2/projects/" + PROJECT_ID + "/batches"))); } + @Test + public void testCreateBatchWithWorkflowStepAssignments() throws Exception + { + assignResponse(HttpStatus.SC_OK, String.format(SUCCESS_RESPONSE_ENVELOPE, "{\"batchUid\" : \"createdBatchUid\"}")); + + String workflowStepUid = "workflowStepUid1"; + String userUid = "userUid1"; + String strategy = "strategy"; + // language=JSON + String requestString = "{" + + "\"translationJobUid\":\"jobUid\"," + + "\"authorize\":true," + + "\"fileUris\":[\"fileUri.json\"]," + + "\"localeWorkflows\":[" + + "{" + + "\"targetLocaleId\":\"fr-FR\"," + + "\"workflowUid\":\"workflowUid\"," + + "\"contentAssignmentStrategy\":\"strategy\"," + + "\"contentAssignments\":[" + + "{" + + "\"workflowStepUid\":\"workflowStepUid1\"," + + "\"userUids\":[\"userUid1\"]" + + "}" + + "]" + + "}" + + "]" + + "}"; + + CreateBatchRequestPTO requestBody = CreateBatchRequestPTO.builder() + .translationJobUid("jobUid") + .authorize(true) + .fileUris(Collections.singletonList("fileUri.json")) + .localeWorkflows(Collections.singletonList(WorkflowPTO.builder() + .targetLocaleId("fr-FR") + .workflowUid("workflowUid") + .contentAssignmentStrategy(strategy) + .contentAssignments( + Collections.singletonList( + ContentAssignmentPTO.builder() + .workflowStepUid(workflowStepUid) + .userUids(Collections.singletonList(userUid)) + .build() + ) + ) + .build() + )) + .build(); + + CreateBatchResponsePTO response = jobBatchesApi.createBatch(PROJECT_ID, requestBody); + + assertEquals("createdBatchUid", response.getBatchUid()); + + RecordedRequest request = mockWebServer.takeRequest(); + assertEquals(POST, request.getMethod()); + assertEquals(requestString, request.getBody().readUtf8()); + assertTrue(request.getPath().startsWith(("/job-batches-api/v2/projects/" + PROJECT_ID + "/batches"))); + } + @Test public void testGetBatch() throws Exception { From 3cafd8f428b9f5d0240b79b2eb88238498034459 Mon Sep 17 00:00:00 2001 From: alubenskyi Date: Wed, 20 Nov 2024 15:56:25 +0200 Subject: [PATCH 2/3] update job batches sdk --- .../api/jobbatches/v2/pto/WorkflowPTO.java | 1 - .../api/jobbatches/v2/JobBatchesApiTest.java | 20 +++++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java b/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java index e7d470b3..9f5428f8 100644 --- a/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java +++ b/smartling-job-batches-api/src/main/java/com/smartling/api/jobbatches/v2/pto/WorkflowPTO.java @@ -15,6 +15,5 @@ public class WorkflowPTO { private String targetLocaleId; private String workflowUid; - private String contentAssignmentStrategy; private List contentAssignments; } diff --git a/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java b/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java index 5983e63c..5e07b804 100644 --- a/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java +++ b/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java @@ -72,7 +72,7 @@ public void testCreateBatch() throws Exception + "\"translationJobUid\":\"jobUid\"," + "\"authorize\":true," + "\"fileUris\":[\"fileUri.json\"]," - + "\"localeWorkflows\":[{\"targetLocaleId\":\"fr-FR\",\"workflowUid\":\"workflowUid\",\"contentAssignmentStrategy\":null,\"contentAssignments\":null}]" + + "\"localeWorkflows\":[{\"targetLocaleId\":\"fr-FR\",\"workflowUid\":\"workflowUid\",\"contentAssignments\":null}]" + "}"; CreateBatchRequestPTO requestBody = CreateBatchRequestPTO.builder() @@ -113,7 +113,6 @@ public void testCreateBatchWithWorkflowStepAssignments() throws Exception + "{" + "\"targetLocaleId\":\"fr-FR\"," + "\"workflowUid\":\"workflowUid\"," - + "\"contentAssignmentStrategy\":\"strategy\"," + "\"contentAssignments\":[" + "{" + "\"workflowStepUid\":\"workflowStepUid1\"," @@ -131,15 +130,14 @@ public void testCreateBatchWithWorkflowStepAssignments() throws Exception .localeWorkflows(Collections.singletonList(WorkflowPTO.builder() .targetLocaleId("fr-FR") .workflowUid("workflowUid") - .contentAssignmentStrategy(strategy) - .contentAssignments( - Collections.singletonList( - ContentAssignmentPTO.builder() - .workflowStepUid(workflowStepUid) - .userUids(Collections.singletonList(userUid)) - .build() - ) - ) + .contentAssignments( + Collections.singletonList( + ContentAssignmentPTO.builder() + .workflowStepUid(workflowStepUid) + .userUids(Collections.singletonList(userUid)) + .build() + ) + ) .build() )) .build(); From e09cbe6c4d7d8fbb3ea4595ea4701c7a6946b000 Mon Sep 17 00:00:00 2001 From: alubenskyi Date: Wed, 20 Nov 2024 16:52:22 +0200 Subject: [PATCH 3/3] fixed imports --- .../api/jobbatches/v2/JobBatchesApiTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java b/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java index 5e07b804..fe02e0af 100644 --- a/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java +++ b/smartling-job-batches-api/src/test/java/com/smartling/api/jobbatches/v2/JobBatchesApiTest.java @@ -1,6 +1,16 @@ package com.smartling.api.jobbatches.v2; -import com.smartling.api.jobbatches.v2.pto.*; +import com.smartling.api.jobbatches.v2.pto.BatchItemStatus; +import com.smartling.api.jobbatches.v2.pto.BatchStatus; +import com.smartling.api.jobbatches.v2.pto.BatchStatusResponsePTO; +import com.smartling.api.jobbatches.v2.pto.CancelBatchActionRequestPTO; +import com.smartling.api.jobbatches.v2.pto.CreateBatchRequestPTO; +import com.smartling.api.jobbatches.v2.pto.CreateBatchResponsePTO; +import com.smartling.api.jobbatches.v2.pto.CreateJobRequestPTO; +import com.smartling.api.jobbatches.v2.pto.CreateJobResponsePTO; +import com.smartling.api.jobbatches.v2.pto.RegisterBatchActionRequestPTO; +import com.smartling.api.jobbatches.v2.pto.WorkflowPTO; +import com.smartling.api.jobbatches.v2.pto.ContentAssignmentPTO; import com.smartling.api.v2.client.ClientConfiguration; import com.smartling.api.v2.client.DefaultClientConfiguration; import com.smartling.api.v2.client.auth.BearerAuthStaticTokenFilter;