1
|
package eu.dnetlib.parthenos.publisher;
|
2
|
|
3
|
import eu.dnetlib.parthenos.virtuoso.VirtuosoClient;
|
4
|
import eu.dnetlib.parthenos.virtuoso.VirtuosoClientFactory;
|
5
|
import org.apache.commons.logging.Log;
|
6
|
import org.apache.commons.logging.LogFactory;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.stereotype.Component;
|
9
|
|
10
|
/**
|
11
|
* Created by Alessia Bardi on 11/08/2017.
|
12
|
*
|
13
|
* @author Alessia Bardi
|
14
|
*/
|
15
|
@Component
|
16
|
public class ParthenosPublisherHelper {
|
17
|
|
18
|
private static final Log log = LogFactory.getLog(ParthenosPublisherHelper.class);
|
19
|
|
20
|
public enum ParthenosTargets{
|
21
|
ALL, SOLR, VIRTUOSO, JRR, OAI
|
22
|
}
|
23
|
|
24
|
@Autowired
|
25
|
private VirtuosoClientFactory virtuosoClientFactory;
|
26
|
|
27
|
public void publish(final String record, final ParthenosTargets target) throws ParthenosPublisherException {
|
28
|
switch(target){
|
29
|
case ALL:
|
30
|
publishVirtuoso(record);
|
31
|
break;
|
32
|
case VIRTUOSO:
|
33
|
publishVirtuoso(record);
|
34
|
break;
|
35
|
default: throw new ParthenosPublisherException("Target "+target+" not supported yet");
|
36
|
}
|
37
|
|
38
|
}
|
39
|
|
40
|
public long unpublish(final String datasourceInterface, final ParthenosTargets target) throws ParthenosPublisherException {
|
41
|
long res = 0;
|
42
|
switch(target){
|
43
|
case ALL:
|
44
|
res = unpublishVirtuoso(datasourceInterface);
|
45
|
break;
|
46
|
case VIRTUOSO:
|
47
|
res = unpublishVirtuoso(datasourceInterface);
|
48
|
break;
|
49
|
default: throw new ParthenosPublisherException("Target "+target+" not supported yet");
|
50
|
}
|
51
|
return res;
|
52
|
}
|
53
|
|
54
|
private void publishVirtuoso(final String record) throws ParthenosPublisherException {
|
55
|
log.debug("Publishing on virtuoso");
|
56
|
VirtuosoClient virtuosoClient = this.virtuosoClientFactory.getVirtuosoClient();
|
57
|
virtuosoClient.feed(record);
|
58
|
}
|
59
|
|
60
|
private long unpublishVirtuoso(final String datasourceInterface) throws ParthenosPublisherException {
|
61
|
log.debug("Unublishing from virtuoso "+datasourceInterface);
|
62
|
VirtuosoClient virtuosoClient = this.virtuosoClientFactory.getVirtuosoClient();
|
63
|
return virtuosoClient.drop(datasourceInterface);
|
64
|
}
|
65
|
|
66
|
// private void publishSolr(final String record){
|
67
|
// SolrClient solr = new CloudSolrClient.Builder().withSolrUrl("http://localhost:8983/solr").build();
|
68
|
//
|
69
|
// }
|
70
|
}
|