-
-
Save seadowg/3425771d3f8eb081d57bdd2b6a9ae68e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.javarosa.core.model.condition.EvaluationContext | |
import org.javarosa.core.model.condition.IFunctionHandler | |
import org.javarosa.xpath.XPathParseTool | |
import org.javarosa.xpath.expr.XPathExpression | |
import org.javarosa.xpath.expr.XPathFuncExpr | |
class PullDataFunctionHandler : IFunctionHandler { | |
override fun getName(): String { | |
return NAME | |
} | |
override fun getPrototypes(): List<Array<Class<Any>>> { | |
return emptyList() | |
} | |
override fun rawArgs(): Boolean { | |
return true | |
} | |
override fun realTime(): Boolean { | |
return false | |
} | |
override fun eval(args: Array<Any>, ec: EvaluationContext): Any { | |
val instanceId = XPathFuncExpr.toString(args[0]) | |
val child = XPathFuncExpr.toString(args[1]) | |
val filterChild = XPathFuncExpr.toString(args[2]) | |
val filterValue = XPathFuncExpr.toString(args[3]) | |
return createExpression(instanceId, child, filterChild, filterValue).eval(ec) | |
} | |
private fun createExpression( | |
instanceId: String, | |
child: String, | |
filterChild: String, | |
filterValue: String | |
): XPathExpression { | |
return XPathParseTool.parseXPath( | |
"instance('$instanceId')/root/item[$filterChild='$filterValue'][position() = 1]/$child" | |
) | |
} | |
companion object { | |
private const val NAME = "pulldata" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment