From 84993ffaba2348391a04a84ed1c0fcd1565f4ccd Mon Sep 17 00:00:00 2001 From: Enrico Ottonello Date: Tue, 16 Feb 2021 18:19:30 +0100 Subject: [PATCH] matching periodo name (if any) overwrites native period name --- .../ariadneplus/elasticsearch/BulkUpload.java | 8 +++ .../elasticsearch/model/AriadneTemporal.java | 9 +++ .../src/main/resources/application.properties | 9 ++- .../read_collection_data_template.sparql | 10 +-- .../sparql/read_record_data_template.sparql | 4 +- .../GraphDbReaderAndESIndexTest.java | 64 ++++++++++++++++--- 6 files changed, 87 insertions(+), 17 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 7ab5ab3..acd844b 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 @@ -102,6 +102,14 @@ public class BulkUpload { } } + 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/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/model/AriadneTemporal.java b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/model/AriadneTemporal.java index 7dd30cc..4263fbb 100644 --- a/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/model/AriadneTemporal.java +++ b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/elasticsearch/model/AriadneTemporal.java @@ -10,6 +10,7 @@ public class AriadneTemporal { private String periodName; private String until; private String uri; + private transient String matchingPeriodOName; public static AriadneTemporal fromRDFJson(JsonElement json) { AriadneTemporal at = new AriadneTemporal(); @@ -72,4 +73,12 @@ public class AriadneTemporal { public static AriadneTemporal fromJson(String json){ return new Gson().fromJson(json, AriadneTemporal.class); } + + public String getMatchingPeriodOName() { + return matchingPeriodOName; + } + + public void setMatchingPeriodOName(String matchingPeriodOName) { + this.matchingPeriodOName = matchingPeriodOName; + } } diff --git a/dnet-ariadneplus-graphdb-publisher/src/main/resources/application.properties b/dnet-ariadneplus-graphdb-publisher/src/main/resources/application.properties index 118fec1..344536e 100644 --- a/dnet-ariadneplus-graphdb-publisher/src/main/resources/application.properties +++ b/dnet-ariadneplus-graphdb-publisher/src/main/resources/application.properties @@ -5,7 +5,7 @@ server.port=8281 graphdb.serverUrl=http://graphdb-test.ariadne.d4science.org:7200 graphdb.writer.user=writer -graphdb.writer.pwd=***** +graphdb.writer.pwd=pwd graphdb.repository=ariadneplus-ts01 graphdb.baseURI=https://ariadne-infrastructure.eu/ @@ -26,11 +26,16 @@ class.map.specifications={\ "substring": "no",\ "element_type": "java.lang.String"\ },\ -"https://www.ariadne-infrastructure.eu/property/periodName": {\ +"https://www.ariadne-infrastructure.eu/property/nativePeriodName": {\ "class_field": "PeriodName",\ "substring": "no",\ "element_type": "java.lang.String"\ },\ +"https://www.ariadne-infrastructure.eu/property/periodOName": {\ +"class_field": "MatchingPeriodOName",\ +"substring": "no",\ +"element_type": "java.lang.String"\ +},\ "https://www.ariadne-infrastructure.eu/property/until": {\ "class_field": "Until",\ "substring": "no",\ diff --git a/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql b/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql index 27b8421..54aa8de 100644 --- a/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql +++ b/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql @@ -42,11 +42,13 @@ CONSTRUCT { ?spatialRegionBox aoprop:boxMaxLon ?spatialLocationBBMaxLon . ?spatialRegionBox aoprop:boxMinLat ?spatialLocationBBMinLat . ?spatialRegionBox aoprop:boxMinLon ?spatialLocationBBMinLon . +%record aoprop:uri ?temporal . +?temporal aoprop:periodOName ?temporalPeriodName . +?temporal aoprop:from ?temporalFrom . +?temporal aoprop:until ?temporalUntil . +?temporal aoprop:uri ?temporal . %record aoprop:uri ?temporalNative . -?temporalNative aoprop:periodName ?temporalNativePeriodName . -?temporalNative aoprop:from ?temporalFrom . -?temporalNative aoprop:until ?temporalUntil . -?temporalNative aoprop:uri ?temporalPeriodO . +?temporalNative aoprop:nativePeriodName ?temporalNativePeriodName . %record aoprop:archeologicalResourceType ?archeologicalResourceType . ?archeologicalResourceType aoprop:name ?archeologicalResourceTypeName . %record aoprop:resourceType ?resourceType . diff --git a/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql b/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql index 7f97aef..b867d9f 100644 --- a/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql +++ b/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql @@ -43,12 +43,12 @@ CONSTRUCT { ?spatialRegionBox aoprop:boxMinLat ?spatialLocationBBMinLat . ?spatialRegionBox aoprop:boxMinLon ?spatialLocationBBMinLon . %record aoprop:uri ?temporal . -?temporal aoprop:periodName ?temporalPeriodName . +?temporal aoprop:periodOName ?temporalPeriodName . ?temporal aoprop:from ?temporalFrom . ?temporal aoprop:until ?temporalUntil . ?temporal aoprop:uri ?temporal . %record aoprop:uri ?temporalNative . -?temporalNative aoprop:periodName ?temporalNativePeriodName . +?temporalNative aoprop:nativePeriodName ?temporalNativePeriodName . %record aoprop:archeologicalResourceType ?archeologicalResourceType . ?archeologicalResourceType aoprop:name ?archeologicalResourceTypeName . %record aoprop:resourceType ?resourceType . 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 90a2974..76597a8 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 @@ -8,6 +8,11 @@ import eu.dnetlib.ariadneplus.reader.ResourceManager; import eu.dnetlib.ariadneplus.reader.RunSPARQLQueryService; import eu.dnetlib.ariadneplus.reader.json.ParseRDFJSON; import org.apache.commons.io.IOUtils; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryResult; +import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager; import org.junit.Ignore; import org.junit.Test; import org.springframework.core.io.ClassPathResource; @@ -27,15 +32,35 @@ public class GraphDbReaderAndESIndexTest { private RunSPARQLQueryService runSPQRLQuery; @Test - public void ads1093RecordTest() throws Exception { - boolean testRecord = true; - String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/1B23A61E-E4DE-3647-8006-0284C729AF85"; - String datasource = "ads"; - String collectionId = "1093"; - readAndIndexTest(testRecord, recordId, datasource, collectionId); + @Ignore + public void uploadAMCRFieldworkTest() throws Exception { + boolean isRecord = true; + String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/AMCR/E61E0F4E-268F-39E4-8EDB-A431AFC505AA"; + String datasource = "amcr"; + String collectionId = "oai"; + readAndIndexTest(isRecord, recordId, datasource, collectionId); } - private void readAndIndexTest(boolean testRecord, String recordId, String datasource, String collectionId) throws Exception { + @Test + public void uploadAMCRDocumentTest() throws Exception { + boolean isRecord = true; + String recordId = "https://ariadne-infrastructure.eu/aocat/Collection/AMCR/FC59581D-DC3A-31DA-922A-98DE764F3D76"; + String datasource = "amcr"; + String collectionId = "oai"; + readAndIndexTest(isRecord, recordId, datasource, collectionId); + } + + @Test + @Ignore + public void uploadADSRecordTest() throws Exception { + boolean isRecord = true; + String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/34E3811A-0BAD-3832-B3A0-3139E8A0285C"; + String datasource = "ads"; + String collectionId = "271"; + readAndIndexTest(isRecord, recordId, datasource, collectionId); + } + + private void readAndIndexTest(boolean isRecord, String recordId, String datasource, String collectionId) throws Exception { final ClassPathResource resource = new ClassPathResource("application.properties"); Properties appProps = new Properties(); appProps.load(resource.getInputStream()); @@ -62,7 +87,7 @@ public class GraphDbReaderAndESIndexTest { bulkUpload.init(appProps.getProperty("elasticsearch.hostname"),appProps.getProperty("elasticsearch.indexname")); runSPQRLQuery.setBulkUpload(bulkUpload); final ClassPathResource queryTemplateResource; - if (testRecord) { + if (isRecord) { queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql"); } else { @@ -70,7 +95,7 @@ public class GraphDbReaderAndESIndexTest { } List recordIds = Arrays.asList(recordId); String queryTemplate = IOUtils.toString(queryTemplateResource.getInputStream(), StandardCharsets.UTF_8.name()); - if (testRecord) { + if (isRecord) { runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, recordIds, datasource, collectionId, false); } else { @@ -103,4 +128,25 @@ public class GraphDbReaderAndESIndexTest { System.out.println(queryTemplate); } + + @Test + @Ignore + public void httpsRequestTest() throws Exception { +// RemoteRepositoryManager manager = new RemoteRepositoryManager("http://graphdb-test.ariadne.d4science.org:7200"); + RemoteRepositoryManager manager = new RemoteRepositoryManager("https://graphdb-test.ariadne.d4science.org"); + manager.init(); + manager.setUsernameAndPassword("writer", "******"); + Repository repository = manager.getRepository("ariadneplus-ts01"); + RepositoryConnection connection = repository.getConnection(); + RepositoryResult contexts = connection.getContextIDs(); + if (contexts!=null) { + System.out.println("##### Primo context "+contexts.next().stringValue()); + } + else { + System.out.println("No contexts "); + } + connection.close(); + repository.shutDown(); + manager.shutDown(); + } }