Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reports api updates #309

Merged
merged 1 commit into from
Jan 25, 2025
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 @@ -19,6 +19,11 @@ public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOExce
return null;
}

return deserializeDate(date);
}

@SneakyThrows
public static Date deserializeDate(String date) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
return format.parse(date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ public <T> String convert(T obj) {
return this.objectMapper.writeValueAsString(obj);
}

public ObjectMapper getObjectMapper() {
return this.objectMapper;
}
}
66 changes: 65 additions & 1 deletion src/main/java/com/crowdin/client/reports/ReportsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,70 @@ public ResponseObject<DownloadLink> downloadOrganizationReport(String reportId)
return ResponseObject.of(responseObject.getData());
}

/**
* @return list of report settings template
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<ReportSettingsTemplate.OrganizationReportSettingsTemplate> listOrganizationReportSettingsTemplates(ListOrganizationReportSettingsParams params) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"projectId", Optional.ofNullable(params.getProjectId()),
"groupId", Optional.ofNullable(params.getGroupId()),
"limit", Optional.ofNullable(params.getLimit()),
"offset", Optional.ofNullable(params.getOffset())
);
OrganizationReportSettingsTemplateList reportSettingsTemplateList = this.httpClient.get(this.url + "/reports/settings-templates", new HttpRequestConfig(queryParams), OrganizationReportSettingsTemplateList.class);
return OrganizationReportSettingsTemplateList.to(reportSettingsTemplateList);
}

/**
* @param request request object
* @return report settings template
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ReportSettingsTemplate.OrganizationReportSettingsTemplate> addOrganizationReportSettingsTemplate(ReportSettingsTemplate.OrganizationReportSettingsTemplate request) throws HttpException, HttpBadRequestException {
OrganizationReportSettingsTemplateResponseObject responseObject = this.httpClient.post(this.url + "/reports/settings-templates", request, new HttpRequestConfig(), OrganizationReportSettingsTemplateResponseObject.class);
return ResponseObject.of(responseObject.getData());
}

/**
* @param reportSettingsTemplateId report settings template identifier
* @return report settings template
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ReportSettingsTemplate.OrganizationReportSettingsTemplate> getOrganizationReportSettingsTemplate(Long reportSettingsTemplateId) throws HttpException, HttpBadRequestException {
OrganizationReportSettingsTemplateResponseObject responseObject = this.httpClient.get(this.url + "/reports/settings-templates/" + reportSettingsTemplateId, new HttpRequestConfig(), OrganizationReportSettingsTemplateResponseObject.class);
return ResponseObject.of(responseObject.getData());
}

/**
* @param reportSettingsTemplateId report settings template identifier
* @param request request object
* @return report settings template
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.patch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ReportSettingsTemplate.OrganizationReportSettingsTemplate> editOrganizationReportSettingsTemplate(Long reportSettingsTemplateId, List<PatchRequest> request) throws HttpException, HttpBadRequestException {
OrganizationReportSettingsTemplateResponseObject responseObject = this.httpClient.patch(this.url + "/reports/settings-templates/" + reportSettingsTemplateId, request, new HttpRequestConfig(), OrganizationReportSettingsTemplateResponseObject.class);
return ResponseObject.of(responseObject.getData());
}

/**
* @param reportSettingsTemplateId report settings template identifier
* @see <ul>
* <li><a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/Reports/operation/api.reports.settings-templates.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void deleteOrganizationReportSettingsTemplate(Long reportSettingsTemplateId) throws HttpException, HttpBadRequestException {
this.httpClient.delete(this.url + "/reports/settings-templates/" + reportSettingsTemplateId, new HttpRequestConfig(), Void.class);
}

/**
* @param projectId project identifier
* @param request request object
Expand Down Expand Up @@ -214,7 +278,7 @@ public ResponseObject<ReportSettingsTemplate> editReportSettingsTemplate(Long pr
* </ul>
*/
public void deleteReportSettingsTemplate(Long projectId, Long reportSettingsTemplateId) throws HttpException, HttpBadRequestException {
this.httpClient.delete(this.url + "/projects/" + projectId + "/settings-templates/" + reportSettingsTemplateId, new HttpRequestConfig(), Void.class);
this.httpClient.delete(this.url + "/projects/" + projectId + "/reports/settings-templates/" + reportSettingsTemplateId, new HttpRequestConfig(), Void.class);
}

// -- USER REPORTS -- //
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.crowdin.client.reports.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class ContributionRawDataGenerateReportRequest extends GenerateReportRequest {
private String name = "contribution-raw-data";
private Schema schema;

@Data
public static class Schema {
private String mode;
private Unit unit;
private List<String> columns;
private List<Long> tmIds;
private List<Long> mtIds;
private List<Long> aiPromptIds;
private Date dateFrom;
private Date dateTo;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class GeneralSchema extends Schema {
private String languageId;
private Long userId;
private List<Long> fileIds;
private List<Long> directoryIds;
private List<Long> branchIds;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class ByTaskSchema extends Schema {
private Long taskId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public static class Schema {
private Unit unit;
private Currency currency;
private ReportsFormat format;
private BaseRatesForm baseRates;
private List<IndividualRate> individualRates;
private NetRateSchemes netRateSchemes;
private Boolean calculateInternalMatches;
private Boolean includePreTranslatedStrings;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class GeneralSchema extends Schema {
private BaseRatesForm baseRates;
private List<IndividualRate> individualRates;
private NetRateSchemes netRateSchemes;
private String languageId;
private List<Long> fileIds;
private List<Long> directoryIds;
Expand All @@ -35,27 +35,12 @@ public static class GeneralSchema extends Schema {
private Date dateTo;
private List<Long> labelIds;
private LabelIncludeType labelIncludeType;
private Long workflowStepId;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class ByTaskSchema extends Schema {
private BaseRatesForm baseRates;
private List<IndividualRate> individualRates;
private NetRateSchemes netRateSchemes;
private Long taskId;
}

@Data
public static class IndividualRate {
private List<String> languageIds;
private List<Long> userIds;
private float fullTranslation;
private float proofread;
}

@Data
public static class NetRateSchemes {
private List<Match> tmMatch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,81 +19,20 @@ public static abstract class Schema {

@Data
@EqualsAndHashCode(callSuper = true)
public static class GroupTranslationCostsPerEditingSchema extends Schema {
public static class GroupTranslationCostsPostEditingSchema extends Schema {
private List<Long> projectIds;
private Unit unit;
private Currency currency;
private ReportsFormat format;
private BaseRatesForm baseRates;
private List<IndividualRate> individualRates;
private NetRateSchemes netRateSchemes;
private Boolean excludeApprovalsForEditedTranslations;
private Boolean preTranslatedStringsCategorizationAdjustment;
private GroupingParameter groupBy;
private Date dateFrom;
private Date dateTo;
private List<String> languageId;
private List<Long> userIds;
private List<Long> branchIds;
private List<Long> labelIds;
private LabelIncludeType labelIncludeType;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class GroupTranslationCostsPerEditingByTaskSchema extends Schema {
private Unit unit;
private Currency currency;
private ReportsFormat format;
private BaseRatesForm baseRates;
private List<IndividualRate> individualRates;
private NetRateSchemes netRateSchemes;
private Long taskId;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class CostsEstimationSchema extends Schema {
private List<Long> projectIds;
private Unit unit;
private Currency currency;
private ReportsFormat format;
private BaseRatesForm baseRates;
private List<IndividualRate> individualRates;
private NetRateSchemes netRateSchemes;
private Boolean calculateInternalMatches;
private Boolean includePreTranslatedStrings;
private String languageId;
private List<Long> branchIds;
private Date dateFrom;
private Date dateTo;
private List<Long> labelIds;
private LabelIncludeType labelIncludeType;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class CostsEstimationByTaskSchema extends Schema {
private List<Long> projectIds;
private Unit unit;
private Currency currency;
private ReportsFormat format;
private BaseRatesForm baseRates;
private List<IndividualRate> individualRates;
private NetRateSchemes netRateSchemes;
private Boolean calculateInternalMatches;
private Boolean includePreTranslatedStrings;
private Long taskId;
}

@Data
@EqualsAndHashCode(callSuper = true)
public static class GroupTranslationCostSchema extends Schema {
private List<Long> projectIds;
private Unit unit;
private Currency currency;
private ReportsFormat format;
private GroupingParameter groupBy;
private Date dateFrom;
private Date dateTo;
}

@Data
Expand All @@ -107,19 +46,4 @@ public static class GroupTopMembersSchema extends Schema {
private Date dateFrom;
private Date dateTo;
}

@Data
public static class IndividualRate {
private List<String> languageIds;
private List<Long> userIds;
private Float fullTranslation;
private Float proofread;
}

@Data
public static class NetRateSchemes {
private List<Match> tmMatch;
private List<Match> mtMatch;
private List<Match> suggestionMatch;
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/crowdin/client/reports/model/IndividualRate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.crowdin.client.reports.model;

import lombok.Data;

import java.util.List;

@Data
public class IndividualRate {
private List<String> languageIds;
private List<Long> userIds;
private Float fullTranslation;
private Float proofread;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.crowdin.client.reports.model;

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

@EqualsAndHashCode(callSuper = true)
@Data
public class ListOrganizationReportSettingsParams extends Pagination {

private Long projectId;
private Long groupId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ public enum MatchType implements EnumConverter<MatchType> {
PERFECT("perfect"),
OPTION_100("100"),
OPTION_99_82("99-82"),
OPTION_81_60("81-60");
OPTION_99_95("99-95"),
OPTION_94_90("94-90"),
OPTION_89_80("89-80"),
OPTION_81_60("81-60"),
TM_MATCH("tm_match"),
APPROVAL("approval"),
NO_MATCH("no_match");

private String value;

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/crowdin/client/reports/model/NetRateSchemes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.crowdin.client.reports.model;

import lombok.Data;

import java.util.List;

@Data
public class NetRateSchemes {
private List<Match> tmMatch;
private List<Match> mtMatch;
private List<Match> suggestionMatch;
private List<Match> aiMatch;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.crowdin.client.reports.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 OrganizationReportSettingsTemplateList {

private List<OrganizationReportSettingsTemplateResponseObject> data;
private Pagination pagination;

public static ResponseList<ReportSettingsTemplate.OrganizationReportSettingsTemplate> to(OrganizationReportSettingsTemplateList reportSettingsTemplateList) {
return ResponseList.of(
reportSettingsTemplateList.getData().stream()
.map(OrganizationReportSettingsTemplateResponseObject::getData)
.map(ResponseObject::of)
.collect(Collectors.toList()),
reportSettingsTemplateList.getPagination()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.crowdin.client.reports.model;

import lombok.Data;

@Data
public class OrganizationReportSettingsTemplateResponseObject {

private ReportSettingsTemplate.OrganizationReportSettingsTemplate data;
}
Loading
Loading