-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6451 from seadowg/entities-pulldata
Add support for pulldata with local entities
- Loading branch information
Showing
9 changed files
with
342 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
49 changes: 49 additions & 0 deletions
49
entities/src/main/java/org/odk/collect/entities/javarosa/filter/PullDataFunctionHandler.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.odk.collect.entities.javarosa.filter | ||
|
||
import org.javarosa.core.model.condition.EvaluationContext | ||
import org.javarosa.core.model.condition.IFunctionHandler | ||
import org.javarosa.xpath.expr.XPathFuncExpr | ||
import org.odk.collect.entities.javarosa.intance.LocalEntitiesInstanceAdapter | ||
import org.odk.collect.entities.storage.EntitiesRepository | ||
|
||
class PullDataFunctionHandler( | ||
entitiesRepository: EntitiesRepository, | ||
private val fallback: IFunctionHandler? = null | ||
) : IFunctionHandler { | ||
|
||
private val instanceAdapter = LocalEntitiesInstanceAdapter(entitiesRepository) | ||
|
||
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 if (instanceAdapter.supportsInstance(instanceId)) { | ||
instanceAdapter.queryEq(instanceId, filterChild, filterValue)!!.firstOrNull() | ||
?.getFirstChild(child)?.value?.value ?: "" | ||
} else { | ||
fallback?.eval(args, ec) ?: "" | ||
} | ||
} | ||
|
||
companion object { | ||
private const val NAME = "pulldata" | ||
} | ||
} |
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
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
Oops, something went wrong.