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"); } } 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); } private void dropDatasourceApisPartitionInfo(final String datasourceApi) throws AriadnePlusPublisherException { log.debug("Drop DatasourceApis Partition Info " + datasourceApi); GraphDBClient graphDBClient = this.graphdbClientFactory.getGraphDBClient(); graphDBClient.dropDatasourceApisPartitionInfo(datasourceApi); } 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; } }