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 @@ -2,6 +2,7 @@

import com.smartling.api.files.v2.pto.DeleteFilePTO;
import com.smartling.api.files.v2.pto.DownloadAllFileTranslationsPTO;
import com.smartling.api.files.v2.pto.DownloadMultipleFilesTranslationsPTO;
import com.smartling.api.files.v2.pto.DownloadMultipleTranslationsPTO;
import com.smartling.api.files.v2.pto.DownloadTranslationPTO;
import com.smartling.api.files.v2.pto.ExportTranslationsPTO;
Expand All @@ -19,10 +20,10 @@
import com.smartling.api.files.v2.pto.RenameFilePto;
import com.smartling.api.files.v2.pto.UploadFilePTO;
import com.smartling.api.files.v2.pto.UploadFileResponse;
import com.smartling.api.files.v2.resteasy.ext.TranslatedFileMultipart;
import com.smartling.api.v2.client.exception.server.DetailedErrorMessage;
import com.smartling.api.v2.response.EmptyData;
import com.smartling.api.v2.response.ListResponse;
import com.smartling.api.files.v2.resteasy.ext.TranslatedFileMultipart;
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;

import javax.ws.rs.BeanParam;
Expand All @@ -33,7 +34,6 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import java.io.InputStream;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
Expand Down Expand Up @@ -79,11 +79,26 @@ public interface FilesApi extends AutoCloseable
@Produces(WILDCARD)
InputStream downloadAllFileTranslations(@PathParam("projectId") String projectId, @BeanParam DownloadAllFileTranslationsPTO downloadAllFileTranslationsPTO);

/**
* @deprecated use downloadMultipleFileTranslations with POST method
*/
@Deprecated
@GET
@Path("/files-api/v2/projects/{projectId}/files/zip")
@Produces(WILDCARD)
InputStream downloadMultipleFileTranslations(@PathParam("projectId") String projectId, @BeanParam DownloadMultipleTranslationsPTO downloadMultipleTranslationsPTO);

/**
* Download multiple translated files as zip archive
*
* @return {@link InputStream} for zip archive with translated files, if files found for the given file filter;
* null, if no files found for the given file filter.
*/
@POST
@Path("/files-api/v2/projects/{projectId}/files/zip")
@Produces(WILDCARD)
InputStream downloadMultipleFileTranslations(@PathParam("projectId") String projectId, DownloadMultipleFilesTranslationsPTO downloadMultipleTranslationsPTO);

@GET
@Path("/files-api/v2/projects/{projectId}/files/list")
ListResponse<FileItemPTO> getFilesList(@PathParam("projectId") String projectId, @BeanParam GetFilesListPTO getFilesListPTO);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.smartling.api.files.v2.pto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Singular;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DownloadMultipleFilesTranslationsPTO
{
@Singular("file")
private List<FileLocalePTO> files;
private RetrievalType retrievalType;
private Boolean includeOriginalStrings;
private FileNameMode fileNameMode;
private LocaleMode localeMode;
private String zipFileName;
private FileFilter fileFilter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.smartling.api.files.v2.pto;

public enum FileFilter
{
/**
* All requested files will be included in the response
*/
ALL_FILES,
/**
* Only fully published files will be included in the response.
*/
PUBLISHED_FILES_ONLY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.smartling.api.files.v2.pto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Singular;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class FileLocalePTO
{
private String fileUri;
@Singular("localeId")
private List<String> localeIds;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.smartling.api.files.v2;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.smartling.api.files.v2.pto.DownloadMultipleFilesTranslationsPTO;
import com.smartling.api.files.v2.pto.DownloadTranslationPTO;
import com.smartling.api.files.v2.pto.FileFilter;
import com.smartling.api.files.v2.pto.FileLocaleLastModifiedPTO;
import com.smartling.api.files.v2.pto.FileLocalePTO;
import com.smartling.api.files.v2.pto.FileLocaleStatusResponse;
import com.smartling.api.files.v2.pto.FileNameMode;
import com.smartling.api.files.v2.pto.GetFileLastModifiedPTO;
import com.smartling.api.files.v2.pto.LocaleMode;
import com.smartling.api.files.v2.pto.UploadFilePTO;
import com.smartling.api.files.v2.pto.UploadFileResponse;
import com.smartling.api.files.v2.resteasy.ext.TranslatedFileMultipart;
Expand All @@ -19,25 +24,27 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static com.github.tomakehurst.wiremock.client.WireMock.aMultipart;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static com.smartling.api.v2.tests.wiremock.SmartlingWireMock.success;
import static com.smartling.api.files.v2.pto.FileType.JSON;
import static com.smartling.api.files.v2.pto.RetrievalType.PUBLISHED;
import static com.smartling.api.v2.tests.wiremock.SmartlingWireMock.postJson;
import static com.smartling.api.v2.tests.wiremock.SmartlingWireMock.success;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;

public class FilesApiIntTest
Expand Down Expand Up @@ -153,7 +160,7 @@ public void shouldUploadFile() throws Exception
.fileUri(FILE_URI)
.file(new ByteArrayInputStream(rawBody.getBytes()))
.directives(directives)
.localeIdsToAuthorize(Arrays.asList("de-DE", "fr"))
.localeIdsToAuthorize(asList("de-DE", "fr"))
.build());

assertEquals(uploadFileResponse.getFileUri(), FILE_URI);
Expand Down Expand Up @@ -260,4 +267,60 @@ public void shouldGetFileLocaleStatus() throws Exception
.withQueryParam("fileUri", equalTo(FILE_URI))
);
}

@Test
public void shouldRetrieveMultipleFilesTranslations() throws Exception
{
final String rawResponseBody = UUID.randomUUID().toString();

final FileLocalePTO firstFileLocalePTO = FileLocalePTO.builder()
.fileUri(FILE_URI + "1")
.localeIds(asList("de-DE", "fr"))
.build();

final FileLocalePTO secondFileLocalePTO = FileLocalePTO.builder()
.fileUri(FILE_URI + "2")
.localeIds(asList("es-ES", "uk-UA", "zh-CN"))
.build();

final DownloadMultipleFilesTranslationsPTO requestBody = DownloadMultipleFilesTranslationsPTO.builder()
.files(asList(firstFileLocalePTO, secondFileLocalePTO))
.retrievalType(PUBLISHED)
.includeOriginalStrings(true)
.fileNameMode(FileNameMode.TRIM_LEADING)
.localeMode(LocaleMode.LOCALE_IN_NAME)
.zipFileName("archive.zip")
.fileFilter(FileFilter.PUBLISHED_FILES_ONLY)
.build();

smartlingApi.stubFor(postJson(urlPathMatching("/files-api/v2/projects/.+/files/zip"))
.withRequestBody(equalToJson("{\n" +
" \"files\": [{\n" +
" \"fileUri\": \"" + FILE_URI + "1\",\n" +
" \"localeIds\": [\"de-DE\", \"fr\"]\n" +
" },{\n" +
" \"fileUri\": \"" + FILE_URI + "2\",\n" +
" \"localeIds\": [\"es-ES\", \"uk-UA\", \"zh-CN\"]\n" +
" }],\n" +
" \"retrievalType\": \"PUBLISHED\",\n" +
" \"includeOriginalStrings\": true,\n" +
" \"fileNameMode\": \"TRIM_LEADING\",\n" +
" \"localeMode\": \"LOCALE_IN_NAME\",\n" +
" \"zipFileName\": \"archive.zip\",\n" +
" \"fileFilter\": \"PUBLISHED_FILES_ONLY\"\n" +
"}")
)
.willReturn(aResponse()
.withHeader("Content-Type", "application/octet-stream")
.withBody(rawResponseBody)
)
);

final InputStream response = filesApi.downloadMultipleFileTranslations(
PROJECT_ID,
requestBody
);

assertEquals(IOUtils.toString(response, UTF_8), rawResponseBody);
}
}