Skip to content

Commit 554eb21

Browse files
authored
Merge branch 'master' into commcare_2.54
2 parents f4d0df4 + 68291dd commit 554eb21

File tree

15 files changed

+311
-138
lines changed

15 files changed

+311
-138
lines changed

src/cli/java/org/commcare/util/screen/EntityScreenContext.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Holds essential meta data associated with the entity screen
55
*/
6-
public class EntityScreenContext {
6+
public class EntityScreenContext extends ScreenContext{
77
private final int mOffSet;
88
private final String mSearchText;
99
private final int mSortIndex;
@@ -21,6 +21,7 @@ public class EntityScreenContext {
2121

2222
public EntityScreenContext(int offset, String searchText, int sortIndex, int casesPerPage,
2323
String[] selectedValues, String detailSelection, boolean isFuzzySearch) {
24+
super(true);
2425
mOffSet = offset;
2526
mSearchText = searchText;
2627
mSortIndex = sortIndex;
@@ -31,6 +32,11 @@ public EntityScreenContext(int offset, String searchText, int sortIndex, int cas
3132
}
3233

3334
public EntityScreenContext() {
35+
this(true);
36+
}
37+
38+
public EntityScreenContext(boolean respectRelevancy) {
39+
super(respectRelevancy);
3440
mOffSet = 0;
3541
mSearchText = null;
3642
mSortIndex = 0;

src/cli/java/org/commcare/util/screen/MenuScreen.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ public boolean handleAutoMenuAdvance(SessionWrapper sessionWrapper, boolean resp
5959
return false;
6060
}
6161

62+
/**
63+
* Checks whether a menu with given menuId exists and is a visible option on menu screen
64+
* @param menuId id of the menu we want to check visiblility for
65+
* @return true if menu exists and is visible, false otherwise
66+
*/
67+
public boolean isMenuVisible(String menuId) {
68+
for (MenuDisplayable menuDisplayable : getMenuDisplayables()) {
69+
if(menuDisplayable.getCommandID().contentEquals(menuId)){
70+
return true;
71+
}
72+
}
73+
return false;
74+
}
75+
6276
class ScreenLogger implements LoggerInterface {
6377

6478
@Override
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.commcare.util.screen;
2+
public class ScreenContext {
3+
4+
private boolean respectRelevancy;
5+
6+
public ScreenContext(boolean respectRelevancy) {
7+
this.respectRelevancy = respectRelevancy;
8+
}
9+
10+
public boolean isRespectRelevancy() {
11+
return respectRelevancy;
12+
}
13+
}

src/main/java/org/commcare/core/interfaces/HttpResponseProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface HttpResponseProcessor {
1212
/**
1313
* Http response was in the 200s
1414
*/
15-
void processSuccess(int responseCode, InputStream responseData);
15+
void processSuccess(int responseCode, InputStream responseData, String apiVersion);
1616

1717
/**
1818
* Http response was in the 400s.

src/main/java/org/commcare/core/interfaces/ResponseStreamAccessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
public interface ResponseStreamAccessor {
77
InputStream getResponseStream() throws IOException;
8+
String getApiVersion();
89
}

src/main/java/org/commcare/core/network/ModernHttpRequester.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*
3434
* @author Phillip Mates ([email protected])
3535
*/
36-
public class ModernHttpRequester implements ResponseStreamAccessor {
36+
public class ModernHttpRequester {
3737
/**
3838
* How long to wait when opening network connection in milliseconds
3939
*/
@@ -87,7 +87,23 @@ public void makeRequestAndProcess() {
8787
}
8888
try {
8989
response = makeRequest();
90-
processResponse(responseProcessor, response.code(), this);
90+
final ModernHttpRequester requester = this;
91+
processResponse(responseProcessor, response.code(), new ResponseStreamAccessor() {
92+
/**
93+
* Only gets called if response processor is supplied
94+
* @return Input Stream from cache
95+
* @throws IOException if an io error happens while reading or writing to cache
96+
*/
97+
@Override
98+
public InputStream getResponseStream() throws IOException {
99+
return requester.getResponseStream(response);
100+
}
101+
102+
@Override
103+
public String getApiVersion() {
104+
return requester.getApiVersion();
105+
}
106+
});
91107
} catch (IOException e) {
92108
e.printStackTrace();
93109
responseProcessor.handleIOException(e);
@@ -153,7 +169,8 @@ public static void processResponse(HttpResponseProcessor responseProcessor,
153169
responseProcessor.handleIOException(e);
154170
return;
155171
}
156-
responseProcessor.processSuccess(responseCode, responseStream);
172+
String apiVersion = streamAccessor.getApiVersion();
173+
responseProcessor.processSuccess(responseCode, responseStream, apiVersion);
157174
} finally {
158175
StreamsUtil.closeStream(responseStream);
159176
}
@@ -181,14 +198,8 @@ public InputStream getResponseStream(Response<ResponseBody> response) throws IOE
181198
return cache.retrieveCache();
182199
}
183200

184-
/**
185-
* Only gets called if response processor is supplied
186-
* @return Input Stream from cache
187-
* @throws IOException if an io error happens while reading or writing to cache
188-
*/
189-
@Override
190-
public InputStream getResponseStream() throws IOException {
191-
return getResponseStream(response);
201+
public String getApiVersion() {
202+
return response != null ? response.headers().get("x-api-current-version") : null;
192203
}
193204

194205
public static RequestBody getPostBody(Multimap<String, String> inputs) {

src/main/java/org/javarosa/core/model/FormDef.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import java.util.Hashtable;
5656
import java.util.Iterator;
5757
import java.util.List;
58-
import java.util.Map;
5958
import java.util.NoSuchElementException;
6059
import java.util.Vector;
6160

@@ -1855,4 +1854,13 @@ public String dispatchSendCallout(String url, Multimap<String, String> paramMap)
18551854
return sendCalloutHandler.performHttpCalloutForResponse(url, paramMap);
18561855
}
18571856
}
1857+
1858+
// Checks if the form element at given form Index belongs to a non counted repeat
1859+
public boolean isNonCountedRepeat(FormIndex formIndex) {
1860+
IFormElement currentElement = getChild(formIndex);
1861+
if (currentElement instanceof GroupDef && ((GroupDef)currentElement).isRepeat()) {
1862+
return ((GroupDef)currentElement).getCountReference() == null;
1863+
}
1864+
return false;
1865+
}
18581866
}

src/main/java/org/javarosa/form/api/FormEntryCaption.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.javarosa.form.api;
22

3+
import org.commcare.cases.util.StringUtils;
34
import org.javarosa.core.model.FormDef;
45
import org.javarosa.core.model.FormIndex;
56
import org.javarosa.core.model.GroupDef;
67
import org.javarosa.core.model.IFormElement;
8+
import org.javarosa.core.services.locale.Localization;
79
import org.javarosa.core.services.locale.Localizer;
810

911
import java.util.Hashtable;
@@ -217,43 +219,45 @@ public String getRepeatText(String typeKey) {
217219

218220
String caption = null;
219221
if ("mainheader".equals(typeKey)) {
220-
caption = g.mainHeader;
222+
caption = getCaptionText(g.mainHeader);
221223
if (caption == null) {
222224
return title;
223225
}
224226
} else if ("add".equals(typeKey)) {
225-
caption = g.addCaption;
227+
caption = getCaptionText(g.addCaption);
226228
if (caption == null) {
227-
return "Add another " + title;
229+
return Localization.getWithDefault("repeat.dialog.add.another", new String[]{title},
230+
"Add another " + title);
228231
}
229232
} else if ("add-empty".equals(typeKey)) {
230-
caption = g.addEmptyCaption;
233+
caption = getCaptionText(g.addEmptyCaption);
231234
if (caption == null) {
232-
caption = g.addCaption;
235+
caption = getCaptionText(g.addCaption);
233236
}
234237
if (caption == null) {
235-
return "None - Add " + title;
238+
return Localization.getWithDefault("repeat.dialog.add.new", new String[]{title},
239+
"Add a new " + title);
236240
}
237241
} else if ("del".equals(typeKey)) {
238-
caption = g.delCaption;
242+
caption = getCaptionText(g.delCaption);
239243
if (caption == null) {
240244
return "Delete " + title;
241245
}
242246
} else if ("done".equals(typeKey)) {
243-
caption = g.doneCaption;
247+
caption = getCaptionText(g.doneCaption);
244248
if (caption == null) {
245249
return "Done";
246250
}
247251
} else if ("done-empty".equals(typeKey)) {
248-
caption = g.doneEmptyCaption;
252+
caption = getCaptionText(g.doneEmptyCaption);
249253
if (caption == null) {
250254
caption = g.doneCaption;
251255
}
252256
if (caption == null) {
253257
return "Skip";
254258
}
255259
} else if ("delheader".equals(typeKey)) {
256-
caption = g.delHeader;
260+
caption = getCaptionText(g.delHeader);
257261
if (caption == null) {
258262
return "Delete which " + title + "?";
259263
}
@@ -265,6 +269,16 @@ public String getRepeatText(String typeKey) {
265269
return form.fillTemplateString(caption, index.getReference(), vars);
266270
}
267271

272+
private String getCaptionText(String textIdOrText) {
273+
if (!StringUtils.isEmpty(textIdOrText)) {
274+
String returnText = getIText(textIdOrText, null);
275+
if (returnText != null) {
276+
return substituteStringArgs(returnText);
277+
}
278+
}
279+
return substituteStringArgs(textIdOrText);
280+
}
281+
268282
//this should probably be somewhere better
269283
public int getNumRepetitions() {
270284
return form.getNumRepetitions(index);
@@ -284,11 +298,11 @@ private String getRepetitionText(String type, FormIndex index, boolean newrep) {
284298

285299
String caption = null;
286300
if ("header".equals(type)) {
287-
caption = g.entryHeader;
301+
caption = getCaptionText(g.entryHeader);
288302
} else if ("choose".equals(type)) {
289-
caption = g.chooseCaption;
303+
caption = getCaptionText(g.chooseCaption);
290304
if (caption == null) {
291-
caption = g.entryHeader;
305+
caption = getCaptionText(g.entryHeader);
292306
}
293307
}
294308
if (caption == null) {

src/main/java/org/javarosa/form/api/FormEntryModel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,8 @@ public String getDebugInfo(FormIndex index, String category) {
625625
return TraceSerialization.serializeEvaluationTrace(indexDebug.get(category),
626626
TraceSerialization.TraceInfoType.FULL_PROFILE, false);
627627
}
628+
629+
public boolean isNonCountedRepeat() {
630+
return getForm().isNonCountedRepeat(getFormIndex());
631+
}
628632
}

src/main/java/org/javarosa/xform/parse/XFormParser.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.javarosa.xform.parse;
22

3+
import org.commcare.cases.util.StringUtils;
34
import org.javarosa.core.model.Constants;
45
import org.javarosa.core.model.DataBinding;
56
import org.javarosa.core.model.FormDef;
@@ -1082,27 +1083,38 @@ private void parseGroupLabel(GroupDef g, Element e) {
10821083
Vector<String> usedAtts = new Vector<>();
10831084
usedAtts.addElement(REF_ATTR);
10841085

1086+
String labelItextId = getItextReference(e);
1087+
g.setTextID(labelItextId);
1088+
if (labelItextId == null) {
1089+
String label = getLabel(e);
1090+
g.setLabelInnerText(label);
1091+
}
10851092

1086-
String label = getLabel(e);
1087-
String ref = e.getAttributeValue("", REF_ATTR);
1093+
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
1094+
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
1095+
}
1096+
}
10881097

1098+
private String getItextReference(Element e) {
1099+
String ref = e.getAttributeValue("", REF_ATTR);
10891100
if (ref != null) {
10901101
if (ref.startsWith(ITEXT_OPEN) && ref.endsWith(ITEXT_CLOSE)) {
10911102
String textRef = ref.substring(ITEXT_OPEN.length(), ref.indexOf(ITEXT_CLOSE));
1092-
10931103
verifyTextMappings(textRef, "Group <label>", true);
1094-
g.setTextID(textRef);
1104+
return textRef;
10951105
} else {
1096-
throw new RuntimeException("malformed ref [" + ref + "] for <label>");
1106+
throw new XFormParseException("malformed ref [" + ref + "] for <label>");
10971107
}
1098-
} else {
1099-
g.setLabelInnerText(label);
11001108
}
1109+
return null;
1110+
}
11011111

1102-
1103-
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
1104-
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
1112+
private String getLabelOrTextId(Element element) {
1113+
String labelItextId = getItextReference(element);
1114+
if (!StringUtils.isEmpty(labelItextId)) {
1115+
return labelItextId;
11051116
}
1117+
return getLabel(element);
11061118
}
11071119

11081120
private String getLabel(Element e) {
@@ -1475,23 +1487,23 @@ private void parseGroup(IFormElement parent, Element e, int groupType) {
14751487

14761488
if (group.isRepeat() && NAMESPACE_JAVAROSA.equals(childNamespace)) {
14771489
if ("chooseCaption".equals(childName)) {
1478-
group.chooseCaption = getLabel(child);
1490+
group.chooseCaption = getLabelOrTextId(child);
14791491
} else if ("addCaption".equals(childName)) {
1480-
group.addCaption = getLabel(child);
1492+
group.addCaption = getLabelOrTextId(child);
14811493
} else if ("delCaption".equals(childName)) {
1482-
group.delCaption = getLabel(child);
1494+
group.delCaption = getLabelOrTextId(child);
14831495
} else if ("doneCaption".equals(childName)) {
1484-
group.doneCaption = getLabel(child);
1496+
group.doneCaption = getLabelOrTextId(child);
14851497
} else if ("addEmptyCaption".equals(childName)) {
1486-
group.addEmptyCaption = getLabel(child);
1498+
group.addEmptyCaption = getLabelOrTextId(child);
14871499
} else if ("doneEmptyCaption".equals(childName)) {
1488-
group.doneEmptyCaption = getLabel(child);
1500+
group.doneEmptyCaption = getLabelOrTextId(child);
14891501
} else if ("entryHeader".equals(childName)) {
1490-
group.entryHeader = getLabel(child);
1502+
group.entryHeader = getLabelOrTextId(child);
14911503
} else if ("delHeader".equals(childName)) {
1492-
group.delHeader = getLabel(child);
1504+
group.delHeader = getLabelOrTextId(child);
14931505
} else if ("mainHeader".equals(childName)) {
1494-
group.mainHeader = getLabel(child);
1506+
group.mainHeader = getLabelOrTextId(child);
14951507
}
14961508
}
14971509
}
@@ -1512,6 +1524,7 @@ private void parseGroup(IFormElement parent, Element e, int groupType) {
15121524
parent.addChild(group);
15131525
}
15141526

1527+
15151528
private TreeReference getFormElementRef(IFormElement fe) {
15161529
if (fe instanceof FormDef) {
15171530
TreeReference ref = TreeReference.rootRef();

0 commit comments

Comments
 (0)