Revision 49001
Added by Alessia Bardi over 6 years ago
ParthenosPublisherHelper.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import eu.dnetlib.parthenos.virtuoso.VirtuosoClient; |
4 | 4 |
import eu.dnetlib.parthenos.virtuoso.VirtuosoClientFactory; |
5 |
import net.sf.saxon.s9api.SaxonApiException; |
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
6 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
8 |
import org.springframework.stereotype.Component; |
|
7 | 9 |
|
8 | 10 |
/** |
9 | 11 |
* Created by Alessia Bardi on 11/08/2017. |
10 | 12 |
* |
11 | 13 |
* @author Alessia Bardi |
12 | 14 |
*/ |
15 |
@Component |
|
13 | 16 |
public class ParthenosPublisherHelper { |
14 | 17 |
|
18 |
private static final Log log = LogFactory.getLog(ParthenosPublisherHelper.class); |
|
19 |
|
|
20 |
public enum ParthenosTargets{ |
|
21 |
ALL, SOLR, VIRTUOSO, JRR, OAI |
|
22 |
} |
|
23 |
|
|
15 | 24 |
@Autowired |
16 | 25 |
private VirtuosoClientFactory virtuosoClientFactory; |
17 | 26 |
|
18 |
public void publish(final String record, final String serializationMode) throws SaxonApiException { |
|
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"); |
|
19 | 56 |
VirtuosoClient virtuosoClient = this.virtuosoClientFactory.getVirtuosoClient(); |
20 |
virtuosoClient.feed(record);
|
|
57 |
virtuosoClient.feed(record); |
|
21 | 58 |
} |
22 | 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 |
} |
|
23 | 65 |
|
66 |
// private void publishSolr(final String record){ |
|
67 |
// SolrClient solr = new CloudSolrClient.Builder().withSolrUrl("http://localhost:8983/solr").build(); |
|
68 |
// |
|
69 |
// } |
|
24 | 70 |
} |
Also available in: Unified diff
API for storing on virtuoso