From 5d9ce6a5fdbe91343f0da446cb8e2a76c5876bba Mon Sep 17 00:00:00 2001 From: Enrico Ottonello Date: Mon, 8 Nov 2021 16:56:28 +0100 Subject: [PATCH] fix geopoint on collection --- .../ariadneplus/elasticsearch/BulkUpload.java | 59 ++++--------------- .../GraphDbReaderAndESIndexTest.java | 14 +---- 2 files changed, 13 insertions(+), 60 deletions(-) diff --git a/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/BulkUpload.java b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/BulkUpload.java index 74fbb0e..508b1dc 100644 --- a/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/BulkUpload.java +++ b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/BulkUpload.java @@ -70,6 +70,17 @@ public class BulkUpload { uri.setLabel(ace.getTypeLabel()); ace.setHas_type(uri); + if (ace.getSpatial()!=null) { + ace.getSpatial() + .stream() + .filter(s -> Objects.nonNull(s.getLat()) && Objects.nonNull(s.getLon())) + .forEach(s -> { + double lat = Double.parseDouble(s.getLat()); + double lon = Double.parseDouble(s.getLon()); + org.elasticsearch.common.geo.GeoPoint geopoint = new org.elasticsearch.common.geo.GeoPoint(lat, lon); + s.setGeopoint(geopoint); + }); + } if (isCollection) { ace.setResourceType("collection"); if (ace.getSpatial()!=null) { @@ -80,9 +91,6 @@ public class BulkUpload { s.setPolygon(s.getWkt()); }); } -// if (ace.getSpatial()==null) { -// ace.setSpatial(Arrays.asList(new Spatial())); -// } } else { ace.setResourceType("dataset"); @@ -95,15 +103,6 @@ public class BulkUpload { }); } if (ace.getSpatial()!=null) { - ace.getSpatial() - .stream() - .filter(s -> Objects.nonNull(s.getLat()) && Objects.nonNull(s.getLon())) - .forEach(s -> { - double lat = Double.parseDouble(s.getLat()); - double lon = Double.parseDouble(s.getLon()); - org.elasticsearch.common.geo.GeoPoint geopoint = new org.elasticsearch.common.geo.GeoPoint(lat, lon); - s.setGeopoint(geopoint); - }); ace.getSpatial() .stream() .filter(s -> Objects.nonNull(s.getBoundingBoxMaxLat()) @@ -124,11 +123,6 @@ public class BulkUpload { PolygonBuilder polygonBuilder = new PolygonBuilder(coordinatesBuilder); String wkt = polygonBuilder.toWKT(); s.setBoundingbox(wkt); -// Coordinate topLeft = new Coordinate(minlon, maxlat); -// Coordinate bottomRight = new Coordinate(maxlon, minlat); -// EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(topLeft, bottomRight); -// String wkt = envelopeBuilder.toWKT(); -// s.setBoundingbox(wkt); }); ace.getSpatial() .stream() @@ -140,10 +134,6 @@ public class BulkUpload { Double.parseDouble(p.getLon()), Double.parseDouble(p.getLat())); }); -// PolygonBuilder polygonBuilder = new PolygonBuilder(coordinatesBuilder); -// String wkt = polygonBuilder.toWKT(); -// log.debug("POLYGON "+wkt); -// s.setPolygon(wkt); }); ace.getSpatial() .stream() @@ -166,39 +156,12 @@ public class BulkUpload { ace.setSpatial(Arrays.asList(uniqueSpatial)); } } -// else { -// if (ace.getSpatial()!=null) { -// Set items = new HashSet<>(); -// List spatialsNoDup = ace.getSpatial().stream() -// .filter(s -> !items.add(s.getPlaceName())) -// .collect(Collectors.toList()); -// ace.getSpatial().clear(); -// ace.setSpatial(spatialsNoDup); -// } -// -// } List dedupSpatials = removeDuplicates(ace.getSpatial()); ace.getSpatial().clear(); ace.setSpatial(dedupSpatials); - - // TODO update following check according to new model definition -// if (ace.getSpatial().size()>1) { -// ace.getSpatial().removeIf(s -> (s.getPlaceName()!=null&&s.getPlaceName().equals("Name not provided")&&Objects.isNull(s.getLocation()))); -// } } -// else { -// ace.setSpatial(Arrays.asList(new Spatial())); -// } } -// if (ace.getTemporal()!=null) { -// ace.getTemporal().stream() -// .filter(t->t.getMatchingPeriodOName()!=null) -// .forEach(t->{ -// t.setPeriodName(t.getMatchingPeriodOName()); -// }); -// } - if (!isCollection) { String uniqueIsPartOf = ace.getUniqueIsPartOf(); if (uniqueIsPartOf != null) { diff --git a/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java b/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java index a44fe6a..d7e85aa 100644 --- a/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java +++ b/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java @@ -241,16 +241,6 @@ public class GraphDbReaderAndESIndexTest { readAndIndexTest(isRecord, recordId, datasource, collectionId); } - @Test -// @Ignore - public void uploadDIMEDigitalImageTest() throws Exception { - boolean isRecord = true; - String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/DIME/F9398BD5-DECB-3FF5-8077-D96893D0D0C6"; - String datasource = "aarhusdime"; - String collectionId = "test"; - readAndIndexTest(isRecord, recordId, datasource, collectionId); - } - @Test // @Ignore public void uploadFastiTest() throws Exception { @@ -345,9 +335,9 @@ public class GraphDbReaderAndESIndexTest { // @Ignore public void uploadDimeBoundingBoxTest() throws Exception { boolean isRecord = true; - String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/DIME/F9398BD5-DECB-3FF5-8077-D96893D0D0C6"; + String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/DIME/0E5FB5C7-6FCA-36AD-BEE5-03C9AFF393CD"; String datasource = "aarhusdime"; - String collectionId = "test"; + String collectionId = "oai"; readAndIndexTest(isRecord, recordId, datasource, collectionId); }