use of com.enonic.xp.util.GeoPoint in project xp by enonic.
the class PropertyTreeMapperTest method raw_values.
@Test
public void raw_values() throws Exception {
final PropertyTree properties = new PropertyTree();
final GeoPoint geoPointValue = GeoPoint.from("80,80");
properties.addGeoPoint("myGeoPoint", geoPointValue);
MapGenerator generator = Mockito.mock(MapGenerator.class);
new PropertyTreeMapper(true, properties).serialize(generator);
Mockito.verify(generator).rawValue("myGeoPoint", geoPointValue);
}
use of com.enonic.xp.util.GeoPoint in project xp by enonic.
the class QueryAggregationParams method geoDistanceAggregationFromParams.
private GeoDistanceAggregationQuery.Builder geoDistanceAggregationFromParams(final String name, final Map<String, Object> params) {
final String fieldName = (String) params.get("field");
final String unit = (String) params.get("unit");
final Map<String, Object> originCoordinates = (Map<String, Object>) params.getOrDefault("origin", emptyMap());
final double lat = Double.parseDouble((String) originCoordinates.get("lat"));
final double lon = Double.parseDouble((String) originCoordinates.get("lon"));
final GeoPoint origin = new GeoPoint(lat, lon);
final List<Map<String, Object>> rangeListParams = (List<Map<String, Object>>) params.getOrDefault("ranges", emptyList());
final List<DistanceRange> ranges = new ArrayList<>();
for (Map<String, Object> rangeParams : rangeListParams) {
final Double from = getDouble(rangeParams, "from");
final Double to = getDouble(rangeParams, "to");
final String key = (String) rangeParams.getOrDefault("key", null);
final DistanceRange range = DistanceRange.create().from(from).to(to).key(key).build();
ranges.add(range);
}
return GeoDistanceAggregationQuery.create(name).fieldName(fieldName).origin(origin).unit(unit).setRanges(ranges);
}
use of com.enonic.xp.util.GeoPoint in project xp by enonic.
the class QueryAggregationParams method geoDistanceAggregationFromParams.
private GeoDistanceAggregationQuery.Builder geoDistanceAggregationFromParams(final String name, final Map<String, Object> params) {
final String fieldName = (String) params.get("field");
final String unit = (String) params.get("unit");
final Map<String, Object> originCoordinates = (Map<String, Object>) params.getOrDefault("origin", emptyMap());
final double lat = Double.parseDouble((String) originCoordinates.get("lat"));
final double lon = Double.parseDouble((String) originCoordinates.get("lon"));
final GeoPoint origin = new GeoPoint(lat, lon);
final List<Map<String, Object>> rangeListParams = (List<Map<String, Object>>) params.getOrDefault("ranges", emptyList());
final List<DistanceRange> ranges = new ArrayList<>();
for (Map<String, Object> rangeParams : rangeListParams) {
final Double from = getDouble(rangeParams, "from");
final Double to = getDouble(rangeParams, "to");
final DistanceRange range = DistanceRange.create().from(from).to(to).build();
ranges.add(range);
}
return GeoDistanceAggregationQuery.create(name).fieldName(fieldName).origin(origin).unit(unit).setRanges(ranges);
}
use of com.enonic.xp.util.GeoPoint in project xp by enonic.
the class ModifyNodeExecutorTest method createUpdateScript.
private PropertyTree createUpdateScript() {
final PropertyTree data = new PropertyTree();
data.setString("myString", "updatedValue");
final PropertySet mySet = data.addSet("mySet");
mySet.setGeoPoint("myGeoPoint", new GeoPoint(0, 0));
return data;
}
use of com.enonic.xp.util.GeoPoint in project xp by enonic.
the class ModifyNodeExecutorTest method modify_user_properties.
@Test
public void modify_user_properties() throws Exception {
final PropertyTree data = new PropertyTree();
data.setString("notChanged", "originalValue");
data.setString("myString", "originalValue");
final PropertySet mySet = data.addSet("mySet");
mySet.setGeoPoint("myGeoPoint", new GeoPoint(30, -30));
final Node originalNode = Node.create().name("myNode").parentPath(NodePath.ROOT).data(data).build();
final EditableNode editableNode = new EditableNode(originalNode);
final PropertyTree updateScript = createUpdateScript();
ModifyNodeExecutor.create().editableNode(editableNode).propertyTree(updateScript).build().execute();
assertEquals(new GeoPoint(0, 0), editableNode.data.getGeoPoint("mySet.myGeoPoint"));
assertEquals("updatedValue", editableNode.data.getString("myString"));
}
Aggregations