diff --git a/src/main/java/org/commcare/suite/model/StackFrameStep.java b/src/main/java/org/commcare/suite/model/StackFrameStep.java index 6258e2ffe..730cd86b8 100644 --- a/src/main/java/org/commcare/suite/model/StackFrameStep.java +++ b/src/main/java/org/commcare/suite/model/StackFrameStep.java @@ -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: diff --git a/src/main/java/org/commcare/xml/StackFrameStepParser.java b/src/main/java/org/commcare/xml/StackFrameStepParser.java index 2252c40a5..e310aca99 100644 --- a/src/main/java/org/commcare/xml/StackFrameStepParser.java +++ b/src/main/java/org/commcare/xml/StackFrameStepParser.java @@ -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; @@ -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; diff --git a/src/test/java/org/commcare/backend/suite/model/test/StackFrameStepTests.java b/src/test/java/org/commcare/backend/suite/model/test/StackFrameStepTests.java index 8e172c0c5..ac33963b0 100644 --- a/src/test/java/org/commcare/backend/suite/model/test/StackFrameStepTests.java +++ b/src/test/java/org/commcare/backend/suite/model/test/StackFrameStepTests.java @@ -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; @@ -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. */ @@ -180,11 +181,11 @@ public void stackWithQueries() throws Exception { StackFrameStep queryFrame = steps.get(2); assertEquals(SessionFrame.STATE_QUERY_REQUEST, queryFrame.getElementType()); - ImmutableMultimap.Builder 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 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()); } }