I have two maps that can be modified by different authors. In this particular use case, I have a limitation where I shouldn't use POJOs or Domain objects, only a Maps.
@Test
fun `Shadow from a map`() {
val javers = JaversBuilder.javers().build()
val exercise = mutableMapOf("_id" to "1", "title" to "my exercise", "starred" to false)
javers.commit("bob", exercise)
exercise["starred"] = true
javers.commit("bob", exercise)
exercise["title"] = "my great exercise"
exercise["starred"] = true
javers.commit("alice", exercise)
val training = mutableMapOf("_id" to "2", "title" to "my training")
javers.commit("alice", training)
training["title"] = "my great training"
javers.commit("jack", training)
val query: JqlQuery = QueryBuilder.byInstance(exercise).build()
val shadows: List<Shadow<Map<*,*>>> = javers.findShadows(query)
assertThat(shadows.size, `is`(3))
}
The test execution displays the following error:
MALFORMED_JQL: Invalid JQL query, object passed to byInstance(Object) query should be instance of Entity or ValueObject, got MapType{ baseType: 'class java.util.LinkedHashMap' } - '{_id=1, title=my great exercise, starred=true}'.
Did you mean byInstanceId(Object localId, Class entityClass)?
JaversException MALFORMED_JQL: Invalid JQL query, object passed to byInstance(Object) query should be instance of Entity or ValueObject, got MapType{ baseType: 'class java.util.LinkedHashMap' } - '{_id=1, title=my great exercise, starred=true}'.
Did you mean byInstanceId(Object localId, Class entityClass)?
at org.javers.repository.jql.FilterDefinition$InstanceFilterDefinition.compile(FilterDefinition.java:91)
at org.javers.repository.jql.JqlQuery.compile(JqlQuery.java:129)
at org.javers.repository.jql.QueryCompiler.compile(QueryCompiler.java:19)
at org.javers.repository.jql.ShadowStreamQueryRunner$StreamQuery.<init>(ShadowStreamQueryRunner.java:59)
at org.javers.repository.jql.ShadowStreamQueryRunner.queryForShadowsStream(ShadowStreamQueryRunner.java:34)
at org.javers.repository.jql.QueryRunner.queryForShadowsStream(QueryRunner.java:32)
at org.javers.core.JaversCore.findShadowsAndStream(JaversCore.java:194)
at org.javers.core.JaversCore.findShadows(JaversCore.java:188)
How should I build the JqlQuery to find the shadows?
You can compare two top level Maps but you cant commit a map to Javers Repository (exception should be thrown) because Maps have no identifiers.