Created
March 13, 2019 14:17
-
-
Save afranzi/4f4d17e2072f3e03a0a951cfd36893e8 to your computer and use it in GitHub Desktop.
Evolve json events using JSLT expressions
This file contains hidden or 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
def evolve(event: ValidationResult[JsonNode]): EvolutionResult[JsonNode] = { | |
val schemasReferenced: Seq[SchemaReferenced] = event.schemasReferenced | |
val json = event.event | |
val schemasToEvolve = schemasReferenced | |
.filter { case SchemaReferenced(_, schemaRef) => hasEvolution(schemaRef) } | |
val eventEvolved = schemasToEvolve | |
.foldLeft(json) { | |
case (jsonEvent: JsonNode, SchemaReferenced(location, schemaRef)) => | |
val evolutionExpr = buildEvolutionExpr(location, schemaRef) | |
val expr: Expression = Parser.compileString(evolutionExpr) | |
expr(jsonEvent) | |
} | |
EvolutionResult( | |
event = json, | |
evolved = eventEvolved, | |
schemasReferenced = schemasReferenced, | |
schemasEvolved = schemasToEvolve | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment