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

retrieve dynamic search for query request #1358

Merged
merged 7 commits into from
Nov 10, 2023
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
8 changes: 8 additions & 0 deletions src/cli/java/org/commcare/util/screen/QueryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class QueryScreen extends Screen {

private boolean defaultSearch;

private boolean dynamicSearch;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this get set for QueryScreen ?

Copy link
Contributor Author

@stephherbers stephherbers Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved 8bfbc6f


public QueryScreen(String domainedUsername, String password, PrintStream out,
VirtualDataInstanceStorage instanceStorage, SessionUtils sessionUtils) {
this.domainedUsername = domainedUsername;
Expand Down Expand Up @@ -91,6 +93,7 @@ public void init(SessionWrapper sessionWrapper) throws CommCareSessionException

mTitle = getTitleLocaleString();
description = getDescriptionLocaleString();
dynamicSearch = getQueryDatum().getDynamicSearch();
}

private String getTitleLocaleString() {
Expand Down Expand Up @@ -211,6 +214,10 @@ public String getDescriptionText() {
return description;
}

public boolean getDynamicSearch() {
return dynamicSearch;
}

@Override
public boolean prompt(PrintStream out) {
if (doDefaultSearch()) {
Expand Down Expand Up @@ -275,6 +282,7 @@ public boolean doDefaultSearch() {
return remoteQuerySessionManager.doDefaultSearch();
}


public RemoteQueryDatum getQueryDatum() {
return remoteQuerySessionManager.getQueryDatum();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ public boolean doDefaultSearch() {
return queryDatum.doDefaultSearch();
}

public boolean getDynamicSearch() {
return queryDatum.getDynamicSearch();
}

// Converts a string containing space separated list of choices
// into a string array of individual choices
public static String[] extractMultipleChoices(String answer) {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/commcare/suite/model/RemoteQueryDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class RemoteQueryDatum extends SessionDatum {
private OrderedHashtable<String, QueryPrompt> userQueryPrompts;
private boolean useCaseTemplate;
private boolean defaultSearch;
private boolean dynamicSearch;
private Text title;
private Text description;

Expand All @@ -45,12 +46,13 @@ public RemoteQueryDatum() {
public RemoteQueryDatum(URL url, String storageInstance,
List<QueryData> hiddenQueryValues,
OrderedHashtable<String, QueryPrompt> userQueryPrompts,
boolean useCaseTemplate, boolean defaultSearch, Text title, Text description) {
boolean useCaseTemplate, boolean defaultSearch, boolean dynamicSearch, Text title, Text description) {
super(storageInstance, url.toString());
this.hiddenQueryValues = hiddenQueryValues;
this.userQueryPrompts = userQueryPrompts;
this.useCaseTemplate = useCaseTemplate;
this.defaultSearch = defaultSearch;
this.dynamicSearch = dynamicSearch;
this.title = title;
this.description = description;
}
Expand Down Expand Up @@ -81,6 +83,10 @@ public boolean doDefaultSearch() {
return defaultSearch;
}

public boolean getDynamicSearch() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename boolean getters in this PR to is{Var} to signify it's a boolean

return dynamicSearch;
}

public Text getTitleText() {
return title;
}
Expand All @@ -102,7 +108,7 @@ public void readExternal(DataInputStream in, PrototypeFactory pf)
description = (Text) ExtUtil.read(in, new ExtWrapNullable(Text.class), pf);
useCaseTemplate = ExtUtil.readBool(in);
defaultSearch = ExtUtil.readBool(in);

dynamicSearch = ExtUtil.readBool(in);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add the corresponding write in writeExternal as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

@Override
Expand All @@ -114,6 +120,7 @@ public void writeExternal(DataOutputStream out) throws IOException {
ExtUtil.write(out, new ExtWrapNullable(description));
ExtUtil.writeBool(out, useCaseTemplate);
ExtUtil.writeBool(out, defaultSearch);
ExtUtil.writeBool(out, dynamicSearch);

}
}
5 changes: 3 additions & 2 deletions src/main/java/org/commcare/xml/SessionDatumParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ private RemoteQueryDatum parseRemoteQueryDatum()
}

boolean defaultSearch = "true".equals(parser.getAttributeValue(null, "default_search"));
boolean dynamicSearch = "true".equals(parser.getAttributeValue(null, "dynamic_search"));
Text title = null;
Text description = null;
ArrayList<QueryData> hiddenQueryValues = new ArrayList<QueryData>();
Expand All @@ -144,7 +145,7 @@ private RemoteQueryDatum parseRemoteQueryDatum()
description = new TextParser(parser).parse();
}
}
return new RemoteQueryDatum(queryUrl, queryResultStorageInstance,
hiddenQueryValues, userQueryPrompts, useCaseTemplate, defaultSearch, title, description);
return new RemoteQueryDatum(queryUrl, queryResultStorageInstance, hiddenQueryValues,
userQueryPrompts, useCaseTemplate, defaultSearch, dynamicSearch, title, description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void testRemoteQueryDatum() throws Exception {

Text description = ((RemoteQueryDatum) datum).getDescriptionText();
Assert.assertEquals("Description text", description.evaluate());

Assert.assertTrue(((RemoteQueryDatum)datum).getDynamicSearch());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/case_claim_example/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<instance id="casedb" src="jr://instance/casedb"/>
<instance id="my-search-input" src="jr://instance/search-input/patients"/>
<session>
<query url="https://www.fake.com/patient_search/" storage-instance="patients">
<query url="https://www.fake.com/patient_search/" storage-instance="patients" dynamic_search="true">
<title>
<text>
<locale id="query.title"/>
Expand Down