From a1881acba9481a612cf03a9328c3e50b7b6d0223 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Fri, 1 Dec 2023 16:41:47 -0800 Subject: [PATCH 01/12] feat: adds groupKey to display element --- .../formplayer/beans/menus/DisplayElement.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java b/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java index 839384d1e..06e941bd8 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java @@ -51,6 +51,9 @@ public class DisplayElement { @Nullable private String requiredMsg; + @Nullable + private String groupKey; + public DisplayElement() { } @@ -68,8 +71,8 @@ public DisplayElement(Action action, EvaluationContext ec) { public DisplayElement(DisplayUnit displayUnit, EvaluationContext ec, String id, @Nullable String input, @Nullable String receive, @Nullable String hidden, @Nullable String value, - @Nullable String[] itemsetChoicesKeys, @Nullable String[] itemsetChoicesLabels, boolean allowBlankValue, boolean required, - String requiredMsg, String error) { + @Nullable String[] itemsetChoicesKeys, @Nullable String[] itemsetChoicesLabels, boolean allowBlankValue, + boolean required, String requiredMsg, String error, @Nullable String groupKey) { this.id = id; this.text = displayUnit.getText().evaluate(ec); if (displayUnit.getImageURI() != null) { @@ -91,6 +94,7 @@ public DisplayElement(DisplayUnit displayUnit, EvaluationContext ec, String id, this.allowBlankValue = allowBlankValue; this.required = required; this.requiredMsg = requiredMsg; + this.groupKey = groupKey; this.error = error; } @@ -187,4 +191,10 @@ public String getError() { public String getRequiredMsg() { return requiredMsg; } + + @JsonGetter(value = "group_key") + @Nullable + public String getGroupKey() { + return groupKey; + } } From ae1b256fa5c3969f5fcf34137b77658c08babfc9 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Mon, 4 Dec 2023 11:39:15 -0800 Subject: [PATCH 02/12] feat: adds groupKey to queryresponse for display element --- .../org/commcare/formplayer/beans/menus/QueryResponseBean.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java index 665104641..fa88aefda 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java @@ -79,7 +79,8 @@ public QueryResponseBean(QueryScreen queryScreen) { queryPromptItem.isAllowBlankValue(), isRequired, requiredMessage, - errors.get(key) + errors.get(key), + queryPromptItem.getGroupKey() ); count++; } From 5b39e818f69c512d98c0bf82886ced0b4a47ac03 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Mon, 4 Dec 2023 18:09:41 -0800 Subject: [PATCH 03/12] feat: adds groupHeader to queryResponse --- .../beans/menus/QueryResponseBean.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java index fa88aefda..dd86a72a0 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java @@ -4,6 +4,7 @@ import org.commcare.modern.util.Pair; import org.commcare.session.RemoteQuerySessionManager; import org.commcare.suite.model.QueryPrompt; +import org.commcare.suite.model.QueryGroup; import org.commcare.util.screen.QueryScreen; import org.javarosa.core.model.condition.EvaluationContext; import org.javarosa.core.model.utils.ItemSetUtils; @@ -14,6 +15,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; +import java.util.Map; /** * Created by willpride on 4/13/16. @@ -23,6 +25,7 @@ public class QueryResponseBean extends MenuBean { private DisplayElement[] displays; private final String type = "query"; private String description; + private OrderedHashtable groupHeader; QueryResponseBean() { } @@ -43,6 +46,10 @@ private void setDisplays(DisplayElement[] displays) { this.displays = displays; } + public OrderedHashtable getGroupHeader(){ + return groupHeader; + } + public QueryResponseBean(QueryScreen queryScreen) { OrderedHashtable queryPromptMap = queryScreen.getUserInputDisplays(); Hashtable currentAnswers = queryScreen.getCurrentAnswers(); @@ -84,6 +91,16 @@ public QueryResponseBean(QueryScreen queryScreen) { ); count++; } + + OrderedHashtable queryGroupMap = queryScreen.getGroupHeaders(); + groupHeader = new OrderedHashtable<>(); + for (Map.Entry entry : queryGroupMap.entrySet()) { + String key = entry.getKey(); + QueryGroup queryGroupItem = entry.getValue(); + String text = queryGroupItem.getDisplay().getText().evaluate(ec); + groupHeader.put(key, text); + } + setTitle(queryScreen.getScreenTitle()); setDescription(queryScreen.getDescriptionText()); setQueryKey(queryScreen.getQueryKey()); From 3120b6c91ce463c4a1a5b0dc46685841bf921b5f Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Mon, 4 Dec 2023 20:41:47 -0800 Subject: [PATCH 04/12] update libs/commcare --- libs/commcare | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/commcare b/libs/commcare index eca503b2f..96ffdfa9a 160000 --- a/libs/commcare +++ b/libs/commcare @@ -1 +1 @@ -Subproject commit eca503b2fc1f70dc0c175959b01efd05908e6434 +Subproject commit 96ffdfa9a934e4244a474589079864c113d68ea1 From 7820a831be77813e3a141d7ddd925ee321e0e10b Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Tue, 5 Dec 2023 09:26:15 -0800 Subject: [PATCH 05/12] style: return in camelcase --- .../org/commcare/formplayer/beans/menus/DisplayElement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java b/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java index 06e941bd8..73b0515c9 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java @@ -192,7 +192,7 @@ public String getRequiredMsg() { return requiredMsg; } - @JsonGetter(value = "group_key") + @JsonGetter(value = "groupKey") @Nullable public String getGroupKey() { return groupKey; From 627513d3ada4bf8bbbffe1459aeecae725bfc14a Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Tue, 5 Dec 2023 10:00:48 -0800 Subject: [PATCH 06/12] style: change response key name --- .../formplayer/beans/menus/QueryResponseBean.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java index dd86a72a0..0e9787190 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java @@ -25,7 +25,7 @@ public class QueryResponseBean extends MenuBean { private DisplayElement[] displays; private final String type = "query"; private String description; - private OrderedHashtable groupHeader; + private OrderedHashtable groupHeaders; QueryResponseBean() { } @@ -46,8 +46,8 @@ private void setDisplays(DisplayElement[] displays) { this.displays = displays; } - public OrderedHashtable getGroupHeader(){ - return groupHeader; + public OrderedHashtable getGroupHeaders(){ + return groupHeaders; } public QueryResponseBean(QueryScreen queryScreen) { @@ -93,12 +93,12 @@ public QueryResponseBean(QueryScreen queryScreen) { } OrderedHashtable queryGroupMap = queryScreen.getGroupHeaders(); - groupHeader = new OrderedHashtable<>(); + groupHeaders = new OrderedHashtable<>(); for (Map.Entry entry : queryGroupMap.entrySet()) { String key = entry.getKey(); QueryGroup queryGroupItem = entry.getValue(); String text = queryGroupItem.getDisplay().getText().evaluate(ec); - groupHeader.put(key, text); + groupHeaders.put(key, text); } setTitle(queryScreen.getScreenTitle()); From 91c766ebcd0024ecb51e24b0ac16bfcbcd2d02fc Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Thu, 7 Dec 2023 16:38:10 -0800 Subject: [PATCH 07/12] test: QueryResponse contains expected groupHeaders and display elements contain correct groupKey --- .../formplayer/tests/CaseClaimTests.java | 21 ++++++++++++++++ .../caseclaim/default/app_strings.txt | 2 ++ .../resources/archives/caseclaim/suite.xml | 24 +++++++++++++++---- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/commcare/formplayer/tests/CaseClaimTests.java b/src/test/java/org/commcare/formplayer/tests/CaseClaimTests.java index 6a7eabfbc..b6c80f1b8 100644 --- a/src/test/java/org/commcare/formplayer/tests/CaseClaimTests.java +++ b/src/test/java/org/commcare/formplayer/tests/CaseClaimTests.java @@ -437,6 +437,27 @@ public void testQueryPromptRequired() throws Exception { assertTrue(queryResponseBean.getDisplays()[4].getRequiredMsg().contentEquals(expectedMessage)); } + @Test + public void testQueryPromptGrouped() throws Exception { + QueryData queryData = new QueryData(); + + QueryResponseBean queryResponseBean = sessionNavigateWithQuery( + new String[]{"1", "action 1"}, + "caseclaim", + queryData, + QueryResponseBean.class); + + String groupKey1 = "group_header_0"; + String groupKey2 = "group_header_3"; + String expectedHeader1 = "Group1 Header"; + String expectedHeader2 = "Group2 Header"; + + assertEquals(queryResponseBean.getGroupHeaders().get(groupKey1), expectedHeader1); + assertEquals(queryResponseBean.getGroupHeaders().get(groupKey2), expectedHeader2); + assertEquals(queryResponseBean.getDisplays()[0].getGroupKey(), groupKey1); + assertEquals(queryResponseBean.getDisplays()[4].getGroupKey(), groupKey2); + } + @Test public void testDependentItemsets_DependentChoicesChangeWithSelection() throws Exception { Hashtable inputs = new Hashtable<>(); diff --git a/src/test/resources/archives/caseclaim/default/app_strings.txt b/src/test/resources/archives/caseclaim/default/app_strings.txt index eed6b88db..828029c75 100644 --- a/src/test/resources/archives/caseclaim/default/app_strings.txt +++ b/src/test/resources/archives/caseclaim/default/app_strings.txt @@ -42,3 +42,5 @@ search_property.m1.age.validation=age should be greater than 18 search_property.m1.age.required=One of age or DOB is required search_property.m1.dob=Date of Birth search_property.m1.dob.required=One of age or DOB is required +search_property.m0.group_header_0=Group1 Header +search_property.m0.group_header_3=Group2 Header diff --git a/src/test/resources/archives/caseclaim/suite.xml b/src/test/resources/archives/caseclaim/suite.xml index 972397bc2..cf977cca4 100644 --- a/src/test/resources/archives/caseclaim/suite.xml +++ b/src/test/resources/archives/caseclaim/suite.xml @@ -371,14 +371,28 @@ - + + + + + + + + + + + + + + + - + @@ -395,7 +409,7 @@ - + @@ -407,7 +421,7 @@ - + @@ -424,7 +438,7 @@ - + From 6ce8417eb81beec2f6545f303f810231b4e719a4 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Thu, 7 Dec 2023 16:39:39 -0800 Subject: [PATCH 08/12] update commcare-core --- libs/commcare | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/commcare b/libs/commcare index 96ffdfa9a..e51a1493b 160000 --- a/libs/commcare +++ b/libs/commcare @@ -1 +1 @@ -Subproject commit 96ffdfa9a934e4244a474589079864c113d68ea1 +Subproject commit e51a1493b85696020fbdc94fabe7c036819624a9 From 1096dc6d6ba589e82b57ec9d8cb8897ff6fa5fa1 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Tue, 12 Dec 2023 13:55:35 -0800 Subject: [PATCH 09/12] refactor: query group is not ordered. It is used by prompt orderedHashtable so depends on that for order --- .../org/commcare/formplayer/beans/menus/QueryResponseBean.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java index 0e9787190..30c3d11d8 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java @@ -92,7 +92,7 @@ public QueryResponseBean(QueryScreen queryScreen) { count++; } - OrderedHashtable queryGroupMap = queryScreen.getGroupHeaders(); + Hashtable queryGroupMap = queryScreen.getGroupHeaders(); groupHeaders = new OrderedHashtable<>(); for (Map.Entry entry : queryGroupMap.entrySet()) { String key = entry.getKey(); From 11d6ed6732f1c192a4c2d7ac19a66aba435f2f64 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Tue, 12 Dec 2023 17:31:10 -0800 Subject: [PATCH 10/12] refactor: extracts logic of evaluation groupHeader --- .../beans/menus/QueryResponseBean.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java index 30c3d11d8..cad313ad6 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/QueryResponseBean.java @@ -25,7 +25,7 @@ public class QueryResponseBean extends MenuBean { private DisplayElement[] displays; private final String type = "query"; private String description; - private OrderedHashtable groupHeaders; + private Hashtable groupHeaders; QueryResponseBean() { } @@ -46,10 +46,14 @@ private void setDisplays(DisplayElement[] displays) { this.displays = displays; } - public OrderedHashtable getGroupHeaders(){ + public Hashtable getGroupHeaders(){ return groupHeaders; } + public void setGroupHeaders(Hashtable groupHeaders){ + this.groupHeaders = groupHeaders; + } + public QueryResponseBean(QueryScreen queryScreen) { OrderedHashtable queryPromptMap = queryScreen.getUserInputDisplays(); Hashtable currentAnswers = queryScreen.getCurrentAnswers(); @@ -92,15 +96,7 @@ public QueryResponseBean(QueryScreen queryScreen) { count++; } - Hashtable queryGroupMap = queryScreen.getGroupHeaders(); - groupHeaders = new OrderedHashtable<>(); - for (Map.Entry entry : queryGroupMap.entrySet()) { - String key = entry.getKey(); - QueryGroup queryGroupItem = entry.getValue(); - String text = queryGroupItem.getDisplay().getText().evaluate(ec); - groupHeaders.put(key, text); - } - + setGroupHeaders(queryScreen.evalGroupHeaders()); setTitle(queryScreen.getScreenTitle()); setDescription(queryScreen.getDescriptionText()); setQueryKey(queryScreen.getQueryKey()); From af803fdfd3eb7c29bdeb8f3640b386f7d343ba23 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Tue, 12 Dec 2023 17:36:28 -0800 Subject: [PATCH 11/12] unneeded as propertt name is default "groupKey" --- .../java/org/commcare/formplayer/beans/menus/DisplayElement.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java b/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java index 73b0515c9..0d001d746 100644 --- a/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java +++ b/src/main/java/org/commcare/formplayer/beans/menus/DisplayElement.java @@ -192,7 +192,6 @@ public String getRequiredMsg() { return requiredMsg; } - @JsonGetter(value = "groupKey") @Nullable public String getGroupKey() { return groupKey; From 519223b3f2c94c7618f3dd914db418c1ec86e622 Mon Sep 17 00:00:00 2001 From: Jonathan Tang Date: Wed, 13 Dec 2023 12:00:43 -0800 Subject: [PATCH 12/12] merge commcare-core --- libs/commcare | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/commcare b/libs/commcare index 4874f31b8..34e5a8170 160000 --- a/libs/commcare +++ b/libs/commcare @@ -1 +1 @@ -Subproject commit 4874f31b865d2d2335eefbb7d02f0a1562ace2d1 +Subproject commit 34e5a8170debe30c231c67448388f5ff0e19838a