Search in sources :

Example 6 with GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class ImageContentProcessorTest method testProcessCreateWithGeoData.

@Test
public void testProcessCreateWithGeoData() throws IOException {
    final XData gpsInfo = createXData(GPS_INFO_METADATA_NAME, "Gps Info", createGpsInfoMixinForm());
    Mockito.when(this.xDataService.getFromContentType(Mockito.any())).thenReturn(XDatas.from(gpsInfo));
    final CreateContentParams params = createContentParams(createAttachments());
    final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().addMetadata("geo lat", "1").addMetadata("geo long", "2").build());
    final GeoPoint geoPoint = new GeoPoint(1.0, 2.0);
    final ProcessCreateResult result = this.imageContentProcessor.processCreate(processCreateParams);
    final ExtraData geoExtraData = result.getCreateContentParams().getExtraDatas().first();
    assertEquals(geoExtraData.getName(), GPS_INFO_METADATA_NAME);
    assertEquals(geoExtraData.getData().getGeoPoint(MediaInfo.GPS_INFO_GEO_POINT, 0), geoPoint);
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Example 7 with GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class GeoDistanceSortFunctionArguments method setLocation.

private void setLocation(final List<ValueExpr> arguments) {
    final Value locationArgument = arguments.get(LOCATION_POSITION).getValue();
    try {
        final GeoPoint geoPoint = locationArgument.asGeoPoint();
        this.latitude = geoPoint.getLatitude();
        this.longitude = geoPoint.getLongitude();
    } catch (Exception e) {
        throw new FunctionQueryBuilderException("geoDistance", LOCATION_POSITION + 1, locationArgument.toString(), e);
    }
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) Value(com.enonic.xp.data.Value)

Example 8 with GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class ImageContentProcessor method extractGeoLocation.

private ExtraData extractGeoLocation(final MediaInfo mediaInfo, final XDatas xDatas) {
    final ImmutableMultimap<String, String> mediaItems = mediaInfo.getMetadata();
    final Double geoLat = parseDouble(mediaItems.get(GEO_LATITUDE).stream().findFirst().orElse(null));
    final Double geoLong = parseDouble(mediaItems.get(GEO_LONGITUDE).stream().findFirst().orElse(null));
    if (geoLat == null || geoLong == null) {
        return null;
    }
    final XData geoMixin = xDatas.getXData(MediaInfo.GPS_INFO_METADATA_NAME);
    if (geoMixin == null) {
        return null;
    }
    final ExtraData extraData = new ExtraData(geoMixin.getName(), new PropertyTree());
    final FormItem formItem = geoMixin.getForm().getFormItems().getItemByName(MediaInfo.GPS_INFO_GEO_POINT);
    if (FormItemType.INPUT.equals(formItem.getType())) {
        final Input input = (Input) formItem;
        if (InputTypeName.GEO_POINT.equals(input.getInputType())) {
            final GeoPoint geoPoint = new GeoPoint(geoLat, geoLong);
            extraData.getData().addGeoPoint(formItem.getName(), ValueTypes.GEO_POINT.convert(geoPoint));
        }
    }
    return extraData;
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) Input(com.enonic.xp.form.Input) FormItem(com.enonic.xp.form.FormItem) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData)

Example 9 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 10 with GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class JavaTypeConvertersTest method convertToGeoPoint.

@Test
public void convertToGeoPoint() {
    assertEquals(GeoPoint.class, JavaTypeConverters.GEO_POINT.convertFrom(GeoPoint.from("22.22, 33.33")).getClass());
    assertEquals(GeoPoint.class, JavaTypeConverters.GEO_POINT.convertFrom(new GeoPoint(2.2, 3.3)).getClass());
    assertEquals(GeoPoint.class, JavaTypeConverters.GEO_POINT.convertFrom("22.22, 33.33").getClass());
    final PropertySet set = new PropertySet();
    set.addDouble("lat", 2.2);
    set.addDouble("lon", 3.3);
    assertEquals(GeoPoint.class, JavaTypeConverters.GEO_POINT.convertFrom(set).getClass());
    assertNull(JavaTypeConverters.GEO_POINT.convertFrom(new Object()));
    assertNull(JavaTypeConverters.GEO_POINT.convertFrom(null));
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) 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