diff --git a/src/main/java/com/crowdin/client/sourcestrings/SourceStringsApi.java b/src/main/java/com/crowdin/client/sourcestrings/SourceStringsApi.java index d6814705b..7376f0d94 100644 --- a/src/main/java/com/crowdin/client/sourcestrings/SourceStringsApi.java +++ b/src/main/java/com/crowdin/client/sourcestrings/SourceStringsApi.java @@ -10,9 +10,13 @@ import com.crowdin.client.core.model.ResponseList; import com.crowdin.client.core.model.ResponseObject; import com.crowdin.client.sourcestrings.model.AddSourceStringRequest; +import com.crowdin.client.sourcestrings.model.AddSourceStringStringsBasedRequest; import com.crowdin.client.sourcestrings.model.SourceString; import com.crowdin.client.sourcestrings.model.SourceStringResponseList; import com.crowdin.client.sourcestrings.model.SourceStringResponseObject; +import com.crowdin.client.sourcestrings.model.UploadStringsProgress; +import com.crowdin.client.sourcestrings.model.UploadStringsProgressResponseObject; +import com.crowdin.client.sourcestrings.model.UploadStringsRequest; import java.util.List; import java.util.Map; @@ -27,6 +31,20 @@ public SourceStringsApi(Credentials credentials, ClientConfig clientConfig) { super(credentials, clientConfig); } + /** + * @param projectId project identifier + * @param uploadId upload identifier + */ + public ResponseObject uploadStringsStatus(Long projectId, String uploadId) throws HttpException, HttpBadRequestException { + UploadStringsProgressResponseObject stringsProgressResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/strings/uploads/" + uploadId, new HttpRequestConfig(), UploadStringsProgressResponseObject.class); + return ResponseObject.of(stringsProgressResponseObject.getData()); + } + + public ResponseObject uploadStrings(Long projectId, UploadStringsRequest request) throws HttpException, HttpBadRequestException { + UploadStringsProgressResponseObject stringsProgressResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/strings/uploads", request, new HttpRequestConfig(), UploadStringsProgressResponseObject.class); + return ResponseObject.of(stringsProgressResponseObject.getData()); + } + /** * @param projectId project identifier * @param fileId file identifier @@ -74,6 +92,11 @@ public ResponseObject addSourceString(Long projectId, AddSourceStr return ResponseObject.of(sourceStringResponseObject.getData()); } + public ResponseObject addSourceStringStringsBased(Long projectId, AddSourceStringStringsBasedRequest request) throws HttpException, HttpBadRequestException { + SourceStringResponseObject sourceStringResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/strings", request, new HttpRequestConfig(), SourceStringResponseObject.class); + return ResponseObject.of(sourceStringResponseObject.getData()); + } + /** * @param projectId project identifier * @param stringId string identifier diff --git a/src/main/java/com/crowdin/client/sourcestrings/model/AddSourceStringStringsBasedRequest.java b/src/main/java/com/crowdin/client/sourcestrings/model/AddSourceStringStringsBasedRequest.java new file mode 100644 index 000000000..7cf67020a --- /dev/null +++ b/src/main/java/com/crowdin/client/sourcestrings/model/AddSourceStringStringsBasedRequest.java @@ -0,0 +1,17 @@ +package com.crowdin.client.sourcestrings.model; + +import lombok.Data; + +import java.util.List; + +@Data +public class AddSourceStringStringsBasedRequest { + + private String text; + private String identifier; + private Long branchId; + private String context; + private Boolean isHidden; + private Integer maxLength; + private List labelIds; +} diff --git a/src/main/java/com/crowdin/client/sourcestrings/model/ImportOptions.java b/src/main/java/com/crowdin/client/sourcestrings/model/ImportOptions.java new file mode 100644 index 000000000..044305eb1 --- /dev/null +++ b/src/main/java/com/crowdin/client/sourcestrings/model/ImportOptions.java @@ -0,0 +1,11 @@ +package com.crowdin.client.sourcestrings.model; + +import lombok.Data; + +@Data +public class ImportOptions { + + private Boolean firstLineContainsHeader; + private Boolean importTranslations; + private Object scheme; +} diff --git a/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsProgress.java b/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsProgress.java new file mode 100644 index 000000000..1a4fd5bb7 --- /dev/null +++ b/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsProgress.java @@ -0,0 +1,30 @@ +package com.crowdin.client.sourcestrings.model; + +import lombok.Data; + +import java.util.Date; +import java.util.List; + +@Data +public class UploadStringsProgress { + + private String identifier; + private String status; + private int progress; + private Attributes attributes; + private Date createdAt; + private Date updatedAt; + private Date startedAt; + private Date finishedAt; + private String eta; + + @Data + public static class Attributes { + private Long branchId; + private Long storageId; + private String fileType; + private Integer parserVersion; + private List labelIds; + private ImportOptions importOptions; + } +} diff --git a/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsProgressResponseObject.java b/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsProgressResponseObject.java new file mode 100644 index 000000000..5ef083154 --- /dev/null +++ b/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsProgressResponseObject.java @@ -0,0 +1,10 @@ +package com.crowdin.client.sourcestrings.model; + +import lombok.Data; + +@Data +public class UploadStringsProgressResponseObject { + + private UploadStringsProgress data; + +} diff --git a/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsRequest.java b/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsRequest.java new file mode 100644 index 000000000..1b5214f55 --- /dev/null +++ b/src/main/java/com/crowdin/client/sourcestrings/model/UploadStringsRequest.java @@ -0,0 +1,18 @@ +package com.crowdin.client.sourcestrings.model; + +import lombok.Data; + +import java.util.List; + +@Data +public class UploadStringsRequest { + + private Long branchId; + private Long storageId; + private String type; + private Integer parserVersion; + private List labelIds; + private Boolean updateStrings; + private Boolean cleanupMode; + private ImportOptions importOptions; +} diff --git a/src/test/java/com/crowdin/client/sourcestrings/SourceStringsApiTest.java b/src/test/java/com/crowdin/client/sourcestrings/SourceStringsApiTest.java index 76cb2f25a..c70bac663 100644 --- a/src/test/java/com/crowdin/client/sourcestrings/SourceStringsApiTest.java +++ b/src/test/java/com/crowdin/client/sourcestrings/SourceStringsApiTest.java @@ -7,8 +7,11 @@ import com.crowdin.client.framework.RequestMock; import com.crowdin.client.framework.TestClient; import com.crowdin.client.sourcestrings.model.AddSourceStringRequest; +import com.crowdin.client.sourcestrings.model.AddSourceStringStringsBasedRequest; import com.crowdin.client.sourcestrings.model.SourceString; import com.crowdin.client.sourcestrings.model.SourceStringForm; +import com.crowdin.client.sourcestrings.model.UploadStringsProgress; +import com.crowdin.client.sourcestrings.model.UploadStringsRequest; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPatch; @@ -31,12 +34,19 @@ public class SourceStringsApiTest extends TestClient { private final Long projectId = 3L; private final Long id = 2814L; private final Long branchId = 667L; + private final Long storageId = 61L; + private final Long labelId = 1L; + private final String uploadId = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3"; @Override public List getMocks() { return Arrays.asList( + RequestMock.build(this.url + "/projects/" + projectId + "/strings/uploads/" + uploadId, HttpGet.METHOD_NAME, "api/strings/uploadStrings.json"), + RequestMock.build(this.url + "/projects/" + projectId + "/strings/uploads", HttpPost.METHOD_NAME, "api/strings/uploadStringsReq.json", "api/strings/uploadStrings.json"), + RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpGet.METHOD_NAME, "api/strings/listStrings.json"), RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpGet.METHOD_NAME, "api/strings/listStrings.json"), RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpPost.METHOD_NAME, "api/strings/addStringRequest.json", "api/strings/string.json"), + RequestMock.build(this.url + "/projects/" + projectId + "/strings", HttpPost.METHOD_NAME, "api/strings/addStringStringsBasedRequest.json", "api/strings/string.json"), RequestMock.build(this.url + "/projects/" + projectId + "/strings/" + id, HttpGet.METHOD_NAME, "api/strings/string.json"), RequestMock.build(this.url + "/projects/" + projectId + "/strings/" + id, HttpDelete.METHOD_NAME), RequestMock.build(this.url + "/projects/" + projectId + "/strings/" + id, HttpPatch.METHOD_NAME, "api/strings/editString.json", "api/strings/string.json"), @@ -44,6 +54,27 @@ public List getMocks() { ); } + @Test + public void uploadStringsStatusTest() { + ResponseObject uploadStringsProgressResponseObject = this.getSourceStringsApi().uploadStringsStatus(projectId, uploadId); + assertEquals(uploadStringsProgressResponseObject.getData().getIdentifier(), uploadId); + assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getBranchId(), branchId); + assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getStorageId(), storageId); + assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getLabelIds().get(0), labelId); + } + + @Test + public void uploadStringsTest() { + UploadStringsRequest request = new UploadStringsRequest(); + request.setBranchId(branchId); + request.setStorageId(storageId); + request.setLabelIds(singletonList(labelId)); + ResponseObject uploadStringsProgressResponseObject = this.getSourceStringsApi().uploadStrings(projectId, request); + assertEquals(uploadStringsProgressResponseObject.getData().getIdentifier(), uploadId); + assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getBranchId(), branchId); + assertEquals(uploadStringsProgressResponseObject.getData().getAttributes().getLabelIds().get(0), labelId); + } + @Test public void listStringsTest() { ResponseList sourceStringResponseList = this.getSourceStringsApi().listSourceStrings(projectId, null, null, null, null, null, null, null, null, null); @@ -70,6 +101,21 @@ public void addStringTest() { assertEquals(sourceStringResponseObject.getData().getText(), text); } + @Test + public void addStringStringsBasedTest() { + AddSourceStringStringsBasedRequest request = new AddSourceStringStringsBasedRequest(); + request.setText(text); + request.setIdentifier("6a1821e6499ebae94de4b880fd93b985"); + request.setBranchId(branchId); + request.setContext("shown on main page"); + request.setIsHidden(false); + request.setMaxLength(35); + request.setLabelIds(Arrays.asList(1L)); + ResponseObject sourceStringResponseObject = this.getSourceStringsApi().addSourceStringStringsBased(projectId, request); + assertEquals(sourceStringResponseObject.getData().getId(), id); + assertEquals(sourceStringResponseObject.getData().getText(), text); + } + @Test public void getStringTest() { ResponseObject sourceStringResponseObject = this.getSourceStringsApi().getSourceString(projectId, id); diff --git a/src/test/resources/api/strings/addStringStringsBasedRequest.json b/src/test/resources/api/strings/addStringStringsBasedRequest.json new file mode 100644 index 000000000..c738be803 --- /dev/null +++ b/src/test/resources/api/strings/addStringStringsBasedRequest.json @@ -0,0 +1,11 @@ +{ + "text": "Not all videos are shown to users. See more", + "identifier": "6a1821e6499ebae94de4b880fd93b985", + "branchId": 667, + "context": "shown on main page", + "isHidden": false, + "maxLength": 35, + "labelIds": [ + 1 + ] +} diff --git a/src/test/resources/api/strings/uploadStrings.json b/src/test/resources/api/strings/uploadStrings.json new file mode 100644 index 000000000..bb7aa9960 --- /dev/null +++ b/src/test/resources/api/strings/uploadStrings.json @@ -0,0 +1,32 @@ +{ + "data": { + "identifier": "50fb3506-4127-4ba8-8296-f97dc7e3e0c3", + "status": "finished", + "progress": 100, + "attributes": { + "branchId": 667, + "storageId": 61, + "fileType": "android", + "parserVersion": 8, + "labelIds": [ + 1 + ], + "importOptions": { + "firstLineContainsHeader": false, + "importTranslations": true, + "scheme": { + "identifier": 0, + "sourcePhrase": 1, + "en": 2, + "de": 3 + } + }, + "updateStrings": false, + "cleanupMode": false + }, + "createdAt": "2019-09-23T11:26:54+00:00", + "updatedAt": "2019-09-23T11:26:54+00:00", + "startedAt": "2019-09-23T11:26:54+00:00", + "finishedAt": "2019-09-23T11:26:54+00:00" + } +} diff --git a/src/test/resources/api/strings/uploadStringsReq.json b/src/test/resources/api/strings/uploadStringsReq.json new file mode 100644 index 000000000..92d6b2e34 --- /dev/null +++ b/src/test/resources/api/strings/uploadStringsReq.json @@ -0,0 +1,7 @@ +{ + "storageId": 61, + "branchId": 667, + "labelIds": [ + 1 + ] +}