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

Add 'croql' param to 'string list' #401

Merged
merged 1 commit into from
Oct 18, 2021
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 @@ -246,9 +246,9 @@ public SourceString addSourceString(AddSourceStringRequest request) {
}

@Override
public List<SourceString> listSourceString(Long fileId, Long branchId, String labelIds, String filter) {
public List<SourceString> 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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/client/ProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface ProjectClient extends Client {

SourceString addSourceString(AddSourceStringRequest request);

List<SourceString> listSourceString(Long fileId, Long branchId, String labelIds, String filter);
List<SourceString> listSourceString(Long fileId, Long branchId, String labelIds, String filter, String croql);

void deleteSourceString(Long id);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ NewAction<ProjectProperties, ProjectClient> stringEdit(
boolean noProgress, Long id, String identifier, String newText, String newContext, Integer newMaxLength, List<String> labelNames, Boolean isHidden);

NewAction<ProjectProperties, ProjectClient> stringList(
boolean noProgress, boolean isVerbose, String file, String filter, String branchName);
boolean noProgress, boolean isVerbose, String file, String filter, String branchName, String croql);

NewAction<PropertiesWithFiles, ProjectClient> uploadSources(
String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public NewAction<ProjectProperties, ProjectClient> stringEdit(

@Override
public NewAction<ProjectProperties, ProjectClient> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceString> sourceStrings = client.listSourceString(null, null, null, null)
List<SourceString> 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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public StringEditAction(
@Override
public void act(Outputter out, ProjectProperties pb, ProjectClient client) {

List<SourceString> sourceStrings = client.listSourceString(null, null, null, null);
List<SourceString> sourceStrings = client.listSourceString(null, null, null, null, null);

List<Long> labelIds = (labelNames != null && !labelNames.isEmpty()) ? this.prepareLabelIds(client) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class StringListAction implements NewAction<ProjectProperties, ProjectClient> {
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
Expand Down Expand Up @@ -68,10 +70,10 @@ public void act(Outputter out, ProjectProperties pb, ProjectClient client) {

List<SourceString> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> checkOptions() {
if (file != null) {
Expand All @@ -35,6 +38,6 @@ protected List<String> checkOptions() {

@Override
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
return actions.stringList(noProgress, isVerbose, file, filter, branchName);
return actions.stringList(noProgress, isVerbose, file, filter, branchName, croql);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public void testStringList(List<SourceString> strings, List<Long> ids, List<Stri
pb = pbBuilder.build();
when(client.downloadFullProject())
.thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).build());
when(client.listSourceString(null, null, null, null))
when(client.listSourceString(null, null, null, null, null))
.thenReturn(strings);


action = new StringDeleteAction(true, ids, texts, identifiers);
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());
}
Expand Down Expand Up @@ -86,15 +86,15 @@ public void testStringList_throwsNotFound() {
pb = pbBuilder.build();
when(client.downloadFullProject())
.thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).build());
when(client.listSourceString(null, null, null, null))
when(client.listSourceString(null, null, null, null, null))
.thenReturn(strings);


action = new StringDeleteAction(true, ids, texts, identifiers);
assertThrows(RuntimeException.class, () -> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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);
}

@Test
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);
}
}