From 8ccf625c775ebd440826cd166ade90ffa3d73397 Mon Sep 17 00:00:00 2001 From: Daniil Barabash Date: Thu, 7 Oct 2021 16:18:48 +0300 Subject: [PATCH] Add 'croql' param to 'string list' --- .../com/crowdin/cli/client/CrowdinProjectClient.java | 4 ++-- .../java/com/crowdin/cli/client/ProjectClient.java | 2 +- src/main/java/com/crowdin/cli/commands/Actions.java | 2 +- .../com/crowdin/cli/commands/actions/CliActions.java | 4 ++-- .../cli/commands/actions/StringDeleteAction.java | 2 +- .../cli/commands/actions/StringEditAction.java | 2 +- .../cli/commands/actions/StringListAction.java | 8 +++++--- .../cli/commands/picocli/StringListSubcommand.java | 5 ++++- src/main/resources/messages/messages.properties | 2 ++ .../crowdin/cli/client/CrowdinProjectClientTest.java | 2 +- .../crowdin/cli/commands/actions/CliActionsTest.java | 2 +- .../cli/commands/actions/StringDeleteActionTest.java | 8 ++++---- .../cli/commands/actions/StringEditActionTest.java | 8 ++++---- .../cli/commands/actions/StringListActionTest.java | 12 ++++++------ .../cli/commands/picocli/PicocliTestUtils.java | 2 +- .../commands/picocli/StringListSubcommandTest.java | 4 ++-- 16 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java b/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java index e2381c22d..6dada29f1 100644 --- a/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java +++ b/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java @@ -246,9 +246,9 @@ public SourceString addSourceString(AddSourceStringRequest request) { } @Override - public List listSourceString(Long fileId, Long branchId, String labelIds, String filter) { + public List listSourceString(Long fileId, Long branchId, String labelIds, String filter, String croql) { return executeRequestFullList((limit, offset) -> this.client.getSourceStringsApi() - .listSourceStrings(this.projectId, fileId, null, branchId, labelIds, null, filter, null, limit, offset)); + .listSourceStrings(this.projectId, fileId, null, branchId, labelIds, croql, filter, null, limit, offset)); } @Override diff --git a/src/main/java/com/crowdin/cli/client/ProjectClient.java b/src/main/java/com/crowdin/cli/client/ProjectClient.java index b5f4d9f5d..e71645c69 100644 --- a/src/main/java/com/crowdin/cli/client/ProjectClient.java +++ b/src/main/java/com/crowdin/cli/client/ProjectClient.java @@ -65,7 +65,7 @@ public interface ProjectClient extends Client { SourceString addSourceString(AddSourceStringRequest request); - List listSourceString(Long fileId, Long branchId, String labelIds, String filter); + List listSourceString(Long fileId, Long branchId, String labelIds, String filter, String croql); void deleteSourceString(Long id); diff --git a/src/main/java/com/crowdin/cli/commands/Actions.java b/src/main/java/com/crowdin/cli/commands/Actions.java index ad62a2e08..ed3276072 100644 --- a/src/main/java/com/crowdin/cli/commands/Actions.java +++ b/src/main/java/com/crowdin/cli/commands/Actions.java @@ -57,7 +57,7 @@ NewAction stringEdit( boolean noProgress, Long id, String identifier, String newText, String newContext, Integer newMaxLength, List labelNames, Boolean isHidden); NewAction stringList( - boolean noProgress, boolean isVerbose, String file, String filter, String branchName); + boolean noProgress, boolean isVerbose, String file, String filter, String branchName, String croql); NewAction uploadSources( String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView); diff --git a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java index 402b62115..3b294df4a 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java +++ b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java @@ -100,9 +100,9 @@ public NewAction stringEdit( @Override public NewAction stringList( - boolean noProgress, boolean isVerbose, String file, String filter, String branchName + boolean noProgress, boolean isVerbose, String file, String filter, String branchName, String croql ) { - return new StringListAction(noProgress, isVerbose, file, filter, branchName); + return new StringListAction(noProgress, isVerbose, file, filter, branchName, croql); } @Override diff --git a/src/main/java/com/crowdin/cli/commands/actions/StringDeleteAction.java b/src/main/java/com/crowdin/cli/commands/actions/StringDeleteAction.java index 15d0f9580..73187e3a0 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/StringDeleteAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/StringDeleteAction.java @@ -40,7 +40,7 @@ public void act(Outputter out, ProjectProperties pb, ProjectClient client) { .stream() .collect(Collectors.toMap((entry) -> entry.getValue().getId(), Map.Entry::getKey)); - List sourceStrings = client.listSourceString(null, null, null, null) + List sourceStrings = client.listSourceString(null, null, null, null, null) .stream() .filter(sourceString -> (ids != null && ids.contains(sourceString.getId())) || (texts != null && sourceString.getText() instanceof String && texts.contains(sourceString.getText())) diff --git a/src/main/java/com/crowdin/cli/commands/actions/StringEditAction.java b/src/main/java/com/crowdin/cli/commands/actions/StringEditAction.java index ab6827706..1073b2ecd 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/StringEditAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/StringEditAction.java @@ -45,7 +45,7 @@ public StringEditAction( @Override public void act(Outputter out, ProjectProperties pb, ProjectClient client) { - List sourceStrings = client.listSourceString(null, null, null, null); + List sourceStrings = client.listSourceString(null, null, null, null, null); List labelIds = (labelNames != null && !labelNames.isEmpty()) ? this.prepareLabelIds(client) : null; diff --git a/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java b/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java index f44cda1a6..ccdad031e 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java @@ -31,13 +31,15 @@ class StringListAction implements NewAction { private final String file; private final String filter; private final String branchName; + private final String croql; - public StringListAction(boolean noProgress, boolean isVerbose, String file, String filter, String branchName) { + public StringListAction(boolean noProgress, boolean isVerbose, String file, String filter, String branchName, String croql) { this.noProgress = noProgress; this.isVerbose = isVerbose; this.file = file; this.filter = filter; this.branchName = branchName; + this.croql = croql; } @Override @@ -68,10 +70,10 @@ public void act(Outputter out, ProjectProperties pb, ProjectClient client) { List sourceStrings; if (StringUtils.isEmpty(file)) { - sourceStrings = client.listSourceString(null, branchId, null, encodedFilter); + sourceStrings = client.listSourceString(null, branchId, null, encodedFilter, croql); } else { if (paths.containsKey(file)) { - sourceStrings = client.listSourceString(paths.get(file).getId(), branchId, null, encodedFilter); + sourceStrings = client.listSourceString(paths.get(file).getId(), branchId, null, encodedFilter, croql); } else { throw new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.file_not_exists"), file)); } diff --git a/src/main/java/com/crowdin/cli/commands/picocli/StringListSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/StringListSubcommand.java index ca5d257fc..5f9b1ddbc 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/StringListSubcommand.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/StringListSubcommand.java @@ -25,6 +25,9 @@ class StringListSubcommand extends ActCommandProject { @CommandLine.Option(names = {"-b", "--branch"}, paramLabel = "...") protected String branchName; + @CommandLine.Option(names = {"--croql"}, paramLabel = "...") + protected String croql; + @Override protected List checkOptions() { if (file != null) { @@ -35,6 +38,6 @@ protected List checkOptions() { @Override protected NewAction getAction(Actions actions) { - return actions.stringList(noProgress, isVerbose, file, filter, branchName); + return actions.stringList(noProgress, isVerbose, file, filter, branchName, croql); } } diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index d19480416..641295e32 100755 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -147,11 +147,13 @@ crowdin.string.list.usage.description=Show a list of source strings in the curre crowdin.string.list.usage.customSynopsis=@|fg(green) crowdin string list|@ [CONFIG OPTIONS] [OPTIONS] crowdin.string.list.file=Show a list of source strings filtered by file path crowdin.string.list.filter=Show a list of source strings filtered by text and context +crowdin.string.list.croql=Retrieve needed localization resources from Crowdin based on specific conditions # CROWDIN STRING EDIT COMMAND crowdin.string.edit.usage.description=Edit existing source string crowdin.string.edit.usage.customSynopsis=@|fg(green) crowdin string edit|@ [CONFIG OPTIONS] [OPTIONS] crowdin.string.edit.id=Numeric string identifier (get via 'crowdin string list') +crowdin.string.edit.identifier=String identifier crowdin.string.edit.text=Specify new text for the source string crowdin.string.edit.context=Set new context for source string crowdin.string.edit.max-length=Set a new max. length of the translated text for the source string diff --git a/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java b/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java index 29ac876df..8225f5be5 100644 --- a/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java +++ b/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java @@ -523,7 +523,7 @@ public void testListSourceString() { when(httpClientMock.get(eq(listSourceStringUrl), any(), eq(SourceStringResponseList.class))) .thenReturn(response); - client.listSourceString(fileId, null, null, "FiLtEr"); + client.listSourceString(fileId, null, null, "FiLtEr", null); verify(httpClientMock).get(eq(listSourceStringUrl), any(), eq(SourceStringResponseList.class)); verifyNoMoreInteractions(httpClientMock); diff --git a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java index 00d7a563a..af0b07d8c 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java @@ -64,7 +64,7 @@ public void testStringEdit() { @Test public void testStringList() { - assertNotNull(actions.stringList(false, false, null, null, null)); + assertNotNull(actions.stringList(false, false, null, null, null, null)); } @Test diff --git a/src/test/java/com/crowdin/cli/commands/actions/StringDeleteActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/StringDeleteActionTest.java index 78bd2969b..9107c6a6a 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/StringDeleteActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/StringDeleteActionTest.java @@ -45,7 +45,7 @@ public void testStringList(List strings, List ids, List strings, List ids, List action.act(Outputter.getDefault(), pb, client)); verify(client).downloadFullProject(); - verify(client).listSourceString(null, null, null, null); + verify(client).listSourceString(null, null, null, null, null); for (SourceString sourceString : strings) { verify(client).deleteSourceString(sourceString.getId()); } diff --git a/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java index 3c0bb4bdd..793db924e 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java @@ -54,7 +54,7 @@ public void testStringList( when(client.downloadFullProject()) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); - when(client.listSourceString(null, null, null, null)) + when(client.listSourceString(null, null, null, null, null)) .thenReturn(Arrays.asList(SourceStringBuilder.standard().setProjectId(42L).setIdentifiers(801L, "old", "old", "old", null).build())); if (newLabels != null) { @@ -89,7 +89,7 @@ public void testStringList( add(RequestBuilder.patch(labelIds, PatchOperation.REPLACE, "/labelIds")); } }}; - verify(client).listSourceString(null, null, null, null); + verify(client).listSourceString(null, null, null, null, null); verify(client).editSourceString(801L, patches); if (newLabels != null) { verify(client).listLabels(); @@ -121,13 +121,13 @@ public void testBothIdAndIdentifier_throws() throws ResponseException { when(client.downloadFullProject()) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); - when(client.listSourceString(null, null, null, null)) + when(client.listSourceString(null, null, null, null, null)) .thenReturn(Arrays.asList(SourceStringBuilder.standard().setProjectId(42L).setIdentifiers(801L, "old", "old", "old", null).build())); action = new StringEditAction(true, null, null, null, null, null, null, null); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).listSourceString(null, null, null, null); + verify(client).listSourceString(null, null, null, null, null); verifyNoMoreInteractions(client); } } diff --git a/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java index f39ee3d87..15dd56edf 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java @@ -41,20 +41,20 @@ public void testStringList(String file, String filter) throws ResponseException when(client.downloadFullProject()) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); - when(client.listSourceString(101L, null, null, filter)) + when(client.listSourceString(101L, null, null, filter, null)) .thenReturn(Arrays.asList(SourceStringBuilder.standard() .setProjectId(Long.parseLong(pb.getProjectId())) .setIdentifiers(701L, "7-0-1", "seven-o-one", "7.0.1", 101L).build())); - action = new StringListAction(true, true, file, filter, null); + action = new StringListAction(true, true, file, filter, null, null); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); verify(client).listLabels(); if (file != null) { - verify(client).listSourceString(101L, null, null, filter); + verify(client).listSourceString(101L, null, null, filter, null); } else { - verify(client).listSourceString(null, null, null, filter); + verify(client).listSourceString(null, null, null, filter, null); } verifyNoMoreInteractions(client); } @@ -76,7 +76,7 @@ public void testGetProjectThrows() throws ResponseException { when(client.downloadFullProject()) .thenThrow(new RuntimeException("Whoops")); - action = new StringListAction(true, true, null, null, null); + action = new StringListAction(true, true, null, null, null, null); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); verify(client).downloadFullProject(); @@ -94,7 +94,7 @@ public void testFileNotExistThrows() throws ResponseException { .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); - action = new StringListAction(true, true, "notexist.csv", null, null); + action = new StringListAction(true, true, "notexist.csv", null, null, null); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); verify(client).downloadFullProject(); diff --git a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java index 7593f8057..a4861f50b 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java @@ -79,7 +79,7 @@ void mockActions() { .thenReturn(actionMock); when(actionsMock.stringEdit(anyBoolean(), any(), any(), any(), any(), any(), any(), any())) .thenReturn(actionMock); - when(actionsMock.stringList(anyBoolean(), anyBoolean(), any(), any(), any())) + when(actionsMock.stringList(anyBoolean(), anyBoolean(), any(), any(), any(), any())) .thenReturn(actionMock); when(actionsMock.uploadSources(any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean())) .thenReturn(actionMock); diff --git a/src/test/java/com/crowdin/cli/commands/picocli/StringListSubcommandTest.java b/src/test/java/com/crowdin/cli/commands/picocli/StringListSubcommandTest.java index 71bb046f0..707982804 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/StringListSubcommandTest.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/StringListSubcommandTest.java @@ -12,7 +12,7 @@ public class StringListSubcommandTest extends PicocliTestUtils { public void testStringList() { this.execute(CommandNames.STRING, CommandNames.STRING_LIST); verify(actionsMock) - .stringList(anyBoolean(), anyBoolean(), any(), any(), any()); + .stringList(anyBoolean(), anyBoolean(), any(), any(), any(), any()); this.check(true); } @@ -20,7 +20,7 @@ public void testStringList() { public void testStringList2() { this.execute(CommandNames.STRING, CommandNames.STRING_LIST, "--file", "some/path/to/file.txt"); verify(actionsMock) - .stringList(anyBoolean(), anyBoolean(), any(), any(), any()); + .stringList(anyBoolean(), anyBoolean(), any(), any(), any(), any()); this.check(true); } } \ No newline at end of file