From ce69945d57fb19b7ac0661fb46a32e060cbcc3d1 Mon Sep 17 00:00:00 2001 From: DGSmartling Date: Fri, 25 Apr 2025 15:18:04 +0200 Subject: [PATCH 1/4] DEVORTEX-5264 Implement recently-published api --- .../com/smartling/api/files/v2/FilesApi.java | 6 +++ .../v2/pto/GetRecentlyPublishedFilesPTO.java | 27 ++++++++++++ .../v2/pto/RecentlyPublishedFileItemPTO.java | 18 ++++++++ .../smartling/api/files/v2/FilesApiTest.java | 42 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/GetRecentlyPublishedFilesPTO.java create mode 100644 smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java diff --git a/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java b/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java index b1a215c5..1f77dd1d 100644 --- a/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java +++ b/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java @@ -12,8 +12,10 @@ import com.smartling.api.files.v2.pto.FileTypesListPTO; import com.smartling.api.files.v2.pto.GetFileLastModifiedPTO; import com.smartling.api.files.v2.pto.GetFilesListPTO; +import com.smartling.api.files.v2.pto.GetRecentlyPublishedFilesPTO; import com.smartling.api.files.v2.pto.ImportTranslationsPTO; import com.smartling.api.files.v2.pto.ImportTranslationsResponse; +import com.smartling.api.files.v2.pto.RecentlyPublishedFileItemPTO; import com.smartling.api.files.v2.pto.RenameFilePto; import com.smartling.api.files.v2.pto.UploadFilePTO; import com.smartling.api.files.v2.pto.UploadFileResponse; @@ -87,6 +89,10 @@ public interface FilesApi extends AutoCloseable @Path("/projects/{projectId}/files/list") ListResponse getFilesList(@PathParam("projectId") String projectId, @BeanParam GetFilesListPTO getFilesListPTO); + @GET + @Path("/projects/{projectId}/files/list/recently-published") + ListResponse getRecentlyPublishedFiles(@PathParam("projectId") String projectId, @BeanParam GetRecentlyPublishedFilesPTO getRecentlyPublishedFilesPTO); + @GET @Path("/files-api/v2/projects/{projectId}/file-types") FileTypesListPTO getFilesTypesList(@PathParam("projectId") String projectId); diff --git a/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/GetRecentlyPublishedFilesPTO.java b/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/GetRecentlyPublishedFilesPTO.java new file mode 100644 index 00000000..90208d59 --- /dev/null +++ b/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/GetRecentlyPublishedFilesPTO.java @@ -0,0 +1,27 @@ +package com.smartling.api.files.v2.pto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import javax.ws.rs.QueryParam; +import java.util.List; + +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +public class GetRecentlyPublishedFilesPTO extends PagedFilter +{ + @QueryParam("publishedAfter") + private String publishedAfter; + + @QueryParam("fileUris[]") + private List fileUris; + + @QueryParam("localeIds[]") + private List localeIds; +} diff --git a/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java b/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java new file mode 100644 index 00000000..12395b94 --- /dev/null +++ b/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java @@ -0,0 +1,18 @@ +package com.smartling.api.files.v2.pto; + +import com.smartling.api.v2.response.ResponseData; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class RecentlyPublishedFileItemPTO implements ResponseData +{ + private String fileUri; + private String localeId; + private Date publishedDate; +} diff --git a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java index ddc5b0fd..37b0def4 100644 --- a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java +++ b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java @@ -7,7 +7,9 @@ import com.smartling.api.files.v2.pto.FileStatusResponse; import com.smartling.api.files.v2.pto.FileType; import com.smartling.api.files.v2.pto.GetFilesListPTO; +import com.smartling.api.files.v2.pto.GetRecentlyPublishedFilesPTO; import com.smartling.api.files.v2.pto.OrderBy; +import com.smartling.api.files.v2.pto.RecentlyPublishedFileItemPTO; import com.smartling.api.files.v2.pto.RetrievalType; import com.smartling.api.files.v2.pto.UploadFilePTO; import com.smartling.api.files.v2.pto.UploadFileResponse; @@ -265,6 +267,46 @@ public void testGetFilesList() throws Exception assertTrue(recordedRequest.getPath().contains("fileTypes=JSON")); } + @Test + public void testGetRecentlyPublishedFilesList() throws Exception { + String getRecentlyPublishedFilesListResponseBody = "" + + "{\n" + + " \"items\": [\n" + + " {\n" + + " \"fileUri\": \"" + FILE_URI + "\",\n" + + " \"localeId\": \"de-DE\",\n" + + " \"publishedDate\": \"2018-07-21T00:56:34Z\"\n" + + " }\n" + + " ],\n" + + " \"totalCount\": 1\n" + + "}\n"; + assignResponse(200, String.format(SUCCESS_RESPONSE_ENVELOPE, getRecentlyPublishedFilesListResponseBody)); + + ListResponse response = filesApi.getRecentlyPublishedFiles( + PROJECT_ID, + GetRecentlyPublishedFilesPTO.builder() + .publishedAfter("2018-07-20T00:6:34Z") + .fileUris(singletonList(FILE_URI)) + .localeIds(singletonList("de-DE")) + .limit(10) + .offset(100) + .build()); + + assertEquals(1, response.getItems().size()); + assertEquals(FILE_URI, response.getItems().get(0).getFileUri()); + assertEquals(date("2018-07-21T00:56:34Z"), response.getItems().get(0).getPublishedDate()); + assertEquals("de-DE", response.getItems().get(0).getLocaleId()); + + RecordedRequest recordedRequest = mockWebServer.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + assertTrue(recordedRequest.getPath().contains("/projects/" + PROJECT_ID + "/files/list/recently-published")); + assertTrue(recordedRequest.getPath().contains("fileUris" + URLEncoder.encode("[]", "UTF-8") + "=" + FILE_URI)); + assertTrue(recordedRequest.getPath().contains("publishedAfter=" + URLEncoder.encode("2018-07-20T00:6:34Z", "UTF-8"))); + assertTrue(recordedRequest.getPath().contains("localeIds" + URLEncoder.encode("[]", "UTF-8") + "=" + "de-DE")); + assertTrue(recordedRequest.getPath().contains("limit=10")); + assertTrue(recordedRequest.getPath().contains("offset=100")); + } + @Test(expected = RestApiRuntimeException.class) public void testHandleError() throws Exception { From 5a9d7a1818a80f7eabc8a333ef9b962af490a9b7 Mon Sep 17 00:00:00 2001 From: DGSmartling Date: Fri, 25 Apr 2025 15:51:28 +0200 Subject: [PATCH 2/4] refactor --- .../com/smartling/api/files/v2/FilesApi.java | 33 +++++++++---------- .../smartling/api/files/v2/FilesApiTest.java | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java b/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java index 1f77dd1d..9f4c9c97 100644 --- a/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java +++ b/smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java @@ -43,54 +43,53 @@ @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) -@Path("/files-api/v2") @DetailedErrorMessage(args = "fileUri") public interface FilesApi extends AutoCloseable { @POST - @Path("/projects/{projectId}/file") + @Path("/files-api/v2/projects/{projectId}/file") @Consumes(MULTIPART_FORM_DATA) UploadFileResponse uploadFile(@PathParam("projectId") String projectId, @MultipartForm UploadFilePTO uploadFilePTO); @GET - @Path("/projects/{projectId}/file") + @Path("/files-api/v2/projects/{projectId}/file") @Produces(WILDCARD) InputStream downloadSourceFile(@PathParam("projectId") String projectId, @QueryParam("fileUri") String fileUri); @GET - @Path("/projects/{projectId}/file/status") + @Path("/files-api/v2/projects/{projectId}/file/status") FileStatusResponse getFileStatus(@PathParam("projectId") String projectId, @QueryParam("fileUri") String fileUri); @GET - @Path("/projects/{projectId}/locales/{localeId}/file/status") + @Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/status") FileLocaleStatusResponse getFileLocaleStatus(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @QueryParam("fileUri") String fileUri); @GET - @Path("/projects/{projectId}/locales/{localeId}/file") + @Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file") @Produces(WILDCARD) InputStream downloadTranslatedFile(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @BeanParam DownloadTranslationPTO downloadTranslationPTO); @GET - @Path("/projects/{projectId}/locales/{localeId}/file") + @Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file") @Produces(MULTIPART_MIXED) TranslatedFileMultipart downloadTranslatedFileMultipart(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @BeanParam DownloadTranslationPTO downloadTranslationPTO); @GET - @Path("/projects/{projectId}/locales/all/file/zip") + @Path("/files-api/v2/projects/{projectId}/locales/all/file/zip") @Produces(WILDCARD) InputStream downloadAllFileTranslations(@PathParam("projectId") String projectId, @BeanParam DownloadAllFileTranslationsPTO downloadAllFileTranslationsPTO); @GET - @Path("/projects/{projectId}/files/zip") + @Path("/files-api/v2/projects/{projectId}/files/zip") @Produces(WILDCARD) InputStream downloadMultipleFileTranslations(@PathParam("projectId") String projectId, @BeanParam DownloadMultipleTranslationsPTO downloadMultipleTranslationsPTO); @GET - @Path("/projects/{projectId}/files/list") + @Path("/files-api/v2/projects/{projectId}/files/list") ListResponse getFilesList(@PathParam("projectId") String projectId, @BeanParam GetFilesListPTO getFilesListPTO); @GET - @Path("/projects/{projectId}/files/list/recently-published") + @Path("/published-files-api/v2/projects/{projectId}/files/list/recently-published") ListResponse getRecentlyPublishedFiles(@PathParam("projectId") String projectId, @BeanParam GetRecentlyPublishedFilesPTO getRecentlyPublishedFilesPTO); @GET @@ -98,28 +97,28 @@ public interface FilesApi extends AutoCloseable FileTypesListPTO getFilesTypesList(@PathParam("projectId") String projectId); @POST - @Path("/projects/{projectId}/file/rename") + @Path("/files-api/v2/projects/{projectId}/file/rename") EmptyData renameFile(@PathParam("projectId") String projectId, RenameFilePto renameFilePto); @POST - @Path("/projects/{projectId}/file/delete") + @Path("/files-api/v2/projects/{projectId}/file/delete") EmptyData deleteFile(@PathParam("projectId") String projectId, DeleteFilePTO deleteFilePTO); @GET - @Path("/projects/{projectId}/file/last-modified") + @Path("/files-api/v2/projects/{projectId}/file/last-modified") ListResponse getFileLastModified(@PathParam("projectId") String projectId, @BeanParam GetFileLastModifiedPTO getFileLastModifiedPto); @GET - @Path("/projects/{projectId}/locales/{localeId}/file/last-modified") + @Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/last-modified") FileLocaleLastModifiedPTO getFileLocaleLastModified(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @BeanParam GetFileLastModifiedPTO getFileLastModifiedPto); @POST - @Path("/projects/{projectId}/locales/{localeId}/file/import") + @Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/import") @Consumes(MULTIPART_FORM_DATA) ImportTranslationsResponse importTranslations(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @MultipartForm ImportTranslationsPTO importTranslationsPTO); @POST - @Path("/projects/{projectId}/locales/{localeId}/file/get-translations") + @Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/get-translations") @Consumes(MULTIPART_FORM_DATA) @Produces(WILDCARD) InputStream exportTranslations(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @MultipartForm ExportTranslationsPTO exportTranslationsPTO); diff --git a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java index 37b0def4..5c95f457 100644 --- a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java +++ b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java @@ -299,7 +299,7 @@ public void testGetRecentlyPublishedFilesList() throws Exception { RecordedRequest recordedRequest = mockWebServer.takeRequest(); assertEquals("GET", recordedRequest.getMethod()); - assertTrue(recordedRequest.getPath().contains("/projects/" + PROJECT_ID + "/files/list/recently-published")); + assertTrue(recordedRequest.getPath().contains("/published-files-api/v2/projects/" + PROJECT_ID + "/files/list/recently-published")); assertTrue(recordedRequest.getPath().contains("fileUris" + URLEncoder.encode("[]", "UTF-8") + "=" + FILE_URI)); assertTrue(recordedRequest.getPath().contains("publishedAfter=" + URLEncoder.encode("2018-07-20T00:6:34Z", "UTF-8"))); assertTrue(recordedRequest.getPath().contains("localeIds" + URLEncoder.encode("[]", "UTF-8") + "=" + "de-DE")); From 1e0e63c6a2e9f84c2ffb1eece2d64f02d3f755fe Mon Sep 17 00:00:00 2001 From: DGSmartling Date: Mon, 28 Apr 2025 11:28:45 +0200 Subject: [PATCH 3/4] refactor --- .../api/files/v2/pto/RecentlyPublishedFileItemPTO.java | 2 +- .../java/com/smartling/api/files/v2/FilesApiTest.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java b/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java index 12395b94..c5bc9225 100644 --- a/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java +++ b/smartling-files-api/src/main/java/com/smartling/api/files/v2/pto/RecentlyPublishedFileItemPTO.java @@ -14,5 +14,5 @@ public class RecentlyPublishedFileItemPTO implements ResponseData { private String fileUri; private String localeId; - private Date publishedDate; + private Date publishDate; } diff --git a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java index 5c95f457..7815d6eb 100644 --- a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java +++ b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java @@ -275,7 +275,7 @@ public void testGetRecentlyPublishedFilesList() throws Exception { " {\n" + " \"fileUri\": \"" + FILE_URI + "\",\n" + " \"localeId\": \"de-DE\",\n" + - " \"publishedDate\": \"2018-07-21T00:56:34Z\"\n" + + " \"publishDate\": \"2018-07-21T00:56:34Z\"\n" + " }\n" + " ],\n" + " \"totalCount\": 1\n" + @@ -294,7 +294,7 @@ public void testGetRecentlyPublishedFilesList() throws Exception { assertEquals(1, response.getItems().size()); assertEquals(FILE_URI, response.getItems().get(0).getFileUri()); - assertEquals(date("2018-07-21T00:56:34Z"), response.getItems().get(0).getPublishedDate()); + assertEquals(date("2018-07-21T00:56:34Z"), response.getItems().get(0).getPublishDate()); assertEquals("de-DE", response.getItems().get(0).getLocaleId()); RecordedRequest recordedRequest = mockWebServer.takeRequest(); @@ -634,6 +634,11 @@ public void testDownloadTranslatedFileMultipartWhenFailedDueToBrokenResponse() t ); } + @Test + public void aaa() { + + } + private static Date date(String date) throws ParseException { return FAPI_DATE_FORMAT.parse(date); From 2fce1bf3c1b8537dbc4236340384277ac928a0e8 Mon Sep 17 00:00:00 2001 From: DGSmartling Date: Mon, 28 Apr 2025 11:35:38 +0200 Subject: [PATCH 4/4] refactor --- .../test/java/com/smartling/api/files/v2/FilesApiTest.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java index 7815d6eb..d0331a37 100644 --- a/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java +++ b/smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java @@ -634,11 +634,6 @@ public void testDownloadTranslatedFileMultipartWhenFailedDueToBrokenResponse() t ); } - @Test - public void aaa() { - - } - private static Date date(String date) throws ParseException { return FAPI_DATE_FORMAT.parse(date);