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
74 changes: 74 additions & 0 deletions src/main/java/com/crowdin/client/sourcefiles/SourceFilesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ public ResponseObject<Branch> editBranch(Long projectId, Long branchId, List<Pat
return ResponseObject.of(branchResponseObject.getData());
}

/**
* @param filter search branches by name or title
* @param projectIds project identifiers (max 50)
* @param userId owner identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset a starting offset in the collection
* @return branches by name or title
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.branches.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.branches.getMany" target="_blank"><b>API Enterprise Documentation</b></a></li>
* </ul>
*/
public ResponseList<Branch> searchBranches(String filter, String projectIds, Integer userId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"filter", Optional.of(filter),
"projectIds", Optional.ofNullable(projectIds),
"userId", Optional.ofNullable(userId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);

BranchResponseList branchResponseList = this.httpClient.get(this.url + "/branches", new HttpRequestConfig(queryParams), BranchResponseList.class);
return BranchResponseList.to(branchResponseList);
}

/**
* @param projectId project identifier
* @param branchId filter by branch id
Expand Down Expand Up @@ -230,6 +255,31 @@ public ResponseObject<Directory> editDirectory(Long projectId, Long directoryId,
return ResponseObject.of(directoryResponseObject.getData());
}

/**
* @param filter search directories by name or title
* @param projectIds project identifiers (max 50)
* @param userId owner identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset a starting offset in the collection
* @return directories by name or title
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.directories.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.directories.getMany" target="_blank"><b>API Enterprise Documentation</b></a></li>
* </ul>
*/
public ResponseList<Directory> searchDirectories(String filter, String projectIds, Integer userId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"filter", Optional.of(filter),
"projectIds", Optional.ofNullable(projectIds),
"userId", Optional.ofNullable(userId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);

DirectoryResponseList directoryResponseList = this.httpClient.get(this.url + "/directories", new HttpRequestConfig(queryParams), DirectoryResponseList.class);
return DirectoryResponseList.to(directoryResponseList);
}

/**
* @param projectId project identifier
* @param branchId filter by branch id
Expand Down Expand Up @@ -482,6 +532,30 @@ public ResponseObject<DownloadLink> downloadFilePreview(Long projectId, Long fil
return ResponseObject.of(downloadLinkResponseObject.getData());
}

/**
* @param filter search files by name or title
* @param projectIds project identifiers (max 50)
* @param userId owner identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset a starting offset in the collection
* @return files by name or title
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.files.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.files.getMany" target="_blank"><b>API Enterprise Documentation</b></a></li>
* </ul>
*/
public ResponseList<? extends FileInfo> searchFiles(String filter, String projectIds, Integer userId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"filter", Optional.of(filter),
"projectIds", Optional.ofNullable(projectIds),
"userId", Optional.ofNullable(userId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);

FileInfoResponseList fileInfoResponseList = this.httpClient.get(this.url + "/files", new HttpRequestConfig(queryParams), FileInfoResponseList.class);
return FileInfoResponseList.to(fileInfoResponseList);
}
/**
* @param projectId project identifier
* @param fileId file identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@ public ResponseObject<SourceString> editSourceString(Long projectId, Long string
return ResponseObject.of(sourceStringResponseObject.getData());
}

/**
* @param filter search strings by the fields selected in scope
* @param projectIds project identifiers (max 50)
* @param userId owner identifier
* @param scope specify field to be the target of filtering (default all)
* @param denormalizePlaceholders enable denormalize placeholders (default 0)
* @param limit maximum numbers of items to retrieve (max 25)
* @param offset a starting offset in the collection
* @return source strings by text/context/key
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.strings.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.strings.getMany" target="_blank"><b>API Enterprise Documentation</b></a></li>
* </ul>
*/
public ResponseList<SourceString> searchSourceStrings(String filter, String projectIds, Integer userId, String scope, Integer denormalizePlaceholders, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"filter", Optional.of(filter),
"projectIds", Optional.ofNullable(projectIds),
"userId", Optional.ofNullable(userId),
"scope", Optional.ofNullable(scope),
"denormalizePlaceholders", Optional.ofNullable(denormalizePlaceholders),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);

SourceStringResponseList sourceStringResponseList = this.httpClient.get(this.url + "/strings", new HttpRequestConfig(queryParams), SourceStringResponseList.class);
return SourceStringResponseList.to(sourceStringResponseList);
}

/**
* @param projectId project identifier
* @param request request object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,35 @@ public ResponseObject<StringTranslation> restoreStringTranslation(Long projectId
return ResponseObject.of(stringTranslationResponseObject.getData());
}

/**
* @param filter search translations by text
* @param projectIds project identifiers (max 50)
* @param userId owner identifier
* @param languageIds target language identifier
* @param denormalizePlaceholders enable denormalize placeholders (default 0)
* @param limit maximum numbers of items to retrieve (max 25)
* @param offset a starting offset in the collection
* @return target-language translations by text
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.translations.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.translations.getMany" target="_blank"><b>API Enterprise Documentation</b></a></li>
* </ul>
*/
public ResponseList<StringTranslation> searchTranslations(String filter, String projectIds, Integer userId, String languageIds, Integer denormalizePlaceholders, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"filter", Optional.of(filter),
"projectIds", Optional.ofNullable(projectIds),
"userId", Optional.ofNullable(userId),
"languageIds", Optional.ofNullable(languageIds),
"denormalizePlaceholders", Optional.ofNullable(denormalizePlaceholders),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);

StringTranslationResponseList stringTranslationResponseList = this.httpClient.get(this.url + "/translations", new HttpRequestConfig(queryParams), StringTranslationResponseList.class);
return StringTranslationResponseList.to(stringTranslationResponseList);
}

/**
* @param projectId project identifier
* @param stringId string identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

public class SourceFilesApiTest extends TestClient {

private final Integer userId = 4;
private final Long branchId = 34L;
private final Long branch2Id = 35L;
private final Long directoryId = 4L;
Expand All @@ -33,21 +34,27 @@ public class SourceFilesApiTest extends TestClient {
private final Long project2Id = 4L;
private final Long project3Id = 5L;
private final Long project4Id = 6L;
private final Long project5Id = 2L;
private final Long fileId = 44L;
private final Long storageId = 61L;
private final Long referenceId = 123L;
private final Long fileRevisionId = 2L;
private final Long buildId = 42L;
private final String branchName = "develop-master";
private final String branchTitle = "Master branch";
private final String sequentBranchName1 = "develop-master-#1";
private final String sequentBranchName2 = "develop-master-#2";
private final String directoryName = "main";
private final String directory2Name = "main-#2";
private final String directoryTitle = "<Description materials>";
private final String fileName = "umbrella_app.xliff";
private final String referenceName = "design_reference.png";
private final String context = "Context for translators";
private final String downloadLink = "test.com";
private final String status = "finished";
private final String exportPattern = "%three_letters_code%";
private final String priority = "normal";
private final String projectIds = "1,2,3";
private final List<Long> attachLabelIds = Arrays.asList(1L);
private final List<Long> detachLabelIds = attachLabelIds;
private final TimeZone tz = TimeZone.getTimeZone("GMT");
Expand All @@ -66,6 +73,10 @@ public List<RequestMock> getMocks() {
RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId, HttpGet.METHOD_NAME, "api/sourcefiles/branch.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId, HttpDelete.METHOD_NAME),
RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId, HttpPatch.METHOD_NAME, "api/sourcefiles/editBranch.json", "api/sourcefiles/branch.json"),
RequestMock.build(this.url + "/branches", HttpGet.METHOD_NAME, "api/sourcefiles/searchBranches.json", new HashMap<String, String>() {{
put("filter", branchName);
put("projectIds", projectIds);
}}),
RequestMock.build(this.url + "/projects/" + projectId + "/directories", HttpGet.METHOD_NAME, "api/sourcefiles/listDirectories.json"),
RequestMock.build(this.url + "/projects/" + project3Id + "/directories", HttpGet.METHOD_NAME, "api/sourcefiles/listDirectoriesOrderByIdAsc.json", new HashMap<String, String>() {{
put("orderBy", "id%20asc");
Expand All @@ -77,6 +88,10 @@ public List<RequestMock> getMocks() {
RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId, HttpGet.METHOD_NAME, "api/sourcefiles/directory.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId, HttpDelete.METHOD_NAME),
RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId, HttpPatch.METHOD_NAME, "api/sourcefiles/editDirectory.json", "api/sourcefiles/directory.json"),
RequestMock.build(this.url + "/directories", HttpGet.METHOD_NAME, "api/sourcefiles/searchDirectories.json", new HashMap<String, Object>() {{
put("filter", directoryName);
put("userId", userId);
}}),
RequestMock.build(this.url + "/projects/" + projectId + "/files", HttpGet.METHOD_NAME, "api/sourcefiles/listFiles.json"),
RequestMock.build(this.url + "/projects/" + project3Id + "/files", HttpGet.METHOD_NAME, "api/sourcefiles/listFiles.json", new HashMap<String, String>() {{
put("orderBy", "id%20asc");
Expand All @@ -94,6 +109,10 @@ public List<RequestMock> getMocks() {
RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId + "/preview", HttpGet.METHOD_NAME, "api/sourcefiles/downloadLink.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId + "/revisions", HttpGet.METHOD_NAME, "api/sourcefiles/listFileRevisions.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId + "/revisions/" + fileRevisionId, HttpGet.METHOD_NAME, "api/sourcefiles/fileRevision.json"),
RequestMock.build(this.url + "/files", HttpGet.METHOD_NAME, "api/sourcefiles/searchFiles.json", new HashMap<String, String>() {{
put("filter", fileName);
put("projectIds", projectIds);
}}),
RequestMock.build(String.format("%s/projects/%d/strings/reviewed-builds", this.url, projectId), HttpGet.METHOD_NAME, "api/sourcefiles/listReviewedSourceFileBuilds.json"),
RequestMock.build(String.format("%s/projects/%d/strings/reviewed-builds", url, projectId), HttpPost.METHOD_NAME, "api/sourcefiles/buildReviewedSourceFilesRequest.json", "api/sourcefiles/buildReviewedSourceFiles.json"),
RequestMock.build(String.format("%s/projects/%d/strings/reviewed-builds/%d", url, projectId, buildId), HttpGet.METHOD_NAME, "api/sourcefiles/checkReviewedSourceFilesBuildStatus.json"),
Expand Down Expand Up @@ -203,6 +222,20 @@ public void editBranchTest() {
assertEquals(branchResponseObject.getData().getName(), branchName);
}

@Test
public void searchBranchesTest() {
ResponseList<Branch> branchResponseList = this.getSourceFilesApi().searchBranches(branchName, projectIds, null, null, null);

assertEquals(branchId, branchResponseList.getData().get(0).getData().getId());
assertEquals(project5Id, branchResponseList.getData().get(0).getData().getProjectId());
assertEquals(branchName, branchResponseList.getData().get(0).getData().getName());
assertEquals(branchTitle, branchResponseList.getData().get(0).getData().getTitle());
assertEquals(new Date(119,Calendar.SEPTEMBER,16,13,48,4), branchResponseList.getData().get(0).getData().getCreatedAt());
assertEquals(new Date(119,Calendar.SEPTEMBER,19,13,25,27), branchResponseList.getData().get(0).getData().getUpdatedAt());
assertEquals(exportPattern, branchResponseList.getData().get(0).getData().getExportPattern());
assertEquals(priority, branchResponseList.getData().get(0).getData().getPriority().name().toLowerCase());
}

@Test
public void listDirectoriesTest() {
ResponseList<Directory> directoryResponseList = this.getSourceFilesApi().listDirectories(projectId, null, null, null, null, null, null);
Expand Down Expand Up @@ -337,6 +370,17 @@ public void editDirectoryTest() {
assertEquals(directoryResponseObject.getData().getName(), directoryName);
}

@Test
public void searchDirectoriesTest() {
ResponseList<Directory> directoryResponseList = this.getSourceFilesApi().searchDirectories(directoryName, null, userId, null, null);

assertEquals(directoryName, directoryResponseList.getData().get(0).getData().getName());
assertEquals(directoryTitle, directoryResponseList.getData().get(0).getData().getTitle());
assertEquals(project5Id, directoryResponseList.getData().get(0).getData().getProjectId());
assertEquals(new Date(119,Calendar.SEPTEMBER,19,14,14,0), directoryResponseList.getData().get(0).getData().getCreatedAt());
assertEquals(priority, directoryResponseList.getData().get(0).getData().getPriority().name().toLowerCase());
}

@Test
public void listFilesTest() {
ResponseList<File> fileResponseList = (ResponseList<File>) this.getSourceFilesApi().listFiles(projectId, null, null, null, null, null, null);
Expand Down Expand Up @@ -647,6 +691,17 @@ private void assertListFilesOrderByIdDesc(ResponseList<File> fileResponseList) {
}
//</editor-fold>

@Test
public void searchFilesTest() {
ResponseList<? extends FileInfo> fileInfoResponseList = this.getSourceFilesApi().searchFiles(fileName, projectIds, null, null, null);

assertEquals(fileName, fileInfoResponseList.getData().get(0).getData().getName());
assertEquals(branchId, fileInfoResponseList.getData().get(0).getData().getBranchId());
assertEquals(fileId, fileInfoResponseList.getData().get(0).getData().getId());
assertEquals(project5Id, fileInfoResponseList.getData().get(0).getData().getProjectId());

}

@Test
public void listAssetReferencesTest() {
ResponseList<AssetReference> referenceResponseList = this.getSourceFilesApi().listAssetReferences(projectId, fileId, null, null);
Expand Down
Loading
Loading