Search in sources :

Example 11 with GeoPoint

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);
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) MapGenerator(com.enonic.xp.script.serializer.MapGenerator) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 12 with GeoPoint

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);
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) ArrayList(java.util.ArrayList) DistanceRange(com.enonic.xp.query.aggregation.DistanceRange) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 13 with GeoPoint

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);
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) ArrayList(java.util.ArrayList) DistanceRange(com.enonic.xp.query.aggregation.DistanceRange) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 14 with GeoPoint

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;
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Example 15 with GeoPoint

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"));
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) PropertySet(com.enonic.xp.data.PropertySet) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Aggregations

GeoPoint (com.enonic.xp.util.GeoPoint)15 PropertyTree (com.enonic.xp.data.PropertyTree)8 Test (org.junit.jupiter.api.Test)7 PropertySet (com.enonic.xp.data.PropertySet)5 ExtraData (com.enonic.xp.content.ExtraData)2 EditableNode (com.enonic.xp.node.EditableNode)2 Node (com.enonic.xp.node.Node)2 DistanceRange (com.enonic.xp.query.aggregation.DistanceRange)2 XData (com.enonic.xp.schema.xdata.XData)2 JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)2 MapGenerator (com.enonic.xp.script.serializer.MapGenerator)2 ArrayList (java.util.ArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 List (java.util.List)2 Map (java.util.Map)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)1 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)1 Value (com.enonic.xp.data.Value)1