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: file command #708

Merged
merged 11 commits into from
Jan 23, 2024
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
2 changes: 2 additions & 0 deletions prepare-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ sed -i.bak -e 's/\*\*--\[no-\]import-eq-suggestions\*\*/`--[no-]import-eq-sugges
sed -i.bak -e 's/\*\*--\[no-\]translate-hidden\*\*/`--[no-]translate-hidden`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]preserve-hierarchy\*\*/`--[no-]preserve-hierarchy`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]auto-tag\*\*/`--[no-]auto-tag`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]cleanup-mode\*\*/`--[no-]cleanup-mode`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]update-strings\*\*/`--[no-]update-strings`/g' -- *.md

rm -- *.md.bak

Expand Down
76 changes: 38 additions & 38 deletions src/main/java/com/crowdin/cli/client/CrowdinClientLabel.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package com.crowdin.cli.client;
import com.crowdin.client.Client;
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
import lombok.AllArgsConstructor;
import java.util.List;
import static java.lang.Long.parseLong;
@AllArgsConstructor
public class CrowdinClientLabel extends CrowdinClientCore implements ClientLabel {
private final Client client;
private final String projectId;
@Override
public List<Label> listLabels() {
return executeRequestFullList((limit, offset) -> this.client.getLabelsApi()
.listLabels(parseLong(this.projectId), limit, offset));
}
@Override
public Label addLabel(AddLabelRequest request) {
return executeRequest(() -> this.client.getLabelsApi()
.addLabel(parseLong(this.projectId), request)
.getData());
}
@Override
public void deleteLabel(Long id) {
executeRequest(() -> {
this.client.getLabelsApi().deleteLabel(parseLong(this.projectId), id);
return null;
});
}
}
package com.crowdin.cli.client;

import com.crowdin.client.Client;
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
import lombok.AllArgsConstructor;

import java.util.List;

import static java.lang.Long.parseLong;

@AllArgsConstructor
public class CrowdinClientLabel extends CrowdinClientCore implements ClientLabel {

private final Client client;
private final String projectId;

@Override
public List<Label> listLabels() {
return executeRequestFullList((limit, offset) -> this.client.getLabelsApi()
.listLabels(parseLong(this.projectId), limit, offset, null));
}

@Override
public Label addLabel(AddLabelRequest request) {
return executeRequest(() -> this.client.getLabelsApi()
.addLabel(parseLong(this.projectId), request)
.getData());
}

@Override
public void deleteLabel(Long id) {
executeRequest(() -> {
this.client.getLabelsApi().deleteLabel(parseLong(this.projectId), id);
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CrowdinClientTask(com.crowdin.client.Client client, String projectId) {
@Override
public List<Task> listTask(Status status) {
return executeRequestFullList((limit, offset) -> this.client.getTasksApi()
.listTasks(Long.valueOf(projectId), limit, offset, status));
.listTasks(Long.valueOf(projectId), limit, offset, status, null));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/client/CrowdinClientTm.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public CrowdinClientTm(com.crowdin.client.Client client) {
@Override
public List<TranslationMemory> listTms() {
return executeRequestFullList((limit, offset) -> this.client.getTranslationMemoryApi()
.listTms(null, limit, offset));
.listTms(null, limit, offset, null));
}

@Override
Expand Down
58 changes: 39 additions & 19 deletions src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,22 @@
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
import com.crowdin.client.projectsgroups.model.ProjectSettings;
import com.crowdin.client.sourcefiles.model.AddBranchRequest;
import com.crowdin.client.sourcefiles.model.AddDirectoryRequest;
import com.crowdin.client.sourcefiles.model.AddFileRequest;
import com.crowdin.client.sourcefiles.model.Branch;
import com.crowdin.client.sourcefiles.model.BuildReviewedSourceFilesRequest;
import com.crowdin.client.sourcefiles.model.Directory;
import com.crowdin.client.sourcefiles.model.ReviewedStringsBuild;
import com.crowdin.client.sourcefiles.model.UpdateFileRequest;
import com.crowdin.client.projectsgroups.model.Type;
import com.crowdin.client.sourcefiles.model.*;
import com.crowdin.client.sourcestrings.model.AddSourceStringRequest;
import com.crowdin.client.sourcestrings.model.SourceString;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import com.crowdin.client.storage.model.Storage;
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
import com.crowdin.client.stringcomments.model.StringComment;
import com.crowdin.client.translations.model.ApplyPreTranslationRequest;
import com.crowdin.client.translations.model.BuildProjectTranslationRequest;
import com.crowdin.client.translations.model.ExportProjectTranslationRequest;
import com.crowdin.client.translations.model.PreTranslationStatus;
import com.crowdin.client.translations.model.ProjectBuild;
import com.crowdin.client.translations.model.UploadTranslationsRequest;
import com.crowdin.client.translations.model.*;
import com.crowdin.client.translationstatus.model.LanguageProgress;
import org.apache.commons.lang3.StringUtils;

import java.io.InputStream;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.BiPredicate;

import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;
Expand Down Expand Up @@ -78,6 +66,10 @@
)
.ifPresent(project::setBranch);
Long branchId = Optional.ofNullable(project.getBranch()).map(Branch::getId).orElse(null);

if (Objects.equals(project.getType(), Type.STRINGS_BASED)) {
return;

Check warning on line 71 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L71

Added line #L71 was not covered by tests
}
project.setFiles(executeRequestFullList((limit, offset) -> this.client.getSourceFilesApi()
.listFiles(this.projectId, branchId, null, null, true, limit, offset)));
project.setDirectories(executeRequestFullList((limit, offset) -> this.client.getSourceFilesApi()
Expand All @@ -92,6 +84,7 @@
private void populateProjectWithInfo(CrowdinProjectInfo project) {
com.crowdin.client.projectsgroups.model.Project projectModel = this.getProject();
project.setProjectId(projectModel.getId());
project.setType(projectModel.getType());
project.setSourceLanguageId(projectModel.getSourceLanguageId());
project.setProjectLanguages(projectModel.getTargetLanguages());
if (projectModel instanceof ProjectSettings) {
Expand Down Expand Up @@ -223,6 +216,20 @@
.addFile(this.projectId, request));
}

@Override
public UploadStringsProgress addSourceStringsBased(UploadStringsRequest request) {
return executeRequest(
() -> this.client.getSourceStringsApi().uploadStrings(this.projectId, request).getData()

Check warning on line 222 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L221-L222

Added lines #L221 - L222 were not covered by tests
);
}

@Override
public UploadStringsProgress getUploadStringsStatus(String uploadId) {
return executeRequest(
() -> this.client.getSourceStringsApi().uploadStringsStatus(this.projectId, uploadId).getData()

Check warning on line 229 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L228-L229

Added lines #L228 - L229 were not covered by tests
);
}

@Override
public void editSource(Long fileId, List<PatchRequest> request) {
executeRequest(() -> this.client.getSourceFilesApi()
Expand Down Expand Up @@ -252,6 +259,12 @@
.uploadTranslations(this.projectId, languageId, request));
}

@Override
public void uploadTranslationStringsBased(String languageId, UploadTranslationsStringsRequest request) {
executeRequest(() -> this.client.getTranslationsApi()
.uploadTranslationStringsBased(this.projectId, languageId, request));
}

Check warning on line 266 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L264-L266

Added lines #L264 - L266 were not covered by tests

@Override
public ProjectBuild startBuildingTranslation(BuildProjectTranslationRequest request) throws ResponseException {
Map<BiPredicate<String, String>, ResponseException> errorHandler = new LinkedHashMap<BiPredicate<String, String>, ResponseException>() {{
Expand All @@ -273,6 +286,13 @@
.getData());
}

@Override
public URL buildProjectFileTranslation(Long fileId, BuildProjectFileTranslationRequest request) {
return url(executeRequest(() -> this.client.getTranslationsApi()
.buildProjectFileTranslation(projectId, fileId, null, request)
.getData()));

Check warning on line 293 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L291-L293

Added lines #L291 - L293 were not covered by tests
}

@Override
public URL downloadBuild(Long buildId) {
return url(executeRequest(() -> this.client.getTranslationsApi()
Expand Down Expand Up @@ -347,7 +367,7 @@
@Override
public List<Label> listLabels() {
return executeRequestFullList((limit, offset) -> this.client.getLabelsApi()
.listLabels(this.projectId, limit, offset));
.listLabels(this.projectId, limit, offset, null));

Check warning on line 370 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L370

Added line #L370 was not covered by tests
}

@Override
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/crowdin/cli/client/CrowdinProjectInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.crowdin.cli.client;

import com.crowdin.client.languages.model.Language;
import com.crowdin.client.projectsgroups.model.Type;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -11,6 +12,7 @@ public class CrowdinProjectInfo {
private Long projectId;
private String sourceLanguageId;
private Access accessLevel;
private Type type;
private Language inContextLanguage;
private LanguageMapping languageMapping;
private List<Language> projectLanguages;
Expand Down Expand Up @@ -44,6 +46,14 @@ public boolean isManagerAccess() {
return accessLevel == Access.MANAGER;
}

public void setType(Type type) {
this.type = type;
}

public Type getType() {
return type;
}

void setInContextLanguage(Language inContextLanguage) {
this.inContextLanguage = inContextLanguage;
}
Expand Down Expand Up @@ -90,5 +100,4 @@ public List<Language> getProjectLanguages(boolean withInContextLang) {
public enum Access {
TRANSLATOR, MANAGER
}

}
28 changes: 14 additions & 14 deletions src/main/java/com/crowdin/cli/client/ProjectClient.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package com.crowdin.cli.client;

import com.crowdin.client.core.model.DownloadLink;
import com.crowdin.client.core.model.PatchRequest;
import com.crowdin.client.distributions.model.DistributionRelease;
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
import com.crowdin.client.sourcefiles.model.AddBranchRequest;
import com.crowdin.client.sourcefiles.model.AddDirectoryRequest;
import com.crowdin.client.sourcefiles.model.AddFileRequest;
import com.crowdin.client.sourcefiles.model.Branch;
import com.crowdin.client.sourcefiles.model.BuildReviewedSourceFilesRequest;
import com.crowdin.client.sourcefiles.model.Directory;
import com.crowdin.client.sourcefiles.model.ReviewedStringsBuild;
import com.crowdin.client.sourcefiles.model.UpdateFileRequest;
import com.crowdin.client.sourcefiles.model.*;
import com.crowdin.client.sourcestrings.model.AddSourceStringRequest;
import com.crowdin.client.sourcestrings.model.SourceString;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
import com.crowdin.client.stringcomments.model.StringComment;
import com.crowdin.client.translations.model.ApplyPreTranslationRequest;
import com.crowdin.client.translations.model.BuildProjectTranslationRequest;
import com.crowdin.client.translations.model.ExportProjectTranslationRequest;
import com.crowdin.client.translations.model.PreTranslationStatus;
import com.crowdin.client.translations.model.ProjectBuild;
import com.crowdin.client.translations.model.UploadTranslationsRequest;
import com.crowdin.client.translations.model.*;
import com.crowdin.client.translationstatus.model.LanguageProgress;

import java.io.InputStream;
Expand Down Expand Up @@ -55,16 +47,24 @@ default CrowdinProjectFull downloadFullProject() {

void addSource(AddFileRequest request) throws ResponseException;

UploadStringsProgress addSourceStringsBased(UploadStringsRequest request);

UploadStringsProgress getUploadStringsStatus(String uploadId);

void editSource(Long fileId, List<PatchRequest> request);

void deleteSource(Long fileId);

void uploadTranslations(String languageId, UploadTranslationsRequest request) throws ResponseException;

void uploadTranslationStringsBased(String languageId, UploadTranslationsStringsRequest request);

ProjectBuild startBuildingTranslation(BuildProjectTranslationRequest request) throws ResponseException;

ProjectBuild checkBuildingTranslation(Long buildId);

URL buildProjectFileTranslation(Long fileId, BuildProjectFileTranslationRequest request);

URL downloadBuild(Long buildId);

ReviewedStringsBuild startBuildingReviewedSources(BuildReviewedSourceFilesRequest request);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,14 @@ NewAction<PropertiesWithFiles, ProjectClient> preTranslate(
NewAction<ProjectProperties, ClientLabel> labelAdd(String title, boolean plainView);

NewAction<ProjectProperties, ClientLabel> labelDelete(String title);

NewAction<ProjectProperties, ProjectClient> fileUpload(File file, String branch, boolean autoUpdate, List<String> labels, String destination, List<String> excludedLanguages, boolean plainView, boolean cleanupMode, boolean updateString);

NewAction<ProjectProperties, ProjectClient> fileUploadTranslation(File file, String branch, String dest, String languageId, boolean plainView);

NewAction<ProjectProperties, ProjectClient> fileDownload(String file, String branch, String destParam);

NewAction<ProjectProperties, ProjectClient> fileDownloadTranslation(String file, String languageId, String branch, String destParam);

NewAction<ProjectProperties, ProjectClient> fileDelete(String file, String branch);
}
25 changes: 25 additions & 0 deletions src/main/java/com/crowdin/cli/commands/actions/CliActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,29 @@ public NewAction<ProjectProperties, ClientLabel> labelAdd(String title, boolean
public NewAction<ProjectProperties, ClientLabel> labelDelete(String title) {
return new LabelDeleteAction(title);
}

@Override
public NewAction<ProjectProperties, ProjectClient> fileUpload(File file, String branch, boolean autoUpdate, List<String> labels, String destination, List<String> excludedLanguages, boolean plainView, boolean cleanupMode, boolean updateStrings) {
return new FileUploadAction(file, branch, autoUpdate, labels, destination, cleanupMode, updateStrings, excludedLanguages, plainView);
}

@Override
public NewAction<ProjectProperties, ProjectClient> fileUploadTranslation(File file, String branch, String dest, String languageId, boolean plainView) {
return new FileUploadTranslationAction(file, branch, dest, languageId, plainView);
}

@Override
public NewAction<ProjectProperties, ProjectClient> fileDownload(String file, String branch, String destParam) {
return new FileDownloadAction(file, branch, destParam);
}

@Override
public NewAction<ProjectProperties, ProjectClient> fileDownloadTranslation(String file, String languageId, String branch, String destParam) {
return new FileDownloadTranslationAction(file, languageId, branch, destParam);
}

@Override
public NewAction<ProjectProperties, ProjectClient> fileDelete(String file, String branch) {
return new FileDeleteAction(file, branch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private ProjectBuild buildTranslation(ProjectClient client, BuildProjectTranslat

return ConsoleSpinner.execute(
out,
"message.spinner.building_translation",
"message.spinner.building_translations",
"error.building_translation",
this.noProgress,
this.plainView,
Expand Down Expand Up @@ -537,7 +537,7 @@ private Map<String, String> doTranslationMapping(
}

private void downloadTranslations(ProjectClient client, Long buildId, String archivePath) {
ConsoleSpinner.execute(out, "message.spinner.downloading_translation", "error.downloading_file", this.noProgress, this.plainView, () -> {
ConsoleSpinner.execute(out, "message.spinner.downloading_translations", "error.downloading_file", this.noProgress, this.plainView, () -> {
URL url = client.downloadBuild(buildId);
try (InputStream data = url.openStream()) {
files.writeToFile(archivePath, data);
Expand Down
Loading
Loading