diff --git a/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/graphdb/GraphDBClient.java b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/graphdb/GraphDBClient.java index fd8f294..c1b3f4b 100644 --- a/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/graphdb/GraphDBClient.java +++ b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/graphdb/GraphDBClient.java @@ -360,6 +360,10 @@ public class GraphDBClient { final ClassPathResource queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql"); String queryTemplate = IOUtils.toString(queryTemplateResource.getInputStream(), StandardCharsets.UTF_8.name()); runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, recordIds, datasource, collectionId); +// List collectionResourceId = runSPQRLQuery.selectCollectionId(datasource, collectionId); +// final ClassPathResource selectCollectionTemplateRes = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql"); +// String selectCollectionTemplate = IOUtils.toString(selectCollectionTemplateRes.getInputStream(), StandardCharsets.UTF_8.name()); +// runSPQRLQuery.executeMultipleQueryGraph(selectCollectionTemplate, collectionResourceId, datasource, collectionId); }catch(Throwable e){ log.error(e); throw new AriadnePlusPublisherException(e); diff --git a/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/reader/RunSPARQLQueryService.java b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/reader/RunSPARQLQueryService.java index 6aee91b..8fac2f4 100644 --- a/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/reader/RunSPARQLQueryService.java +++ b/dnet-ariadneplus-graphdb-publisher/src/main/java/eu/dnetlib/ariadneplus/reader/RunSPARQLQueryService.java @@ -161,7 +161,7 @@ public class RunSPARQLQueryService { } public List selectRecordIds(String datasource, String collectionId){ - log.debug("Retrieving recordIds from GraphDB ..."); + log.debug("Retrieving record Ids from GraphDB ..."); String queryTemplate = "PREFIX rdf: \n" + "select * \n" + "from \n" + @@ -169,9 +169,25 @@ public class RunSPARQLQueryService { "\t?recordId rdf:type .\n" + "} \n"; String query = queryTemplate.replaceAll("%datasource", datasource).replaceAll("%collectionId", collectionId); + return executeSelect(query); + } + + public List selectCollectionId(String datasource, String collectionId){ + log.debug("Retrieving collection Id from GraphDB ..."); + String queryTemplate = "PREFIX rdf: \n" + + "select * \n" + + "from \n" + + "where { \n" + + "\t?recordId rdf:type .\n" + + "} \n"; + String query = queryTemplate.replaceAll("%datasource", datasource).replaceAll("%collectionId", collectionId); + return executeSelect(query); + } + + private List executeSelect(String query){ openConnection(); String jsonRecord = null; - List recordIds = new ArrayList<>(); + List results = new ArrayList<>(); try { log.debug("Started at: "+Calendar.getInstance().getTime().toString()); TupleQuery selectQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query); @@ -180,16 +196,16 @@ public class RunSPARQLQueryService { while (selectQueryResult.hasNext()) { BindingSet recordSet = selectQueryResult.next(); org.eclipse.rdf4j.model.Value recordIdValue = recordSet.getValue("recordId"); - recordIds.add(recordIdValue.stringValue()); + results.add(recordIdValue.stringValue()); counter++; } - log.debug("Total recordIds retrieved: "+counter); + log.debug("Total records retrieved: "+counter); log.debug("Finished at: "+Calendar.getInstance().getTime().toString()); } catch(Exception e){ e.printStackTrace(); } finally{ closeConnection(); } - return recordIds; + return results; } } 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 new file mode 100644 index 0000000..33449aa --- /dev/null +++ b/dnet-ariadneplus-graphdb-publisher/src/main/resources/eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql @@ -0,0 +1,124 @@ +PREFIX aocat: +PREFIX rdfs: +PREFIX skos: +PREFIX aoprop: +PREFIX onto: +PREFIX ariadneplus: +PREFIX time: + +CONSTRUCT { +%record aoprop:identifier %record . +%record aoprop:originalId ?originalId . +%record aoprop:issued ?issued . +%record aoprop:modified ?modified . +%record aoprop:partOf ?partOf . +%record aoprop:creator ?creator . +?creator aoprop:name ?creatorName . +?creator aoprop:email ?creatorEmail . +%record aoprop:contributor ?contributor . +?contributor aoprop:name ?contributorName . +?contributor aoprop:email ?contributorEmail . +%record aoprop:legalResponsible ?legalResponsible . +?legalResponsible aoprop:name ?legalResponsibleName . +?legalResponsible aoprop:email ?legalResponsibleEmail . +%record aoprop:owner ?owner . +?owner aoprop:name ?ownerName . +?owner aoprop:email ?ownerEmail . +%record aoprop:publisher ?publisher . +?publisher aoprop:name ?publisherName . +?publisher aoprop:email ?publisherEmail . +%record aoprop:accessPolicy ?accessPolicy . +%record aoprop:accessRights ?accessRights . +%record aoprop:landingPage ?landingPage . +%record aoprop:spatialRegion ?spatialRegion . +?spatialRegion aoprop:placeName ?spatialPlaceName . +?spatialRegion aoprop:spatialCoordinateSystem ?spatialCoordinateSystem . +%record aoprop:spatialRegionPoint ?spatialRegionPoint . +?spatialRegionPoint aoprop:lat ?spatialLocationLat . +?spatialRegionPoint aoprop:lon ?spatialLocationLon . +%record aoprop:spatialRegionBox ?spatialRegionBox . +?spatialRegionBox aoprop:boxMaxLat ?spatialLocationBBMaxLat . +?spatialRegionBox aoprop:boxMaxLon ?spatialLocationBBMaxLon . +?spatialRegionBox aoprop:boxMinLat ?spatialLocationBBMinLat . +?spatialRegionBox aoprop:boxMinLon ?spatialLocationBBMinLon . +%record aoprop:uri ?temporal . +?temporal aoprop:periodName ?temporalPeriodName . +?temporal aoprop:from ?temporalFrom . +?temporal aoprop:until ?temporalUntil . +%record aoprop:uri ?temporalNative . +?temporalNative aoprop:periodName ?temporalNativePeriodName . +%record aoprop:archeologicalResourceType ?archeologicalResourceType . +?archeologicalResourceType aoprop:name ?archeologicalResourceTypeName . +%record aoprop:resourceType ?resourceType . +%record aoprop:nativeSubject ?nativeSubject . +?nativeSubject aoprop:prefLabel ?nativeSubjectPrefLabel . +?nativeSubject aoprop:rdfAbout ?nativeSubject . +%record aoprop:derivedSubject ?derivedSubject . +?derivedSubject aoprop:prefLabel ?derivedSubjectPrefLabel . +?derivedSubject aoprop:source "Getty AAT" . +%record aoprop:aatSubjects ?derivedSubject . +?derivedSubject aoprop:id ?derivedSubject . +?derivedSubject aoprop:label ?derivedSubjectPrefLabel . +?derivedSubject aoprop:lang ?aatSubjectsLang . +%record aoprop:title ?title . +%record aoprop:description ?description . +%record aoprop:language ?language . +} +from +from +from +from +from +where { + %record aocat:has_language / skos:prefLabel ?language . + %record aocat:has_original_id ?originalId . + %record aocat:has_creator ?creator . + ?creator aocat:has_name ?creatorName . + %record aocat:has_title ?title . + %record aocat:has_type / skos:prefLabel ?resourceType . + optional { + ?creator aocat:has_email ?creatorEmail . + } + optional { + %record aocat:has_description ?description . + } + optional { + %record aocat:has_access_policy / rdfs:label ?accessPolicy . + } + optional { + %record aocat:has_landing_page / rdfs:label ?landingPage . + } + + { + select * + where { + %record aocat:was_issued ?issued . + %record aocat:was_modified ?modified . + %record aocat:has_contributor ?contributor . + ?contributor aocat:has_name ?contributorName . + %record aocat:has_responsible ?legalResponsible . + ?legalResponsible aocat:has_name ?legalResponsibleName . + %record aocat:has_owner ?owner . + ?owner aocat:has_name ?ownerName . + %record aocat:has_publisher ?publisher . + ?publisher aocat:has_name ?publisherName . + %record aocat:has_access_rights ?accessRights . + %record aocat:has_ARIADNE_subject ?archeologicalResourceType . + ?archeologicalResourceType skos:prefLabel ?archeologicalResourceTypeName . + optional { + ?contributor aocat:has_email ?contributorEmail . + } + optional { + ?legalResponsible aocat:has_email ?legalResponsibleEmail . + } + optional { + ?owner aocat:has_email ?ownerEmail . + } + optional { + ?publisher aocat:has_email ?publisherEmail . + } + } + } + + BIND (lang(?derivedSubjectPrefLabel) as ?aatSubjectsLang) +} \ No newline at end of file