Skip to content

Commit

Permalink
Dirty hack for enabling the usage of mongoDB Index2d
Browse files Browse the repository at this point in the history
If one type contains properties named lon and lat, reorder properties to have these two at the top.
For performing filtering on geo coordinates in Documents of the mongoDB (e.g. operation geoWithin), the Json
document containing the coordinates must have the longitude/X coordinate as first property and the latitude/Y
coordinate as second property (property names are irrelevant!).
But as JsonSlurper reorders the properties in alphabetic sequence, we can not force the necessary
longitude / latitude sequence by defining it in the model json.
Therefore this code tests for the existence of the properties lon and lat. If both are present,
then the properties are reordered so that lon and lat come first!
  • Loading branch information
SpeedsterF2 committed Aug 14, 2018
1 parent 0cc672c commit e9be23f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/groovy/de/lisaplus/atlas/builder/JsonSchemaBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ class JsonSchemaBuilder implements IModelBuilder {
propertyParent.properties.each { propObj ->
propList.add(creeateSimpleProperty(model, parentName,currentSchemaPath,propObj))
}
// Dirty hack for enabling the usage of mongoDB Index2d:
// For performing filtering on geo coordinates in Documents of the mongoDB (e.g. operation geoWithin), the Json
// document containing the coordinates must have the longitude/X coordinate as first property and the latitude/Y
// coordinate as second property (property names are irrelevant!).
// But as JsonSlurper reorders the properties in alphabetic sequence, we can not force the necessary
// longitude / latitude sequence by defining it in the model json.
// Therefore this code tests for the existence of the properties lon and lat. If both are present,
// then the properties are reordered so that lon and lat come first!
Property lonProp = propList.find {prop -> prop.name == 'lon'}
Property latProp = propList.find {prop -> prop.name == 'lat'}
if (lonProp && latProp) {
propList.remove(lonProp)
propList.remove(latProp)
propList.add(0, latProp)
propList.add(0, lonProp)
}
return propList
}

Expand Down

0 comments on commit e9be23f

Please sign in to comment.