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..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 @@ -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; @@ -41,79 +43,82 @@ @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("/published-files-api/v2/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); @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/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..c5bc9225 --- /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 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 ddc5b0fd..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 @@ -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" + + " \"publishDate\": \"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).getPublishDate()); + assertEquals("de-DE", response.getItems().get(0).getLocaleId()); + + RecordedRequest recordedRequest = mockWebServer.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + 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")); + assertTrue(recordedRequest.getPath().contains("limit=10")); + assertTrue(recordedRequest.getPath().contains("offset=100")); + } + @Test(expected = RestApiRuntimeException.class) public void testHandleError() throws Exception {