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);
}
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);
}
}
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;
}
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 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));
}
Aggregations