Skip to content

Commit faaa2f4

Browse files
authored
DEVORTEX-5264 Implement recently-published api (#112)
1 parent 87cb568 commit faaa2f4

File tree

4 files changed

+108
-16
lines changed

4 files changed

+108
-16
lines changed

smartling-files-api/src/main/java/com/smartling/api/files/v2/FilesApi.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import com.smartling.api.files.v2.pto.FileTypesListPTO;
1313
import com.smartling.api.files.v2.pto.GetFileLastModifiedPTO;
1414
import com.smartling.api.files.v2.pto.GetFilesListPTO;
15+
import com.smartling.api.files.v2.pto.GetRecentlyPublishedFilesPTO;
1516
import com.smartling.api.files.v2.pto.ImportTranslationsPTO;
1617
import com.smartling.api.files.v2.pto.ImportTranslationsResponse;
18+
import com.smartling.api.files.v2.pto.RecentlyPublishedFileItemPTO;
1719
import com.smartling.api.files.v2.pto.RenameFilePto;
1820
import com.smartling.api.files.v2.pto.UploadFilePTO;
1921
import com.smartling.api.files.v2.pto.UploadFileResponse;
@@ -41,79 +43,82 @@
4143

4244
@Produces(APPLICATION_JSON)
4345
@Consumes(APPLICATION_JSON)
44-
@Path("/files-api/v2")
4546
@DetailedErrorMessage(args = "fileUri")
4647
public interface FilesApi extends AutoCloseable
4748
{
4849
@POST
49-
@Path("/projects/{projectId}/file")
50+
@Path("/files-api/v2/projects/{projectId}/file")
5051
@Consumes(MULTIPART_FORM_DATA)
5152
UploadFileResponse uploadFile(@PathParam("projectId") String projectId, @MultipartForm UploadFilePTO uploadFilePTO);
5253

5354
@GET
54-
@Path("/projects/{projectId}/file")
55+
@Path("/files-api/v2/projects/{projectId}/file")
5556
@Produces(WILDCARD)
5657
InputStream downloadSourceFile(@PathParam("projectId") String projectId, @QueryParam("fileUri") String fileUri);
5758

5859
@GET
59-
@Path("/projects/{projectId}/file/status")
60+
@Path("/files-api/v2/projects/{projectId}/file/status")
6061
FileStatusResponse getFileStatus(@PathParam("projectId") String projectId, @QueryParam("fileUri") String fileUri);
6162

6263
@GET
63-
@Path("/projects/{projectId}/locales/{localeId}/file/status")
64+
@Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/status")
6465
FileLocaleStatusResponse getFileLocaleStatus(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @QueryParam("fileUri") String fileUri);
6566

6667
@GET
67-
@Path("/projects/{projectId}/locales/{localeId}/file")
68+
@Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file")
6869
@Produces(WILDCARD)
6970
InputStream downloadTranslatedFile(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @BeanParam DownloadTranslationPTO downloadTranslationPTO);
7071

7172
@GET
72-
@Path("/projects/{projectId}/locales/{localeId}/file")
73+
@Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file")
7374
@Produces(MULTIPART_MIXED)
7475
TranslatedFileMultipart downloadTranslatedFileMultipart(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @BeanParam DownloadTranslationPTO downloadTranslationPTO);
7576

7677
@GET
77-
@Path("/projects/{projectId}/locales/all/file/zip")
78+
@Path("/files-api/v2/projects/{projectId}/locales/all/file/zip")
7879
@Produces(WILDCARD)
7980
InputStream downloadAllFileTranslations(@PathParam("projectId") String projectId, @BeanParam DownloadAllFileTranslationsPTO downloadAllFileTranslationsPTO);
8081

8182
@GET
82-
@Path("/projects/{projectId}/files/zip")
83+
@Path("/files-api/v2/projects/{projectId}/files/zip")
8384
@Produces(WILDCARD)
8485
InputStream downloadMultipleFileTranslations(@PathParam("projectId") String projectId, @BeanParam DownloadMultipleTranslationsPTO downloadMultipleTranslationsPTO);
8586

8687
@GET
87-
@Path("/projects/{projectId}/files/list")
88+
@Path("/files-api/v2/projects/{projectId}/files/list")
8889
ListResponse<FileItemPTO> getFilesList(@PathParam("projectId") String projectId, @BeanParam GetFilesListPTO getFilesListPTO);
8990

91+
@GET
92+
@Path("/published-files-api/v2/projects/{projectId}/files/list/recently-published")
93+
ListResponse<RecentlyPublishedFileItemPTO> getRecentlyPublishedFiles(@PathParam("projectId") String projectId, @BeanParam GetRecentlyPublishedFilesPTO getRecentlyPublishedFilesPTO);
94+
9095
@GET
9196
@Path("/files-api/v2/projects/{projectId}/file-types")
9297
FileTypesListPTO getFilesTypesList(@PathParam("projectId") String projectId);
9398

9499
@POST
95-
@Path("/projects/{projectId}/file/rename")
100+
@Path("/files-api/v2/projects/{projectId}/file/rename")
96101
EmptyData renameFile(@PathParam("projectId") String projectId, RenameFilePto renameFilePto);
97102

98103
@POST
99-
@Path("/projects/{projectId}/file/delete")
104+
@Path("/files-api/v2/projects/{projectId}/file/delete")
100105
EmptyData deleteFile(@PathParam("projectId") String projectId, DeleteFilePTO deleteFilePTO);
101106

102107
@GET
103-
@Path("/projects/{projectId}/file/last-modified")
108+
@Path("/files-api/v2/projects/{projectId}/file/last-modified")
104109
ListResponse<FileLocaleLastModifiedPTO> getFileLastModified(@PathParam("projectId") String projectId, @BeanParam GetFileLastModifiedPTO getFileLastModifiedPto);
105110

106111
@GET
107-
@Path("/projects/{projectId}/locales/{localeId}/file/last-modified")
112+
@Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/last-modified")
108113
FileLocaleLastModifiedPTO getFileLocaleLastModified(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @BeanParam GetFileLastModifiedPTO getFileLastModifiedPto);
109114

110115
@POST
111-
@Path("/projects/{projectId}/locales/{localeId}/file/import")
116+
@Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/import")
112117
@Consumes(MULTIPART_FORM_DATA)
113118
ImportTranslationsResponse importTranslations(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @MultipartForm ImportTranslationsPTO importTranslationsPTO);
114119

115120
@POST
116-
@Path("/projects/{projectId}/locales/{localeId}/file/get-translations")
121+
@Path("/files-api/v2/projects/{projectId}/locales/{localeId}/file/get-translations")
117122
@Consumes(MULTIPART_FORM_DATA)
118123
@Produces(WILDCARD)
119124
InputStream exportTranslations(@PathParam("projectId") String projectId, @PathParam("localeId") String localeId, @MultipartForm ExportTranslationsPTO exportTranslationsPTO);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.smartling.api.files.v2.pto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.NoArgsConstructor;
7+
import lombok.experimental.SuperBuilder;
8+
9+
import javax.ws.rs.QueryParam;
10+
import java.util.List;
11+
12+
@EqualsAndHashCode(callSuper = true)
13+
@Data
14+
@NoArgsConstructor
15+
@AllArgsConstructor
16+
@SuperBuilder
17+
public class GetRecentlyPublishedFilesPTO extends PagedFilter
18+
{
19+
@QueryParam("publishedAfter")
20+
private String publishedAfter;
21+
22+
@QueryParam("fileUris[]")
23+
private List<String> fileUris;
24+
25+
@QueryParam("localeIds[]")
26+
private List<String> localeIds;
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.smartling.api.files.v2.pto;
2+
3+
import com.smartling.api.v2.response.ResponseData;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.util.Date;
9+
10+
@Data
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
public class RecentlyPublishedFileItemPTO implements ResponseData
14+
{
15+
private String fileUri;
16+
private String localeId;
17+
private Date publishDate;
18+
}

smartling-files-api/src/test/java/com/smartling/api/files/v2/FilesApiTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.smartling.api.files.v2.pto.FileStatusResponse;
88
import com.smartling.api.files.v2.pto.FileType;
99
import com.smartling.api.files.v2.pto.GetFilesListPTO;
10+
import com.smartling.api.files.v2.pto.GetRecentlyPublishedFilesPTO;
1011
import com.smartling.api.files.v2.pto.OrderBy;
12+
import com.smartling.api.files.v2.pto.RecentlyPublishedFileItemPTO;
1113
import com.smartling.api.files.v2.pto.RetrievalType;
1214
import com.smartling.api.files.v2.pto.UploadFilePTO;
1315
import com.smartling.api.files.v2.pto.UploadFileResponse;
@@ -265,6 +267,46 @@ public void testGetFilesList() throws Exception
265267
assertTrue(recordedRequest.getPath().contains("fileTypes=JSON"));
266268
}
267269

270+
@Test
271+
public void testGetRecentlyPublishedFilesList() throws Exception {
272+
String getRecentlyPublishedFilesListResponseBody = "" +
273+
"{\n" +
274+
" \"items\": [\n" +
275+
" {\n" +
276+
" \"fileUri\": \"" + FILE_URI + "\",\n" +
277+
" \"localeId\": \"de-DE\",\n" +
278+
" \"publishDate\": \"2018-07-21T00:56:34Z\"\n" +
279+
" }\n" +
280+
" ],\n" +
281+
" \"totalCount\": 1\n" +
282+
"}\n";
283+
assignResponse(200, String.format(SUCCESS_RESPONSE_ENVELOPE, getRecentlyPublishedFilesListResponseBody));
284+
285+
ListResponse<RecentlyPublishedFileItemPTO> response = filesApi.getRecentlyPublishedFiles(
286+
PROJECT_ID,
287+
GetRecentlyPublishedFilesPTO.builder()
288+
.publishedAfter("2018-07-20T00:6:34Z")
289+
.fileUris(singletonList(FILE_URI))
290+
.localeIds(singletonList("de-DE"))
291+
.limit(10)
292+
.offset(100)
293+
.build());
294+
295+
assertEquals(1, response.getItems().size());
296+
assertEquals(FILE_URI, response.getItems().get(0).getFileUri());
297+
assertEquals(date("2018-07-21T00:56:34Z"), response.getItems().get(0).getPublishDate());
298+
assertEquals("de-DE", response.getItems().get(0).getLocaleId());
299+
300+
RecordedRequest recordedRequest = mockWebServer.takeRequest();
301+
assertEquals("GET", recordedRequest.getMethod());
302+
assertTrue(recordedRequest.getPath().contains("/published-files-api/v2/projects/" + PROJECT_ID + "/files/list/recently-published"));
303+
assertTrue(recordedRequest.getPath().contains("fileUris" + URLEncoder.encode("[]", "UTF-8") + "=" + FILE_URI));
304+
assertTrue(recordedRequest.getPath().contains("publishedAfter=" + URLEncoder.encode("2018-07-20T00:6:34Z", "UTF-8")));
305+
assertTrue(recordedRequest.getPath().contains("localeIds" + URLEncoder.encode("[]", "UTF-8") + "=" + "de-DE"));
306+
assertTrue(recordedRequest.getPath().contains("limit=10"));
307+
assertTrue(recordedRequest.getPath().contains("offset=100"));
308+
}
309+
268310
@Test(expected = RestApiRuntimeException.class)
269311
public void testHandleError() throws Exception
270312
{

0 commit comments

Comments
 (0)