Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack query datum Support for Session Endpoints #1328

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/org/commcare/suite/model/StackFrameStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ public StackFrameStep defineStep(EvaluationContext ec, SessionDatum neededDatum)
case SessionFrame.STATE_SMART_LINK:
StackFrameStep defined = new StackFrameStep(elementType, id, evaluateValue(ec));
extras.forEach((key, value) -> {
XPathExpression expr = (XPathExpression) value;
defined.addExtra(key, FunctionUtils.toString(expr.eval(ec)));
if (value instanceof QueryData) {
defined.addExtra(key, ((QueryData)value).getValues(ec));
} else {
throw new RuntimeException("Invalid data type for step extra " + key);
}
});
return defined;
default:
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/commcare/xml/StackFrameStepParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.commcare.xml;

import org.commcare.session.SessionFrame;
import org.commcare.suite.model.QueryData;
import org.commcare.suite.model.StackFrameStep;
import org.javarosa.xml.ElementParser;
import org.javarosa.xml.util.InvalidStructureException;
Expand Down Expand Up @@ -62,14 +63,8 @@ private StackFrameStep parseQuery() throws InvalidStructureException, IOExceptio
while (nextTagInBlock("query")) {
String tagName = parser.getName();
if ("data".equals(tagName)) {
String key = parser.getAttributeValue(null, "key");
String ref = parser.getAttributeValue(null, "ref");
try {
step.addExtra(key, XPathParseTool.parseXPath(ref));
} catch (XPathSyntaxException e) {
String errorMessage = "'ref' value is not a valid xpath expression: " + ref;
throw new InvalidStructureException(errorMessage, this.parser);
}
QueryData queryData = new QueryDataParser(parser).parse();
step.addExtra(queryData.getKey(), queryData);
}
}
return step;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.commcare.backend.suite.model.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;

import org.cli.MockSessionUtils;
Expand All @@ -20,11 +26,6 @@
import java.io.InputStream;
import java.util.Vector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
* Created by amstone326 on 8/7/15.
*/
Expand Down Expand Up @@ -180,11 +181,11 @@ public void stackWithQueries() throws Exception {
StackFrameStep queryFrame = steps.get(2);
assertEquals(SessionFrame.STATE_QUERY_REQUEST, queryFrame.getElementType());

ImmutableMultimap.Builder<String, Object> builder = ImmutableMultimap.builder();
builder.put("case_type", "patient");
builder.put("x_commcare_data_registry", "test");
builder.put("case_id", "case_one");
builder.put("case_id", "dupe1");
ImmutableMultimap.Builder<String, ImmutableList> builder = ImmutableMultimap.builder();
builder.put("case_type", ImmutableList.of("patient"));
builder.put("x_commcare_data_registry", ImmutableList.of("test"));
builder.put("case_id", ImmutableList.of("case_one"));
builder.put("case_id", ImmutableList.of("dupe1"));
assertEquals(builder.build(), queryFrame.getExtras());
}
}