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