Skip to content

Commit fc87d6c

Browse files
committed
Add logging for case type missmatch
1 parent a51950d commit fc87d6c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/java/org/commcare/formplayer/services/CaseSearchHelper.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.ArrayListMultimap;
44
import com.google.common.collect.Multimap;
55

6+
import io.sentry.SentryLevel;
67
import org.apache.commons.logging.Log;
78
import org.apache.commons.logging.LogFactory;
89
import org.commcare.cases.instance.CaseInstanceTreeElement;
@@ -16,6 +17,7 @@
1617
import org.commcare.formplayer.session.MenuSession;
1718
import org.commcare.formplayer.sqlitedb.CaseSearchDB;
1819
import org.commcare.formplayer.sqlitedb.SQLiteDB;
20+
import org.commcare.formplayer.util.FormplayerSentry;
1921
import org.commcare.formplayer.util.SerializationUtil;
2022
import org.commcare.formplayer.web.client.WebClient;
2123
import org.commcare.util.screen.ScreenUtils;
@@ -82,7 +84,10 @@ public AbstractTreeElement getExternalRoot(String instanceId, ExternalDataInstan
8284
throws UnfullfilledRequirementsException, XmlPullParserException, InvalidStructureException,
8385
IOException {
8486

87+
88+
8589
skipCache = true;
90+
// System.out.println("getExternalRoot");
8691

8792
Multimap<String, String> requestData = source.getRequestData();
8893
String url = source.getSourceUri();
@@ -100,6 +105,7 @@ public AbstractTreeElement getExternalRoot(String instanceId, ExternalDataInstan
100105
IStorageUtilityIndexed<Case> caseSearchStorage = caseSearchSandbox.getCaseStorage();
101106
FormplayerCaseIndexTable caseSearchIndexTable = getCaseIndexTable(caseSearchSandbox, caseSearchTableName);
102107
if (skipCache || !caseSearchStorage.isStorageExists()) {
108+
Collection<String> requestCaseTypes = requestData.get("case_type");
103109
String responseString = webClient.postFormData(url, requestData);
104110
if (responseString != null) {
105111
byte[] responseBytes = responseString.getBytes(StandardCharsets.UTF_8);
@@ -112,6 +118,17 @@ public AbstractTreeElement getExternalRoot(String instanceId, ExternalDataInstan
112118
if (root != null) {
113119
cache.put(cacheKey, root);
114120
}
121+
122+
for (int i = 0; i < root.getNumChildren(); i++) {
123+
TreeElement child = root.getChildAt(i);
124+
String attributeValue = child.getAttributeValue(null, "case_type");
125+
126+
if (attributeValue != null && !requestCaseTypes.contains(attributeValue)) {
127+
Exception e = new Exception("Returned case type did not match request. Expected: " + requestCaseTypes.toString() + " Got: " + attributeValue + "\n" +
128+
"Url: " + url + " request data: " + requestData.toString());
129+
FormplayerSentry.captureException(e, SentryLevel.WARNING);
130+
}
131+
}
115132
return root;
116133
}
117134
}

0 commit comments

Comments
 (0)