/** * */ package eu.dnetlib.ariadneplus; import eu.dnetlib.ariadneplus.elasticsearch.BulkUpload; 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.junit.Ignore; import org.junit.Test; import org.springframework.core.io.ClassPathResource; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.Properties; /** * @author enrico.ottonello * */ //@Ignore public class GraphDbReaderAndESIndexTest { private RunSPARQLQueryService runSPQRLQuery; @Test // @Ignore public void readAndIndexTest() throws Exception { final ClassPathResource resource = new ClassPathResource("application.properties"); Properties appProps = new Properties(); appProps.load(resource.getInputStream()); runSPQRLQuery = new RunSPARQLQueryService(); runSPQRLQuery.setupConnection( appProps.getProperty("graphdb.writer.user"), appProps.getProperty("graphdb.writer.pwd"), appProps.getProperty("graphdb.serverUrl"), appProps.getProperty("graphdb.repository")); ParseRDFJSON parseRDFJSON = new ParseRDFJSON(); parseRDFJSON.setCatalogEntryJsonPath(appProps.getProperty("catalog.entry.path")); parseRDFJSON.setCatalogEntryCollectionJsonPath(appProps.getProperty("catalog.entry.collection.path")); runSPQRLQuery.setParser(parseRDFJSON); ResourceManager resourceManager = new ResourceManager(); resourceManager.setup( appProps.getProperty("type.path"), appProps.getProperty("general.classpath"), appProps.getProperty("exclude.predicates"), appProps.getProperty("class.map.specifications") ); runSPQRLQuery.setResourceManager(resourceManager); BulkUpload bulkUpload = new BulkUpload(); bulkUpload.init(appProps.getProperty("elasticsearch.hostname"),appProps.getProperty("elasticsearch.indexname")); runSPQRLQuery.setBulkUpload(bulkUpload); String recordId; final ClassPathResource queryTemplateResource; boolean testRecord = false; if (testRecord) { recordId = "https://ariadne-infrastructure.eu/aocat/Resource/3037F979-F94F-380B-A6A6-3972ED10E61C"; queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql"); } else { recordId = "https://ariadne-infrastructure.eu/aocat/Collection/CENIEH/A4A042CF-4FD6-3FB4-B701-CBC8A1653ADA"; queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql"); } String datasource = "cenieh"; String collectionId = "171"; List recordIds = Arrays.asList(recordId); String queryTemplate = IOUtils.toString(queryTemplateResource.getInputStream(), StandardCharsets.UTF_8.name()); if (testRecord) { runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, recordIds, datasource, collectionId, false); } else { runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, recordIds, datasource, collectionId, true); } } @Test @Ignore public void selectRecordsTest() throws Exception { final ClassPathResource resource = new ClassPathResource("application.properties"); Properties appProps = new Properties(); appProps.load(resource.getInputStream()); String datasource = "ads"; String collectionId = "271"; runSPQRLQuery = new RunSPARQLQueryService(); runSPQRLQuery.setupConnection( appProps.getProperty("graphdb.writer.user"), appProps.getProperty("graphdb.writer.pwd"), appProps.getProperty("repository.url"), appProps.getProperty("graphdb.repository")); runSPQRLQuery.selectRecordIds(datasource, collectionId); } @Test @Ignore public void loadQueryTest() throws Exception { final ClassPathResource resource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql"); String queryTemplate = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8.name()); System.out.println(queryTemplate); } }