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
4 changes: 4 additions & 0 deletions src/main/java/com/crowdin/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.crowdin.client.sourcestrings.SourceStringsApi;
import com.crowdin.client.storage.StorageApi;
import com.crowdin.client.stringcomments.StringCommentsApi;
import com.crowdin.client.stringcorrections.StringCorrectionsApi;
import com.crowdin.client.stringtranslations.StringTranslationsApi;
import com.crowdin.client.tasks.TasksApi;
import com.crowdin.client.teams.TeamsApi;
Expand Down Expand Up @@ -74,6 +75,7 @@ public class Client extends CrowdinApi {
private final ClientsApi clientsApi;
private final BranchesApi branchesApi;
private final AIApi aiApi;
private final StringCorrectionsApi stringCorrectionsApi;

public Client(Credentials credentials) {
super(credentials);
Expand Down Expand Up @@ -110,6 +112,7 @@ public Client(Credentials credentials) {
this.clientsApi = new ClientsApi(credentials);
this.branchesApi = new BranchesApi(credentials);
this.aiApi = new AIApi(credentials);
this.stringCorrectionsApi = new StringCorrectionsApi(credentials);
}

public Client(Credentials credentials, ClientConfig clientConfig) {
Expand Down Expand Up @@ -147,6 +150,7 @@ public Client(Credentials credentials, ClientConfig clientConfig) {
this.clientsApi = new ClientsApi(credentials, clientConfig);
this.branchesApi = new BranchesApi(credentials, clientConfig);
this.aiApi = new AIApi(credentials, clientConfig);
this.stringCorrectionsApi = new StringCorrectionsApi(credentials, clientConfig);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.crowdin.client.stringcorrections;

import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.http.HttpRequestConfig;
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
import com.crowdin.client.core.http.exceptions.HttpException;
import com.crowdin.client.core.model.ClientConfig;
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.core.model.ResponseList;
import com.crowdin.client.core.model.ResponseObject;
import com.crowdin.client.stringcorrections.model.*;

import java.util.Map;
import java.util.Optional;

public class StringCorrectionsApi extends CrowdinApi {


public StringCorrectionsApi(Credentials credentials) {
super(credentials);
}

public StringCorrectionsApi(Credentials credentials, ClientConfig clientConfig) {
super(credentials, clientConfig);
}

/**
* @param projectId project identifier
* @param params query params
* @return list of corrections
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<Correction> listCorrections(Long projectId, ListCorrectionsQueryParams params) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"stringId", Optional.of(params.getStringId()),
"orderBy", Optional.ofNullable(params.getOrderBy()),
"denormalizePlaceholders", Optional.ofNullable(params.getDenormalizePlaceholders()),
"limit", Optional.ofNullable(params.getLimit()),
"offset", Optional.ofNullable(params.getOffset())
);
CorrectionResponseList response = this.httpClient.get(this.url + "/projects/" + projectId + "/corrections", new HttpRequestConfig(queryParams), CorrectionResponseList.class);
return CorrectionResponseList.to(response);
}

/**
* @param projectId project identifier
* @param request request object
* @return newly created correction
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<Correction> addCorrection(Long projectId, AddCorrectionRequest request) throws HttpException, HttpBadRequestException {
CorrectionResponseObject response = this.httpClient.post(this.url + "/projects/" + projectId + "/corrections", request, new HttpRequestConfig(), CorrectionResponseObject.class);
return ResponseObject.of(response.getData());
}

/**
* @param projectId project identifier
* @param correctionId correction identifier
* @return correction object
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<Correction> getCorrection(Long projectId, Long correctionId) throws HttpException, HttpBadRequestException {
CorrectionResponseObject response = this.httpClient.get(this.url + "/projects/" + projectId + "/corrections/" + correctionId, new HttpRequestConfig(), CorrectionResponseObject.class);
return ResponseObject.of(response.getData());
}

/**
* @param projectId project identifier
* @param stringId string identifier
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.deleteMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void deleteCorrections(Long projectId, Long stringId) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"stringId", Optional.of(stringId)
);
this.httpClient.delete(this.url + "/projects/" + projectId + "/corrections", new HttpRequestConfig(queryParams), Void.class);
}

/**
* @param projectId project identifier
* @param correctionId correction identifier
* @return newly created correction
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.put" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<Correction> restoreCorrection(Long projectId, Long correctionId) throws HttpException, HttpBadRequestException {
CorrectionResponseObject response = this.httpClient.put(this.url + "/projects/" + projectId + "/corrections/" + correctionId, null, new HttpRequestConfig(), CorrectionResponseObject.class);
return ResponseObject.of(response.getData());
}

/**
* @param projectId project identifier
* @param correctionId correction identifier
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void deleteCorrection(Long projectId, Long correctionId) throws HttpException, HttpBadRequestException {
this.httpClient.delete(this.url + "/projects/" + projectId + "/corrections/" + correctionId, new HttpRequestConfig(), Void.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.crowdin.client.stringcorrections.model;

import lombok.Data;

@Data
public class AddCorrectionRequest {
private Long stringId;
private String text;
private String pluralCategoryName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.crowdin.client.stringcorrections.model;

import lombok.Data;

import java.util.Date;

@Data
public class Correction {

private Long id;
private String text;
private String pluralCategoryName;
private User user;
private Date createdAt;

@Data
public static class User {
private Long id;
private String username;
private String fullName;
private String avatarUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.crowdin.client.stringcorrections.model;

import com.crowdin.client.core.model.Pagination;
import com.crowdin.client.core.model.ResponseList;
import com.crowdin.client.core.model.ResponseObject;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
public class CorrectionResponseList {

private List<CorrectionResponseObject> data;
private Pagination pagination;

public static ResponseList<Correction> to(CorrectionResponseList correctionResponseList) {
return ResponseList.of(
correctionResponseList.getData().stream()
.map(CorrectionResponseObject::getData)
.map(ResponseObject::of)
.collect(Collectors.toList()),
correctionResponseList.getPagination()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.crowdin.client.stringcorrections.model;

import lombok.Data;

@Data
public class CorrectionResponseObject {

private Correction data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.crowdin.client.stringcorrections.model;

import com.crowdin.client.core.model.BooleanInt;
import com.crowdin.client.core.model.Pagination;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ListCorrectionsQueryParams extends Pagination {
private Long stringId;
private String orderBy;
private BooleanInt denormalizePlaceholders;
}
11 changes: 11 additions & 0 deletions src/test/java/com/crowdin/client/framework/RequestMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public static RequestMock build(String url, String httpMethod, String responseFi
);
}

public static RequestMock build(String url, String httpMethod, Map<String, ?> urlParams) {
return new RequestMock(
url,
null,
null,
httpMethod,
urlParams,
Collections.emptyMap()
);
}

public static RequestMock build(String url, String httpMethod) {
return new RequestMock(
url,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.crowdin.client.stringcorrections.bundles;

import com.crowdin.client.core.model.ResponseList;
import com.crowdin.client.core.model.ResponseObject;
import com.crowdin.client.framework.RequestMock;
import com.crowdin.client.framework.TestClient;
import com.crowdin.client.stringcorrections.model.AddCorrectionRequest;
import com.crowdin.client.stringcorrections.model.Correction;
import com.crowdin.client.stringcorrections.model.ListCorrectionsQueryParams;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class StringCorrectionsApiTest extends TestClient {

private final Long projectId = 1L;
private final Long stringId = 35434L;
private final Long correctionId = 190695L;
private final String text = "This string has been corrected";
private final String pluralCategoryName = "few";

@Override
public List<RequestMock> getMocks() {
return Arrays.asList(
RequestMock.build(this.url + "/projects/" + projectId + "/corrections", HttpGet.METHOD_NAME, "api/stringcorrections/listCorrectionsResponse.json", new HashMap<String, Long>() {{
put("stringId", stringId);
}}),
RequestMock.build(this.url + "/projects/" + projectId + "/corrections", HttpPost.METHOD_NAME, "api/stringcorrections/addCorrectionRequest.json", "api/stringcorrections/correction.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/corrections/" + correctionId, HttpGet.METHOD_NAME, "api/stringcorrections/correction.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/corrections/" + correctionId, HttpDelete.METHOD_NAME),
RequestMock.build(this.url + "/projects/" + projectId + "/corrections", HttpDelete.METHOD_NAME, new HashMap<String, Long>() {{
put("stringId", stringId);
}}),
RequestMock.build(this.url + "/projects/" + projectId + "/corrections/" + correctionId, HttpPut.METHOD_NAME, "api/stringcorrections/correction.json")
);
}

@Test
public void listCorrectionsTest() {
ListCorrectionsQueryParams listCorrectionsQueryParams = new ListCorrectionsQueryParams();
listCorrectionsQueryParams.setStringId(stringId);
ResponseList<Correction> response = this.getStringCorrectionsApi().listCorrections(projectId, listCorrectionsQueryParams);
assertNotNull(response);
assertEquals(1, response.getData().size());
assertEquals(response.getData().get(0).getData().getId(), correctionId);
assertEquals(response.getData().get(0).getData().getText(), text);
assertEquals(response.getData().get(0).getData().getPluralCategoryName(), pluralCategoryName);
}

@Test
public void addCorrectionTest() {
AddCorrectionRequest request = new AddCorrectionRequest();
request.setStringId(stringId);
request.setPluralCategoryName(pluralCategoryName);
request.setText(text);

ResponseObject<Correction> response = this.getStringCorrectionsApi().addCorrection(projectId, request);
assertEquals(response.getData().getText(), text);
assertEquals(response.getData().getId(), correctionId);
assertEquals(response.getData().getPluralCategoryName(), pluralCategoryName);
}

@Test
public void getCorrectionTest() {
ResponseObject<Correction> response = this.getStringCorrectionsApi().getCorrection(projectId, correctionId);
assertEquals(response.getData().getText(), text);
assertEquals(response.getData().getId(), correctionId);
assertEquals(response.getData().getPluralCategoryName(), pluralCategoryName);
}

@Test
public void deleteCorrectionTest() {
this.getStringCorrectionsApi().deleteCorrection(projectId, correctionId);
}

@Test
public void deleteCorrectionsTest() {
this.getStringCorrectionsApi().deleteCorrections(projectId, stringId);
}

@Test
public void restoreCorrectionsTest() {
ResponseObject<Correction> response = this.getStringCorrectionsApi().restoreCorrection(projectId, correctionId);
assertEquals(response.getData().getText(), text);
assertEquals(response.getData().getId(), correctionId);
assertEquals(response.getData().getPluralCategoryName(), pluralCategoryName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stringId": 35434,
"text": "This string has been corrected",
"pluralCategoryName": "few"
}
14 changes: 14 additions & 0 deletions src/test/resources/api/stringcorrections/correction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"data": {
"id": 190695,
"text": "This string has been corrected",
"pluralCategoryName": "few",
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Smith",
"avatarUrl": ""
},
"createdAt": "2019-09-23T11:26:54+00:00"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"offset": 0,
"limit": 25,
"data": [
{
"data": {
"id": 190695,
"text": "This string has been corrected",
"pluralCategoryName": "few",
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Smith",
"avatarUrl": ""
},
"createdAt": "2019-09-23T11:26:54+00:00"
}
}
]
}
Loading