2020-06-10 19:39:53 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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;
|
2020-06-11 18:20:42 +02:00
|
|
|
import org.apache.commons.io.IOUtils;
|
2020-06-10 19:39:53 +02:00
|
|
|
import org.junit.Ignore;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
2020-06-11 18:20:42 +02:00
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2020-06-10 19:39:53 +02:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author enrico.ottonello
|
|
|
|
*
|
|
|
|
*/
|
2020-09-22 16:40:51 +02:00
|
|
|
@Ignore
|
2020-06-10 19:39:53 +02:00
|
|
|
public class GraphDbReaderAndESIndexTest {
|
|
|
|
|
|
|
|
private RunSPARQLQueryService runSPQRLQuery;
|
|
|
|
|
|
|
|
@Test
|
2020-06-16 02:36:16 +02:00
|
|
|
// @Ignore
|
2020-06-10 19:39:53 +02:00
|
|
|
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"),
|
2020-06-16 02:36:16 +02:00
|
|
|
appProps.getProperty("graphdb.serverUrl"),
|
2020-06-10 19:39:53 +02:00
|
|
|
appProps.getProperty("graphdb.repository"));
|
|
|
|
ParseRDFJSON parseRDFJSON = new ParseRDFJSON();
|
|
|
|
parseRDFJSON.setCatalogEntryJsonPath(appProps.getProperty("catalog.entry.path"));
|
2020-07-08 22:00:28 +02:00
|
|
|
parseRDFJSON.setCatalogEntryCollectionJsonPath(appProps.getProperty("catalog.entry.collection.path"));
|
2020-06-10 19:39:53 +02:00
|
|
|
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();
|
2020-06-16 02:36:16 +02:00
|
|
|
bulkUpload.init(appProps.getProperty("elasticsearch.hostname"),appProps.getProperty("elasticsearch.indexname"));
|
2020-06-10 19:39:53 +02:00
|
|
|
runSPQRLQuery.setBulkUpload(bulkUpload);
|
2020-07-17 17:42:08 +02:00
|
|
|
String recordId;
|
|
|
|
final ClassPathResource queryTemplateResource;
|
2020-09-17 16:32:43 +02:00
|
|
|
boolean testRecord = false;
|
2020-07-17 17:42:08 +02:00
|
|
|
if (testRecord) {
|
2020-08-12 15:47:55 +02:00
|
|
|
recordId = "https://ariadne-infrastructure.eu/aocat/Resource/D200902C-A1C2-346E-8F37-E8A429260ADE";
|
2020-07-17 17:42:08 +02:00
|
|
|
queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql");
|
|
|
|
}
|
|
|
|
else {
|
2020-09-17 16:32:43 +02:00
|
|
|
recordId = "https://ariadne-infrastructure.eu/aocat/Collection/ADS/371CCB1B-A7B6-3CC8-B341-36049515B47E";
|
2020-07-17 17:42:08 +02:00
|
|
|
queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql");
|
|
|
|
}
|
|
|
|
|
2020-06-11 18:20:42 +02:00
|
|
|
String datasource = "ads";
|
2020-09-17 16:32:43 +02:00
|
|
|
String collectionId = "272_monument";
|
2020-06-11 18:20:42 +02:00
|
|
|
List<String> recordIds = Arrays.asList(recordId);
|
|
|
|
String queryTemplate = IOUtils.toString(queryTemplateResource.getInputStream(), StandardCharsets.UTF_8.name());
|
2020-07-17 17:42:08 +02:00
|
|
|
if (testRecord) {
|
|
|
|
runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, recordIds, datasource, collectionId, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, recordIds, datasource, collectionId, true);
|
|
|
|
}
|
2020-06-11 18:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Ignore
|
|
|
|
public void selectRecordsTest() throws Exception {
|
|
|
|
final ClassPathResource resource = new ClassPathResource("application.properties");
|
|
|
|
Properties appProps = new Properties();
|
|
|
|
appProps.load(resource.getInputStream());
|
2020-06-16 02:36:16 +02:00
|
|
|
String datasource = "ads";
|
|
|
|
String collectionId = "271";
|
2020-06-11 18:20:42 +02:00
|
|
|
runSPQRLQuery = new RunSPARQLQueryService();
|
|
|
|
runSPQRLQuery.setupConnection(
|
|
|
|
appProps.getProperty("graphdb.writer.user"),
|
|
|
|
appProps.getProperty("graphdb.writer.pwd"),
|
|
|
|
appProps.getProperty("repository.url"),
|
|
|
|
appProps.getProperty("graphdb.repository"));
|
2020-06-16 02:36:16 +02:00
|
|
|
runSPQRLQuery.selectRecordIds(datasource, collectionId);
|
2020-06-11 18:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
2020-06-10 19:39:53 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|