Skip to content

Commit

Permalink
Merge branch 'master' into commcare_2.54
Browse files Browse the repository at this point in the history
  • Loading branch information
avazirna authored Aug 23, 2024
2 parents f4d0df4 + 68291dd commit 554eb21
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Holds essential meta data associated with the entity screen
*/
public class EntityScreenContext {
public class EntityScreenContext extends ScreenContext{
private final int mOffSet;
private final String mSearchText;
private final int mSortIndex;
Expand All @@ -21,6 +21,7 @@ public class EntityScreenContext {

public EntityScreenContext(int offset, String searchText, int sortIndex, int casesPerPage,
String[] selectedValues, String detailSelection, boolean isFuzzySearch) {
super(true);
mOffSet = offset;
mSearchText = searchText;
mSortIndex = sortIndex;
Expand All @@ -31,6 +32,11 @@ public EntityScreenContext(int offset, String searchText, int sortIndex, int cas
}

public EntityScreenContext() {
this(true);
}

public EntityScreenContext(boolean respectRelevancy) {
super(respectRelevancy);
mOffSet = 0;
mSearchText = null;
mSortIndex = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/cli/java/org/commcare/util/screen/MenuScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public boolean handleAutoMenuAdvance(SessionWrapper sessionWrapper, boolean resp
return false;
}

/**
* Checks whether a menu with given menuId exists and is a visible option on menu screen
* @param menuId id of the menu we want to check visiblility for
* @return true if menu exists and is visible, false otherwise
*/
public boolean isMenuVisible(String menuId) {
for (MenuDisplayable menuDisplayable : getMenuDisplayables()) {
if(menuDisplayable.getCommandID().contentEquals(menuId)){
return true;
}
}
return false;
}

class ScreenLogger implements LoggerInterface {

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/cli/java/org/commcare/util/screen/ScreenContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.commcare.util.screen;
public class ScreenContext {

private boolean respectRelevancy;

public ScreenContext(boolean respectRelevancy) {
this.respectRelevancy = respectRelevancy;
}

public boolean isRespectRelevancy() {
return respectRelevancy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface HttpResponseProcessor {
/**
* Http response was in the 200s
*/
void processSuccess(int responseCode, InputStream responseData);
void processSuccess(int responseCode, InputStream responseData, String apiVersion);

/**
* Http response was in the 400s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

public interface ResponseStreamAccessor {
InputStream getResponseStream() throws IOException;
String getApiVersion();
}
33 changes: 22 additions & 11 deletions src/main/java/org/commcare/core/network/ModernHttpRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @author Phillip Mates ([email protected])
*/
public class ModernHttpRequester implements ResponseStreamAccessor {
public class ModernHttpRequester {
/**
* How long to wait when opening network connection in milliseconds
*/
Expand Down Expand Up @@ -87,7 +87,23 @@ public void makeRequestAndProcess() {
}
try {
response = makeRequest();
processResponse(responseProcessor, response.code(), this);
final ModernHttpRequester requester = this;
processResponse(responseProcessor, response.code(), new ResponseStreamAccessor() {
/**
* Only gets called if response processor is supplied
* @return Input Stream from cache
* @throws IOException if an io error happens while reading or writing to cache
*/
@Override
public InputStream getResponseStream() throws IOException {
return requester.getResponseStream(response);
}

@Override
public String getApiVersion() {
return requester.getApiVersion();
}
});
} catch (IOException e) {
e.printStackTrace();
responseProcessor.handleIOException(e);
Expand Down Expand Up @@ -153,7 +169,8 @@ public static void processResponse(HttpResponseProcessor responseProcessor,
responseProcessor.handleIOException(e);
return;
}
responseProcessor.processSuccess(responseCode, responseStream);
String apiVersion = streamAccessor.getApiVersion();
responseProcessor.processSuccess(responseCode, responseStream, apiVersion);
} finally {
StreamsUtil.closeStream(responseStream);
}
Expand Down Expand Up @@ -181,14 +198,8 @@ public InputStream getResponseStream(Response<ResponseBody> response) throws IOE
return cache.retrieveCache();
}

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

public static RequestBody getPostBody(Multimap<String, String> inputs) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/javarosa/core/model/FormDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Vector;

Expand Down Expand Up @@ -1855,4 +1854,13 @@ public String dispatchSendCallout(String url, Multimap<String, String> paramMap)
return sendCalloutHandler.performHttpCalloutForResponse(url, paramMap);
}
}

// Checks if the form element at given form Index belongs to a non counted repeat
public boolean isNonCountedRepeat(FormIndex formIndex) {
IFormElement currentElement = getChild(formIndex);
if (currentElement instanceof GroupDef && ((GroupDef)currentElement).isRepeat()) {
return ((GroupDef)currentElement).getCountReference() == null;
}
return false;
}
}
40 changes: 27 additions & 13 deletions src/main/java/org/javarosa/form/api/FormEntryCaption.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.javarosa.form.api;

import org.commcare.cases.util.StringUtils;
import org.javarosa.core.model.FormDef;
import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.GroupDef;
import org.javarosa.core.model.IFormElement;
import org.javarosa.core.services.locale.Localization;
import org.javarosa.core.services.locale.Localizer;

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

String caption = null;
if ("mainheader".equals(typeKey)) {
caption = g.mainHeader;
caption = getCaptionText(g.mainHeader);
if (caption == null) {
return title;
}
} else if ("add".equals(typeKey)) {
caption = g.addCaption;
caption = getCaptionText(g.addCaption);
if (caption == null) {
return "Add another " + title;
return Localization.getWithDefault("repeat.dialog.add.another", new String[]{title},
"Add another " + title);
}
} else if ("add-empty".equals(typeKey)) {
caption = g.addEmptyCaption;
caption = getCaptionText(g.addEmptyCaption);
if (caption == null) {
caption = g.addCaption;
caption = getCaptionText(g.addCaption);
}
if (caption == null) {
return "None - Add " + title;
return Localization.getWithDefault("repeat.dialog.add.new", new String[]{title},
"Add a new " + title);
}
} else if ("del".equals(typeKey)) {
caption = g.delCaption;
caption = getCaptionText(g.delCaption);
if (caption == null) {
return "Delete " + title;
}
} else if ("done".equals(typeKey)) {
caption = g.doneCaption;
caption = getCaptionText(g.doneCaption);
if (caption == null) {
return "Done";
}
} else if ("done-empty".equals(typeKey)) {
caption = g.doneEmptyCaption;
caption = getCaptionText(g.doneEmptyCaption);
if (caption == null) {
caption = g.doneCaption;
}
if (caption == null) {
return "Skip";
}
} else if ("delheader".equals(typeKey)) {
caption = g.delHeader;
caption = getCaptionText(g.delHeader);
if (caption == null) {
return "Delete which " + title + "?";
}
Expand All @@ -265,6 +269,16 @@ public String getRepeatText(String typeKey) {
return form.fillTemplateString(caption, index.getReference(), vars);
}

private String getCaptionText(String textIdOrText) {
if (!StringUtils.isEmpty(textIdOrText)) {
String returnText = getIText(textIdOrText, null);
if (returnText != null) {
return substituteStringArgs(returnText);
}
}
return substituteStringArgs(textIdOrText);
}

//this should probably be somewhere better
public int getNumRepetitions() {
return form.getNumRepetitions(index);
Expand All @@ -284,11 +298,11 @@ private String getRepetitionText(String type, FormIndex index, boolean newrep) {

String caption = null;
if ("header".equals(type)) {
caption = g.entryHeader;
caption = getCaptionText(g.entryHeader);
} else if ("choose".equals(type)) {
caption = g.chooseCaption;
caption = getCaptionText(g.chooseCaption);
if (caption == null) {
caption = g.entryHeader;
caption = getCaptionText(g.entryHeader);
}
}
if (caption == null) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/javarosa/form/api/FormEntryModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,8 @@ public String getDebugInfo(FormIndex index, String category) {
return TraceSerialization.serializeEvaluationTrace(indexDebug.get(category),
TraceSerialization.TraceInfoType.FULL_PROFILE, false);
}

public boolean isNonCountedRepeat() {
return getForm().isNonCountedRepeat(getFormIndex());
}
}
51 changes: 32 additions & 19 deletions src/main/java/org/javarosa/xform/parse/XFormParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.javarosa.xform.parse;

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

String labelItextId = getItextReference(e);
g.setTextID(labelItextId);
if (labelItextId == null) {
String label = getLabel(e);
g.setLabelInnerText(label);
}

String label = getLabel(e);
String ref = e.getAttributeValue("", REF_ATTR);
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}

private String getItextReference(Element e) {
String ref = e.getAttributeValue("", REF_ATTR);
if (ref != null) {
if (ref.startsWith(ITEXT_OPEN) && ref.endsWith(ITEXT_CLOSE)) {
String textRef = ref.substring(ITEXT_OPEN.length(), ref.indexOf(ITEXT_CLOSE));

verifyTextMappings(textRef, "Group <label>", true);
g.setTextID(textRef);
return textRef;
} else {
throw new RuntimeException("malformed ref [" + ref + "] for <label>");
throw new XFormParseException("malformed ref [" + ref + "] for <label>");
}
} else {
g.setLabelInnerText(label);
}
return null;
}


if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
private String getLabelOrTextId(Element element) {
String labelItextId = getItextReference(element);
if (!StringUtils.isEmpty(labelItextId)) {
return labelItextId;
}
return getLabel(element);
}

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

if (group.isRepeat() && NAMESPACE_JAVAROSA.equals(childNamespace)) {
if ("chooseCaption".equals(childName)) {
group.chooseCaption = getLabel(child);
group.chooseCaption = getLabelOrTextId(child);
} else if ("addCaption".equals(childName)) {
group.addCaption = getLabel(child);
group.addCaption = getLabelOrTextId(child);
} else if ("delCaption".equals(childName)) {
group.delCaption = getLabel(child);
group.delCaption = getLabelOrTextId(child);
} else if ("doneCaption".equals(childName)) {
group.doneCaption = getLabel(child);
group.doneCaption = getLabelOrTextId(child);
} else if ("addEmptyCaption".equals(childName)) {
group.addEmptyCaption = getLabel(child);
group.addEmptyCaption = getLabelOrTextId(child);
} else if ("doneEmptyCaption".equals(childName)) {
group.doneEmptyCaption = getLabel(child);
group.doneEmptyCaption = getLabelOrTextId(child);
} else if ("entryHeader".equals(childName)) {
group.entryHeader = getLabel(child);
group.entryHeader = getLabelOrTextId(child);
} else if ("delHeader".equals(childName)) {
group.delHeader = getLabel(child);
group.delHeader = getLabelOrTextId(child);
} else if ("mainHeader".equals(childName)) {
group.mainHeader = getLabel(child);
group.mainHeader = getLabelOrTextId(child);
}
}
}
Expand All @@ -1512,6 +1524,7 @@ private void parseGroup(IFormElement parent, Element e, int groupType) {
parent.addChild(group);
}


private TreeReference getFormElementRef(IFormElement fe) {
if (fe instanceof FormDef) {
TreeReference ref = TreeReference.rootRef();
Expand Down
Loading

0 comments on commit 554eb21

Please sign in to comment.