AriadnePlus/dnet-ariadneplus-graphdb-pu.../src/main/java/eu/dnetlib/ariadneplus/publisher/AriadnePlusPublisherHelper....

111 lines
3.6 KiB
Java
Raw Normal View History

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");
}
}
public void feedProvenance(final String datasource, final String datasourceApi, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
switch(target){
case GRAPHDB:
feedProvenance(datasource, datasourceApi);
break;
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
}
}
public void dropDatasourceApiGraph(final String datasourceApi, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
switch(target){
case GRAPHDB:
dropDatasourceApiGraph(datasourceApi);
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;
}
public String updateSparql(final String queryValue, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
String res;
switch(target){
case GRAPHDB:
res = updateSparqlGraphDB(queryValue);
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 {
log.debug("Publishing on graphdb");
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
graphDBClient.feed(record);
}
private void feedProvenance(final String datasource, final String datasourceApi) throws AriadnePlusPublisherException {
log.debug("Feed Provenance " + datasource + " - " + datasourceApi);
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
graphDBClient.feedProvenance(datasource, datasourceApi);
}
2019-12-12 12:58:30 +01:00
private void dropDatasourceApiGraph(final String datasourceApi) throws AriadnePlusPublisherException {
log.debug("Drop DatasourceApis Partition Info " + datasourceApi);
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
graphDBClient.dropDatasourceApiGraph(datasourceApi);
}
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();
return 0;
2019-12-12 12:58:30 +01:00
}
private String updateSparqlGraphDB(final String queryValue) throws AriadnePlusPublisherException {
log.info("updateSparqlGraphDB "+queryValue);
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
return graphDBClient. updateSparql(queryValue);
}
2019-12-12 12:58:30 +01:00
}