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

95 lines
3.1 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 datasourceApi, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
switch(target){
case GRAPHDB:
feedProvenance(datasourceApi);
break;
default: throw new AriadnePlusPublisherException("Target "+target+" not supported yet");
}
}
public void dropDatasourceApisPartitionInfo(final String datasourceApi, final AriadnePlusTargets target) throws AriadnePlusPublisherException {
switch(target){
case GRAPHDB:
dropDatasourceApisPartitionInfo(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;
}
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 datasourceApi) throws AriadnePlusPublisherException {
log.debug("Feed Provenance " + datasourceApi);
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
graphDBClient.feedProvenance(datasourceApi);
}
2019-12-12 12:58:30 +01:00
private void dropDatasourceApisPartitionInfo(final String datasourceApi) throws AriadnePlusPublisherException {
log.debug("Drop DatasourceApis Partition Info " + datasourceApi);
GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient();
graphDBClient.dropDatasourceApisPartitionInfo(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();
long deletedTriples = graphDBClient.drop(datasourceInterface);
log.info("# triples deleted for "+datasourceInterface+": "+deletedTriples);
return deletedTriples;
}
}