Skip to content

Commit d00ce51

Browse files
committed
wip: second part of orderBy implementation in list methods. List projects, directories, files, branches and source strings
1 parent 02dd81c commit d00ce51

14 files changed

Lines changed: 941 additions & 73 deletions

src/main/java/com/crowdin/client/projectsgroups/ProjectsGroupsApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ public ResponseList<? extends Project> listProjects(Long groupId, Integer hasMan
135135
options.setHasManagerAccess(hasManagerAccess);
136136
options.setLimit(limit);
137137
options.setOffset(offset);
138-
options.setOrderByFields(orderBy);
138+
options.setOrderByList(orderBy);
139139
return listProjects(options);
140140
}
141141

142142
public ResponseList<? extends Project> listProjects(ListProjectOptions options) throws HttpException, HttpBadRequestException {
143-
String orderBy = options.getOrderByFields() != null
144-
? OrderByField.generateSortParam(options.getOrderByFields())
143+
String orderBy = options.getOrderByList() != null
144+
? OrderByField.generateSortParam(options.getOrderByList())
145145
: options.getOrderBy();
146146

147147
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(

src/main/java/com/crowdin/client/projectsgroups/model/ListProjectOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public class ListProjectOptions extends Pagination {
1515
private Integer hasManagerAccess;
1616
private String orderBy;
1717
private Integer type;
18-
private List<OrderByField> orderByFields;
18+
private List<OrderByField> orderByList;
1919
}

src/main/java/com/crowdin/client/sourcefiles/SourceFilesApi.java

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
import com.crowdin.client.core.http.HttpRequestConfig;
55
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
66
import com.crowdin.client.core.http.exceptions.HttpException;
7-
import com.crowdin.client.core.model.ClientConfig;
8-
import com.crowdin.client.core.model.Credentials;
9-
import com.crowdin.client.core.model.DownloadLink;
10-
import com.crowdin.client.core.model.DownloadLinkResponseObject;
11-
import com.crowdin.client.core.model.PatchRequest;
12-
import com.crowdin.client.core.model.ResponseList;
13-
import com.crowdin.client.core.model.ResponseObject;
7+
import com.crowdin.client.core.model.*;
148
import com.crowdin.client.sourcefiles.model.*;
159

1610
import java.util.List;
@@ -47,6 +41,29 @@ public ResponseList<Branch> listBranches(Long projectId, String name, Integer li
4741
return BranchResponseList.to(branchResponseList);
4842
}
4943

44+
/**
45+
* @param projectId project identifier
46+
* @param name filter by branch name
47+
* @param limit maximum number of items to retrieve (default 25)
48+
* @param offset starting offset in the collection (default 0)
49+
* @param orderBy list of OrderByField
50+
* @return list of branches
51+
* @see <ul>
52+
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.branches.getMany" target="_blank"><b>API Documentation</b></a></li>
53+
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.branches.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
54+
* </ul>
55+
*/
56+
public ResponseList<Branch> listBranches(Long projectId, String name, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException {
57+
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
58+
"name", Optional.ofNullable(name),
59+
"limit", Optional.ofNullable(limit),
60+
"offset", Optional.ofNullable(offset),
61+
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
62+
);
63+
BranchResponseList branchResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/branches", new HttpRequestConfig(queryParams), BranchResponseList.class);
64+
return BranchResponseList.to(branchResponseList);
65+
}
66+
5067
/**
5168
* @param projectId project identifier
5269
* @param request request object
@@ -129,6 +146,35 @@ public ResponseList<Directory> listDirectories(Long projectId, Long branchId, Lo
129146
return DirectoryResponseList.to(directoryResponseList);
130147
}
131148

149+
/**
150+
* @param projectId project identifier
151+
* @param branchId filter by branch id
152+
* @param directoryId filter by directory id
153+
* @param filter filter directories by name
154+
* @param recursion use to list directories recursively
155+
* @param limit maximum number of items to retrieve (default 25)
156+
* @param offset starting offset in the collection (default 0)
157+
* @param orderBy list of OrderByField
158+
* @return list of directories
159+
* @see <ul>
160+
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.directories.getMany" target="_blank"><b>API Documentation</b></a></li>
161+
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.directories.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
162+
* </ul>
163+
*/
164+
public ResponseList<Directory> listDirectories(Long projectId, Long branchId, Long directoryId, String filter, Object recursion, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException {
165+
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
166+
"branchId", Optional.ofNullable(branchId),
167+
"directoryId", Optional.ofNullable(directoryId),
168+
"filter", Optional.ofNullable(filter),
169+
"recursion", Optional.ofNullable(recursion),
170+
"limit", Optional.ofNullable(limit),
171+
"offset", Optional.ofNullable(offset),
172+
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
173+
);
174+
DirectoryResponseList directoryResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/directories", new HttpRequestConfig(queryParams), DirectoryResponseList.class);
175+
return DirectoryResponseList.to(directoryResponseList);
176+
}
177+
132178
/**
133179
* @param projectId project identifier
134180
* @param request request object
@@ -211,6 +257,35 @@ public ResponseList<? extends FileInfo> listFiles(Long projectId, Long branchId,
211257
return FileInfoResponseList.to(fileInfoResponseList);
212258
}
213259

260+
/**
261+
* @param projectId project identifier
262+
* @param branchId filter by branch id
263+
* @param directoryId filter by directory id
264+
* @param filter filter files by name
265+
* @param recursion use to list directories recursively
266+
* @param limit maximum number of items to retrieve (default 25)
267+
* @param offset starting offset in the collection (default 0)
268+
* @param orderBy list of OrderByField
269+
* @return list of files
270+
* @see <ul>
271+
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.files.getMany" target="_blank"><b>API Documentation</b></a></li>
272+
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.files.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
273+
* </ul>
274+
*/
275+
public ResponseList<? extends FileInfo> listFiles(Long projectId, Long branchId, Long directoryId, String filter, Object recursion, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException {
276+
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
277+
"branchId", Optional.ofNullable(branchId),
278+
"directoryId", Optional.ofNullable(directoryId),
279+
"filter", Optional.ofNullable(filter),
280+
"recursion", Optional.ofNullable(recursion),
281+
"limit", Optional.ofNullable(limit),
282+
"offset", Optional.ofNullable(offset),
283+
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
284+
);
285+
FileInfoResponseList fileInfoResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/files", new HttpRequestConfig(queryParams), FileInfoResponseList.class);
286+
return FileInfoResponseList.to(fileInfoResponseList);
287+
}
288+
214289
/**
215290
* @param projectId project identifier
216291
* @param request request object

src/main/java/com/crowdin/client/sourcestrings/SourceStringsApi.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
import com.crowdin.client.core.http.HttpRequestConfig;
55
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
66
import com.crowdin.client.core.http.exceptions.HttpException;
7-
import com.crowdin.client.core.model.ClientConfig;
8-
import com.crowdin.client.core.model.Credentials;
9-
import com.crowdin.client.core.model.PatchRequest;
10-
import com.crowdin.client.core.model.ResponseList;
11-
import com.crowdin.client.core.model.ResponseObject;
7+
import com.crowdin.client.core.model.*;
128
import com.crowdin.client.sourcestrings.model.*;
139

1410
import java.util.List;
@@ -71,9 +67,22 @@ public ResponseList<SourceString> listSourceStrings(Long projectId, Long fileId,
7167
return listSourceStrings(projectId, params);
7268
}
7369

70+
/**
71+
* @param projectId project identifier
72+
* @param params Query params
73+
* @return list of source strings
74+
* @see <ul>
75+
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.strings.getMany" target="_blank"><b>API Documentation</b></a></li>
76+
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
77+
* </ul>
78+
*/
7479
public ResponseList<SourceString> listSourceStrings(Long projectId, ListSourceStringsParams params) throws HttpException, HttpBadRequestException {
80+
String orderBy = params.getOrderByList() != null
81+
? OrderByField.generateSortParam(params.getOrderByList())
82+
: params.getOrderBy();
83+
7584
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
76-
"orderBy", Optional.ofNullable(params.getOrderBy()),
85+
"orderBy", Optional.ofNullable(orderBy),
7786
"denormalizePlaceholders", Optional.ofNullable(params.getDenormalizePlaceholders()),
7887
"labelIds", Optional.ofNullable(params.getLabelIds()),
7988
"fileId", Optional.ofNullable(params.getFileId()),

src/main/java/com/crowdin/client/sourcestrings/model/ListSourceStringsParams.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.crowdin.client.sourcestrings.model;
22

3+
import com.crowdin.client.core.model.OrderByField;
34
import lombok.Builder;
45
import lombok.Data;
56

7+
import java.util.List;
8+
69
@Data
710
@Builder
811
public class ListSourceStringsParams {
@@ -19,4 +22,5 @@ public class ListSourceStringsParams {
1922
private String scope;
2023
private Integer limit;
2124
private Integer offset;
25+
private List<OrderByField> orderByList;
2226
}

0 commit comments

Comments
 (0)