Skip to content

Commit

Permalink
Merge pull request #1358 from dimagi/dynamicSearchSuite
Browse files Browse the repository at this point in the history
retrieve dynamic search for query request
  • Loading branch information
shubham1g5 authored Nov 10, 2023
2 parents b51bfe9 + e0e60cd commit fbf8145
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
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;

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() {
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);
}

@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

0 comments on commit fbf8145

Please sign in to comment.