Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FileItemPTO> getFilesList(@PathParam("projectId") String projectId, @BeanParam GetFilesListPTO getFilesListPTO);

@GET
@Path("/published-files-api/v2/projects/{projectId}/files/list/recently-published")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as prefix of the endpoint is published-files-api it seemed we should have them in PublishedFilesApi.java file.

ListResponse<RecentlyPublishedFileItemPTO> 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<FileLocaleLastModifiedPTO> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> fileUris;

@QueryParam("localeIds[]")
private List<String> localeIds;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<RecentlyPublishedFileItemPTO> 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
{
Expand Down