/** * */ 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 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); } private void readAndIndexTest(boolean testRecord, String recordId, String datasource, String collectionId) 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); final ClassPathResource queryTemplateResource; if (testRecord) { queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql"); } else { queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql"); } 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); } }