Skip to content

Commit

Permalink
fix: check strings upload status (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Aug 30, 2024
1 parent 2c15c57 commit e6e1416
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.crowdin.client.languages.model.Language;
import com.crowdin.client.projectsgroups.model.Type;
import com.crowdin.client.sourcefiles.model.*;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -316,7 +317,31 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {
String.format(RESOURCE_BUNDLE.getString("error.upload_to_storage"), sourceFile.getAbsolutePath()));
}
try {
client.addSourceStringsBased(request);
ConsoleSpinner.execute(
out,
"message.spinner.uploading_strings",
"message.spinner.upload_strings_failed",
this.plainView,
this.plainView,
() -> {
UploadStringsProgress uploadStrings = client.addSourceStringsBased(request);
String uploadId = uploadStrings.getIdentifier();

while (!"finished".equalsIgnoreCase(uploadStrings.getStatus())) {
ConsoleSpinner.update(
String.format(RESOURCE_BUNDLE.getString("message.spinner.uploading_strings_percents"),
uploadStrings.getProgress()));
Thread.sleep(1000);

uploadStrings = client.getUploadStringsStatus(uploadId);

if ("failed".equalsIgnoreCase(uploadStrings.getStatus())) {
throw new RuntimeException(RESOURCE_BUNDLE.getString("message.spinner.upload_strings_failed"));
}
}
ConsoleSpinner.update(String.format(RESOURCE_BUNDLE.getString("message.spinner.uploading_strings_percents"), 100));
return uploadStrings;
});
} catch (Exception e) {
errorsPresented.set(true);
throw ExitCodeExceptionMapper.remap(e, String.format(RESOURCE_BUNDLE.getString("error.uploading_file"), fileFullPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.crowdin.client.sourcefiles.model.SpreadsheetFileImportOptions;
import com.crowdin.client.sourcefiles.model.UpdateFileRequest;
import com.crowdin.client.sourcestrings.model.ImportOptions;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -797,23 +798,27 @@ public void testUploadOneSource_StringBasedProject() throws ResponseException {
ProjectClient client = mock(ProjectClient.class);
CrowdinProjectFull build = ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).addBranches(2L, "main").build();
build.setType(Type.STRINGS_BASED);
UploadStringsRequest uploadStringsRequest = new UploadStringsRequest() {
{
setStorageId(1L);
setBranchId(2L);
setImportOptions(new ImportOptions());
}};
UploadStringsProgress uploadStringsProgress = new UploadStringsProgress();
uploadStringsProgress.setIdentifier("testid");
uploadStringsProgress.setStatus("finished");
when(client.downloadFullProject())
.thenReturn(build);
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);
when(client.addSourceStringsBased(eq(uploadStringsRequest))).thenReturn(uploadStringsProgress);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("main", false, false, true, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
verify(client).listLabels();
verify(client).uploadStorage(eq("first.po"), any());
UploadStringsRequest uploadStringsRequest = new UploadStringsRequest() {
{
setStorageId(1L);
setBranchId(2L);
setImportOptions(new ImportOptions());
}};
verify(client).addSourceStringsBased(eq(uploadStringsRequest));
verifyNoMoreInteractions(client);
}
Expand Down

0 comments on commit e6e1416

Please sign in to comment.