1
|
package eu.dnetlib.parthenos.publisher;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.net.URISyntaxException;
|
5
|
|
6
|
import eu.dnetlib.parthenos.jrr.JRRPublisher;
|
7
|
import eu.dnetlib.parthenos.virtuoso.VirtuosoClient;
|
8
|
import eu.dnetlib.parthenos.virtuoso.VirtuosoClientFactory;
|
9
|
import org.apache.commons.logging.Log;
|
10
|
import org.apache.commons.logging.LogFactory;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.stereotype.Component;
|
13
|
|
14
|
/**
|
15
|
* Created by Alessia Bardi on 11/08/2017.
|
16
|
*
|
17
|
* @author Alessia Bardi
|
18
|
*/
|
19
|
@Component
|
20
|
public class ParthenosPublisherHelper {
|
21
|
|
22
|
private static final Log log = LogFactory.getLog(ParthenosPublisherHelper.class);
|
23
|
|
24
|
public enum ParthenosTargets{
|
25
|
VIRTUOSO, JRR
|
26
|
}
|
27
|
|
28
|
@Autowired
|
29
|
private VirtuosoClientFactory virtuosoClientFactory;
|
30
|
@Autowired
|
31
|
private JRRPublisher jrrPublisher;
|
32
|
|
33
|
public void publish(final String record, final ParthenosTargets target) throws ParthenosPublisherException {
|
34
|
switch(target){
|
35
|
case VIRTUOSO:
|
36
|
publishVirtuoso(record);
|
37
|
break;
|
38
|
case JRR:
|
39
|
try {
|
40
|
publishJRR(record);
|
41
|
break;
|
42
|
} catch(IOException | URISyntaxException | InterruptedException e){
|
43
|
throw new ParthenosPublisherException(e);
|
44
|
}
|
45
|
default: throw new ParthenosPublisherException("Target "+target+" not supported yet");
|
46
|
}
|
47
|
|
48
|
}
|
49
|
|
50
|
public long unpublish(final String datasourceInterface, final ParthenosTargets target) throws ParthenosPublisherException {
|
51
|
long res = 0;
|
52
|
switch(target){
|
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 void publishJRR(final String record)
|
68
|
throws ParthenosPublisherException, IOException, URISyntaxException, InterruptedException {
|
69
|
log.debug("Publishing on JRR (registry and catalogue)");
|
70
|
jrrPublisher.register(record);
|
71
|
}
|
72
|
|
73
|
private int unpublishJRR(final String datasourceInterface){
|
74
|
//TODO: for this to work we have to add somewhere the information about the dsInterface from which the resource was initially collected
|
75
|
//Note that this method might not be a good idea if we want to keep the uuid and only update the facets/rels
|
76
|
//maybe it is worth to implement the incremental in the ResourceRegistrator. We slow down things, but it may be worthy...
|
77
|
log.debug("Unpublishing from registry "+datasourceInterface);
|
78
|
//TODO: implement me
|
79
|
throw new UnsupportedOperationException("Not implemented yet");
|
80
|
}
|
81
|
|
82
|
private long unpublishVirtuoso(final String datasourceInterface) {
|
83
|
log.info("Unpublishing from virtuoso "+datasourceInterface);
|
84
|
VirtuosoClient virtuosoClient = this.virtuosoClientFactory.getVirtuosoClient();
|
85
|
long deletedTriples = virtuosoClient.drop(datasourceInterface);
|
86
|
log.info("# triples deleted for "+datasourceInterface+": "+deletedTriples);
|
87
|
return deletedTriples;
|
88
|
}
|
89
|
|
90
|
public void dropRegistry(){
|
91
|
log.debug("Dropping JRR");
|
92
|
//TODO: implement me
|
93
|
throw new UnsupportedOperationException("Not implemented yet");
|
94
|
}
|
95
|
|
96
|
|
97
|
}
|