Revision 49145
Added by Alessia Bardi about 7 years ago
modules/dnet-parthenos-publisher/trunk/dnet-parthenos-publisher.iml | ||
---|---|---|
83 | 83 |
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.1.Final" level="project" /> |
84 | 84 |
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.3" level="project" /> |
85 | 85 |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.9" level="project" /> |
86 |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" /> |
|
87 |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.9" level="project" /> |
|
88 | 86 |
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.10.RELEASE" level="project" /> |
89 | 87 |
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.10.RELEASE" level="project" /> |
90 | 88 |
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" /> |
... | ... | |
98 | 96 |
<orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.4.1" level="project" /> |
99 | 97 |
<orderEntry type="library" name="Maven: org.noggit:noggit:0.6" level="project" /> |
100 | 98 |
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" /> |
99 |
<orderEntry type="module" module-name="parthenos-entities" /> |
|
100 |
<orderEntry type="library" name="Maven: org.gcube.information-system:information-system-model:1.6.0-SNAPSHOT" level="project" /> |
|
101 |
<orderEntry type="library" name="Maven: org.gcube.information-system:gcube-resources:1.6.0-SNAPSHOT" level="project" /> |
|
102 |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" /> |
|
103 |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.9" level="project" /> |
|
104 |
<orderEntry type="module" module-name="resource-registry-publisher" /> |
|
105 |
<orderEntry type="library" name="Maven: org.gcube.common:authorization-client:2.0.1-4.6.1-134803" level="project" /> |
|
106 |
<orderEntry type="library" name="Maven: org.gcube.common:common-authorization:2.0.2-4.6.1-144378" level="project" /> |
|
107 |
<orderEntry type="library" name="Maven: org.gcube.core:common-configuration-scanner:1.0.0-4.6.1-144261" level="project" /> |
|
108 |
<orderEntry type="library" name="Maven: org.gcube.resources.discovery:ic-client:1.0.3-4.6.1-142503" level="project" /> |
|
109 |
<orderEntry type="library" name="Maven: org.gcube.core:common-scope:1.2.0-4.6.1-125717" level="project" /> |
|
110 |
<orderEntry type="library" name="Maven: org.gcube.core:common-scope-maps:1.0.7-4.6.1-150560" level="project" /> |
|
111 |
<orderEntry type="library" name="Maven: org.gcube.resources.discovery:discovery-client:1.0.1-4.6.1-125857" level="project" /> |
|
112 |
<orderEntry type="library" name="Maven: org.gcube.resources:common-gcore-resources:1.3.3-4.6.1-144114" level="project" /> |
|
113 |
<orderEntry type="library" name="Maven: org.gcube.core:common-gcore-stubs:1.2.2-4.6.1-132342" level="project" /> |
|
114 |
<orderEntry type="library" name="Maven: org.gcube.information-system:resource-registry-api:1.6.0-SNAPSHOT" level="project" /> |
|
115 |
<orderEntry type="library" name="Maven: org.gcube.information-system:resource-registry-client:1.5.0-SNAPSHOT" level="project" /> |
|
101 | 116 |
</component> |
102 | 117 |
</module> |
modules/dnet-parthenos-publisher/trunk/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ParthenosRegistryPublisherSetter.java | ||
---|---|---|
1 |
package org.gcube.informationsystem.resourceregistry.publisher; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by Alessia Bardi on 26/09/2017. |
|
5 |
* |
|
6 |
* @author Alessia Bardi |
|
7 |
*/ |
|
8 |
public class ParthenosRegistryPublisherSetter { |
|
9 |
|
|
10 |
public static void forceToURL(String url) { |
|
11 |
ResourceRegistryPublisherFactory.forceToURL(url); |
|
12 |
} |
|
13 |
|
|
14 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/org/gcube/informationsystem/resourceregistry/client/ParthenosRegistryClientSetter.java | ||
---|---|---|
1 |
package org.gcube.informationsystem.resourceregistry.client; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by Alessia Bardi on 26/09/2017. |
|
5 |
* |
|
6 |
* @author Alessia Bardi |
|
7 |
*/ |
|
8 |
public class ParthenosRegistryClientSetter { |
|
9 |
|
|
10 |
public static void forceToURL(String url) { |
|
11 |
ResourceRegistryClientFactory.forceToURL(url); |
|
12 |
} |
|
13 |
|
|
14 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/RegistryClientFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.parthenos.registry; |
|
2 |
|
|
3 |
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException; |
|
4 |
import eu.dnetlib.parthenos.publisher.SaxonHelper; |
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
import org.gcube.informationsystem.resourceregistry.client.ParthenosRegistryClientSetter; |
|
8 |
import org.gcube.informationsystem.resourceregistry.publisher.ParthenosRegistryPublisherSetter; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.beans.factory.annotation.Value; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
|
|
13 |
/** |
|
14 |
* Created by Alessia Bardi on 26/09/2017. |
|
15 |
* |
|
16 |
* @author Alessia Bardi |
|
17 |
*/ |
|
18 |
@Component |
|
19 |
public class RegistryClientFactory { |
|
20 |
|
|
21 |
private static final Log log = LogFactory.getLog(RegistryClientFactory.class); |
|
22 |
|
|
23 |
@Value("${gcube.registry.baseurl}") |
|
24 |
private String registryBaseURL; |
|
25 |
@Value("${gcube.registry.uri.base.default}") |
|
26 |
private String defaultBaseURI; |
|
27 |
|
|
28 |
@Autowired |
|
29 |
private SaxonHelper saxonHelper; |
|
30 |
@Autowired |
|
31 |
private GCubeResourceGenerator resourceGenerator; |
|
32 |
|
|
33 |
public RegistryClient getRegistryClient() throws ParthenosPublisherException { |
|
34 |
log.debug("Creating RegistryClient for "+registryBaseURL); |
|
35 |
ParthenosRegistryClientSetter.forceToURL(registryBaseURL); |
|
36 |
ParthenosRegistryPublisherSetter.forceToURL(registryBaseURL); |
|
37 |
return new RegistryClient(registryBaseURL, getSaxonHelper(), defaultBaseURI, getResourceGenerator()); |
|
38 |
} |
|
39 |
|
|
40 |
public String getRegistryBaseURL() { |
|
41 |
return registryBaseURL; |
|
42 |
} |
|
43 |
|
|
44 |
public void setRegistryBaseURL(final String registryBaseURL) { |
|
45 |
this.registryBaseURL = registryBaseURL; |
|
46 |
} |
|
47 |
|
|
48 |
public SaxonHelper getSaxonHelper() { |
|
49 |
return saxonHelper; |
|
50 |
} |
|
51 |
|
|
52 |
public void setSaxonHelper(final SaxonHelper saxonHelper) { |
|
53 |
this.saxonHelper = saxonHelper; |
|
54 |
} |
|
55 |
|
|
56 |
public String getDefaultBaseURI() { |
|
57 |
return defaultBaseURI; |
|
58 |
} |
|
59 |
|
|
60 |
public void setDefaultBaseURI(final String defaultBaseURI) { |
|
61 |
this.defaultBaseURI = defaultBaseURI; |
|
62 |
} |
|
63 |
|
|
64 |
public GCubeResourceGenerator getResourceGenerator() { |
|
65 |
return resourceGenerator; |
|
66 |
} |
|
67 |
|
|
68 |
public void setResourceGenerator(final GCubeResourceGenerator resourceGenerator) { |
|
69 |
this.resourceGenerator = resourceGenerator; |
|
70 |
} |
|
71 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/GCubeResourceGenerator.java | ||
---|---|---|
1 |
package eu.dnetlib.parthenos.registry; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import com.google.common.collect.Lists; |
|
6 |
import com.google.common.collect.Maps; |
|
7 |
import eu.dnetlib.parthenos.publisher.SaxonHelper; |
|
8 |
import net.sf.saxon.s9api.*; |
|
9 |
import org.apache.commons.lang3.StringUtils; |
|
10 |
import org.apache.commons.logging.Log; |
|
11 |
import org.apache.commons.logging.LogFactory; |
|
12 |
import org.gcube.informationsystem.model.ER; |
|
13 |
import org.springframework.beans.factory.annotation.Autowired; |
|
14 |
import org.springframework.stereotype.Component; |
|
15 |
|
|
16 |
/** |
|
17 |
* Created by Alessia Bardi on 26/09/2017. |
|
18 |
* |
|
19 |
* @author Alessia Bardi |
|
20 |
*/ |
|
21 |
@Component |
|
22 |
public class GCubeResourceGenerator { |
|
23 |
|
|
24 |
private static final Log log = LogFactory.getLog(GCubeResourceGenerator.class); |
|
25 |
|
|
26 |
private static final String OAI_NAMESPACE_URI = "http://www.openarchives.org/OAI/2.0/"; |
|
27 |
private static final String DRI_NAMESPACE_URI = "http://www.driver-repository.eu/namespace/dri"; |
|
28 |
private static final String RDF_NAMESPACE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private SaxonHelper saxonHelper; |
|
32 |
private XPathSelector xpathSelectorRDFDescription; |
|
33 |
private XPathSelector xpathSelectorObjIdentifier; |
|
34 |
|
|
35 |
/** |
|
36 |
* Generates the Gcube ER instances (Entity [Resource/Facet] and Relation) to be registered from a given RDF record serialised in RDF/XML PLAIN format. |
|
37 |
* @param rdfRecord RDF record in RDF/XML PLAIN format |
|
38 |
* @return an Iterable of GCube ER or an empty Iterable if the record is blank or is without objIdentifier |
|
39 |
*/ |
|
40 |
public Iterable<ER> getGCubeER(final String rdfRecord) throws SaxonApiException { |
|
41 |
//This map contains the pair (rdf:about, registryUUID) registered so far, useful I guess to create relationships between resources/facets. |
|
42 |
Map<String,String> resourceIdentifiers = Maps.newHashMap(); |
|
43 |
if (StringUtils.isBlank(rdfRecord)) { |
|
44 |
log.warn("Got empty record"); |
|
45 |
return Lists.newArrayList(); |
|
46 |
} |
|
47 |
//let's avoid to parse from scratch for every xpath |
|
48 |
XdmNode document = this.saxonHelper.help().parseXML(rdfRecord); |
|
49 |
xpathSelectorObjIdentifier.setContextItem(document); |
|
50 |
String objIdentifier = xpathSelectorObjIdentifier.evaluateSingle().getStringValue(); |
|
51 |
if (StringUtils.isBlank(objIdentifier)) { |
|
52 |
log.warn("Got record with no objIdentifier -- skipping"); |
|
53 |
return Lists.newArrayList(); |
|
54 |
} |
|
55 |
xpathSelectorRDFDescription.setContextItem(document); |
|
56 |
for(XdmItem xdmItem : xpathSelectorRDFDescription){ |
|
57 |
XdmNode node = (XdmNode) xdmItem; |
|
58 |
|
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
return null; |
|
64 |
} |
|
65 |
|
|
66 |
private String extractFromRecord(final String record, final XPathSelector xPathSelector) { |
|
67 |
try { |
|
68 |
return this.saxonHelper.help().setSerializerProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes").evaluateSingleAsString(record, xPathSelector); |
|
69 |
} catch (SaxonApiException e) { |
|
70 |
throw new RuntimeException("Cannot extract content ", e); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
private void prepareXpathSelectors() throws SaxonApiException { |
|
75 |
Map<String, String> namespaces = Maps.newHashMap(); |
|
76 |
namespaces.put("oai", OAI_NAMESPACE_URI); |
|
77 |
namespaces.put("dri", DRI_NAMESPACE_URI); |
|
78 |
namespaces.put("rdf", RDF_NAMESPACE_URI); |
|
79 |
xpathSelectorObjIdentifier = this.saxonHelper.help().prepareXPathSelector("//oai:header/dri:objIdentifier/text()", namespaces); |
|
80 |
xpathSelectorRDFDescription = this.saxonHelper.help().prepareXPathSelector("//oai:metadata/rdf:RDF/rdf:Description", namespaces); |
|
81 |
} |
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
public GCubeResourceGenerator() throws SaxonApiException { |
|
86 |
prepareXpathSelectors(); |
|
87 |
} |
|
88 |
|
|
89 |
public SaxonHelper getSaxonHelper() { |
|
90 |
return saxonHelper; |
|
91 |
} |
|
92 |
|
|
93 |
public void setSaxonHelper(final SaxonHelper saxonHelper) { |
|
94 |
this.saxonHelper = saxonHelper; |
|
95 |
} |
|
96 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/RegistryClient.java | ||
---|---|---|
1 |
package eu.dnetlib.parthenos.registry; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import com.google.common.collect.Maps; |
|
6 |
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException; |
|
7 |
import eu.dnetlib.parthenos.publisher.SaxonHelper; |
|
8 |
import net.sf.saxon.s9api.SaxonApiException; |
|
9 |
import net.sf.saxon.s9api.Serializer; |
|
10 |
import net.sf.saxon.s9api.XPathSelector; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
14 |
import org.gcube.informationsystem.model.ER; |
|
15 |
import org.gcube.informationsystem.model.entity.Facet; |
|
16 |
import org.gcube.informationsystem.model.entity.Resource; |
|
17 |
import org.gcube.informationsystem.model.relation.Relation; |
|
18 |
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; |
|
19 |
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; |
|
20 |
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; |
|
21 |
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory; |
|
22 |
|
|
23 |
/** |
|
24 |
* Created by Alessia Bardi on 26/09/2017. |
|
25 |
* |
|
26 |
* @author Alessia Bardi |
|
27 |
*/ |
|
28 |
public class RegistryClient { |
|
29 |
|
|
30 |
private static final Log log = LogFactory.getLog(RegistryClient.class); |
|
31 |
|
|
32 |
private static final String OAI_NAMESPACE_URI = "http://www.openarchives.org/OAI/2.0/"; |
|
33 |
private static final String DRI_NAMESPACE_URI = "http://www.driver-repository.eu/namespace/dri"; |
|
34 |
private static final String RDF_NAMESPACE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; |
|
35 |
|
|
36 |
private GCubeResourceGenerator resourceGenerator; |
|
37 |
private SaxonHelper saxonHelper; |
|
38 |
private XPathSelector xpathSelectorObjIdentifier; |
|
39 |
private XPathSelector xpathSelectorCollectionDate; |
|
40 |
private XPathSelector xpathSelectorTransformationDate; |
|
41 |
private XPathSelector xpathSelectorDatasourceName; |
|
42 |
private XPathSelector xpathSelectorDatasourceApi; |
|
43 |
private XPathSelector xpathSelectorRDF; |
|
44 |
|
|
45 |
private ResourceRegistryPublisher resourceRegistryPublisher; |
|
46 |
private ResourceRegistryClient resourceRegistryClient; |
|
47 |
private String registryBaseURL; |
|
48 |
private String defaultBaseURI; |
|
49 |
|
|
50 |
protected RegistryClient(final String registryBaseURL, final SaxonHelper saxonHelper, final String defaultBaseURI, final GCubeResourceGenerator resourceGenerator) |
|
51 |
throws ParthenosPublisherException { |
|
52 |
this.registryBaseURL = registryBaseURL; |
|
53 |
this.saxonHelper = saxonHelper; |
|
54 |
this.defaultBaseURI = defaultBaseURI; |
|
55 |
this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); |
|
56 |
this.resourceRegistryClient = ResourceRegistryClientFactory.create(); |
|
57 |
this.resourceGenerator = resourceGenerator; |
|
58 |
try { |
|
59 |
prepareXpathSelectors(); |
|
60 |
}catch(SaxonApiException e){ |
|
61 |
throw new ParthenosPublisherException(e); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
public int register(final String record) throws ParthenosPublisherException{ |
|
66 |
try { |
|
67 |
if (StringUtils.isBlank(record)) { |
|
68 |
log.warn("Got empty record"); |
|
69 |
return 0; |
|
70 |
} |
|
71 |
String objIdentifier = extractFromRecord(record, xpathSelectorObjIdentifier); |
|
72 |
if (StringUtils.isBlank(objIdentifier)) { |
|
73 |
log.warn("Got record with no objIdentifier -- skipping"); |
|
74 |
return 0; |
|
75 |
} |
|
76 |
|
|
77 |
for(ER r : resourceGenerator.getGCubeER(record) ){ |
|
78 |
if(r instanceof Resource){ |
|
79 |
//TODO: handle resource |
|
80 |
//and we need to go class by class unless there is a clever way to pass the Class to the publisher method |
|
81 |
//getResourceRegistryPublisher().createResource(X.class, r); |
|
82 |
} |
|
83 |
else{ |
|
84 |
if(r instanceof Facet){ |
|
85 |
//TODO: handle facet |
|
86 |
} |
|
87 |
else{ |
|
88 |
if(r instanceof Relation){ |
|
89 |
//TODO handle rel |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
} |
|
95 |
return 0; |
|
96 |
}catch(Throwable e){ |
|
97 |
log.error(e.getMessage()); |
|
98 |
throw new ParthenosPublisherException(e); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
private void prepareXpathSelectors() throws SaxonApiException { |
|
104 |
Map<String, String> namespaces = Maps.newHashMap(); |
|
105 |
namespaces.put("oai", OAI_NAMESPACE_URI); |
|
106 |
namespaces.put("dri", DRI_NAMESPACE_URI); |
|
107 |
namespaces.put("rdf", RDF_NAMESPACE_URI); |
|
108 |
xpathSelectorObjIdentifier = this.saxonHelper.help().prepareXPathSelector("//oai:header/dri:objIdentifier/text()", namespaces); |
|
109 |
xpathSelectorCollectionDate = this.saxonHelper.help().prepareXPathSelector("//oai:header/dri:dateOfCollection/text()", namespaces); |
|
110 |
xpathSelectorTransformationDate = this.saxonHelper.help().prepareXPathSelector("//oai:header/dri:dateOfTransformation/text()", namespaces); |
|
111 |
xpathSelectorDatasourceName = this.saxonHelper.help().prepareXPathSelector("//oai:header/dri:datasourcename/text()", namespaces); |
|
112 |
xpathSelectorDatasourceApi = this.saxonHelper.help().prepareXPathSelector("//oai:header/dri:datasourceapi/text()", namespaces); |
|
113 |
xpathSelectorRDF = this.saxonHelper.help().prepareXPathSelector("//oai:metadata/rdf:RDF", namespaces); |
|
114 |
} |
|
115 |
|
|
116 |
private String extractFromRecord(final String record, final XPathSelector xPathSelector) { |
|
117 |
try { |
|
118 |
return this.saxonHelper.help().setSerializerProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes").evaluateSingleAsString(record, xPathSelector); |
|
119 |
} catch (SaxonApiException e) { |
|
120 |
throw new RuntimeException("Cannot extract content ", e); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
public void setSaxonHelper(final SaxonHelper saxonHelper) { |
|
126 |
this.saxonHelper = saxonHelper; |
|
127 |
} |
|
128 |
|
|
129 |
public String getRegistryBaseURL() { |
|
130 |
return registryBaseURL; |
|
131 |
} |
|
132 |
|
|
133 |
public void setRegistryBaseURL(final String registryBaseURL) { |
|
134 |
this.registryBaseURL = registryBaseURL; |
|
135 |
} |
|
136 |
|
|
137 |
public void setDefaultBaseURI(final String defaultBaseURI) { |
|
138 |
this.defaultBaseURI = defaultBaseURI; |
|
139 |
} |
|
140 |
|
|
141 |
public SaxonHelper getSaxonHelper() { |
|
142 |
return saxonHelper; |
|
143 |
} |
|
144 |
|
|
145 |
public String getDefaultBaseURI() { |
|
146 |
return defaultBaseURI; |
|
147 |
} |
|
148 |
|
|
149 |
public GCubeResourceGenerator getResourceGenerator() { |
|
150 |
return resourceGenerator; |
|
151 |
} |
|
152 |
|
|
153 |
public void setResourceGenerator(final GCubeResourceGenerator resourceGenerator) { |
|
154 |
this.resourceGenerator = resourceGenerator; |
|
155 |
} |
|
156 |
|
|
157 |
public ResourceRegistryPublisher getResourceRegistryPublisher() { |
|
158 |
return resourceRegistryPublisher; |
|
159 |
} |
|
160 |
|
|
161 |
public void setResourceRegistryPublisher(final ResourceRegistryPublisher resourceRegistryPublisher) { |
|
162 |
this.resourceRegistryPublisher = resourceRegistryPublisher; |
|
163 |
} |
|
164 |
|
|
165 |
public ResourceRegistryClient getResourceRegistryClient() { |
|
166 |
return resourceRegistryClient; |
|
167 |
} |
|
168 |
|
|
169 |
public void setResourceRegistryClient(final ResourceRegistryClient resourceRegistryClient) { |
|
170 |
this.resourceRegistryClient = resourceRegistryClient; |
|
171 |
} |
|
172 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoClient.java | ||
---|---|---|
66 | 66 |
} |
67 | 67 |
} |
68 | 68 |
|
69 |
//TODO: exploit new method eu.dnetlib.parthenos.publisher.SaxonHelper.Helper.parseXML() to avoid re-parsing the full record. |
|
70 |
|
|
69 | 71 |
public long feed(final String record) throws ParthenosPublisherException{ |
70 | 72 |
try { |
71 | 73 |
if (StringUtils.isBlank(record)) { |
... | ... | |
184 | 186 |
xpathSelectorRDF = this.saxonHelper.help().prepareXPathSelector("//oai:metadata/rdf:RDF", namespaces); |
185 | 187 |
} |
186 | 188 |
|
187 |
private String extractFromRecord(final String record, final XPathSelector xPathSelector) { |
|
189 |
private String extractFromRecord(final String record, final XPathSelector xPathSelector) {
|
|
188 | 190 |
try { |
189 | 191 |
return this.saxonHelper.help().setSerializerProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes").evaluateSingleAsString(record, xPathSelector); |
190 | 192 |
} catch (SaxonApiException e) { |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/publisher/ParthenosPublisherHelper.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.parthenos.publisher; |
2 | 2 |
|
3 |
import eu.dnetlib.parthenos.registry.RegistryClient; |
|
4 |
import eu.dnetlib.parthenos.registry.RegistryClientFactory; |
|
3 | 5 |
import eu.dnetlib.parthenos.virtuoso.VirtuosoClient; |
4 | 6 |
import eu.dnetlib.parthenos.virtuoso.VirtuosoClientFactory; |
5 | 7 |
import org.apache.commons.logging.Log; |
... | ... | |
23 | 25 |
|
24 | 26 |
@Autowired |
25 | 27 |
private VirtuosoClientFactory virtuosoClientFactory; |
28 |
@Autowired |
|
29 |
private RegistryClientFactory registryClientFactory; |
|
26 | 30 |
|
27 | 31 |
public void publish(final String record, final ParthenosTargets target) throws ParthenosPublisherException { |
28 | 32 |
switch(target){ |
29 | 33 |
case ALL: |
30 | 34 |
publishVirtuoso(record); |
35 |
publishJRR(record); |
|
31 | 36 |
break; |
32 | 37 |
case VIRTUOSO: |
33 | 38 |
publishVirtuoso(record); |
34 | 39 |
break; |
40 |
case JRR: |
|
41 |
publishJRR(record); |
|
35 | 42 |
default: throw new ParthenosPublisherException("Target "+target+" not supported yet"); |
36 | 43 |
} |
37 | 44 |
|
... | ... | |
57 | 64 |
virtuosoClient.feed(record); |
58 | 65 |
} |
59 | 66 |
|
67 |
private void publishJRR(final String record) throws ParthenosPublisherException { |
|
68 |
log.debug("Publishing on Registry"); |
|
69 |
RegistryClient registryClient = this.registryClientFactory.getRegistryClient(); |
|
70 |
registryClient.register(record); |
|
71 |
} |
|
72 |
|
|
60 | 73 |
private long unpublishVirtuoso(final String datasourceInterface) throws ParthenosPublisherException { |
61 | 74 |
log.debug("Unublishing from virtuoso "+datasourceInterface); |
62 | 75 |
VirtuosoClient virtuosoClient = this.virtuosoClientFactory.getVirtuosoClient(); |
63 | 76 |
return virtuosoClient.drop(datasourceInterface); |
64 | 77 |
} |
65 | 78 |
|
66 |
// private void publishSolr(final String record){ |
|
67 |
// SolrClient solr = new CloudSolrClient.Builder().withSolrUrl("http://localhost:8983/solr").build(); |
|
68 |
// |
|
69 |
// } |
|
79 |
|
|
70 | 80 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/publisher/SaxonHelper.java | ||
---|---|---|
38 | 38 |
return this; |
39 | 39 |
} |
40 | 40 |
|
41 |
public XdmNode parseXML(final String xmlSource) throws SaxonApiException { |
|
42 |
SAXSource source = new SAXSource(new InputSource(new StringReader(xmlSource))); |
|
43 |
DocumentBuilder docBuilder = xmlProcessor.newDocumentBuilder(); |
|
44 |
return docBuilder.build(source); |
|
45 |
} |
|
46 |
|
|
41 | 47 |
/** |
42 | 48 |
* Evaluate the given xpath on the given XML source. |
43 | 49 |
* |
... | ... | |
59 | 65 |
* @return an XdmItem resulting from the evaluation of the xpath. Returns null if nothing matches. |
60 | 66 |
*/ |
61 | 67 |
public XdmItem evaluateSingle(final String xmlSource, final XPathSelector xpathSelector) throws SaxonApiException { |
62 |
SAXSource source = new SAXSource(new InputSource(new StringReader(xmlSource))); |
|
63 |
DocumentBuilder docBuilder = xmlProcessor.newDocumentBuilder(); |
|
64 |
XdmNode xdmNode = docBuilder.build(source); |
|
68 |
XdmNode xdmNode = parseXML(xmlSource); |
|
65 | 69 |
xpathSelector.setContextItem(xdmNode); |
66 | 70 |
return xpathSelector.evaluateSingle(); |
67 | 71 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/resources/application.properties | ||
---|---|---|
3 | 3 |
virtuoso.connectionstring = jdbc:virtuoso://localhost:1111 |
4 | 4 |
virtuoso.pwd = dba |
5 | 5 |
virtuoso.usr = dba |
6 |
virtuoso.uri.base.default = http://parthenos.d4science.org/handle/ |
|
6 |
virtuoso.uri.base.default = http://parthenos.d4science.org/handle/ |
|
7 |
|
|
8 |
gcube.registry.baseurl = http://gcube.parthenos.d4science.org/resource-registry/er/ |
|
9 |
gcube.registry.uri.base.default = http://parthenos.d4science.org/handle/ |
modules/dnet-parthenos-publisher/trunk/pom.xml | ||
---|---|---|
4 | 4 |
<groupId>org.springframework.boot</groupId> |
5 | 5 |
<artifactId>spring-boot-starter-parent</artifactId> |
6 | 6 |
<version>1.5.6.RELEASE</version> |
7 |
<relativePath />
|
|
7 |
<relativePath/> |
|
8 | 8 |
</parent> |
9 | 9 |
|
10 | 10 |
<modelVersion>4.0.0</modelVersion> |
... | ... | |
14 | 14 |
<version>2.0.1-SNAPSHOT</version> |
15 | 15 |
<scm> |
16 | 16 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet50/modules/dnet-parthenos-publisher/trunk</developerConnection> |
17 |
<url>https://github.com/spring-projects/spring-boot/spring-boot-starter-parent/dnet-parthenos-publisher</url>
|
|
18 |
</scm>
|
|
17 |
<url>https://github.com/spring-projects/spring-boot/spring-boot-starter-parent/dnet-parthenos-publisher</url>
|
|
18 |
</scm>
|
|
19 | 19 |
<ciManagement> |
20 | 20 |
<system>jenkins</system> |
21 | 21 |
<url>https://jenkins-dnet.d4science.org/view/DNet50/job/DSL50_dnet-parthenos-publisher/</url> |
... | ... | |
56 | 56 |
<enabled>true</enabled> |
57 | 57 |
</snapshots> |
58 | 58 |
</repository> |
59 |
<repository> |
|
60 |
<id>gcube-snapshots</id> |
|
61 |
<name>gCube Snapshots</name> |
|
62 |
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/gcube-snapshots</url> |
|
63 |
<releases> |
|
64 |
<enabled>false</enabled> |
|
65 |
</releases> |
|
66 |
<snapshots> |
|
67 |
<enabled>true</enabled> |
|
68 |
</snapshots> |
|
69 |
</repository> |
|
70 |
<repository> |
|
71 |
<id>gcube-releases</id> |
|
72 |
<name>gCube Releases</name> |
|
73 |
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/gcube-releases</url> |
|
74 |
<snapshots> |
|
75 |
<enabled>false</enabled> |
|
76 |
</snapshots> |
|
77 |
<releases> |
|
78 |
<enabled>true</enabled> |
|
79 |
</releases> |
|
80 |
</repository> |
|
81 |
<repository> |
|
82 |
<id>gcube-externals</id> |
|
83 |
<name>gCube Externals</name> |
|
84 |
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/gcube-externals</url> |
|
85 |
<snapshots> |
|
86 |
<enabled>false</enabled> |
|
87 |
</snapshots> |
|
88 |
<releases> |
|
89 |
<enabled>true</enabled> |
|
90 |
</releases> |
|
91 |
</repository> |
|
59 | 92 |
</repositories> |
60 | 93 |
|
61 | 94 |
<dependencies> |
62 |
<!--<!– Needed for SaxonHelper class –>--> |
|
63 |
<!--<dependency>--> |
|
64 |
<!--<groupId>eu.dnetlib</groupId>--> |
|
65 |
<!--<artifactId>dnet-core-components</artifactId>--> |
|
66 |
<!--<version>2.0.0-SAXONHE-SNAPSHOT</version>--> |
|
67 |
<!--</dependency>--> |
|
68 | 95 |
<dependency> |
69 | 96 |
<groupId>net.sf.saxon</groupId> |
70 | 97 |
<artifactId>Saxon-HE</artifactId> |
... | ... | |
128 | 155 |
<artifactId>solr-solrj</artifactId> |
129 | 156 |
<version>[5.0.0,6.0.0)</version> |
130 | 157 |
</dependency> |
158 |
|
|
159 |
<dependency> |
|
160 |
<groupId>org.gcube.information-system</groupId> |
|
161 |
<artifactId>parthenos-entities</artifactId> |
|
162 |
<version>LATEST</version> |
|
163 |
</dependency> |
|
164 |
<dependency> |
|
165 |
<groupId>org.gcube.information-system</groupId> |
|
166 |
<artifactId>resource-registry-publisher</artifactId> |
|
167 |
<version>LATEST</version> |
|
168 |
</dependency> |
|
169 |
<dependency> |
|
170 |
<groupId>org.gcube.information-system</groupId> |
|
171 |
<artifactId>resource-registry-client</artifactId> |
|
172 |
<version>LATEST</version> |
|
173 |
</dependency> |
|
131 | 174 |
</dependencies> |
132 | 175 |
|
133 | 176 |
<build> |
Also available in: Unified diff
getting ready to use the GCube Parthenos Registry