2019-12-12 12:58:30 +01:00
|
|
|
package eu.dnetlib.ariadneplus.publisher;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import eu.dnetlib.ariadneplus.graphdb.GraphDBClient;
|
|
|
|
import eu.dnetlib.ariadneplus.graphdb.GraphDBClientFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author enrico.ottonello
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Component
|
|
|
|
public class AriadnePlusPublisherHelper {
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(AriadnePlusPublisherHelper.class);
|
|
|
|
|
|
|
|
public enum AriadnePlusTargets{
|
|
|
|
GRAPHDB
|
|
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private GraphDBClientFactory graphdbClientFactory;
|
|
|
|
|
|
|
|
public void publish(final String record, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
|
|
|
|
switch(target){
|
|
|
|
case GRAPHDB:
|
|
|
|
publishGraphDB(record);
|
|
|
|
break;
|
|
|
|
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-24 10:52:04 +01:00
|
|
|
public void feedProvenance(final String datasource, final String datasourceApi, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
|
2019-12-13 14:53:15 +01:00
|
|
|
switch(target){
|
|
|
|
case GRAPHDB:
|
2020-01-24 10:52:04 +01:00
|
|
|
feedProvenance(datasource, datasourceApi);
|
2019-12-13 14:53:15 +01:00
|
|
|
break;
|
|
|
|
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-19 14:33:54 +01:00
|
|
|
public void dropDatasourceApiGraph(final String datasourceApi, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
|
2020-01-14 16:55:45 +01:00
|
|
|
switch(target){
|
|
|
|
case GRAPHDB:
|
2020-02-19 14:33:54 +01:00
|
|
|
dropDatasourceApiGraph(datasourceApi);
|
2020-01-14 16:55:45 +01:00
|
|
|
break;
|
|
|
|
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-12 12:58:30 +01:00
|
|
|
public long unpublish(final String datasourceInterface, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
|
|
|
|
long res = 0;
|
|
|
|
switch(target){
|
|
|
|
case GRAPHDB:
|
|
|
|
res = unpublishGraphDB(datasourceInterface);
|
|
|
|
break;
|
|
|
|
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-05-29 16:19:55 +02:00
|
|
|
public String updateSparql(final String queryValue, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
|
2020-05-27 23:07:08 +02:00
|
|
|
String res;
|
|
|
|
switch(target){
|
|
|
|
case GRAPHDB:
|
2020-05-29 16:19:55 +02:00
|
|
|
res = updateSparqlGraphDB(queryValue);
|
2020-05-27 23:07:08 +02:00
|
|
|
break;
|
|
|
|
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-05-30 17:21:03 +02:00
|
|
|
public String feedFromURL(final String dataUrl, final String context, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
|
|
|
|
String res;
|
|
|
|
switch(target){
|
|
|
|
case GRAPHDB:
|
|
|
|
res = feedFromURL(dataUrl, context);
|
|
|
|
break;
|
|
|
|
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-06-12 18:14:41 +02:00
|
|
|
public String indexOnES(final String datasource, final String collectionId, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
|
|
|
|
String res;
|
|
|
|
switch(target){
|
|
|
|
case GRAPHDB:
|
|
|
|
res = indexOnES(datasource, collectionId);
|
|
|
|
break;
|
|
|
|
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-12-12 12:58:30 +01:00
|
|
|
private void publishGraphDB(final String record) throws AriadnePlusPublisherException {
|
|
|
|
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
|
|
|
|
graphDBClient.feed(record);
|
|
|
|
}
|
2019-12-13 14:53:15 +01:00
|
|
|
|
2020-01-24 10:52:04 +01:00
|
|
|
private void feedProvenance(final String datasource, final String datasourceApi) throws AriadnePlusPublisherException {
|
|
|
|
log.debug("Feed Provenance " + datasource + " - " + datasourceApi);
|
2019-12-13 14:53:15 +01:00
|
|
|
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
|
2020-01-24 10:52:04 +01:00
|
|
|
graphDBClient.feedProvenance(datasource, datasourceApi);
|
2019-12-13 14:53:15 +01:00
|
|
|
}
|
2019-12-12 12:58:30 +01:00
|
|
|
|
2020-02-19 14:33:54 +01:00
|
|
|
private void dropDatasourceApiGraph(final String datasourceApi) throws AriadnePlusPublisherException {
|
2020-01-14 16:55:45 +01:00
|
|
|
log.debug("Drop DatasourceApis Partition Info " + datasourceApi);
|
|
|
|
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
|
2020-02-19 14:33:54 +01:00
|
|
|
graphDBClient.dropDatasourceApiGraph(datasourceApi);
|
2020-01-14 16:55:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-12 12:58:30 +01:00
|
|
|
private long unpublishGraphDB(final String datasourceInterface) {
|
|
|
|
log.info("Unpublishing from graphdb "+datasourceInterface);
|
|
|
|
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
|
2020-01-24 10:52:04 +01:00
|
|
|
|
|
|
|
return 0;
|
2019-12-12 12:58:30 +01:00
|
|
|
}
|
2020-05-27 23:07:08 +02:00
|
|
|
|
2020-05-29 16:19:55 +02:00
|
|
|
private String updateSparqlGraphDB(final String queryValue) throws AriadnePlusPublisherException {
|
|
|
|
log.info("updateSparqlGraphDB "+queryValue);
|
2020-05-27 23:07:08 +02:00
|
|
|
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
|
2020-05-30 17:21:03 +02:00
|
|
|
return graphDBClient.updateSparql(queryValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String feedFromURL(final String dataUrl, final String context) throws AriadnePlusPublisherException {
|
|
|
|
log.info("feedFromURL "+dataUrl + " " + context);
|
|
|
|
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
|
|
|
|
return graphDBClient.feedFromURL(dataUrl, context);
|
2020-05-27 23:07:08 +02:00
|
|
|
}
|
2020-06-12 18:14:41 +02:00
|
|
|
|
|
|
|
private String indexOnES(final String datasource, final String collectionId) throws AriadnePlusPublisherException {
|
|
|
|
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
|
|
|
|
return graphDBClient.indexOnES(datasource, collectionId);
|
|
|
|
}
|
2019-12-12 12:58:30 +01:00
|
|
|
}
|