|
|
|
@ -1,12 +1,11 @@
|
|
|
|
|
package eu.dnetlib.ariadneplus.graphdb;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import com.google.common.base.Splitter;
|
|
|
|
|
import eu.dnetlib.ariadneplus.elasticsearch.BulkUpload;
|
|
|
|
@ -375,4 +374,53 @@ public class GraphDBClient {
|
|
|
|
|
}
|
|
|
|
|
return "Records: ".concat(recordsIndexReport).concat(" Collection: ").concat(collectionIndexReport);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<String> selectIdentifiers(String datasource, String collectionId, String resourceType) throws AriadnePlusPublisherException {
|
|
|
|
|
List <String> identifiers = Collections.emptyList();
|
|
|
|
|
try {
|
|
|
|
|
log.info("Select "+resourceType+" Identifiers from "+ datasource + " " + collectionId);
|
|
|
|
|
if (resourceType.equals("COLLECTION")) {
|
|
|
|
|
identifiers = runSPQRLQuery.selectCollectionIds(datasource, collectionId);
|
|
|
|
|
log.info(String.format("Found %d collections for datasource %s - %s", identifiers.size(), datasource, collectionId));
|
|
|
|
|
}
|
|
|
|
|
else if (resourceType.equals("RECORD")) {
|
|
|
|
|
identifiers = runSPQRLQuery.selectRecordIds(datasource, collectionId);
|
|
|
|
|
log.info(String.format("Found %d records for datasource %s - %s", identifiers.size(), datasource, collectionId));
|
|
|
|
|
}
|
|
|
|
|
}catch(Throwable e){
|
|
|
|
|
log.error(e);
|
|
|
|
|
throw new AriadnePlusPublisherException(e);
|
|
|
|
|
}
|
|
|
|
|
return identifiers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String indexOnESByIdentifiers(String datasource, String collectionId, String resourceType, List <String> identifiers) throws AriadnePlusPublisherException {
|
|
|
|
|
String report = "";
|
|
|
|
|
try {
|
|
|
|
|
log.info("Start indexing from "+ datasource + " " + collectionId);
|
|
|
|
|
runSPQRLQuery.setupConnection( getWriterUser(), getWriterPwd(), this.graphDBServerUrl, getRepository());
|
|
|
|
|
runSPQRLQuery.setParser(parseRDFJSON);
|
|
|
|
|
runSPQRLQuery.setResourceManager(resourceManager);
|
|
|
|
|
runSPQRLQuery.setBulkUpload(bulkUpload);
|
|
|
|
|
|
|
|
|
|
if (resourceType.equals("COLLECTION")) {
|
|
|
|
|
if (!identifiers.isEmpty()) {
|
|
|
|
|
final ClassPathResource selectCollectionTemplateRes = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_collection_data_template.sparql");
|
|
|
|
|
String selectCollectionTemplate = IOUtils.toString(selectCollectionTemplateRes.getInputStream(), StandardCharsets.UTF_8.name());
|
|
|
|
|
report = runSPQRLQuery.executeMultipleQueryGraph(selectCollectionTemplate, identifiers, datasource, collectionId, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (resourceType.equals("RECORD")) {
|
|
|
|
|
if(!identifiers.isEmpty()) {
|
|
|
|
|
final ClassPathResource queryTemplateResource = new ClassPathResource("eu/dnetlib/ariadneplus/sparql/read_record_data_template.sparql");
|
|
|
|
|
String queryTemplate = IOUtils.toString(queryTemplateResource.getInputStream(), StandardCharsets.UTF_8.name());
|
|
|
|
|
report = runSPQRLQuery.executeMultipleQueryGraph(queryTemplate, identifiers, datasource, collectionId, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (RuntimeException | IOException re) {
|
|
|
|
|
throw new AriadnePlusPublisherException(re);
|
|
|
|
|
}
|
|
|
|
|
return "Resources: ".concat(report);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|