33import com .google .common .collect .ArrayListMultimap ;
44import com .google .common .collect .Multimap ;
55
6+ import io .sentry .SentryLevel ;
67import org .apache .commons .logging .Log ;
78import org .apache .commons .logging .LogFactory ;
89import org .commcare .cases .instance .CaseInstanceTreeElement ;
1617import org .commcare .formplayer .session .MenuSession ;
1718import org .commcare .formplayer .sqlitedb .CaseSearchDB ;
1819import org .commcare .formplayer .sqlitedb .SQLiteDB ;
20+ import org .commcare .formplayer .util .FormplayerSentry ;
1921import org .commcare .formplayer .util .SerializationUtil ;
2022import org .commcare .formplayer .web .client .WebClient ;
2123import 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