163 lines
6.7 KiB
Java
163 lines
6.7 KiB
Java
/**
|
|
*
|
|
*/
|
|
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.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;
|
|
|
|
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 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);
|
|
}
|
|
|
|
@Test
|
|
@Ignore
|
|
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
|
|
public void uploadAMCRSiteTest() throws Exception {
|
|
boolean isRecord = true;
|
|
String recordId = "https://ariadne-infrastructure.eu/aocat/Resource/AMCR/3C7EC936-A7CA-3720-B3DC-413A25754FD4";
|
|
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());
|
|
|
|
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 (isRecord) {
|
|
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<String> recordIds = Arrays.asList(recordId);
|
|
String queryTemplate = IOUtils.toString(queryTemplateResource.getInputStream(), StandardCharsets.UTF_8.name());
|
|
if (isRecord) {
|
|
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);
|
|
|
|
}
|
|
|
|
@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<Resource> 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();
|
|
}
|
|
}
|